AuthController.php 25 KB

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