UserController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\api\logic\FirmLogic;
  16. use app\api\logic\UserAddressLogic;
  17. use app\api\logic\UserLogic;
  18. use app\api\validate\FirmValidate;
  19. use app\api\validate\PasswordValidate;
  20. use app\api\validate\SetUserInfoValidate;
  21. use app\api\validate\UserValidate;
  22. /**
  23. * 用户控制器
  24. * Class UserController
  25. * @package app\api\controller
  26. */
  27. class UserController extends BaseApiController
  28. {
  29. public array $notNeedLogin = ['resetPassword'];
  30. /**
  31. * @notes 获取个人中心
  32. * @return \think\response\Json
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. * @author 段誉
  37. * @date 2022/9/16 18:19
  38. */
  39. public function center()
  40. {
  41. $data = UserLogic::center($this->userInfo);
  42. return $this->success('', $data);
  43. }
  44. /**
  45. * @notes 获取个人信息
  46. * @return \think\response\Json
  47. * @author 段誉
  48. * @date 2022/9/20 19:46
  49. */
  50. public function info()
  51. {
  52. $result = UserLogic::info($this->userId);
  53. return $this->data($result);
  54. }
  55. /**
  56. * @notes 重置密码
  57. * @return \think\response\Json
  58. * @author 段誉
  59. * @date 2022/9/16 18:06
  60. */
  61. public function resetPassword()
  62. {
  63. $params = (new PasswordValidate())->post()->goCheck('resetPassword');
  64. $result = UserLogic::resetPassword($params);
  65. if (true === $result) {
  66. return $this->success('操作成功', [], 1, 1);
  67. }
  68. return $this->fail(UserLogic::getError());
  69. }
  70. /**
  71. * @notes 修改密码
  72. * @return \think\response\Json
  73. * @author 段誉
  74. * @date 2022/9/20 19:16
  75. */
  76. public function changePassword()
  77. {
  78. $params = (new PasswordValidate())->post()->goCheck('changePassword');
  79. $result = UserLogic::changePassword($params, $this->userId);
  80. if (true === $result) {
  81. return $this->success('操作成功', [], 1, 1);
  82. }
  83. return $this->fail(UserLogic::getError());
  84. }
  85. /**
  86. * @notes 获取小程序手机号
  87. * @return \think\response\Json
  88. * @author 段誉
  89. * @date 2022/9/21 16:46
  90. */
  91. public function getMobileByMnp()
  92. {
  93. $params = (new UserValidate())->post()->goCheck('getMobileByMnp');
  94. $params['user_id'] = $this->userId;
  95. $result = UserLogic::getMobileByMnp($params);
  96. if ($result === false) {
  97. return $this->fail(UserLogic::getError());
  98. }
  99. return $this->success('绑定成功', [], 1, 1);
  100. }
  101. /**
  102. * @notes 编辑用户信息
  103. * @return \think\response\Json
  104. * @author 段誉
  105. * @date 2022/9/21 17:01
  106. */
  107. public function setInfo()
  108. {
  109. $params = (new SetUserInfoValidate())->post()->goCheck(null, ['id' => $this->userId]);
  110. $result = UserLogic::setInfo($this->userId, $params);
  111. if (false === $result) {
  112. return $this->fail(UserLogic::getError());
  113. }
  114. return $this->success('操作成功', [], 1, 1);
  115. }
  116. /**
  117. * @notes 绑定/变更 手机号
  118. * @return \think\response\Json
  119. * @author 段誉
  120. * @date 2022/9/21 17:29
  121. */
  122. public function bindMobile()
  123. {
  124. $params = (new UserValidate())->post()->goCheck('bindMobile');
  125. $params['user_id'] = $this->userId;
  126. $result = UserLogic::bindMobile($params);
  127. if($result) {
  128. return $this->success('绑定成功', [], 1, 1);
  129. }
  130. return $this->fail(UserLogic::getError());
  131. }
  132. public function saveFirmUserInfo()
  133. {
  134. $params = (new FirmValidate())->post()->goCheck('saveUserInfo');
  135. $result = UserLogic::saveFirmUserInfo($params,$this->userId);
  136. if (true === $result) {
  137. return $this->success('已提交', [], 1, 1);
  138. }
  139. return $this->fail(FirmLogic::getError());
  140. }
  141. }