AuthController.php 28 KB

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