AuthController.php 23 KB

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