AuthController.php 25 KB

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