AuthController.php 24 KB

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