Users.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\api\controller;
  10. use app\api\validate\Login;
  11. use app\api\validate\Register;
  12. use app\api\validate\Forget;
  13. use app\api\validate\Sms;
  14. use think\exception\ValidateException;
  15. use think\facade\Request;
  16. use app\api\service\Users as UsersService;
  17. class Users extends Base {
  18. /**
  19. * 会员登录
  20. * @return \think\response\Json
  21. */
  22. public function login(){
  23. try{
  24. $post = Request::param();
  25. validate(Login::class)->scene('login')->check($post);
  26. return $this->returnAjax("登录成功,正在为您跳转中…", 1,UsersService::login($post));
  27. }catch (ValidateException $e){
  28. return $this->returnAjax($e->getError(), 0);
  29. } catch (\Exception $ex){
  30. return $this->returnAjax($ex->getMessage(), 0);
  31. }
  32. }
  33. /**
  34. * 注册
  35. * @return \think\response\Json
  36. */
  37. public function register(){
  38. try{
  39. $post = Request::param();
  40. validate(Register::class)->scene('register')->check($post);
  41. return $this->returnAjax("注册成功,正在为您跳转中…", 1,UsersService::register($post));
  42. }catch (ValidateException $e){
  43. return $this->returnAjax($e->getError(), 0);
  44. } catch (\Exception $ex){
  45. return $this->returnAjax($ex->getMessage(), 0);
  46. }
  47. }
  48. /**
  49. * 修改密码
  50. * @return \think\response\Json
  51. */
  52. public function forget(){
  53. try{
  54. $post = Request::param();
  55. validate(Forget::class)->scene('forget')->check($post);
  56. return $this->returnAjax("修改密码成功!", 1,UsersService::forget($post));
  57. }catch (ValidateException $e){
  58. return $this->returnAjax($e->getError(), 0);
  59. } catch (\Exception $ex){
  60. return $this->returnAjax($ex->getMessage(), 0);
  61. }
  62. }
  63. /**
  64. * 自动登录
  65. * @return \think\response\Json
  66. */
  67. public function autologin(){
  68. try{
  69. return $this->returnAjax("登录成功!",1000,UsersService::autologin());
  70. }catch(\Exception $ex){
  71. return json(["info"=>$ex->getMessage(),"status"=>"-1002"]);
  72. }
  73. }
  74. /**
  75. * 发送短信
  76. * @return \think\response\Json
  77. */
  78. public function send_sms(){
  79. try{
  80. $post = Request::param();
  81. validate(Sms::class)->scene('sms')->check($post);
  82. return $this->returnAjax(UsersService::sendSMS($post), 1);
  83. }catch (ValidateException $e){
  84. return $this->returnAjax($e->getError(), 0);
  85. } catch (\Exception $ex){
  86. return $this->returnAjax($ex->getMessage(),$ex->getCode());
  87. }
  88. }
  89. }