AuthController.php 26 KB

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