AuthController.php 25 KB

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