AuthController.php 22 KB

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