Member.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\constant\CommonConstant;
  4. use app\common\service\UserService;
  5. use hg\apidoc\annotation as Apidoc;
  6. /**
  7. * @Apidoc\Title("我的")
  8. * @Apidoc\Group("api")
  9. * @Apidoc\Sort("2")
  10. */
  11. class Member extends Base
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. parent::checkLogin();
  17. }
  18. /**
  19. * 获取个人信息
  20. *
  21. * @Apidoc\Method("POST")
  22. * @Apidoc\Returned("avatar", type="string", desc="头像地址")
  23. * @Apidoc\Returned("nickname", type="string", desc="昵称")
  24. * @Apidoc\Returned("name", type="string", desc="姓名")
  25. * @Apidoc\Returned("mobile", type="string", desc="手机号码")
  26. * @Apidoc\Returned("department", type="string", desc="部门(多个部门以逗号分隔)")
  27. * @Apidoc\Returned("title", type="string", desc="职位")
  28. * @Apidoc\Returned("signature", type="string", desc="个人签名")
  29. * @Apidoc\Returned("signature_status", type="string", desc="签名状态:1=未操作,2=待审核,3=审核通过,4=审核驳回")
  30. * @Apidoc\Returned("department_list", type="array", desc="部门列表")
  31. * @Apidoc\Returned("subject", type="string", desc="主体名称")
  32. */
  33. public function user_info()
  34. {
  35. $user = $this->user;
  36. unset($user['status'],$user['is_deleted'],$user['create_at']);
  37. $department_data = UserService::get_user_department_list($user['department']);;
  38. $user['department_list'] = $department_data;
  39. $user['subject_image'] = 'https://static-legacy.dingtalk.com/media/lADPDgfLSTijRwbNA0jNAlg_600_840.jpg';
  40. $user['subject'] = '学校名称';
  41. $this->success('获取成功', $user);
  42. }
  43. /**
  44. * 编辑个人信息
  45. *
  46. * @Apidoc\Method("POST")
  47. * @Apidoc\Param("type", type="integer", require=true, desc="类型:1=头像地址,2=昵称,3=手机号码,4=签名")
  48. * @Apidoc\Param("avatar", type="string", require=false, desc="头像地址")
  49. * @Apidoc\Param("nickname", type="string", require=false, desc="昵称")
  50. * @Apidoc\Param("mobile", type="string", require=false, desc="手机号码")
  51. * @Apidoc\Param("signature", type="string", require=false, desc="签名")
  52. */
  53. public function edit()
  54. {
  55. $type = input('type') ?: 0;
  56. $avatar = input('avatar') ?: '';
  57. $nickname = input('nickname') ?: '';
  58. $mobile = input('mobile') ?: '';
  59. $signature = input('signature') ?: '';
  60. $data = [];
  61. switch ($type){
  62. case 1:
  63. if (!$avatar) {
  64. $this->error('请上传头像');
  65. }
  66. break;
  67. case 2:
  68. if (!$nickname) {
  69. $this->error('请输入昵称');
  70. }
  71. break;
  72. case 3:
  73. if (!preg_match("/^1[23456789]\d{9}$/", $mobile)) {
  74. $this->error('手机号格式不正确');
  75. }
  76. break;
  77. case 4:
  78. if (!$signature) {
  79. $this->error('请上传签名');
  80. }
  81. break;
  82. }
  83. if ($avatar) {
  84. $data['avatar'] = $avatar;
  85. }
  86. if ($nickname) {
  87. $data['nickname'] = $nickname;
  88. }
  89. if ($mobile) {
  90. if (!preg_match("/^1[23456789]\d{9}$/", $mobile)) {
  91. $this->error('手机号格式不正确');
  92. }
  93. $data['mobile'] = $mobile;
  94. }
  95. if ($signature) {
  96. $data['signature'] = $signature;
  97. $data['signature_status'] = CommonConstant::SIGNATURE_STATUS_2;
  98. }
  99. if ($data) {
  100. $user = $this->user;
  101. $user->save($data);
  102. }
  103. $this->success('编辑成功');
  104. }
  105. }