AuthController.php 23 KB

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