AuthController.php 24 KB

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