Login.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\cashier\storeapi\controller;
  11. use app\model\system\User as UserModel;
  12. use app\storeapi\controller\Captcha;
  13. use app\storeapi\controller\BaseStoreApi;
  14. /**
  15. * 门店登录控制器
  16. */
  17. class Login extends BaseStoreApi
  18. {
  19. public function __construct()
  20. {
  21. $this->params = input();
  22. $this->getApiConfig();
  23. }
  24. public function login()
  25. {
  26. if (empty($this->params[ "username" ])) return $this->response($this->error([], "账号不能为空!"));
  27. if (empty($this->params[ "password" ])) return $this->response($this->error([], "密码不可为空!"));
  28. $captcha = new Captcha();
  29. $check_res = $captcha->checkCaptcha();
  30. if ($check_res[ 'code' ] < 0) return $this->response($check_res);
  31. // 登录
  32. $login = new UserModel();
  33. $res = $login->uniAppLogin($this->params[ 'username' ], $this->params[ "password" ], 'store');
  34. //生成access_token
  35. if ($res[ 'code' ] >= 0) {
  36. if (empty($res[ 'data' ]['user_group_list'])) return $this->response($this->error('', '没有可管理的门店'));
  37. $token = $this->createToken($res[ 'data' ]);
  38. return $this->response($this->success([
  39. 'token' => $token,
  40. 'site_id' => $res[ 'data' ][ 'site_id' ],
  41. 'store_id' => $res[ 'data' ]['user_group_list'][0]['store_id']
  42. ]));
  43. }
  44. return $this->response($res);
  45. }
  46. }