User.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\User as UserModel;
  4. use think\Exception;
  5. /**
  6. * 用户管理
  7. * Class User
  8. * @package app\api
  9. */
  10. class User extends Controller
  11. {
  12. /**
  13. * 用户自动登录
  14. * @return array
  15. * @throws \app\common\exception\BaseException
  16. * @throws \think\Exception
  17. * @throws \think\exception\DbException
  18. */
  19. public function login()
  20. {
  21. $model = new UserModel;
  22. return $this->renderSuccess([
  23. 'user_id' => $model->login($this->request->post()),
  24. 'token' => $model->getToken()
  25. ]);
  26. }
  27. /**
  28. * 当前用户详情
  29. * @return array
  30. * @throws \app\common\exception\BaseException
  31. * @throws \think\exception\DbException
  32. */
  33. public function detail()
  34. {
  35. // 当前用户信息
  36. $userInfo = $this->getUser();
  37. return $this->renderSuccess(compact('userInfo'));
  38. }
  39. /**
  40. * 设置支付密码
  41. * @return array
  42. * @throws \app\common\exception\BaseException
  43. * @throws \think\exception\DbException
  44. */
  45. public function setPayPassword()
  46. {
  47. try {
  48. $userInfo = $this->getUser();
  49. if(empty($userInfo)){
  50. throw new Exception('用户信息不存在或未登录');
  51. }
  52. $password = input('password','');
  53. if(\app\api\service\User::setPayPassword($userInfo['user_id'], $password)){
  54. return $this->renderSuccess([],'设置成功');
  55. }else{
  56. return $this->renderError('设置失败');
  57. }
  58. }catch (\Exception $exception){
  59. return $this->renderError($exception->getMessage()?:'设置失败');
  60. }
  61. }
  62. /**
  63. * 设置支付密码
  64. * @return array
  65. * @throws \app\common\exception\BaseException
  66. * @throws \think\exception\DbException
  67. */
  68. public function setProfile()
  69. {
  70. try {
  71. $userInfo = $this->getUser();
  72. if(empty($userInfo)){
  73. throw new Exception('用户信息不存在或未注册');
  74. }
  75. $post = input();
  76. if(\app\api\service\User::setProfile($userInfo['user_id'], $post)){
  77. return $this->renderSuccess([],$userInfo['status']==1? '设置成功':'设置成功,请耐心等候审核');
  78. }else{
  79. return $this->renderError('设置失败');
  80. }
  81. }catch (\Exception $exception){
  82. return $this->renderError($exception->getMessage()?:'设置失败');
  83. }
  84. }
  85. }