AuthController.php 24 KB

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