Member.php 3.5 KB

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