AuthController.php 23 KB

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