AuthController.php 28 KB

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