AuthController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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, [2366, 2812, 4004])) {
  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, [2366, 2812, 4004])) {
  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. $sjId = $shopAdmin['sjId'] ?? 0;
  402. $shopId = $admin['currentGhsShopId'] ?? 0;
  403. if (empty($shopId)) {
  404. util::fail('没有权限登录');
  405. }
  406. //获取token
  407. $token = jwt::getNewToken($adminId);
  408. util::success(['token' => $token, 'account' => $sjId, 'shopId' => $shopId]);
  409. }
  410. //静默获取小程序用户信息
  411. public function actionMiniInfo()
  412. {
  413. //供货商平台
  414. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  415. $code = Yii::$app->request->get('code', '');
  416. $wxMiniBase = WxOpenClass::getGhsWxInfo();
  417. $appId = $wxMiniBase['miniAppId'];
  418. $appSecret = $wxMiniBase['miniAppSecret'];
  419. if (empty($appSecret)) {
  420. //没有管理店铺不允许登录
  421. util::success(['token' => '', 'number' => 1]);
  422. }
  423. $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
  424. $curl = new curl\Curl();
  425. $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
  426. $result = $curl->get($url);
  427. $arr = Json::decode($result);
  428. $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
  429. $openid = $arr['openid'] ?? '';
  430. if (empty($openid)) {
  431. //没有管理店铺不允许登录
  432. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 2]);
  433. }
  434. $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
  435. Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
  436. $admin = AdminClass::getByCondition(['ghsMiniOpenId' => $openid]);
  437. if (empty($admin)) {
  438. //没有管理店铺不允许登录
  439. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 3]);
  440. }
  441. $adminId = $admin['id'];
  442. $openShop = $admin['openGhsShop'] ?? 1;
  443. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  444. if (empty($currentShopId)) {
  445. //没有管理店铺不允许登录
  446. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 4]);
  447. }
  448. $currentShop = ShopClass::getById($currentShopId, true);
  449. if (empty($currentShop)) {
  450. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 4]);
  451. }
  452. $mainId = $currentShop->mainId ?? 0;
  453. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  454. if (empty($shopAdmin)) {
  455. //没有管理店铺不允许登录
  456. util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 5]);
  457. }
  458. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  459. $shopAdmin->save();
  460. $shopAdminId = $shopAdmin->id ?? 0;
  461. //是否有切换门店的权限
  462. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  463. $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
  464. $token = jwt::getNewToken($adminId);
  465. $showDemo = 1;
  466. $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
  467. $shop = ShopClass::getById($currentShopId, true);
  468. $skCustomId = $shop->skCustomId ?? 0;
  469. $apiHost = Yii::$app->params['ghsHost'];
  470. $imgUploadApi = $apiHost . '/upload/save-file';
  471. //使用手册
  472. $cacheKey = 'close_book_' . $shopAdminId;
  473. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  474. $showBook = !empty($hasClose) ? 0 : 1;
  475. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  476. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  477. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  478. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  479. if ($ghsUpgrading == 1) {
  480. util::fail('系统升级中,稍后再试');
  481. }
  482. $lookAllShop = 0;
  483. if (getenv('YII_ENV') == 'production') {
  484. if ($adminId == 4 || $adminId == 51) {
  485. $lookAllShop = 1;
  486. }
  487. } else {
  488. $lookAllShop = 1;
  489. }
  490. //惠雅鲜花员工不能看收入情况
  491. if (in_array($adminId, [2366, 2812, 4004])) {
  492. $shopAdmin->super = 0;
  493. }
  494. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  495. util::success([
  496. 'token' => $token,
  497. 'admin' => $admin,
  498. 'shopAdminId' => $shopAdminId,
  499. 'shopId' => $currentShopId,
  500. 'switchShop' => $switchShop,
  501. 'openShop' => $openShop,
  502. 'showDemo' => $showDemo,
  503. //有小程序新版本提示更新
  504. 'update' => $remind,
  505. 'skCustomId' => $skCustomId,
  506. 'apiHost' => $apiHost,
  507. 'imgUploadApi' => $imgUploadApi,
  508. 'showBook' => $showBook,
  509. 'hasHitNavigate' => $hasHitNavigate,
  510. 'staff' => $shopAdmin,
  511. 'lookAllShop' => $lookAllShop,
  512. ]);
  513. }
  514. //app登陆 ssh 20211219
  515. public function actionAppLogin()
  516. {
  517. $get = Yii::$app->request->get();
  518. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  519. if (stringUtil::isMobile($mobile) == false) {
  520. util::fail('请填写正确手机号');
  521. }
  522. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  523. if (empty($password)) {
  524. util::fail('请输入密码');
  525. }
  526. $admin = AdminService::getByCondition(['mobile' => $mobile], true);
  527. if (empty($admin)) {
  528. util::fail('请先注册哦...');
  529. }
  530. if (password_verify($password, $admin->password) == false) {
  531. util::fail('密码错误');
  532. }
  533. $openShop = $admin->openGhsShop ?? 1;
  534. $currentShopId = $admin->currentGhsShopId ?? 0;
  535. if (empty($currentShopId)) {
  536. if ($openShop == 2) {
  537. util::fail('审核中');
  538. }
  539. util::fail('请先注册');
  540. }
  541. $currentShop = \bizGhs\shop\classes\ShopClass::getById($currentShopId, true);
  542. if (empty($currentShop)) {
  543. util::fail('没有找到门店');
  544. }
  545. $mainId = $currentShop->mainId ?? 0;
  546. $adminId = $admin->id;
  547. $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  548. if (empty($shopAdmin)) {
  549. util::fail('您没有权限');
  550. }
  551. if ($shopAdmin->delStatus == 1) {
  552. util::fail('您没有权限哦');
  553. }
  554. if ($shopAdmin->status == 0) {
  555. util::fail("您的账号已被冻结");
  556. }
  557. $token = jwt::getNewToken($adminId);
  558. $shopAdminId = $shopAdmin->id ?? 0;
  559. //是否有切换门店的权限
  560. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  561. //1没有开店 2已申请待审核 3已开店
  562. $openShop = $admin['openGhsShop'] ?? 1;
  563. $showDemo = 1;
  564. $shop = ShopClass::getById($currentShopId, true);
  565. $skCustomId = $shop->skCustomId ?? 0;
  566. $apiHost = Yii::$app->params['ghsHost'];
  567. $imgUploadApi = $apiHost . '/upload/save-file';
  568. //使用手册
  569. $cacheKey = 'close_book_' . $shopAdminId;
  570. $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  571. $showBook = !empty($hasClose) ? 0 : 1;
  572. $cacheKey = 'has_hit_navigate_' . $shopAdminId;
  573. $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  574. $hasHitNavigate = !empty($hasHit) ? 1 : 0;
  575. $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
  576. if ($ghsUpgrading == 1) {
  577. util::fail('系统升级中,稍后再试');
  578. }
  579. $lookAllShop = 0;
  580. if (getenv('YII_ENV') == 'production') {
  581. if ($adminId == 4 || $adminId == 51) {
  582. $lookAllShop = 1;
  583. }
  584. } else {
  585. $lookAllShop = 1;
  586. }
  587. //惠雅鲜花员工不能看收入情况
  588. if (in_array($adminId, [2366, 2812, 4004])) {
  589. $shopAdmin->super = 0;
  590. }
  591. //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
  592. util::success([
  593. 'token' => $token,
  594. 'admin' => $admin,
  595. 'shopAdminId' => $shopAdminId,
  596. 'shopId' => $currentShopId,
  597. 'switchShop' => $switchShop,
  598. 'openShop' => $openShop,
  599. 'showDemo' => $showDemo,
  600. //有小程序新版本提示更新
  601. 'update' => 0,
  602. 'skCustomId' => $skCustomId,
  603. 'apiHost' => $apiHost,
  604. 'imgUploadApi' => $imgUploadApi,
  605. 'showBook' => $showBook,
  606. 'hasHitNavigate' => $hasHitNavigate,
  607. 'staff' => $shopAdmin,
  608. 'lookAllShop' => $lookAllShop,
  609. ]);
  610. }
  611. //最新版本 ssh 20220211
  612. public function actionGetApkVersion()
  613. {
  614. $version = getenv('GHS_NEW_APK_VERSION') == false ? '100' : getenv('GHS_NEW_APK_VERSION');
  615. $mustUpdate = getenv('GHS_NEW_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('GHS_NEW_APK_VERSION_MUST_UPDATE');
  616. $updateText = '增加退货报损流程;入库改价流程优化;新增打价格码';
  617. util::success(['version' => $version, 'mustUpdate' => $mustUpdate, 'updateText' => $updateText]);
  618. }
  619. //收银台apk更新 ssh 20220310
  620. public function actionGetPadApkVersion()
  621. {
  622. $version = getenv('GHS_NEW_PAD_APK_VERSION') == false ? '100' : getenv('GHS_NEW_PAD_APK_VERSION');
  623. $mustUpdate = getenv('GHS_NEW_PAD_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('GHS_NEW_PAD_APK_VERSION_MUST_UPDATE');
  624. util::success(['version' => $version, 'mustUpdate' => $mustUpdate]);
  625. }
  626. //注册使用协议 ssh 20220327
  627. public function actionRegister()
  628. {
  629. $html = AgreementClass::xhbRegister(0);
  630. util::success(['html' => $html]);
  631. }
  632. //隐私政策 ssh 20220327
  633. public function actionPrivacy()
  634. {
  635. $html = AgreementClass::xhbPrivacy(0);
  636. util::success(['html' => $html]);
  637. }
  638. }