Member.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. */
  10. class Member extends Base
  11. {
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. parent::checkLogin();
  16. }
  17. /**
  18. * @Apidoc\Title("获取个人信息")
  19. * @Apidoc\Desc("个人信息")
  20. * @Apidoc\Method("GET")
  21. * @Apidoc\Author("HG")
  22. * @Apidoc\Tag("")
  23. * @Apidoc\Returned("phone", type="int", desc="手机号")
  24. * @Apidoc\Returned("name", type="string", desc="姓名")
  25. * @Apidoc\Returned("nickname", type="string", desc="昵称")
  26. * @Apidoc\Returned("headimg", type="string", desc="头像地址")
  27. * @Apidoc\Returned("title", type="string", desc="职称")
  28. * @Apidoc\Returned("department", type="string", desc="部门(多个部门以逗号分隔)")
  29. * @Apidoc\Returned("signature", type="string", desc="个人签名")
  30. */
  31. public function user_info()
  32. {
  33. $uid = $this->user_id;
  34. $field = 'phone,name,nickname,headimg,title,department,signature';
  35. $info = Db::name('store_member')->field($field)->where('id',$uid)->find();
  36. $this->success('获取成功',$info);
  37. }
  38. /**
  39. * @Apidoc\Title("编辑个人信息")
  40. * @Apidoc\Desc("个人信息")
  41. * @Apidoc\Method("POST")
  42. * @Apidoc\Author("HG")
  43. * @Apidoc\Tag("")
  44. * @Apidoc\Query("type", type="int", require=true, desc="修改的类型(1:昵称,2:签名,3:手机号)")
  45. * @Apidoc\Query("nickname", type="string", desc="昵称")
  46. * @Apidoc\Query("signature", type="string", desc="签名")
  47. * @Apidoc\Query("phone", type="string", desc="手机号")
  48. */
  49. public function edit()
  50. {
  51. $uid = $this->user_id;
  52. $type = input('type');
  53. $nickname = input('nickname');
  54. $signature = input('signature');
  55. $phone = input('phone');
  56. if(!in_array($type,[1,2,3])){
  57. $this->error('参数错误');
  58. }
  59. if($type == 1){
  60. if(empty($nickname)){
  61. $this->error('参数错误');
  62. }
  63. $update_data['nickname'] = $nickname;
  64. }elseif ($type == 2){
  65. if(empty($signature)){
  66. $this->error('参数错误');
  67. }
  68. $update_data['signature'] = $signature;
  69. }elseif ($type == 2){
  70. if(empty($phone)){
  71. $this->error('参数错误');
  72. }
  73. if(!preg_match("/^1[23456789]\d{9}$/", $phone)){
  74. $this->error('手机号格式不正确');
  75. }
  76. $update_data['phone'] = $phone;
  77. }
  78. Db::name('store_member')->where('id',$uid)->update($update_data);
  79. $this->success('编辑成功');
  80. }
  81. }