AuthController.php 25 KB

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