AuthController.php 27 KB

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