Login.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: TABLE ME
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-08-25 17:23
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\warehouse\controller;
  13. use app\model\admin\Admin;
  14. use app\model\admin\AdminMenu;
  15. use app\model\warehouse\Warehouse;
  16. use app\Request;
  17. use library\exceptions\GeneralException;
  18. use library\lib\weixina;
  19. use library\services\UtilService;
  20. use library\utils\Captcha;
  21. use library\utils\Qiniu;
  22. use think\facade\Db;
  23. class Login
  24. {
  25. /**
  26. * 用户登录端
  27. * @param Request $request
  28. */
  29. public function index(Request $request)
  30. {
  31. [$account, $pwd, $imgcode] = UtilService::getMore([
  32. ['account','','empty','请输入登录账户'],
  33. ['pwd','','empty','请输入登录密码'],
  34. ['imgcode','','empty','验证码不能为空'],
  35. ],$request,true);
  36. if (!(new Captcha)->check($imgcode)) {
  37. return app('json')->fail('验证码错误,请重新输入');
  38. }
  39. //获取登录
  40. $adminInfo = Warehouse::login($account,$pwd);
  41. if(empty($adminInfo)) {
  42. return app('json')->fail(Warehouse::getErrorInfo('用户名错误,请重新输入'));
  43. }
  44. //生成令牌
  45. $token = Warehouse::createToken($adminInfo, 'warehouse');
  46. if(empty($token)) {
  47. return app('json')->fail(Warehouse::getErrorInfo());
  48. }
  49. return app('json')->success([
  50. 'token' => $token['token'],
  51. 'expires_time' => $token['params']['exp'],
  52. 'user_info' => [
  53. 'id' => $adminInfo->getData('id'),
  54. 'username' => $adminInfo->getData('username'),
  55. 'name' => $adminInfo->getData('name'),
  56. 'lx_name' => $adminInfo->getData('lx_name')
  57. ],
  58. ]);
  59. }
  60. /**
  61. * 用户发生退出
  62. */
  63. public function logut(){
  64. }
  65. /**
  66. * 验证码
  67. * @return \app\adminapi\controller\Login|\think\Response
  68. */
  69. public function captcha()
  70. {
  71. return (new Captcha())->create();
  72. }
  73. }