AuthController.php 24 KB

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