UserController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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\UserLogic;
  16. use app\api\validate\PasswordValidate;
  17. use app\api\validate\SetUserInfoValidate;
  18. use app\api\validate\UserValidate;
  19. /**
  20. * 用户控制器
  21. * Class UserController
  22. * @package app\api\controller
  23. */
  24. class UserController extends BaseApiController
  25. {
  26. public array $notNeedLogin = ['resetPassword'];
  27. /**
  28. * @notes 获取个人中心
  29. * @return \think\response\Json
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @author 段誉
  34. * @date 2022/9/16 18:19
  35. */
  36. public function center()
  37. {
  38. $data = UserLogic::center($this->userInfo);
  39. return $this->success('', $data);
  40. }
  41. /**
  42. * @notes 获取个人信息
  43. * @return \think\response\Json
  44. * @author 段誉
  45. * @date 2022/9/20 19:46
  46. */
  47. public function info()
  48. {
  49. $result = UserLogic::info($this->userId);
  50. return $this->data($result);
  51. }
  52. /**
  53. * @notes 重置密码
  54. * @return \think\response\Json
  55. * @author 段誉
  56. * @date 2022/9/16 18:06
  57. */
  58. public function resetPassword()
  59. {
  60. $params = (new PasswordValidate())->post()->goCheck('resetPassword');
  61. $result = UserLogic::resetPassword($params);
  62. if (true === $result) {
  63. return $this->success('操作成功', [], 1, 1);
  64. }
  65. return $this->fail(UserLogic::getError());
  66. }
  67. /**
  68. * @notes 修改密码
  69. * @return \think\response\Json
  70. * @author 段誉
  71. * @date 2022/9/20 19:16
  72. */
  73. public function changePassword()
  74. {
  75. $params = (new PasswordValidate())->post()->goCheck('changePassword');
  76. $result = UserLogic::changePassword($params, $this->userId);
  77. if (true === $result) {
  78. return $this->success('操作成功', [], 1, 1);
  79. }
  80. return $this->fail(UserLogic::getError());
  81. }
  82. /**
  83. * @notes 获取小程序手机号
  84. * @return \think\response\Json
  85. * @author 段誉
  86. * @date 2022/9/21 16:46
  87. */
  88. public function getMobileByMnp()
  89. {
  90. $params = (new UserValidate())->post()->goCheck('getMobileByMnp');
  91. $params['user_id'] = $this->userId;
  92. $result = UserLogic::getMobileByMnp($params);
  93. if ($result === false) {
  94. return $this->fail(UserLogic::getError());
  95. }
  96. return $this->success('绑定成功', [], 1, 1);
  97. }
  98. /**
  99. * @notes 编辑用户信息
  100. * @return \think\response\Json
  101. * @author 段誉
  102. * @date 2022/9/21 17:01
  103. */
  104. public function setInfo()
  105. {
  106. $params = (new SetUserInfoValidate())->post()->goCheck(null, ['id' => $this->userId]);
  107. $result = UserLogic::setInfo($this->userId, $params);
  108. if (false === $result) {
  109. return $this->fail(UserLogic::getError());
  110. }
  111. return $this->success('操作成功', [], 1, 1);
  112. }
  113. /**
  114. * @notes 绑定/变更 手机号
  115. * @return \think\response\Json
  116. * @author 段誉
  117. * @date 2022/9/21 17:29
  118. */
  119. public function bindMobile()
  120. {
  121. $params = (new UserValidate())->post()->goCheck('bindMobile');
  122. $params['user_id'] = $this->userId;
  123. $result = UserLogic::bindMobile($params);
  124. if($result) {
  125. return $this->success('绑定成功', [], 1, 1);
  126. }
  127. return $this->fail(UserLogic::getError());
  128. }
  129. }