AuthController.php 28 KB

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