AuthController.php 23 KB

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