Member.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\api\controller;
  3. use think\Db;
  4. use app\common\model\User;
  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("phone", type="int", desc="手机号")
  23. * @Apidoc\Returned("name", type="string", desc="姓名")
  24. * @Apidoc\Returned("nickname", type="string", desc="昵称")
  25. * @Apidoc\Returned("headimg", type="string", desc="头像地址")
  26. * @Apidoc\Returned("title", type="string", desc="职称")
  27. * @Apidoc\Returned("department", type="string", desc="部门(多个部门以逗号分隔)")
  28. * @Apidoc\Returned("signature", type="string", desc="个人签名")
  29. */
  30. public function user_info()
  31. {
  32. $user = $this->user;
  33. $this->success('获取成功',$user);
  34. }
  35. /**
  36. * 编辑个人信息
  37. *
  38. * @Apidoc\Method("POST")
  39. * @Apidoc\Param("type", type="int", require=true, desc="修改的类型(1:昵称,2:签名,3:手机号)")
  40. * @Apidoc\Param("nickname", type="string", desc="昵称")
  41. * @Apidoc\Param("signature", type="string", desc="签名")
  42. * @Apidoc\Param("phone", type="string", desc="手机号")
  43. */
  44. public function edit()
  45. {
  46. $uid = $this->user_id;
  47. $type = input('type');
  48. $nickname = input('nickname');
  49. $signature = input('signature');
  50. $phone = input('phone');
  51. if(!in_array($type,[1,2,3])){
  52. $this->error('参数错误');
  53. }
  54. if($type == 1){
  55. if(empty($nickname)){
  56. $this->error('参数错误');
  57. }
  58. $update_data['nickname'] = $nickname;
  59. }elseif ($type == 2){
  60. if(empty($signature)){
  61. $this->error('参数错误');
  62. }
  63. $update_data['signature'] = $signature;
  64. }elseif ($type == 2){
  65. if(empty($phone)){
  66. $this->error('参数错误');
  67. }
  68. if(!preg_match("/^1[23456789]\d{9}$/", $phone)){
  69. $this->error('手机号格式不正确');
  70. }
  71. $update_data['phone'] = $phone;
  72. }
  73. Db::name('store_member')->where('id',$uid)->update($update_data);
  74. $this->success('编辑成功');
  75. }
  76. }