AuthController.php 24 KB

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