AuthController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizHd\admin\classes\ShopAdminClass;
  6. use bizGhs\shop\services\ShopAdminService;
  7. use bizGhs\admin\services\AdminService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use common\components\dict;
  10. use common\components\httpUtil;
  11. use common\components\imgUtil;
  12. use common\components\jwt;
  13. use common\components\util;
  14. use Yii;
  15. use common\components\stringUtil;
  16. use biz\sj\services\MerchantService;
  17. use bizHd\user\services\UserService;
  18. use common\services\xhMerchantService;
  19. use common\components\wxUtil;
  20. use linslin\yii2\curl;
  21. use yii\helpers\Json;
  22. //用户登陆
  23. class AuthController extends PublicController
  24. {
  25. //微信手机号一键登录 ssh 20210121
  26. public function actionWxMobileLogin()
  27. {
  28. $post = Yii::$app->request->post();
  29. $iv = $post['iv'];
  30. $encryptedData = $post['encryptedData'];
  31. $merchant = WxOpenClass::getGhsWxInfo();
  32. $appId = $merchant['miniAppId'];
  33. $miniOpenId = $post['miniOpenId'] ?? '';
  34. if (empty($miniOpenId)) {
  35. util::fail('登录失败...');
  36. }
  37. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  38. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  39. if (empty($sessionKey)) {
  40. util::fail('登录失败了哦');
  41. }
  42. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  43. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  44. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  45. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  46. if ($errCode != 0) {
  47. util::fail('登录失败..');
  48. }
  49. $arr = Json::decode($result);
  50. $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  51. if (empty($phoneNumber)) {
  52. util::fail('登录失败了');
  53. }
  54. $admin = AdminClass::getByCondition(['mobile' => $phoneNumber]);
  55. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  56. $openShop = $admin['openGhsShop'] ?? 1;
  57. if (empty($currentShopId)) {
  58. if ($openShop == 2) {
  59. util::fail('审核中');
  60. }
  61. util::fail('请先注册');
  62. }
  63. $currentShop = ShopClass::getById($currentShopId, true);
  64. if (empty($currentShop)) {
  65. util::fail('没有找到门店');
  66. }
  67. $mainId = $currentShop->mainId ?? 0;
  68. $adminId = $admin['id'] ?? 0;
  69. //1没有开店 2已申请待审核 3已开店
  70. $openShop = $admin['openGhsShop'] ?? 1;
  71. if ($openShop == 2) {
  72. util::fail('帐号审核中');
  73. }
  74. $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
  75. if (empty($shopAdmin)) {
  76. util::fail('请先注册');
  77. }
  78. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  79. $shopAdmin->save();
  80. $shopAdminId = $shopAdmin->id ?? 0;
  81. //是否有切换门店的权限
  82. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  83. $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
  84. $token = jwt::getNewToken($adminId);
  85. $showDemo = 1;
  86. $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
  87. $shop = ShopClass::getById($currentShopId, true);
  88. $skCustomId = $shop->skCustomId ?? 0;
  89. $apiHost = Yii::$app->params['ghsHost'];
  90. $imgUploadApi = $apiHost . '/upload/save-file';
  91. //使用手册
  92. $cacheKey = 'close_book_' . $shopAdminId;
  93. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  94. $showBook = !empty($hasClose) ? 0 : 1;
  95. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  96. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  97. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  98. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  99. if ($ghsUpgrading == 1) {
  100. util::fail('系统升级中,稍后再试');
  101. }
  102. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  103. util::success([
  104. 'token' => $token,
  105. 'admin' => $admin,
  106. 'shopAdminId' => $shopAdminId,
  107. 'shopId' => $currentShopId,
  108. 'switchShop' => $switchShop,
  109. 'openShop' => $openShop,
  110. 'showDemo' => $showDemo,
  111. //有小程序新版本提示更新
  112. 'update' => $remind,
  113. 'skCustomId' => $skCustomId,
  114. 'apiHost' => $apiHost,
  115. 'imgUploadApi' => $imgUploadApi,
  116. 'showBook' => $showBook,
  117. 'hasHitNavigate' => $hasHitNavigate,
  118. ]);
  119. }
  120. //本机号码一键登录 ssh 20210117
  121. public function actionPhoneLogin()
  122. {
  123. $get = Yii::$app->request->get();
  124. $access_token = $get['access_token'] ?? '';
  125. $openid = $get['openid'] ?? '';
  126. if (empty($access_token) || empty($openid)) {
  127. util::fail('参数错误');
  128. }
  129. //密钥,需要和uniCloud里的一致
  130. $secret = 'XHB2021198819640123';
  131. $params = ['access_token' => $access_token, 'openid' => $openid];
  132. $stringSignTemp = '';
  133. foreach ($params as $k => $v) {
  134. $stringSignTemp .= $k . '=' . $v . '&';
  135. }
  136. $stringSignTemp = rtrim($stringSignTemp, '&');
  137. $sign = hash_hmac('sha256', $stringSignTemp, $secret);
  138. $url = Yii::$app->params['ghsUniCloudHost'] . "/getMobileNumber?access_token=" . $access_token . "&sign=" . $sign . "&" . $stringSignTemp;
  139. $curl = new curl\Curl();
  140. $respond = $curl->get($url);
  141. Yii::info($respond);
  142. $result = json_decode($respond, true);
  143. if (isset($result['code']) == false || $result['code'] != 1) {
  144. util::fail('获取手机号失败');
  145. }
  146. $phoneNumber = $result['data']['phoneNumber'] ?? '';
  147. if (empty($phoneNumber)) {
  148. util::fail('没有获取到手机号');
  149. }
  150. $ptStyle = dict::getDict('ptStyle', 'ghs');
  151. $admin = AdminClass::getByCondition(['mobile' => $phoneNumber, 'style' => $ptStyle]);
  152. if (empty($admin)) {
  153. $adminInfo = [
  154. 'name' => $phoneNumber,
  155. 'mobile' => $phoneNumber,
  156. 'style' => $ptStyle,
  157. ];
  158. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  159. $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
  160. }
  161. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  162. $openShop = $admin['openGhsShop'] ?? 1;
  163. if (empty($currentShopId)) {
  164. if ($openShop == 2) {
  165. util::fail('审核中');
  166. }
  167. util::fail('请先注册');
  168. }
  169. $adminId = $admin['id'] ?? 0;
  170. //1没有开店 2已申请待审核 3已开店
  171. $openShop = $admin['openGhsShop'] ?? 1;
  172. if ($openShop == 2) {
  173. util::fail('帐号审核中');
  174. }
  175. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
  176. if (empty($shopAdmin)) {
  177. util::fail('请先注册');
  178. }
  179. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  180. $shopAdmin->save();
  181. $shopAdminId = $shopAdmin->id ?? 0;
  182. //是否有切换门店的权限
  183. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  184. $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
  185. $token = jwt::getNewToken($adminId);
  186. $showDemo = 1;
  187. $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
  188. $shop = ShopClass::getById($currentShopId, true);
  189. $skCustomId = $shop->skCustomId ?? 0;
  190. $apiHost = Yii::$app->params['ghsHost'];
  191. $imgUploadApi = $apiHost . '/upload/save-file';
  192. //使用手册
  193. $cacheKey = 'close_book_' . $shopAdminId;
  194. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  195. $showBook = !empty($hasClose) ? 0 : 1;
  196. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  197. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  198. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  199. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  200. if ($ghsUpgrading == 1) {
  201. util::fail('系统升级中,稍后再试');
  202. }
  203. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  204. util::success([
  205. 'token' => $token,
  206. 'admin' => $admin,
  207. 'shopAdminId' => $shopAdminId,
  208. 'shopId' => $currentShopId,
  209. 'switchShop' => $switchShop,
  210. 'openShop' => $openShop,
  211. 'showDemo' => $showDemo,
  212. //有小程序新版本提示更新
  213. 'update' => $remind,
  214. 'skCustomId' => $skCustomId,
  215. 'apiHost' => $apiHost,
  216. 'imgUploadApi' => $imgUploadApi,
  217. 'showBook' => $showBook,
  218. 'hasHitNavigate' => $hasHitNavigate,
  219. ]);
  220. util::success(['admin' => $admin]);
  221. }
  222. //准备授权 ssh 2019.11.19
  223. public function actionPrepare()
  224. {
  225. $get = Yii::$app->request->get();
  226. $url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
  227. if (empty($url)) {
  228. util::fail('没有网址');
  229. }
  230. $account = httpUtil::getAccount($url);
  231. if (empty($account)) {
  232. util::fail('没有商家帐号');
  233. }
  234. $merchant = MerchantService::getById($account);
  235. if (empty($merchant)) {
  236. util::fail('商家无效');
  237. }
  238. /**
  239. * authScope 参数的说明
  240. * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
  241. * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
  242. * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
  243. * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
  244. */
  245. $authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
  246. $urlEncode = stringUtil::urlSafeB64Encode($url);
  247. //微信授权获取code ssh 2019.11.24
  248. $isOpen = 2;
  249. wxUtil::getCode($urlEncode, $merchant, $authScope, $isOpen);
  250. util::end();
  251. }
  252. //微信授权获取用户信息 ssh 2019.11.20
  253. public function actionGetUserInfo()
  254. {
  255. $get = Yii::$app->request->get();
  256. $code = isset($get['code']) ? $get['code'] : '';
  257. if (empty($code)) {
  258. util::fail('没有获取用户code');
  259. }
  260. if (isset($get['state']) && $get['state'] == 'authdeny') {
  261. util::fail('auth fail');
  262. }
  263. $urlEncode = $get['url'];
  264. $url = stringUtil::urlSafeBase64Decode($urlEncode);
  265. $account = httpUtil::getAccount($url);
  266. if (empty($account)) {
  267. util::stop('商店ID无效!!');
  268. }
  269. $merchant = xhMerchantService::getByAccount($account);
  270. if (empty($merchant)) {
  271. util::stop('商店无效');
  272. }
  273. $sjId = $merchant['id'];
  274. $authScope = isset($get['authScope']) ? $get['authScope'] : '';
  275. if (empty($authScope)) {
  276. util::stop('没有授权类型');
  277. }
  278. $data = wxUtil::getOpenId($code, $merchant, 2);
  279. if ($data === false) {
  280. //微信授权获取code ssh 2019.11.24
  281. wxUtil::getCode($urlEncode, $merchant, $authScope, 2);
  282. util::end();
  283. }
  284. $openId = $data['openid'];
  285. $access_token = $data['access_token'];
  286. $user = UserService::getByOpenId($openId);
  287. //用户来源
  288. $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
  289. $source = $userSource['name'];
  290. if (empty($user)) {
  291. //$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
  292. $originalInfo = [];
  293. $originalInfo['openId'] = $openId;
  294. $originalInfo['sjId'] = $sjId;
  295. //没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
  296. if ($authScope == 'snsapi_userinfo') {
  297. $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
  298. $originalInfo = array_merge($baseInfo, $originalInfo);
  299. $originalInfo['isFull'] = 1;
  300. $originalInfo['unionId'] = $baseInfo['unionid'];
  301. $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
  302. $originalInfo['nickName'] = $baseInfo['nickName'];
  303. }
  304. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  305. } else {
  306. if ($user['isFull'] == 0) {
  307. if ($authScope == 'snsapi_userinfo') {
  308. $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
  309. $originalInfo = $baseInfo;
  310. $originalInfo['isFull'] = 1;
  311. $originalInfo['unionId'] = $baseInfo['unionid'];
  312. $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
  313. $originalInfo['openId'] = $baseInfo['openid'];
  314. $originalInfo['nickName'] = $baseInfo['nickName'];
  315. $originalInfo['sjId'] = $sjId;
  316. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  317. }
  318. }
  319. }
  320. //这个的基类没有设置统一的全局变量,这里进行设置一次
  321. $userId = $user['id'];
  322. $admin = AdminService::getByCondition(['userId' => $userId]);
  323. if (empty($admin)) {
  324. util::fail('您没有权限访问');
  325. }
  326. $adminId = $admin['id'];
  327. //获取token
  328. $token = jwt::getNewToken($adminId);
  329. $url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
  330. $this->redirect($url);
  331. }
  332. //登陆并拿到token ssh 2019.11.23
  333. public function actionLogin()
  334. {
  335. $get = Yii::$app->request->get();
  336. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  337. if (stringUtil::isMobile($mobile) == false) {
  338. util::fail('请填写正常的手机号');
  339. }
  340. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  341. if (empty($password)) {
  342. util::fail('请输入密码');
  343. }
  344. $admin = AdminService::getByCondition(['mobile' => $mobile, 'style' => AdminClass::STYLE_GHS]);
  345. if (password_verify($password, $admin['password']) == false) {
  346. util::fail('密码错误');
  347. }
  348. $adminId = $admin['id'];
  349. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'delStatus' => 0]);
  350. if ($shopAdmin['status'] == 0) {
  351. util::fail("您的账号还未激活");
  352. }
  353. $sjId = isset($shopAdmin['sjId']) ? $shopAdmin['sjId'] : 0;
  354. $shopId = $shopAdmin['shopId'] ?? 0;
  355. if (empty($shopId)) {
  356. util::fail('您不是管理员');
  357. }
  358. //获取token
  359. $token = jwt::getNewToken($adminId);
  360. util::success(['token' => $token, 'account' => $sjId, 'shopId' => $shopId]);
  361. }
  362. //静默获取小程序用户信息
  363. public function actionMiniInfo()
  364. {
  365. //供应商平台
  366. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  367. $code = Yii::$app->request->get('code', '');
  368. $wxMiniBase = WxOpenClass::getGhsWxInfo();
  369. $appId = $wxMiniBase['miniAppId'];
  370. $appSecret = $wxMiniBase['miniAppSecret'];
  371. if (empty($appSecret)) {
  372. //没有管理店铺不允许登录
  373. util::success(['token' => '', 'number' => 1]);
  374. }
  375. $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
  376. $curl = new curl\Curl();
  377. $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
  378. $result = $curl->get($url);
  379. $arr = Json::decode($result);
  380. $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
  381. $openid = $arr['openid'] ?? '';
  382. if (empty($openid)) {
  383. //没有管理店铺不允许登录
  384. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 2]);
  385. }
  386. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
  387. Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
  388. $admin = AdminClass::getByCondition(['ghsMiniOpenId' => $openid]);
  389. if (empty($admin)) {
  390. //没有管理店铺不允许登录
  391. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 3]);
  392. }
  393. $adminId = $admin['id'];
  394. $openShop = $admin['openGhsShop'] ?? 1;
  395. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  396. if (empty($currentShopId)) {
  397. //没有管理店铺不允许登录
  398. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 4]);
  399. }
  400. $currentShop = ShopClass::getById($currentShopId, true);
  401. if (empty($currentShop)) {
  402. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 4]);
  403. }
  404. $mainId = $currentShop->mainId ?? 0;
  405. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  406. if (empty($shopAdmin)) {
  407. //没有管理店铺不允许登录
  408. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 5]);
  409. }
  410. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  411. $shopAdmin->save();
  412. $shopAdminId = $shopAdmin->id ?? 0;
  413. //是否有切换门店的权限
  414. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  415. $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
  416. $token = jwt::getNewToken($adminId);
  417. $showDemo = 1;
  418. $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
  419. $shop = ShopClass::getById($currentShopId, true);
  420. $skCustomId = $shop->skCustomId ?? 0;
  421. $apiHost = Yii::$app->params['ghsHost'];
  422. $imgUploadApi = $apiHost . '/upload/save-file';
  423. //使用手册
  424. $cacheKey = 'close_book_' . $shopAdminId;
  425. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  426. $showBook = !empty($hasClose) ? 0 : 1;
  427. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  428. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  429. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  430. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  431. if ($ghsUpgrading == 1) {
  432. util::fail('系统升级中,稍后再试');
  433. }
  434. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  435. util::success([
  436. 'token' => $token,
  437. 'admin' => $admin,
  438. 'shopAdminId' => $shopAdminId,
  439. 'shopId' => $currentShopId,
  440. 'switchShop' => $switchShop,
  441. 'openShop' => $openShop,
  442. 'showDemo' => $showDemo,
  443. //有小程序新版本提示更新
  444. 'update' => $remind,
  445. 'skCustomId' => $skCustomId,
  446. 'apiHost' => $apiHost,
  447. 'imgUploadApi' => $imgUploadApi,
  448. 'showBook' => $showBook,
  449. 'hasHitNavigate' => $hasHitNavigate,
  450. ]);
  451. }
  452. //app登陆 ssh 20211219
  453. public function actionAppLogin()
  454. {
  455. $get = Yii::$app->request->get();
  456. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  457. if (stringUtil::isMobile($mobile) == false) {
  458. util::fail('请填写正确手机号');
  459. }
  460. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  461. if (empty($password)) {
  462. util::fail('请输入密码');
  463. }
  464. $admin = AdminService::getByCondition(['mobile' => $mobile], true);
  465. if (password_verify($password, $admin->password) == false) {
  466. util::fail('密码错误');
  467. }
  468. $openShop = $admin->openGhsShop ?? 1;
  469. $currentShopId = $admin->currentGhsShopId ?? 0;
  470. if (empty($currentShopId)) {
  471. if ($openShop == 2) {
  472. util::fail('审核中');
  473. }
  474. util::fail('请先注册');
  475. }
  476. $currentShop = \bizGhs\shop\classes\ShopClass::getById($currentShopId, true);
  477. if (empty($currentShop)) {
  478. util::fail('没有找到门店');
  479. }
  480. $mainId = $currentShop->mainId ?? 0;
  481. $adminId = $admin->id;
  482. $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  483. if (empty($shopAdmin)) {
  484. util::fail('您没有权限');
  485. }
  486. if ($shopAdmin->delStatus == 1) {
  487. util::fail('您没有权限哦');
  488. }
  489. if ($shopAdmin->status == 0) {
  490. util::fail("您的账号已冻结");
  491. }
  492. $token = jwt::getNewToken($adminId);
  493. $shopAdminId = $shopAdmin->id ?? 0;
  494. //是否有切换门店的权限
  495. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  496. //1没有开店 2已申请待审核 3已开店
  497. $openShop = $admin['openGhsShop'] ?? 1;
  498. $showDemo = 1;
  499. $shop = ShopClass::getById($currentShopId, true);
  500. $skCustomId = $shop->skCustomId ?? 0;
  501. $apiHost = Yii::$app->params['ghsHost'];
  502. $imgUploadApi = $apiHost . '/upload/save-file';
  503. //使用手册
  504. $cacheKey = 'close_book_' . $shopAdminId;
  505. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  506. $showBook = !empty($hasClose) ? 0 : 1;
  507. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  508. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  509. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  510. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  511. if ($ghsUpgrading == 1) {
  512. util::fail('系统升级中,稍后再试');
  513. }
  514. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  515. util::success([
  516. 'token' => $token,
  517. 'admin' => $admin,
  518. 'shopAdminId' => $shopAdminId,
  519. 'shopId' => $currentShopId,
  520. 'switchShop' => $switchShop,
  521. 'openShop' => $openShop,
  522. 'showDemo' => $showDemo,
  523. //有小程序新版本提示更新
  524. 'update' => 0,
  525. 'skCustomId' => $skCustomId,
  526. 'apiHost' => $apiHost,
  527. 'imgUploadApi' => $imgUploadApi,
  528. 'showBook' => $showBook,
  529. 'hasHitNavigate' => $hasHitNavigate,
  530. ]);
  531. }
  532. //最新版本 ssh 20220211
  533. public function actionGetApkVersion()
  534. {
  535. $version = getenv('GHS_NEW_APK_VERSION') == false ? '1.0.0' : getenv('GHS_NEW_APK_VERSION');
  536. $mustUpdate = getenv('GHS_NEW_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('GHS_NEW_APK_VERSION_MUST_UPDATE');
  537. util::success(['version' => $version, 'mustUpdate' => $mustUpdate]);
  538. }
  539. //收银台apk更新 ssh 20220310
  540. public function actionGetPadApkVersion()
  541. {
  542. $version = getenv('GHS_NEW_PAD_APK_VERSION') == false ? '1.0.0' : getenv('GHS_NEW_PAD_APK_VERSION');
  543. $mustUpdate = getenv('GHS_NEW_PAD_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('GHS_NEW_PAD_APK_VERSION_MUST_UPDATE');
  544. util::success(['version' => $version, 'mustUpdate' => $mustUpdate]);
  545. }
  546. }