AuthController.php 23 KB

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