Member.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\constant\CommonConstant;
  4. use app\common\model\Department;
  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="签名状态:0=待审核,1=审核通过,2=审核驳回")
  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. $user['department_list'] = Department::field('dept_id,name')->where('dept_id', 'in', $user['department'])->select();
  38. $user['subject'] = '学校名称';
  39. $this->success('获取成功', $user);
  40. }
  41. /**
  42. * 编辑个人信息
  43. *
  44. * @Apidoc\Method("POST")
  45. * @Apidoc\Param("type", type="integer", require=true, desc="类型:1=头像地址,2=昵称,3=手机号码,4=签名")
  46. * @Apidoc\Param("avatar", type="string", require=false, desc="头像地址")
  47. * @Apidoc\Param("nickname", type="string", require=false, desc="昵称")
  48. * @Apidoc\Param("mobile", type="string", require=false, desc="手机号码")
  49. * @Apidoc\Param("signature", type="string", require=false, desc="签名")
  50. */
  51. public function edit()
  52. {
  53. $type = input('type') ?: 0;
  54. $avatar = input('avatar') ?: '';
  55. $nickname = input('nickname') ?: '';
  56. $mobile = input('mobile') ?: '';
  57. $signature = input('signature') ?: '';
  58. $data = [];
  59. switch ($type){
  60. case 1:
  61. if (!$avatar) {
  62. $this->error('请上传头像');
  63. }
  64. break;
  65. case 2:
  66. if (!$nickname) {
  67. $this->error('请输入昵称');
  68. }
  69. break;
  70. case 3:
  71. if (!preg_match("/^1[23456789]\d{9}$/", $mobile)) {
  72. $this->error('手机号格式不正确');
  73. }
  74. break;
  75. case 4:
  76. if (!$signature) {
  77. $this->error('请上传签名');
  78. }
  79. break;
  80. }
  81. if ($avatar) {
  82. $data['avatar'] = $avatar;
  83. }
  84. if ($nickname) {
  85. $data['nickname'] = $nickname;
  86. }
  87. if ($mobile) {
  88. if (!preg_match("/^1[23456789]\d{9}$/", $mobile)) {
  89. $this->error('手机号格式不正确');
  90. }
  91. $data['mobile'] = $mobile;
  92. }
  93. if ($signature) {
  94. $data['signature'] = $signature;
  95. $data['signature_status'] = CommonConstant::IS_WHO_0;
  96. }
  97. if ($data) {
  98. $user = $this->user;
  99. $user->save($data);
  100. }
  101. $this->success('编辑成功');
  102. }
  103. }