Login.php 1.4 KB

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