AuthController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizHd\admin\classes\ShopAdminClass;
  6. use bizHd\admin\services\ShopAdminService;
  7. use bizHd\admin\services\AdminService;
  8. use bizHd\user\classes\UserClass;
  9. use bizHd\wx\services\WxOpenService;
  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. * 用户登陆
  26. */
  27. class AuthController extends PublicController
  28. {
  29. //微信手机号一键登录 ssh 20210121
  30. public function actionWxMobileLogin()
  31. {
  32. $post = Yii::$app->request->post();
  33. $iv = $post['iv'];
  34. $encryptedData = $post['encryptedData'];
  35. $merchant = WxOpenService::getWxMiniBase();
  36. $appId = $merchant['miniAppId'];
  37. $miniOpenId = $post['miniOpenId'] ?? '';
  38. if (empty($miniOpenId)) {
  39. util::success(['hasNoOpenId' => 1], '登录失败');
  40. }
  41. $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
  42. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  43. if (empty($sessionKey)) {
  44. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  45. noticeUtil::push($cacheKey . " 登录失败!!sessionKey空的", '15280215347');
  46. util::success(['hasNoOpenId' => 1], '登录失败');
  47. }
  48. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  49. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  50. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  51. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  52. if ($errCode != 0) {
  53. Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
  54. noticeUtil::push($cacheKey . " 登录失败!!!!sessionKey异常", '15280215347');
  55. util::success(['hasNoOpenId' => 1], '登录失败');
  56. }
  57. $arr = Json::decode($result);
  58. $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  59. if (empty($phoneNumber)) {
  60. noticeUtil::push($cacheKey . " 登录失败了!获取手机号失败", '15280215347');
  61. util::success(['hasNoOpenId' => 1], '登录失败');
  62. }
  63. $admin = AdminService::getByCondition(['mobile' => $phoneNumber]);
  64. if (empty($admin)) {
  65. util::fail('请先注册');
  66. }
  67. $adminId = $admin['id'];
  68. AdminClass::updateById($adminId, ['miniOpenId' => $miniOpenId]);
  69. $admin['miniOpenId'] = $miniOpenId;
  70. $openShop = $admin['openShop'] ?? 1;
  71. $currentShopId = $admin['currentShopId'] ?? 0;
  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. $pfShopId = $currentShop->pfShopId ?? 0;
  83. $onlyCg = $currentShop->onlyCg ?? 1;
  84. $mainId = $currentShop->mainId ?? 0;
  85. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
  86. if (empty($shopAdmin)) {
  87. util::fail('没有权限操作');
  88. }
  89. if ($shopAdmin->status == 0) {
  90. util::fail("您的账号已冻结");
  91. }
  92. $token = jwt::getNewToken($adminId);
  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. $prefix = imgUtil::getPrefix();
  99. $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
  100. $admin['avatar'] = $avatar;
  101. $showDemo = 1;
  102. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  103. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  104. if ($hdUpgrading == 1) {
  105. util::fail('系统升级中,稍后再试');
  106. }
  107. $apiHost = Yii::$app->params['hdHost'];
  108. $imgUploadApi = $apiHost . '/upload/save-file';
  109. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  110. util::success([
  111. 'token' => $token,
  112. 'admin' => $admin,
  113. 'shopId' => $currentShopId,
  114. 'shopAdminId' => $shopAdminId,
  115. 'switchShop' => $switchShop,
  116. 'pfShopId' => $pfShopId,
  117. 'onlyCg' => $onlyCg,
  118. 'showDemo' => $showDemo,
  119. 'imgUploadApi' => $imgUploadApi,
  120. //有小程序新版本提示更新
  121. 'update' => $remind,
  122. ]);
  123. }
  124. //app登陆 ssh 20211219
  125. public function actionAppLogin()
  126. {
  127. $get = Yii::$app->request->get();
  128. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  129. if (stringUtil::isMobile($mobile) == false) {
  130. util::fail('请填写正确手机号');
  131. }
  132. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  133. if (empty($password)) {
  134. util::fail('请输入密码');
  135. }
  136. $admin = AdminService::getByCondition(['mobile' => $mobile]);
  137. if (empty($admin)) {
  138. util::fail('请先注册...');
  139. }
  140. if (password_verify($password, $admin['password']) == false) {
  141. util::fail('密码错误');
  142. }
  143. $openShop = $admin['openShop'] ?? 1;
  144. $currentShopId = $admin['currentShopId'] ?? 0;
  145. if (empty($currentShopId)) {
  146. if ($openShop == 2) {
  147. util::fail('审核中');
  148. }
  149. util::fail('请先注册');
  150. }
  151. $currentShop = \bizHd\shop\classes\ShopClass::getById($currentShopId, true);
  152. if (empty($currentShop)) {
  153. util::fail('没有找到门店');
  154. }
  155. $mainId = $currentShop->mainId ?? 0;
  156. $pfShopId = $currentShop->pfShopId ?? 0;
  157. $onlyCg = $currentShop->onlyCg ?? 1;
  158. $adminId = $admin['id'];
  159. $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  160. if (empty($shopAdmin)) {
  161. util::fail('没有权限操作');
  162. }
  163. if ($shopAdmin->status == 0) {
  164. util::fail("您的账号已冻结");
  165. }
  166. if ($shopAdmin->delStatus == 1) {
  167. util::fail("您的账号已删除");
  168. }
  169. $token = jwt::getNewToken($adminId);
  170. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  171. $shopAdmin->save();
  172. $shopAdminId = $shopAdmin->id ?? 0;
  173. //是否有切换门店的权限
  174. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  175. $prefix = imgUtil::getPrefix();
  176. $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
  177. $admin['avatar'] = $avatar;
  178. $showDemo = 1;
  179. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  180. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  181. if ($hdUpgrading == 1) {
  182. util::fail('系统升级中,稍后再试');
  183. }
  184. $apiHost = Yii::$app->params['hdHost'];
  185. $imgUploadApi = $apiHost . '/upload/save-file';
  186. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  187. util::success([
  188. 'token' => $token,
  189. 'admin' => $admin,
  190. 'shopId' => $currentShopId,
  191. 'shopAdminId' => $shopAdminId,
  192. 'switchShop' => $switchShop,
  193. 'pfShopId' => $pfShopId,
  194. 'onlyCg' => $onlyCg,
  195. 'imgUploadApi' => $imgUploadApi,
  196. 'showDemo' => $showDemo,
  197. //有小程序新版本提示更新
  198. 'update' => $remind,
  199. ]);
  200. }
  201. //本机号码一键登录 ssh 20210117
  202. public function actionPhoneLogin()
  203. {
  204. $get = Yii::$app->request->get();
  205. $access_token = $get['access_token'] ?? '';
  206. $openid = $get['openid'] ?? '';
  207. if (empty($access_token) || empty($openid)) {
  208. util::fail('参数错误');
  209. }
  210. //密钥,需要和uniCloud里的一致
  211. $secret = 'XHB2021198819640123';
  212. $params = ['access_token' => $access_token, 'openid' => $openid];
  213. $stringSignTemp = '';
  214. foreach ($params as $k => $v) {
  215. $stringSignTemp .= $k . '=' . $v . '&';
  216. }
  217. $stringSignTemp = rtrim($stringSignTemp, '&');
  218. $sign = hash_hmac('sha256', $stringSignTemp, $secret);
  219. $url = Yii::$app->params['hdUniCloudHost'] . "/getMobileNumber?access_token=" . $access_token . "&sign=" . $sign . "&" . $stringSignTemp;
  220. $curl = new curl\Curl();
  221. $respond = $curl->get($url);
  222. Yii::info($respond);
  223. $result = json_decode($respond, true);
  224. if (isset($result['code']) == false || $result['code'] != 1) {
  225. util::fail('获取手机号失败');
  226. }
  227. $phoneNumber = $result['data']['phoneNumber'] ?? '';
  228. if (empty($phoneNumber)) {
  229. util::fail('没有获取到手机号');
  230. }
  231. $admin = AdminService::getByCondition(['mobile' => $phoneNumber]);
  232. if (empty($admin)) {
  233. util::fail('请先注册');
  234. }
  235. $openShop = $admin['openShop'] ?? 1;
  236. $currentShopId = $admin['currentShopId'] ?? 0;
  237. if (empty($currentShopId)) {
  238. if ($openShop == 2) {
  239. util::fail('审核中');
  240. }
  241. util::fail('请先注册');
  242. }
  243. $currentShop = ShopClass::getById($currentShopId, true);
  244. if (empty($currentShop)) {
  245. util::fail('登录失败,没有找到门店');
  246. }
  247. $pfShopId = $currentShop->pfShopId ?? 0;
  248. $onlyCg = $currentShop->onlyCg ?? 1;
  249. $adminId = $admin['id'];
  250. $mainId = $currentShop->mainId ?? 0;
  251. $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  252. if (empty($shopAdmin)) {
  253. util::fail('没有权限操作');
  254. }
  255. if ($shopAdmin->status == 0) {
  256. util::fail("您的账号已冻结");
  257. }
  258. if ($shopAdmin->delStatus == 1) {
  259. util::fail("您的账号已删除");
  260. }
  261. $token = jwt::getNewToken($adminId);
  262. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  263. $shopAdmin->save();
  264. $shopAdminId = $shopAdmin->id ?? 0;
  265. //是否有切换门店的权限
  266. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  267. $prefix = imgUtil::getPrefix();
  268. $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
  269. $admin['avatar'] = $avatar;
  270. $showDemo = 1;
  271. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  272. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  273. if ($hdUpgrading == 1) {
  274. util::fail('系统升级中,稍后再试');
  275. }
  276. $apiHost = Yii::$app->params['hdHost'];
  277. $imgUploadApi = $apiHost . '/upload/save-file';
  278. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  279. util::success([
  280. 'token' => $token,
  281. 'admin' => $admin,
  282. 'shopId' => $currentShopId,
  283. 'shopAdminId' => $shopAdminId,
  284. 'pfShopId' => $pfShopId,
  285. 'onlyCg' => $onlyCg,
  286. 'switchShop' => $switchShop,
  287. 'showDemo' => $showDemo,
  288. 'imgUploadApi' => $imgUploadApi,
  289. //有小程序新版本提示更新
  290. 'update' => $remind,
  291. ]);
  292. }
  293. //准备授权 ssh 2019.11.19
  294. public function actionPrepare()
  295. {
  296. $get = Yii::$app->request->get();
  297. $url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
  298. if (empty($url)) {
  299. util::fail('没有网址');
  300. }
  301. $account = httpUtil::getAccount($url);
  302. if (empty($account)) {
  303. util::fail('没有商家帐号');
  304. }
  305. $merchant = MerchantService::getById($account);
  306. if (empty($merchant)) {
  307. util::fail('商家无效');
  308. }
  309. /**
  310. * authScope 参数的说明
  311. * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
  312. * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
  313. * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
  314. * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
  315. */
  316. $authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
  317. $urlEncode = stringUtil::urlSafeB64Encode($url);
  318. //微信授权获取code ssh 2019.11.24
  319. $isOpen = 1;
  320. wxUtil::getCode($urlEncode, $merchant, $authScope, $isOpen);
  321. util::end();
  322. }
  323. //微信授权获取用户信息 ssh 2019.11.20
  324. public function actionGetUserInfo()
  325. {
  326. $get = Yii::$app->request->get();
  327. $code = isset($get['code']) ? $get['code'] : '';
  328. if (empty($code)) {
  329. util::fail('没有获取用户code');
  330. }
  331. if (isset($get['state']) && $get['state'] == 'authdeny') {
  332. util::fail('auth fail');
  333. }
  334. $urlEncode = $get['url'];
  335. $url = stringUtil::urlSafeBase64Decode($urlEncode);
  336. $account = httpUtil::getAccount($url);
  337. if (empty($account)) {
  338. util::stop('商店ID无效!!');
  339. }
  340. $merchant = xhMerchantService::getByAccount($account);
  341. if (empty($merchant)) {
  342. util::stop('商店无效');
  343. }
  344. $sjId = $merchant['id'];
  345. $authScope = isset($get['authScope']) ? $get['authScope'] : '';
  346. if (empty($authScope)) {
  347. util::stop('没有授权类型');
  348. }
  349. $data = wxUtil::getOpenId($code, $merchant, 1);
  350. if ($data === false) {
  351. //微信授权获取code ssh 2019.11.24
  352. wxUtil::getCode($urlEncode, $merchant, $authScope, 1);
  353. util::end();
  354. }
  355. $openId = $data['openid'];
  356. $access_token = $data['access_token'];
  357. $user = UserService::getByOpenId($openId);
  358. //用户来源
  359. $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
  360. $source = $userSource['name'];
  361. if (empty($user)) {
  362. //$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
  363. $originalInfo = [];
  364. $originalInfo['openId'] = $openId;
  365. $originalInfo['sjId'] = $sjId;
  366. //没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
  367. if ($authScope == 'snsapi_userinfo') {
  368. $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
  369. $originalInfo = array_merge($baseInfo, $originalInfo);
  370. $originalInfo['isFull'] = 1;
  371. $originalInfo['unionId'] = $baseInfo['unionid'];
  372. $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
  373. $originalInfo['nickName'] = $baseInfo['nickName'];
  374. }
  375. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  376. } else {
  377. if ($user['isFull'] == 0) {
  378. if ($authScope == 'snsapi_userinfo') {
  379. $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
  380. $originalInfo = $baseInfo;
  381. $originalInfo['isFull'] = 1;
  382. $originalInfo['unionId'] = $baseInfo['unionid'];
  383. $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
  384. $originalInfo['openId'] = $baseInfo['openid'];
  385. $originalInfo['nickName'] = $baseInfo['nickName'];
  386. $originalInfo['sjId'] = $sjId;
  387. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  388. }
  389. }
  390. }
  391. //这个的基类没有设置统一的全局变量,这里进行设置一次
  392. $userId = $user['id'];
  393. $admin = AdminService::getByCondition(['userId' => $userId]);
  394. if (empty($admin)) {
  395. util::fail('您没有权限访问');
  396. }
  397. $adminId = $admin['id'];
  398. //获取token
  399. $token = jwt::getNewToken($adminId);
  400. $url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
  401. $this->redirect($url);
  402. }
  403. //登陆并拿到token ssh 2019.11.23
  404. public function actionLogin()
  405. {
  406. $get = Yii::$app->request->get();
  407. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  408. if (stringUtil::isMobile($mobile) == false) {
  409. util::fail('请填写正常的手机号');
  410. }
  411. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  412. if (empty($password)) {
  413. util::fail('请输入密码');
  414. }
  415. $admin = AdminService::getByCondition(['mobile' => $mobile, 'style' => AdminClass::STYLE_HD]);
  416. if (empty($admin)) {
  417. util::fail('请先注册哦');
  418. }
  419. if (password_verify($password, $admin['password']) == false) {
  420. util::fail('密码错误');
  421. }
  422. $adminId = $admin['id'];
  423. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'delStatus' => 0]);
  424. $sjId = isset($shopAdmin['sjId']) ? $shopAdmin['sjId'] : 0;
  425. $shopId = $shopAdmin['shopId'] ?? 0;
  426. if (empty($shopId)) {
  427. util::fail('您不是管理员');
  428. }
  429. //获取token
  430. $token = jwt::getNewToken($adminId);
  431. util::success(['token' => $token, 'account' => $sjId, 'shopId' => $shopId]);
  432. }
  433. //静默获取小程序用户信息
  434. public function actionMiniInfo()
  435. {
  436. //花店平台
  437. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  438. $code = Yii::$app->request->get('code', '');
  439. $wxMiniBase = WxOpenService::getWxMiniBase();
  440. $appId = $wxMiniBase['miniAppId'];
  441. $appSecret = $wxMiniBase['miniAppSecret'];
  442. if (empty($appSecret)) {
  443. Yii::info('没有找到小程序的密钥');
  444. //没有管理店铺不允许登录
  445. util::success(['token' => '']);
  446. }
  447. $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
  448. $curl = new curl\Curl();
  449. $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
  450. $result = $curl->get($url);
  451. $arr = Json::decode($result);
  452. $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
  453. $openid = $arr['openid'] ?? '';
  454. $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
  455. Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
  456. if (empty($openid)) {
  457. Yii::info(json_encode($arr));
  458. //没有管理店铺不允许登录
  459. util::success(['token' => '', 'currentMiniOpenId' => $openid]);
  460. }
  461. $admin = AdminService::getByCondition(['miniOpenId' => $openid]);
  462. if (empty($admin)) {
  463. //没有管理店铺不允许登录
  464. util::success(['token' => '', 'currentMiniOpenId' => $openid]);
  465. }
  466. $adminId = $admin['id'];
  467. $currentShopId = $admin['currentShopId'] ?? 0;
  468. if (empty($currentShopId)) {
  469. //没有管理店铺不允许登录
  470. util::success(['token' => '', 'currentMiniOpenId' => $openid]);
  471. }
  472. $currentShop = ShopClass::getById($currentShopId, true);
  473. if (empty($currentShop)) {
  474. //没有管理店铺不允许登录
  475. util::success(['token' => '', 'currentMiniOpenId' => $openid]);
  476. }
  477. $mainId = $currentShop->mainId ?? 0;
  478. $pfShopId = $currentShop->pfShopId ?? 0;
  479. $onlyCg = $currentShop->onlyCg ?? 1;
  480. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
  481. if (empty($shopAdmin)) {
  482. //没有管理店铺不允许登录
  483. util::success(['token' => '', 'currentMiniOpenId' => $openid]);
  484. }
  485. if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
  486. //账号冻结不再自动登录
  487. util::success(['token' => '', 'currentMiniOpenId' => $openid]);
  488. }
  489. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  490. $shopAdmin->save();
  491. $shopAdminId = $shopAdmin->id ?? 0;
  492. //是否有切换门店的权限
  493. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  494. $prefix = imgUtil::getPrefix();
  495. $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
  496. $admin['avatar'] = $avatar;
  497. $token = jwt::getNewToken($adminId);
  498. $showDemo = 1;
  499. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  500. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  501. if ($hdUpgrading == 1) {
  502. util::fail('系统升级中,稍后再试');
  503. }
  504. $apiHost = Yii::$app->params['hdHost'];
  505. $imgUploadApi = $apiHost . '/upload/save-file';
  506. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  507. util::success([
  508. 'token' => $token,
  509. 'admin' => $admin,
  510. 'shopId' => $currentShopId,
  511. 'shopAdminId' => $shopAdminId,
  512. 'switchShop' => $switchShop,
  513. 'pfShopId' => $pfShopId,
  514. 'onlyCg' => $onlyCg,
  515. 'showDemo' => $showDemo,
  516. 'imgUploadApi' => $imgUploadApi,
  517. //有小程序新版本提示更新
  518. 'update' => $remind,
  519. ]);
  520. }
  521. //获取收款码的二维码图片 ssh 20210602
  522. public function actionGatheringImgUrl()
  523. {
  524. $id = Yii::$app->request->get('id', 0);
  525. $shop = ShopClass::getById($id, true);
  526. if (empty($shop)) {
  527. util::fail('没有找到门店');
  528. }
  529. $sjId = $shop->sjId;
  530. $imgUrl = ShopClass::generateGatheringCode($sjId, $id);
  531. $fileResource = file_get_contents($imgUrl);
  532. header('Content-type: image/jpeg');
  533. echo $fileResource;
  534. }
  535. //最新版本 ssh 20220211
  536. public function actionGetApkVersion()
  537. {
  538. $version = getenv('HD_NEW_APK_VERSION') == false ? '1.0.0' : getenv('HD_NEW_APK_VERSION');
  539. $mustUpdate = getenv('HD_NEW_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('HD_NEW_APK_VERSION_MUST_UPDATE');
  540. util::success(['version' => $version, 'mustUpdate' => $mustUpdate]);
  541. }
  542. //收银台apk更新 ssh 20220310
  543. public function actionGetPadApkVersion()
  544. {
  545. $version = getenv('HD_NEW_PAD_APK_VERSION') == false ? '1.0.0' : getenv('HD_NEW_PAD_APK_VERSION');
  546. $mustUpdate = getenv('HD_NEW_PAD_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('HD_NEW_PAD_APK_VERSION_MUST_UPDATE');
  547. util::success(['version' => $version, 'mustUpdate' => $mustUpdate]);
  548. }
  549. }