AuthController.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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 bizGhs\item\classes\LabelClass;
  7. use bizHd\admin\classes\ShopAdminClass;
  8. use bizGhs\shop\services\ShopAdminService;
  9. use bizGhs\admin\services\AdminService;
  10. use biz\wx\classes\WxOpenClass;
  11. use common\components\dict;
  12. use common\components\httpUtil;
  13. use common\components\imgUtil;
  14. use common\components\jwt;
  15. use common\components\noticeUtil;
  16. use common\components\sms;
  17. use common\components\util;
  18. use Yii;
  19. use common\components\stringUtil;
  20. use biz\sj\services\MerchantService;
  21. use bizHd\user\services\UserService;
  22. use common\services\xhMerchantService;
  23. use common\components\wxUtil;
  24. use linslin\yii2\curl;
  25. use yii\helpers\Json;
  26. //用户登陆
  27. class AuthController extends PublicController
  28. {
  29. //获取手机号
  30. public function actionGetMobile()
  31. {
  32. $post = Yii::$app->request->post();
  33. $iv = $post['iv'];
  34. $encryptedData = $post['encryptedData'];
  35. $merchant = WxOpenClass::getGhsWxInfo();
  36. $appId = $merchant['miniAppId'];
  37. $miniOpenId = $post['miniOpenId'] ?? '';
  38. if (empty($miniOpenId)) {
  39. util::success(['hasNoOpenId' => 1], '登录失败,没有miniOpenId');
  40. }
  41. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  42. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  43. if (empty($sessionKey)) {
  44. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  45. util::success(['hasNoOpenId' => 1], '登录失败!');
  46. }
  47. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  48. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  49. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  50. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  51. if ($errCode != 0) {
  52. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  53. util::success(['hasNoOpenId' => 1], '登录失败...');
  54. }
  55. $arr = Json::decode($result);
  56. $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  57. if (empty($phoneNumber)) {
  58. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  59. util::success(['hasNoOpenId' => 1], '登录失败了哦');
  60. }
  61. $cacheKey = 'getMobile_' . $phoneNumber;
  62. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 1]);
  63. util::success(['mobile' => $phoneNumber]);
  64. }
  65. //获取微信昵称
  66. public function actionGetNickname()
  67. {
  68. $post = Yii::$app->request->post();
  69. $iv = $post['iv'] ?? '';
  70. $encryptedData = $post['encryptedData'] ?? '';
  71. $merchant = WxOpenClass::getGhsWxInfo();
  72. $appId = $merchant['miniAppId'];
  73. $miniOpenId = $post['miniOpenId'] ?? '';
  74. if (empty($miniOpenId)) {
  75. util::fail('获取失败,请重新打开小程序');
  76. }
  77. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  78. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  79. if (empty($sessionKey)) {
  80. util::fail('获取失败,请重新打开小程序');
  81. }
  82. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  83. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  84. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  85. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  86. if ($errCode != 0) {
  87. util::fail('获取微信昵称失败');
  88. }
  89. $arr = Json::decode($result);
  90. $nickName = $arr['nickName'] ?? '';
  91. if (empty($nickName)) {
  92. util::fail('没获取到微信昵称');
  93. }
  94. util::success(['name' => $nickName, 'nickName' => $nickName]);
  95. }
  96. //微信手机号一键登录 ssh 20210121
  97. public function actionWxMobileLogin()
  98. {
  99. $post = Yii::$app->request->post();
  100. $iv = $post['iv'];
  101. $encryptedData = $post['encryptedData'];
  102. $merchant = WxOpenClass::getGhsWxInfo();
  103. $appId = $merchant['miniAppId'];
  104. $miniOpenId = $post['miniOpenId'] ?? '';
  105. if (empty($miniOpenId)) {
  106. util::success(['hasNoOpenId' => 1], '登录失败,没有miniOpenId');
  107. }
  108. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  109. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  110. if (empty($sessionKey)) {
  111. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  112. //noticeUtil::push($cacheKey . " 登录失败!!sessionKey空的", '15280215347');
  113. util::success(['hasNoOpenId' => 1], '登录失败。');
  114. }
  115. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  116. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  117. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  118. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  119. if ($errCode != 0) {
  120. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  121. //noticeUtil::push($cacheKey . " 批发商 登录失败!!!!sessionKey异常", '15280215347');
  122. util::success(['hasNoOpenId' => 1], '登录失败!');
  123. }
  124. $arr = Json::decode($result);
  125. $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  126. if (empty($phoneNumber)) {
  127. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  128. noticeUtil::push($cacheKey . "批发商 登录失败了!获取手机号失败", '15280215347');
  129. util::success(['hasNoOpenId' => 1], '登录失败了哦');
  130. }
  131. $admin = AdminClass::getByCondition(['mobile' => $phoneNumber]);
  132. if (empty($admin)) {
  133. util::fail('请先注册或请店长添加自己为员工');
  134. }
  135. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  136. $openShop = $admin['openGhsShop'] ?? 1;
  137. if (empty($currentShopId)) {
  138. if ($openShop == 2) {
  139. util::fail('审核中');
  140. }
  141. util::fail('请先注册..');
  142. }
  143. $currentShop = ShopClass::getById($currentShopId, true);
  144. if (empty($currentShop)) {
  145. util::fail('没有找到门店69');
  146. }
  147. $mainId = $currentShop->mainId ?? 0;
  148. $adminId = $admin['id'] ?? 0;
  149. if (isset($admin['ghsMiniOpenId']) && empty($admin['ghsMiniOpenId'])) {
  150. AdminClass::updateById($adminId, ['ghsMiniOpenId' => $miniOpenId]);
  151. }
  152. $admin['miniOpenId'] = $miniOpenId;
  153. //1没有开店 2已申请待审核 3已开店
  154. $openShop = $admin['openGhsShop'] ?? 1;
  155. if ($openShop == 2) {
  156. util::fail('帐号审核中');
  157. }
  158. $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
  159. if (empty($shopAdmin)) {
  160. util::fail('请先注册...');
  161. }
  162. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  163. $shopAdmin->save();
  164. $shopAdminId = $shopAdmin->id ?? 0;
  165. //是否有切换门店的权限
  166. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  167. $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
  168. $token = jwt::getNewToken($adminId);
  169. $showDemo = 1;
  170. $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
  171. $shop = ShopClass::getById($currentShopId, true);
  172. $skCustomId = $shop->skCustomId ?? 0;
  173. $apiHost = Yii::$app->params['ghsHost'];
  174. $imgUploadApi = $apiHost . '/upload/save-file';
  175. //使用手册
  176. $cacheKey = 'close_book_' . $shopAdminId;
  177. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  178. $showBook = !empty($hasClose) ? 0 : 1;
  179. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  180. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  181. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  182. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  183. if ($ghsUpgrading == 1) {
  184. $allowShopAdminIdsStr = getenv('GHS_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
  185. $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
  186. if (!in_array($shopAdminId, $allowShopAdminIds)) {
  187. util::fail('系统升级中,稍后再试');
  188. }
  189. }
  190. $lookAllShop = 0;
  191. if (getenv('YII_ENV') == 'production') {
  192. $couldLookAllShop = dict::getDict('couldLookAllShop');
  193. if (in_array($adminId, $couldLookAllShop)) {
  194. $lookAllShop = 1;
  195. }
  196. } else {
  197. $lookAllShop = 1;
  198. }
  199. //惠雅鲜花员工不能看收入情况
  200. if (in_array($adminId, [2366, 2812, 4004])) {
  201. $shopAdmin->super = 0;
  202. }
  203. $labelList = LabelClass::getMyUnUseLabelList($mainId);
  204. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  205. util::success([
  206. 'token' => $token,
  207. 'admin' => $admin,
  208. 'shopAdminId' => $shopAdminId,
  209. 'shopId' => $currentShopId,
  210. 'switchShop' => $switchShop,
  211. 'openShop' => $openShop,
  212. 'showDemo' => $showDemo,
  213. //有小程序新版本提示更新
  214. 'update' => $remind,
  215. 'skCustomId' => $skCustomId,
  216. 'apiHost' => $apiHost,
  217. 'imgUploadApi' => $imgUploadApi,
  218. 'showBook' => $showBook,
  219. 'hasHitNavigate' => $hasHitNavigate,
  220. 'staff' => $shopAdmin,
  221. 'lookAllShop' => $lookAllShop,
  222. 'labelList' => $labelList,
  223. ]);
  224. }
  225. //本机号码一键登录 ssh 20210117
  226. public function actionPhoneLogin()
  227. {
  228. $get = Yii::$app->request->get();
  229. $access_token = $get['access_token'] ?? '';
  230. $openid = $get['openid'] ?? '';
  231. if (empty($access_token) || empty($openid)) {
  232. util::fail('参数错误');
  233. }
  234. //密钥,需要和uniCloud里的一致
  235. $secret = 'XHB2021198819640123';
  236. $params = ['access_token' => $access_token, 'openid' => $openid];
  237. $stringSignTemp = '';
  238. foreach ($params as $k => $v) {
  239. $stringSignTemp .= $k . '=' . $v . '&';
  240. }
  241. $stringSignTemp = rtrim($stringSignTemp, '&');
  242. $sign = hash_hmac('sha256', $stringSignTemp, $secret);
  243. $url = Yii::$app->params['ghsUniCloudHost'] . "/getMobileNumber?access_token=" . $access_token . "&sign=" . $sign . "&" . $stringSignTemp;
  244. $curl = new curl\Curl();
  245. $respond = $curl->get($url);
  246. Yii::info($respond);
  247. $result = json_decode($respond, true);
  248. if (isset($result['code']) == false || $result['code'] != 1) {
  249. util::fail('获取手机号失败');
  250. }
  251. $phoneNumber = $result['data']['phoneNumber'] ?? '';
  252. if (empty($phoneNumber)) {
  253. util::fail('没有获取到手机号');
  254. }
  255. $ptStyle = dict::getDict('ptStyle', 'ghs');
  256. $admin = AdminClass::getByCondition(['mobile' => $phoneNumber, 'style' => $ptStyle]);
  257. if (empty($admin)) {
  258. $adminInfo = [
  259. 'name' => $phoneNumber,
  260. 'mobile' => $phoneNumber,
  261. 'style' => $ptStyle,
  262. ];
  263. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  264. $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
  265. }
  266. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  267. $openShop = $admin['openGhsShop'] ?? 1;
  268. if (empty($currentShopId)) {
  269. if ($openShop == 2) {
  270. util::fail('审核中');
  271. }
  272. util::fail('请先注册');
  273. }
  274. $adminId = $admin['id'] ?? 0;
  275. //1没有开店 2已申请待审核 3已开店
  276. $openShop = $admin['openGhsShop'] ?? 1;
  277. if ($openShop == 2) {
  278. util::fail('帐号审核中');
  279. }
  280. $currentShop = ShopClass::getById($currentShopId, true);
  281. if (empty($currentShop)) {
  282. util::fail('没有找到门店70');
  283. }
  284. $mainId = $currentShop->mainId ?? 0;
  285. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  286. if (empty($shopAdmin)) {
  287. util::fail('请先注册');
  288. }
  289. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  290. $shopAdmin->save();
  291. $shopAdminId = $shopAdmin->id ?? 0;
  292. //是否有切换门店的权限
  293. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  294. $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
  295. $token = jwt::getNewToken($adminId);
  296. $showDemo = 1;
  297. $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
  298. $shop = ShopClass::getById($currentShopId, true);
  299. $skCustomId = $shop->skCustomId ?? 0;
  300. $apiHost = Yii::$app->params['ghsHost'];
  301. $imgUploadApi = $apiHost . '/upload/save-file';
  302. //使用手册
  303. $cacheKey = 'close_book_' . $shopAdminId;
  304. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  305. $showBook = !empty($hasClose) ? 0 : 1;
  306. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  307. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  308. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  309. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  310. if ($ghsUpgrading == 1) {
  311. $allowShopAdminIdsStr = getenv('GHS_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
  312. $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
  313. if (!in_array($shopAdminId, $allowShopAdminIds)) {
  314. util::fail('系统升级中,稍后再试');
  315. }
  316. }
  317. $lookAllShop = 0;
  318. if (getenv('YII_ENV') == 'production') {
  319. $couldLookAllShop = dict::getDict('couldLookAllShop');
  320. if (in_array($adminId, $couldLookAllShop)) {
  321. $lookAllShop = 1;
  322. }
  323. } else {
  324. $lookAllShop = 1;
  325. }
  326. //惠雅鲜花员工不能看收入情况
  327. if (in_array($adminId, [2366, 2812, 4004])) {
  328. $shopAdmin->super = 0;
  329. }
  330. $labelList = LabelClass::getMyUnUseLabelList($mainId);
  331. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  332. util::success([
  333. 'token' => $token,
  334. 'admin' => $admin,
  335. 'shopAdminId' => $shopAdminId,
  336. 'shopId' => $currentShopId,
  337. 'switchShop' => $switchShop,
  338. 'openShop' => $openShop,
  339. 'showDemo' => $showDemo,
  340. //有小程序新版本提示更新
  341. 'update' => $remind,
  342. 'skCustomId' => $skCustomId,
  343. 'apiHost' => $apiHost,
  344. 'imgUploadApi' => $imgUploadApi,
  345. 'showBook' => $showBook,
  346. 'hasHitNavigate' => $hasHitNavigate,
  347. 'staff' => $shopAdmin,
  348. 'lookAllShop' => $lookAllShop,
  349. 'labelList' => $labelList,
  350. ]);
  351. util::success(['admin' => $admin]);
  352. }
  353. //准备授权 ssh 2019.11.19
  354. public function actionPrepare()
  355. {
  356. $get = Yii::$app->request->get();
  357. $url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
  358. if (empty($url)) {
  359. util::fail('没有网址');
  360. }
  361. $account = httpUtil::getAccount($url);
  362. if (empty($account)) {
  363. util::fail('没有商家帐号');
  364. }
  365. $merchant = MerchantService::getById($account);
  366. if (empty($merchant)) {
  367. util::fail('商家无效');
  368. }
  369. /**
  370. * authScope 参数的说明
  371. * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
  372. * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
  373. * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
  374. * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
  375. */
  376. $authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
  377. $urlEncode = stringUtil::urlSafeB64Encode($url);
  378. //微信授权获取code ssh 2019.11.24
  379. $isOpen = 2;
  380. wxUtil::getCode($urlEncode, $merchant, $authScope, $isOpen);
  381. util::end();
  382. }
  383. //微信授权获取用户信息 ssh 2019.11.20
  384. public function actionGetUserInfo()
  385. {
  386. $get = Yii::$app->request->get();
  387. $code = isset($get['code']) ? $get['code'] : '';
  388. if (empty($code)) {
  389. util::fail('没有获取用户code');
  390. }
  391. if (isset($get['state']) && $get['state'] == 'authdeny') {
  392. util::fail('auth fail');
  393. }
  394. $urlEncode = $get['url'];
  395. $url = stringUtil::urlSafeBase64Decode($urlEncode);
  396. $account = httpUtil::getAccount($url);
  397. if (empty($account)) {
  398. util::stop('商店ID无效!!');
  399. }
  400. $merchant = xhMerchantService::getByAccount($account);
  401. if (empty($merchant)) {
  402. util::stop('商店无效');
  403. }
  404. $sjId = $merchant['id'];
  405. $authScope = isset($get['authScope']) ? $get['authScope'] : '';
  406. if (empty($authScope)) {
  407. util::stop('没有授权类型');
  408. }
  409. $data = wxUtil::getOpenId($code, $merchant, 2);
  410. if ($data === false) {
  411. //微信授权获取code ssh 2019.11.24
  412. wxUtil::getCode($urlEncode, $merchant, $authScope, 2);
  413. util::end();
  414. }
  415. $openId = $data['openid'];
  416. $access_token = $data['access_token'];
  417. $user = UserService::getByOpenId($openId);
  418. //用户来源
  419. $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
  420. $source = $userSource['name'];
  421. if (empty($user)) {
  422. //$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
  423. $originalInfo = [];
  424. $originalInfo['openId'] = $openId;
  425. $originalInfo['sjId'] = $sjId;
  426. //没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
  427. if ($authScope == 'snsapi_userinfo') {
  428. $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
  429. $originalInfo = array_merge($baseInfo, $originalInfo);
  430. $originalInfo['isFull'] = 1;
  431. $originalInfo['unionId'] = $baseInfo['unionid'];
  432. $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
  433. $originalInfo['nickName'] = $baseInfo['nickName'];
  434. }
  435. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  436. } else {
  437. if ($user['isFull'] == 0) {
  438. if ($authScope == 'snsapi_userinfo') {
  439. $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
  440. $originalInfo = $baseInfo;
  441. $originalInfo['isFull'] = 1;
  442. $originalInfo['unionId'] = $baseInfo['unionid'];
  443. $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
  444. $originalInfo['openId'] = $baseInfo['openid'];
  445. $originalInfo['nickName'] = $baseInfo['nickName'];
  446. $originalInfo['sjId'] = $sjId;
  447. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  448. }
  449. }
  450. }
  451. //这个的基类没有设置统一的全局变量,这里进行设置一次
  452. $userId = $user['id'];
  453. $admin = AdminService::getByCondition(['userId' => $userId]);
  454. if (empty($admin)) {
  455. util::fail('您无法访问');
  456. }
  457. $adminId = $admin['id'];
  458. //获取token
  459. $token = jwt::getNewToken($adminId);
  460. $url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
  461. $this->redirect($url);
  462. }
  463. //登陆并拿到token ssh 2019.11.23
  464. public function actionLogin()
  465. {
  466. $get = Yii::$app->request->get();
  467. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  468. if (stringUtil::isMobile($mobile) == false) {
  469. util::fail('请填写正常的手机号');
  470. }
  471. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  472. if (empty($password)) {
  473. util::fail('请输入密码');
  474. }
  475. $admin = AdminService::getByCondition(['mobile' => $mobile]);
  476. if (empty($admin)) {
  477. util::fail('请先注册吧');
  478. }
  479. if (password_verify($password, $admin['password']) == false) {
  480. util::fail('密码错误');
  481. }
  482. $adminId = $admin['id'];
  483. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'delStatus' => 0]);
  484. $sjId = $shopAdmin['sjId'] ?? 0;
  485. $shopId = $admin['currentGhsShopId'] ?? 0;
  486. if (empty($shopId)) {
  487. util::fail('没有权限登录');
  488. }
  489. //获取token
  490. $token = jwt::getNewToken($adminId);
  491. util::success(['token' => $token, 'account' => $sjId, 'shopId' => $shopId]);
  492. }
  493. //静默获取小程序用户信息
  494. public function actionMiniInfo()
  495. {
  496. //供货商平台
  497. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  498. $code = Yii::$app->request->get('code', '');
  499. $wxMiniBase = WxOpenClass::getGhsWxInfo();
  500. $appId = $wxMiniBase['miniAppId'];
  501. $appSecret = $wxMiniBase['miniAppSecret'];
  502. if (empty($appSecret)) {
  503. //没有管理店铺不允许登录
  504. util::success(['token' => '', 'number' => 1]);
  505. }
  506. $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
  507. $curl = new curl\Curl();
  508. $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
  509. $result = $curl->get($url);
  510. $arr = Json::decode($result);
  511. $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
  512. $openid = $arr['openid'] ?? '';
  513. if (empty($openid)) {
  514. //没有管理店铺不允许登录
  515. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 2]);
  516. }
  517. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
  518. Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
  519. $admin = AdminClass::getByCondition(['ghsMiniOpenId' => $openid]);
  520. if (empty($admin)) {
  521. //没有管理店铺不允许登录
  522. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 3]);
  523. }
  524. $adminId = $admin['id'];
  525. //切换账号,多个地方要同步修改,关键词 change_account
  526. // if (getenv('YII_ENV') == 'production') {
  527. // if ($adminId == 4) {
  528. // $adminId = 16020;
  529. // $admin = AdminClass::getById($adminId);
  530. // }
  531. // } else {
  532. // if ($adminId == 919) {
  533. // $adminId = 1109;
  534. // $admin = AdminClass::getById($adminId);
  535. // }
  536. // }
  537. $openShop = $admin['openGhsShop'] ?? 1;
  538. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  539. if (empty($currentShopId)) {
  540. //没有管理店铺不允许登录
  541. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 4]);
  542. }
  543. $currentShop = ShopClass::getById($currentShopId, true);
  544. if (empty($currentShop)) {
  545. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 4]);
  546. }
  547. $mainId = $currentShop->mainId ?? 0;
  548. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  549. if (empty($shopAdmin)) {
  550. //没有管理店铺不允许登录
  551. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 5]);
  552. }
  553. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  554. $shopAdmin->save();
  555. $shopAdminId = $shopAdmin->id ?? 0;
  556. //是否有切换门店的权限
  557. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  558. $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
  559. $token = jwt::getNewToken($adminId);
  560. $showDemo = 1;
  561. $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
  562. $shop = ShopClass::getById($currentShopId, true);
  563. $skCustomId = $shop->skCustomId ?? 0;
  564. $mainId = $shop->mainId ?? 0;
  565. $apiHost = Yii::$app->params['ghsHost'];
  566. $imgUploadApi = $apiHost . '/upload/save-file';
  567. //使用手册
  568. $cacheKey = 'close_book_' . $shopAdminId;
  569. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  570. $showBook = !empty($hasClose) ? 0 : 1;
  571. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  572. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  573. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  574. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  575. if ($ghsUpgrading == 1) {
  576. $allowShopAdminIdsStr = getenv('GHS_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
  577. $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
  578. if (!in_array($shopAdminId, $allowShopAdminIds)) {
  579. util::fail('系统升级中,稍后再试');
  580. }
  581. }
  582. $lookAllShop = 0;
  583. if (getenv('YII_ENV') == 'production') {
  584. $couldLookAllShop = dict::getDict('couldLookAllShop');
  585. if (in_array($adminId, $couldLookAllShop)) {
  586. $lookAllShop = 1;
  587. }
  588. } else {
  589. $lookAllShop = 1;
  590. }
  591. //惠雅鲜花员工不能看收入情况
  592. if (in_array($adminId, [2366, 2812, 4004])) {
  593. $shopAdmin->super = 0;
  594. }
  595. $labelList = LabelClass::getMyUnUseLabelList($mainId);
  596. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  597. util::success([
  598. 'token' => $token,
  599. 'admin' => $admin,
  600. 'shopAdminId' => $shopAdminId,
  601. 'shopId' => $currentShopId,
  602. 'switchShop' => $switchShop,
  603. 'openShop' => $openShop,
  604. 'showDemo' => $showDemo,
  605. //有小程序新版本提示更新
  606. 'update' => $remind,
  607. 'skCustomId' => $skCustomId,
  608. 'apiHost' => $apiHost,
  609. 'imgUploadApi' => $imgUploadApi,
  610. 'showBook' => $showBook,
  611. 'hasHitNavigate' => $hasHitNavigate,
  612. 'staff' => $shopAdmin,
  613. 'lookAllShop' => $lookAllShop,
  614. 'labelList' => $labelList,
  615. 'currentMiniOpenId' => $openid
  616. ]);
  617. }
  618. //app登陆 ssh 20211219
  619. public function actionAppLogin()
  620. {
  621. $getParams = Yii::$app->request->get();
  622. $postParams = Yii::$app->request->post();
  623. $allParams = array_merge($getParams, $postParams);
  624. $mobile = $allParams['mobile'] ?? 0;
  625. if (!stringUtil::isMobile($mobile)) {
  626. util::fail('请填写正确手机号');
  627. }
  628. $password = !empty($allParams['password']) ? $allParams['password'] : '';
  629. if (empty($password)) {
  630. util::fail('请输入密码');
  631. }
  632. $admin = AdminService::getByCondition(['mobile' => $mobile], true);
  633. if (empty($admin)) {
  634. util::fail('请先注册哦...');
  635. }
  636. if (!password_verify($password, $admin->password)) {
  637. util::fail('密码错误');
  638. }
  639. $openShop = $admin->openGhsShop ?? 1;
  640. $currentShopId = $admin->currentGhsShopId ?? 0;
  641. if (empty($currentShopId)) {
  642. if ($openShop == 2) {
  643. util::fail('审核中');
  644. }
  645. util::fail('请先注册');
  646. }
  647. $currentShop = \bizGhs\shop\classes\ShopClass::getById($currentShopId, true);
  648. if (empty($currentShop)) {
  649. util::fail('没有找到门店71');
  650. }
  651. $mainId = $currentShop->mainId ?? 0;
  652. $adminId = $admin->id;
  653. $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  654. if (empty($shopAdmin)) {
  655. util::fail('您没有权限');
  656. }
  657. if ($shopAdmin->delStatus == 1) {
  658. util::fail('您没有权限哦');
  659. }
  660. if ($shopAdmin->status == 0) {
  661. util::fail("您的账号已被冻结");
  662. }
  663. $token = jwt::getNewToken($adminId);
  664. $shopAdminId = $shopAdmin->id ?? 0;
  665. //是否有切换门店的权限
  666. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  667. //1没有开店 2已申请待审核 3已开店
  668. $openShop = $admin['openGhsShop'] ?? 1;
  669. $showDemo = 1;
  670. $shop = ShopClass::getById($currentShopId, true);
  671. $skCustomId = $shop->skCustomId ?? 0;
  672. $apiHost = Yii::$app->params['ghsHost'];
  673. $imgUploadApi = $apiHost . '/upload/save-file';
  674. //使用手册
  675. $cacheKey = 'close_book_' . $shopAdminId;
  676. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  677. $showBook = !empty($hasClose) ? 0 : 1;
  678. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  679. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  680. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  681. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  682. if ($ghsUpgrading == 1) {
  683. $allowShopAdminIdsStr = getenv('GHS_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
  684. $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
  685. if (!in_array($shopAdminId, $allowShopAdminIds)) {
  686. util::fail('系统升级中,稍后再试');
  687. }
  688. }
  689. $lookAllShop = 0;
  690. if (getenv('YII_ENV') == 'production') {
  691. $couldLookAllShop = dict::getDict('couldLookAllShop');
  692. if (in_array($adminId, $couldLookAllShop)) {
  693. $lookAllShop = 1;
  694. }
  695. } else {
  696. $lookAllShop = 1;
  697. }
  698. //惠雅鲜花员工不能看收入情况
  699. if (in_array($adminId, [2366, 2812, 4004])) {
  700. $shopAdmin->super = 0;
  701. }
  702. $labelList = LabelClass::getMyUnUseLabelList($mainId);
  703. //把设备状态更新为登录
  704. if (isset($allParams['deviceId']) && $allParams['deviceId'] != '') {
  705. $device = \bizGhs\device\classes\GhsDeviceClass::getByCondition(['shopId'=>$currentShopId, 'deviceId'=>$allParams['deviceId']], true);
  706. if ($device) {
  707. $device->status = 1;
  708. $device->save();
  709. }
  710. }
  711. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  712. util::success([
  713. 'token' => $token,
  714. 'admin' => $admin,
  715. 'shopAdminId' => $shopAdminId,
  716. 'shopId' => $currentShopId,
  717. 'switchShop' => $switchShop,
  718. 'openShop' => $openShop,
  719. 'showDemo' => $showDemo,
  720. //有小程序新版本提示更新
  721. 'update' => 0,
  722. 'skCustomId' => $skCustomId,
  723. 'apiHost' => $apiHost,
  724. 'imgUploadApi' => $imgUploadApi,
  725. 'showBook' => $showBook,
  726. 'hasHitNavigate' => $hasHitNavigate,
  727. 'staff' => $shopAdmin,
  728. 'lookAllShop' => $lookAllShop,
  729. 'labelList' => $labelList,
  730. ]);
  731. }
  732. //最新版本 ssh 20220211
  733. public function actionGetApkVersion()
  734. {
  735. $version = getenv('GHS_NEW_APK_VERSION') == false ? '100' : getenv('GHS_NEW_APK_VERSION');
  736. $mustUpdate = getenv('GHS_NEW_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('GHS_NEW_APK_VERSION_MUST_UPDATE');
  737. $updateText = '零售系统上线升级';
  738. util::success(['version' => $version, 'mustUpdate' => $mustUpdate, 'updateText' => $updateText]);
  739. }
  740. //收银台apk更新 ssh 20220310
  741. public function actionGetPadApkVersion()
  742. {
  743. $version = getenv('GHS_NEW_PAD_APK_VERSION') == false ? '100' : getenv('GHS_NEW_PAD_APK_VERSION');
  744. $mustUpdate = getenv('GHS_NEW_PAD_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('GHS_NEW_PAD_APK_VERSION_MUST_UPDATE');
  745. util::success(['version' => $version, 'mustUpdate' => $mustUpdate]);
  746. }
  747. //注册使用协议 ssh 20220327
  748. public function actionRegister()
  749. {
  750. $html = AgreementClass::xhbRegister(1);
  751. util::success(['html' => $html]);
  752. }
  753. //隐私政策 ssh 20220327
  754. public function actionPrivacy()
  755. {
  756. $html = AgreementClass::xhbPrivacy(1);
  757. util::success(['html' => $html]);
  758. }
  759. /**
  760. * 【用途】发送登录短信验证码
  761. * 【为什么】供短信登录功能获取验证码,并包含防刷安全限制(单手机号60秒锁、每日上限5条)
  762. */
  763. public function actionSendLoginSms()
  764. {
  765. $getParams = Yii::$app->request->get();
  766. $postParams = Yii::$app->request->post();
  767. $allParams = array_merge($getParams, $postParams);
  768. $mobile = $allParams['mobile'] ?? '';
  769. $captchaVerifyParam = $allParams['captchaVerifyParam'] ?? '';
  770. if (!stringUtil::isMobile($mobile)) {
  771. util::fail('请填写正确手机号');
  772. }
  773. // 1. 验证阿里云人机验证码(生产环境强制,本地环境若未传则容灾放行)
  774. if (empty($captchaVerifyParam)) {
  775. if (Yii::getAlias('@env') !== 'local') {
  776. util::fail('请先完成人机验证');
  777. }
  778. } else {
  779. if (!$this->verifyAliyunCaptcha($captchaVerifyParam)) {
  780. util::fail('人机验证未通过,请重试');
  781. }
  782. }
  783. // 2. 安全检查:单手机号 60 秒防刷
  784. $lockKey = 'LOGIN_SMS_LOCK_' . $mobile;
  785. if (Yii::$app->redis->executeCommand('GET', [$lockKey])) {
  786. util::fail('发送过于频繁,请稍后再试');
  787. }
  788. // 3. 安全检查:单手机号每日上限 5 条
  789. $dayKey = 'LOGIN_SMS_COUNT_' . date('Ymd') . '_' . $mobile;
  790. $sendCount = (int)Yii::$app->redis->executeCommand('GET', [$dayKey]);
  791. if ($sendCount >= 5) {
  792. util::fail('该手机号今日获取验证码已达上限');
  793. }
  794. // 4. 生成 6 位随机验证码并保存至 Redis(有效期 5 分钟)
  795. $code = (string)rand(100000, 999999);
  796. $codeCacheKey = 'LOGIN_SMS_CODE_' . $mobile;
  797. Yii::$app->redis->executeCommand('SETEX', [$codeCacheKey, 300, $code]);
  798. // 5. 调用系统自带的限流发送组件 (内置了 IP 60秒锁和每日15条限制)
  799. $minute = 5;
  800. sms::send($mobile . ',' . $code . ',' . $minute, '登录验证码:{$var},{$var}分钟内有效');
  801. // 6. 写入单手机号限制锁
  802. Yii::$app->redis->executeCommand('SETEX', [$lockKey, 60, '1']);
  803. Yii::$app->redis->executeCommand('SETEX', [$dayKey, 86400, $sendCount + 1]);
  804. util::complete('验证码发送成功');
  805. }
  806. /**
  807. * 【用途】校验阿里云验证码2.0
  808. * 【为什么】利用已安装的 alibabacloud/client 进行通用 RPC 调用,校验前端传来的验证参数
  809. */
  810. private function verifyAliyunCaptcha($captchaVerifyParam)
  811. {
  812. if (empty($captchaVerifyParam)) {
  813. return false;
  814. }
  815. try {
  816. $accessKeyId = Yii::$app->params['aliyun']['accessKeyId'] ?? Yii::$app->params['accessKeyId'] ?? '';
  817. $accessKeySecret = Yii::$app->params['aliyun']['accessKeySecret'] ?? Yii::$app->params['accessKeySecret'] ?? '';
  818. $sceneId = Yii::$app->params['aliyun']['captchaSceneId'] ?? Yii::$app->params['aliyunCaptchaSceneId'] ?? 'YOUR_SCENE_ID';
  819. if (empty($accessKeyId) || empty($accessKeySecret)) {
  820. Yii::error("阿里云验证码校验失败:未配置 AccessKey");
  821. return false;
  822. }
  823. // 初始化阿里云客户端
  824. \AlibabaCloud\Client\AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
  825. ->regionId('cn-hangzhou')
  826. ->asDefaultClient();
  827. // 发起通用 RPC 请求调用 VerifyIntelligentCaptcha
  828. $result = \AlibabaCloud\Client\AlibabaCloud::rpc()
  829. ->product('Captcha')
  830. ->version('2023-03-05')
  831. ->action('VerifyIntelligentCaptcha')
  832. ->method('POST')
  833. ->scheme('https')
  834. ->options([
  835. 'query' => [
  836. 'CaptchaVerifyParam' => $captchaVerifyParam,
  837. 'SceneId' => $sceneId,
  838. ],
  839. ])
  840. ->request();
  841. $data = $result->toArray();
  842. Yii::info("阿里云验证码返回结果: " . json_encode($data), 'captcha');
  843. // 兼容可能包裹在 Result 节点下或扁平结构
  844. $verifyResult = $data['Result']['VerifyResult'] ?? $data['VerifyResult'] ?? null;
  845. if ($verifyResult === true) {
  846. return true;
  847. }
  848. return false;
  849. } catch (\Exception $e) {
  850. Yii::error("阿里云验证码校验异常: " . $e->getMessage());
  851. // 容灾策略:如果是本地环境,可以放行
  852. if (Yii::getAlias('@env') === 'local') {
  853. return true;
  854. }
  855. return false;
  856. }
  857. }
  858. /**
  859. * 【用途】短信验证码登录
  860. * 【为什么】提供免密码快捷登录方式,验证通过后自动签发 JWT Token 并返回商家后台所需的所有初始化数据
  861. */
  862. public function actionSmsLogin()
  863. {
  864. $getParams = Yii::$app->request->get();
  865. $postParams = Yii::$app->request->post();
  866. $allParams = array_merge($getParams, $postParams);
  867. $mobile = $allParams['mobile'] ?? '';
  868. $code = $allParams['code'] ?? '';
  869. if (empty($mobile) || empty($code)) {
  870. util::fail('手机号和验证码不能为空');
  871. }
  872. if (!stringUtil::isMobile($mobile)) {
  873. util::fail('请填写正确手机号');
  874. }
  875. // 1. 校验验证码
  876. $codeCacheKey = 'LOGIN_SMS_CODE_' . $mobile;
  877. $savedCode = Yii::$app->redis->executeCommand('GET', [$codeCacheKey]);
  878. if (empty($savedCode) || $savedCode !== $code) {
  879. util::fail('验证码错误或已过期');
  880. }
  881. // 2. 验证通过,立即销毁验证码以确保一次性使用
  882. Yii::$app->redis->executeCommand('DEL', [$codeCacheKey]);
  883. // 3. 查找用户并执行登录
  884. $admin = AdminService::getByCondition(['mobile' => $mobile], true);
  885. if (empty($admin)) {
  886. util::fail('请先注册哦...');
  887. }
  888. $openShop = $admin->openGhsShop ?? 1;
  889. $currentShopId = $admin->currentGhsShopId ?? 0;
  890. if (empty($currentShopId)) {
  891. if ($openShop == 2) {
  892. util::fail('审核中');
  893. }
  894. util::fail('请先注册');
  895. }
  896. $currentShop = \bizGhs\shop\classes\ShopClass::getById($currentShopId, true);
  897. if (empty($currentShop)) {
  898. util::fail('没有找到门店71');
  899. }
  900. $mainId = $currentShop->mainId ?? 0;
  901. $adminId = $admin->id;
  902. $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  903. if (empty($shopAdmin)) {
  904. util::fail('您没有权限');
  905. }
  906. if ($shopAdmin->delStatus == 1) {
  907. util::fail('您没有权限哦');
  908. }
  909. if ($shopAdmin->status == 0) {
  910. util::fail("您的账号已被冻结");
  911. }
  912. $token = jwt::getNewToken($adminId);
  913. $shopAdminId = $shopAdmin->id ?? 0;
  914. //是否有切换门店的权限
  915. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  916. //1没有开店 2已申请待审核 3已开店
  917. $openShop = $admin['openGhsShop'] ?? 1;
  918. $showDemo = 1;
  919. $shop = ShopClass::getById($currentShopId, true);
  920. $skCustomId = $shop->skCustomId ?? 0;
  921. $apiHost = Yii::$app->params['ghsHost'];
  922. $imgUploadApi = $apiHost . '/upload/save-file';
  923. //使用手册
  924. $cacheKey = 'close_book_' . $shopAdminId;
  925. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  926. $showBook = !empty($hasClose) ? 0 : 1;
  927. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  928. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  929. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  930. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  931. if ($ghsUpgrading == 1) {
  932. $allowShopAdminIdsStr = getenv('GHS_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
  933. $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
  934. if (!in_array($shopAdminId, $allowShopAdminIds)) {
  935. util::fail('系统升级中,稍后再试');
  936. }
  937. }
  938. $lookAllShop = 0;
  939. if (getenv('YII_ENV') == 'production') {
  940. $couldLookAllShop = dict::getDict('couldLookAllShop');
  941. if (in_array($adminId, $couldLookAllShop)) {
  942. $lookAllShop = 1;
  943. }
  944. } else {
  945. $lookAllShop = 1;
  946. }
  947. //惠雅鲜花员工不能看收入情况
  948. if (in_array($adminId, [2366, 2812, 4004])) {
  949. $shopAdmin->super = 0;
  950. }
  951. $labelList = LabelClass::getMyUnUseLabelList($mainId);
  952. //把设备状态更新为登录
  953. if (isset($allParams['deviceId']) && $allParams['deviceId'] != '') {
  954. $device = \bizGhs\device\classes\GhsDeviceClass::getByCondition(['shopId'=>$currentShopId, 'deviceId'=>$allParams['deviceId']], true);
  955. if ($device) {
  956. $device->status = 1;
  957. $device->save();
  958. }
  959. }
  960. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  961. util::success([
  962. 'token' => $token,
  963. 'admin' => $admin,
  964. 'shopAdminId' => $shopAdminId,
  965. 'shopId' => $currentShopId,
  966. 'switchShop' => $switchShop,
  967. 'openShop' => $openShop,
  968. 'showDemo' => $showDemo,
  969. //有小程序新版本提示更新
  970. 'update' => 0,
  971. 'skCustomId' => $skCustomId,
  972. 'apiHost' => $apiHost,
  973. 'imgUploadApi' => $imgUploadApi,
  974. 'showBook' => $showBook,
  975. 'hasHitNavigate' => $hasHitNavigate,
  976. 'staff' => $shopAdmin,
  977. 'lookAllShop' => $lookAllShop,
  978. 'labelList' => $labelList,
  979. ]);
  980. }
  981. }