AuthController.php 24 KB

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