AuthController.php 29 KB

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