AuthController.php 23 KB

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