UserCenter.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\UserLevelRank;
  4. use app\common\model\UserMessage;
  5. use app\common\validate\UserVali;
  6. use think\Db;
  7. use app\common\model\User;
  8. /**
  9. * @title 会员个人中心
  10. * @controller UserCenter
  11. * @group base
  12. */
  13. class UserCenter extends Base
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. parent::checkLogin();
  19. }
  20. /**
  21. * @title 获取个人信息
  22. * @desc 个人信息
  23. * @author qc
  24. * @url /api/User_center/getUserInfo
  25. * @method GET
  26. * @tag 个人信息
  27. * @header name:Authorization require:1 desc:Token
  28. * @return name:id type:int default:-- desc:会员id
  29. * @return name:phone type:int default:-- desc:手机号
  30. * @return name:openid type:string default:-- desc:openid
  31. * @return name:name type:string default:-- desc:昵称
  32. * @return name:headimg type:string default:-- desc:头像地址
  33. *
  34. */
  35. public function getUserInfo()
  36. {
  37. $field = 'id,phone,name,level_id,headimg,openid';
  38. $user_info = User::field($field)->where('id',$this->user_id)->find()->toArray();
  39. $this->success('获取成功',['detail'=>$user_info]);
  40. }
  41. /**
  42. * @title 编辑个人信息
  43. * @desc 编辑个人信息
  44. * @author qc
  45. * @url /api/User_center/updateUserInfo
  46. * @method POST
  47. * @tag 编辑信息
  48. * @header name:Authorization require:1 desc:Token
  49. * @param name:name type:string default:-- desc:昵称
  50. * @param name:headimg type:string default:-- desc:头像地址
  51. * @return name:id type:int default:-- desc:会员id
  52. * @return name:phone type:int default:-- desc:手机号
  53. * @return name:openid type:string default:-- desc:openid
  54. * @return name:name type:string default:-- desc:昵称
  55. * @return name:headimg type:string default:-- desc:头像地址
  56. */
  57. public function updateUserInfo()
  58. {
  59. $headimg = input('post.headimg');
  60. $name = trim(input('post.name',''));
  61. $update_data= [];
  62. $update_data['name'] = $name;
  63. $update_data['headimg'] = $headimg;
  64. Db::name('store_member')->where('id',$this->user_id)->update($update_data);
  65. $field = 'id,phone,name,headimg,openid';
  66. $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find();
  67. $this->success('编辑成功',['detail'=>$user_info]);
  68. }
  69. /**
  70. * @title 绑定手机号
  71. * @desc 绑定手机号
  72. * @author qc
  73. * @url /api/User_center/modifyPhone
  74. * @method POST
  75. * @header name:Authorization require:1 desc:Token
  76. * @param name:phone type:int require:1 default:-- desc:手机号
  77. * @param name:code type:int require:1 default:-- desc:手机号验证码
  78. * @return name:phone type:int default:-- desc:手机号
  79. * @return name:name type:string default:-- desc:昵称
  80. * @return name:headimg type:string default:-- desc:头像地址
  81. */
  82. public function modifyPhone()
  83. {
  84. $uid = $this->user_id;
  85. $phone = input('post.phone');
  86. $code = input('post.code');
  87. if(empty($phone) || empty($code) ) $this->error('参数错误');
  88. $field = 'id,phone,name,headimg';
  89. $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find();
  90. if($user_info['phone'] == $phone)$this->error('更换手机号与绑定手机号一致!');
  91. $check_code = $this->checkPhoneCode($phone,$code);
  92. if(!$check_code) $this->error('验证码错误');
  93. //判断手机号是否已注册
  94. $member_id = Db::name('store_member')
  95. ->where('phone','=',$phone)->where('is_deleted','=',0)->where('id','<>',$this->user_id)->value('id');
  96. if($member_id) $this->error('手机号已注册过');
  97. Db::name('store_member')->where('id',$uid)->update(['phone'=>$phone]);
  98. $user_info['phone'] = $phone;
  99. $this->updatePhoneCode($check_code);
  100. $this->success('绑定成功',$user_info);
  101. }
  102. }