| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118 |
- <?php
- namespace hd\controllers;
- use biz\admin\classes\AdminClass;
- use biz\pt\classes\AgreementClass;
- use biz\shop\classes\ShopClass;
- use bizHd\admin\classes\ShopAdminClass;
- use bizHd\admin\services\ShopAdminService;
- use bizHd\admin\services\AdminService;
- use bizHd\member\classes\MemberLevelClass;
- use bizHd\recharge\classes\RechargeSqClass;
- use bizHd\shop\classes\ShopExtClass;
- use bizHd\wx\services\WxOpenService;
- use common\components\dict;
- use common\components\httpUtil;
- use common\components\imgUtil;
- use common\components\jwt;
- use common\components\sms;
- use common\components\util;
- use Yii;
- use common\components\stringUtil;
- use biz\sj\services\MerchantService;
- use bizHd\user\services\UserService;
- use common\services\xhMerchantService;
- use common\components\wxUtil;
- use linslin\yii2\curl;
- use yii\helpers\Json;
- /**
- * 用户登陆
- */
- class AuthController extends PublicController
- {
- //小程序获取手机号并登录 (新接口) ssh 20250728
- public function actionGetMiniMobile()
- {
- $post = Yii::$app->request->post();
- $code = $post['code'] ?? '';
- $miniOpenId = $post['miniOpenId'] ?? '';
- if (empty($code)) {
- util::fail('参数错误:缺少code');
- }
- // 使用 miniUtil 封装好的方法获取手机号 (ptStyle=1 表示花店端)
- $merchant = WxOpenService::getWxMiniBase();
- $res = \common\components\miniUtil::getPhoneNumber($merchant, $code, 1);
- if (isset($res['errcode']) && $res['errcode'] == 0) {
- $phoneNumber = $res['phone_info']['purePhoneNumber'] ?? '';
- if (empty($phoneNumber)) {
- util::fail('获取手机号内容为空');
- }
- // 登录逻辑 (同步自 actionWxMobileLogin)
- $admin = AdminService::getByCondition(['mobile' => $phoneNumber]);
- if (empty($admin)) {
- util::fail('请先注册');
- }
- $adminId = $admin['id'];
- AdminClass::updateById($adminId, ['miniOpenId' => $miniOpenId]);
- $admin['miniOpenId'] = $miniOpenId;
- $openShop = $admin['openShop'] ?? 1;
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (empty($currentShopId)) {
- if ($openShop == 2) {
- util::fail('审核中');
- }
- util::fail('请先注册');
- }
- $currentShop = ShopClass::getById($currentShopId, true);
- if (empty($currentShop)) {
- util::fail('没有找到门店36');
- }
- $pfShopId = $currentShop->pfShopId ?? 0;
- $onlyCg = $currentShop->onlyCg ?? 1;
- $mainId = $currentShop->mainId ?? 0;
- $shareLogo = imgUtil::groupImg('buy_logo.jpg');
- if (isset($currentShop->shareLogo) && !empty($currentShop->shareLogo)) {
- $shareLogo = imgUtil::groupImg($currentShop->shareLogo);
- }
- $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
- if (empty($shopAdmin)) {
- util::fail('无法操作');
- }
- if ($shopAdmin->status == 0) {
- util::fail("您的账号已被冻结");
- }
- $token = jwt::getNewToken($adminId);
- $shopAdmin->lastLogin = date("Y-m-d H:i:s");
- $shopAdmin->save();
- $shopAdminId = $shopAdmin->id ?? 0;
- //是否有切换门店的权限
- $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
- $prefix = imgUtil::getPrefix();
- $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
- $admin['avatar'] = $avatar;
- $showDemo = 1;
- $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
- $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
- if ($hdUpgrading == 1) {
- $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
- $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
- if (!in_array($shopAdminId, $allowShopAdminIds)) {
- util::fail('系统升级中,稍后再试');
- }
- }
- $apiHost = Yii::$app->params['hdHost'];
- $imgUploadApi = $apiHost . '/upload/save-file';
- //惠雅鲜花员工不能看收入情况
- if (in_array($adminId, [2366, 2812, 4004])) {
- $shopAdmin->super = 0;
- }
- //充值送钱有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词recharge_sq_init ssh 20251229
- RechargeSqClass::initData($currentShop);
- //会员等级有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词member_level_init ssh 20251229
- MemberLevelClass::initData($currentShop);
- //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
- util::success([
- 'token' => $token,
- 'admin' => $admin,
- 'shopId' => $currentShopId,
- 'shopAdminId' => $shopAdminId,
- 'switchShop' => $switchShop,
- 'pfShopId' => $pfShopId,
- 'onlyCg' => $onlyCg,
- 'shareLogo' => $shareLogo,
- 'showDemo' => $showDemo,
- 'imgUploadApi' => $imgUploadApi,
- //有小程序新版本提示更新
- 'update' => $remind,
- 'staff' => $shopAdmin,
- ]);
- } else {
- $errMsg = $res['errmsg'] ?? '获取手机号失败';
- $errCode = $res['errcode'] ?? -1;
- Yii::info("小程序新接口获取手机号失败 (HD):code={$errCode}, msg={$errMsg}");
- noticeUtil::push("花店小程序新接口获取手机号失败:code={$errCode}, msg={$errMsg}", '15280215347');
- util::fail("获取手机号失败:{$errMsg}({$errCode})");
- }
- }
- //获取手机号 ssh 20250217
- public function actionGetMobile()
- {
- $post = Yii::$app->request->post();
- $iv = $post['iv'];
- $encryptedData = $post['encryptedData'];
- $merchant = WxOpenService::getWxMiniBase();
- $appId = $merchant['miniAppId'];
- $miniOpenId = $post['miniOpenId'] ?? '';
- if (empty($miniOpenId)) {
- util::success(['hasNoOpenId' => 1], '登录失败,没有miniOpenId');
- }
- $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($sessionKey)) {
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- //noticeUtil::push($cacheKey . " 登录失败!!sessionKey空的", '15280215347');
- util::success(['hasNoOpenId' => 1], '登录失败!');
- }
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- //noticeUtil::push($cacheKey . " 登录失败!!!!sessionKey异常", '15280215347');
- util::success(['hasNoOpenId' => 1], '登录失败...');
- }
- $arr = Json::decode($result);
- $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
- if (empty($phoneNumber)) {
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- //noticeUtil::push($cacheKey . " 登录失败了!获取手机号失败", '15280215347');
- util::success(['hasNoOpenId' => 1], '登录失败了哦');
- }
- $cacheKey = 'getMobile_' . $phoneNumber;
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 1]);
- util::success(['mobile' => $phoneNumber]);
- }
- //获取微信昵称
- public function actionGetNickname()
- {
- $post = Yii::$app->request->post();
- $iv = $post['iv'] ?? '';
- $encryptedData = $post['encryptedData'] ?? '';
- $merchant = WxOpenService::getWxMiniBase();
- $appId = $merchant['miniAppId'];
- $miniOpenId = $post['miniOpenId'] ?? '';
- if (empty($miniOpenId)) {
- util::fail('获取失败,请重新打开小程序');
- }
- $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($sessionKey)) {
- util::fail('获取失败,请重新打开小程序');
- }
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- util::fail('获取微信昵称失败');
- }
- $arr = Json::decode($result);
- $nickName = $arr['nickName'] ?? '';
- if (empty($nickName)) {
- util::fail('没获取到微信昵称');
- }
- util::success(['name' => $nickName, 'nickName' => $nickName]);
- }
- //微信手机号一键登录 ssh 20210121
- public function actionWxMobileLogin()
- {
- $post = Yii::$app->request->post();
- $iv = $post['iv'];
- $encryptedData = $post['encryptedData'];
- $merchant = WxOpenService::getWxMiniBase();
- $appId = $merchant['miniAppId'];
- $miniOpenId = $post['miniOpenId'] ?? '';
- if (empty($miniOpenId)) {
- util::success(['hasNoOpenId' => 1], '登录失败,没有miniOpenId');
- }
- $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($sessionKey)) {
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- //noticeUtil::push($cacheKey . " 登录失败!!sessionKey空的", '15280215347');
- util::success(['hasNoOpenId' => 1], '登录失败!');
- }
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- //noticeUtil::push($cacheKey . " 登录失败!!!!sessionKey异常", '15280215347');
- util::success(['hasNoOpenId' => 1], '登录失败...');
- }
- $arr = Json::decode($result);
- $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
- if (empty($phoneNumber)) {
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- //noticeUtil::push($cacheKey . " 登录失败了!获取手机号失败", '15280215347');
- util::success(['hasNoOpenId' => 1], '登录失败了哦');
- }
- $admin = AdminService::getByCondition(['mobile' => $phoneNumber]);
- if (empty($admin)) {
- util::fail('请先注册');
- }
- $adminId = $admin['id'];
- AdminClass::updateById($adminId, ['miniOpenId' => $miniOpenId]);
- $admin['miniOpenId'] = $miniOpenId;
- $openShop = $admin['openShop'] ?? 1;
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (empty($currentShopId)) {
- if ($openShop == 2) {
- util::fail('审核中');
- }
- util::fail('请先注册');
- }
- $currentShop = ShopClass::getById($currentShopId, true);
- if (empty($currentShop)) {
- util::fail('没有找到门店36');
- }
- $pfShopId = $currentShop->pfShopId ?? 0;
- $onlyCg = $currentShop->onlyCg ?? 1;
- $mainId = $currentShop->mainId ?? 0;
- $shareLogo = imgUtil::groupImg('buy_logo.jpg');
- if (isset($currentShop->shareLogo) && !empty($currentShop->shareLogo)) {
- $shareLogo = imgUtil::groupImg($currentShop->shareLogo);
- }
- $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
- if (empty($shopAdmin)) {
- util::fail('无法操作');
- }
- if ($shopAdmin->status == 0) {
- util::fail("您的账号已被冻结");
- }
- $token = jwt::getNewToken($adminId);
- $shopAdmin->lastLogin = date("Y-m-d H:i:s");
- $shopAdmin->save();
- $shopAdminId = $shopAdmin->id ?? 0;
- //是否有切换门店的权限
- $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
- $prefix = imgUtil::getPrefix();
- $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
- $admin['avatar'] = $avatar;
- $showDemo = 1;
- $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
- $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
- if ($hdUpgrading == 1) {
- $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
- $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
- if (!in_array($shopAdminId, $allowShopAdminIds)) {
- util::fail('系统升级中,稍后再试');
- }
- }
- $apiHost = Yii::$app->params['hdHost'];
- $imgUploadApi = $apiHost . '/upload/save-file';
- //惠雅鲜花员工不能看收入情况
- if (in_array($adminId, [2366, 2812, 4004])) {
- $shopAdmin->super = 0;
- }
- //充值送钱有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词recharge_sq_init ssh 20251229
- RechargeSqClass::initData($currentShop);
- //会员等级有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词member_level_init ssh 20251229
- MemberLevelClass::initData($currentShop);
- //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
- util::success([
- 'token' => $token,
- 'admin' => $admin,
- 'shopId' => $currentShopId,
- 'shopAdminId' => $shopAdminId,
- 'switchShop' => $switchShop,
- 'pfShopId' => $pfShopId,
- 'onlyCg' => $onlyCg,
- 'shareLogo' => $shareLogo,
- 'showDemo' => $showDemo,
- 'imgUploadApi' => $imgUploadApi,
- //有小程序新版本提示更新
- 'update' => $remind,
- 'staff' => $shopAdmin,
- ]);
- }
- //app登陆 ssh 20211219
- public function actionAppLogin()
- {
- $getParams = Yii::$app->request->get();
- $postParams = Yii::$app->request->post();
- $allParams = array_merge($getParams, $postParams);
- $mobile = $allParams['mobile'] ?? 0;
- if (!stringUtil::isMobile($mobile)) {
- util::fail('请填写正确手机号');
- }
- $password = !empty($allParams['password']) ? $allParams['password'] : '';
- if (empty($password)) {
- util::fail('请输入密码');
- }
- $admin = AdminService::getByCondition(['mobile' => $mobile]);
- if (empty($admin)) {
- util::fail('请先注册...');
- }
- if (!password_verify($password, $admin['password'])) {
- util::fail('密码错误');
- }
- $openShop = $admin['openShop'] ?? 1;
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (empty($currentShopId)) {
- if ($openShop == 2) {
- util::fail('审核中');
- }
- util::fail('请先注册');
- }
- $currentShop = \bizHd\shop\classes\ShopClass::getById($currentShopId, true);
- if (empty($currentShop)) {
- util::fail('没有找到门店37');
- }
- $mainId = $currentShop->mainId ?? 0;
- $pfShopId = $currentShop->pfShopId ?? 0;
- $onlyCg = $currentShop->onlyCg ?? 1;
- $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShop->id], false, false, 'reachVip');
- $shareLogo = imgUtil::groupImg('buy_logo.jpg');
- if (isset($currentShop->shareLogo) && !empty($currentShop->shareLogo)) {
- $shareLogo = imgUtil::groupImg($currentShop->shareLogo);
- }
- $adminId = $admin['id'];
- $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
- if (empty($shopAdmin)) {
- util::fail('无法操作');
- }
- if ($shopAdmin->status == 0) {
- util::fail("您的账号已被冻结");
- }
- if ($shopAdmin->delStatus == 1) {
- util::fail("您的账号已删除");
- }
- $token = jwt::getNewToken($adminId);
- $shopAdmin->lastLogin = date("Y-m-d H:i:s");
- $shopAdmin->save();
- $shopAdminId = $shopAdmin->id ?? 0;
- //是否有切换门店的权限
- $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
- $prefix = imgUtil::getPrefix();
- $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
- $admin['avatar'] = $avatar;
- $showDemo = 1;
- $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
- $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
- if ($hdUpgrading == 1) {
- $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
- $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
- if (!in_array($shopAdminId, $allowShopAdminIds)) {
- util::fail('系统升级中,稍后再试');
- }
- }
- $apiHost = Yii::$app->params['hdHost'];
- $imgUploadApi = $apiHost . '/upload/save-file';
- //惠雅鲜花员工不能看收入情况
- if (in_array($adminId, [2366, 2812, 4004])) {
- $shopAdmin->super = 0;
- }
- //充值送钱有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词recharge_sq_init ssh 20251229
- RechargeSqClass::initData($currentShop);
- //会员等级有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词member_level_init ssh 20251229
- MemberLevelClass::initData($currentShop);
- //把设备状态更新为登录
- if (isset($allParams['deviceId']) && $allParams['deviceId'] != '') {
- $device = \bizHd\device\classes\HdDeviceClass::getByCondition(['shopId' => $currentShopId, 'deviceId' => $allParams['deviceId']], true);
- if ($device) {
- $device->status = 1;
- $device->save();
- }
- }
- unset($admin['password']); //返回的用户数据删除密码字段,防止密码加密方法被反查
- //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
- util::success([
- 'token' => $token,
- 'admin' => $admin,
- 'shopId' => $currentShopId,
- 'shopAdminId' => $shopAdminId,
- 'switchShop' => $switchShop,
- 'pfShopId' => $pfShopId,
- 'onlyCg' => $onlyCg,
- 'shareLogo' => $shareLogo,
- 'imgUploadApi' => $imgUploadApi,
- 'showDemo' => $showDemo,
- //有小程序新版本提示更新
- 'update' => $remind,
- 'staff' => $shopAdmin,
- 'reachVip' => $shopExt['reachVip'] //用于判断是否开启vip
- ]);
- }
- //本机号码一键登录 ssh 20210117
- public function actionPhoneLogin()
- {
- $get = Yii::$app->request->get();
- $access_token = $get['access_token'] ?? '';
- $openid = $get['openid'] ?? '';
- if (empty($access_token) || empty($openid)) {
- util::fail('参数错误');
- }
- //密钥,需要和uniCloud里的一致
- $secret = 'XHB2021198819640123';
- $params = ['access_token' => $access_token, 'openid' => $openid];
- $stringSignTemp = '';
- foreach ($params as $k => $v) {
- $stringSignTemp .= $k . '=' . $v . '&';
- }
- $stringSignTemp = rtrim($stringSignTemp, '&');
- $sign = hash_hmac('sha256', $stringSignTemp, $secret);
- $url = Yii::$app->params['hdUniCloudHost'] . "/getMobileNumber?access_token=" . $access_token . "&sign=" . $sign . "&" . $stringSignTemp;
- $curl = new curl\Curl();
- $respond = $curl->get($url);
- Yii::info($respond);
- $result = json_decode($respond, true);
- if (isset($result['code']) == false || $result['code'] != 1) {
- util::fail('获取手机号失败');
- }
- $phoneNumber = $result['data']['phoneNumber'] ?? '';
- if (empty($phoneNumber)) {
- util::fail('没有获取到手机号');
- }
- $admin = AdminService::getByCondition(['mobile' => $phoneNumber]);
- if (empty($admin)) {
- util::fail('请先注册');
- }
- $openShop = $admin['openShop'] ?? 1;
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (empty($currentShopId)) {
- if ($openShop == 2) {
- util::fail('审核中');
- }
- util::fail('请先注册');
- }
- $currentShop = ShopClass::getById($currentShopId, true);
- if (empty($currentShop)) {
- util::fail('登录失败,没有找到门店38');
- }
- $pfShopId = $currentShop->pfShopId ?? 0;
- $onlyCg = $currentShop->onlyCg ?? 1;
- $shareLogo = imgUtil::groupImg('buy_logo.jpg');
- if (isset($currentShop->shareLogo) && !empty($currentShop->shareLogo)) {
- $shareLogo = imgUtil::groupImg($currentShop->shareLogo);
- }
- $adminId = $admin['id'];
- $mainId = $currentShop->mainId ?? 0;
- $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
- if (empty($shopAdmin)) {
- util::fail('无法操作');
- }
- if ($shopAdmin->status == 0) {
- util::fail("您的账号已被冻结");
- }
- if ($shopAdmin->delStatus == 1) {
- util::fail("您的账号已删除");
- }
- $token = jwt::getNewToken($adminId);
- $shopAdmin->lastLogin = date("Y-m-d H:i:s");
- $shopAdmin->save();
- $shopAdminId = $shopAdmin->id ?? 0;
- //是否有切换门店的权限
- $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
- $prefix = imgUtil::getPrefix();
- $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
- $admin['avatar'] = $avatar;
- $showDemo = 1;
- $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
- $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
- if ($hdUpgrading == 1) {
- $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
- $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
- if (!in_array($shopAdminId, $allowShopAdminIds)) {
- util::fail('系统升级中,稍后再试');
- }
- }
- $apiHost = Yii::$app->params['hdHost'];
- $imgUploadApi = $apiHost . '/upload/save-file';
- //惠雅鲜花员工不能看收入情况
- if (in_array($adminId, [2366, 2812, 4004])) {
- $shopAdmin->super = 0;
- }
- //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
- util::success([
- 'token' => $token,
- 'admin' => $admin,
- 'shopId' => $currentShopId,
- 'shopAdminId' => $shopAdminId,
- 'pfShopId' => $pfShopId,
- 'onlyCg' => $onlyCg,
- 'shareLogo' => $shareLogo,
- 'switchShop' => $switchShop,
- 'showDemo' => $showDemo,
- 'imgUploadApi' => $imgUploadApi,
- //有小程序新版本提示更新
- 'update' => $remind,
- 'staff' => $shopAdmin,
- ]);
- }
- //准备授权 ssh 2019.11.19
- public function actionPrepare()
- {
- $get = Yii::$app->request->get();
- $url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
- if (empty($url)) {
- util::fail('没有网址');
- }
- $account = httpUtil::getAccount($url);
- if (empty($account)) {
- util::fail('没有商家帐号');
- }
- $merchant = MerchantService::getById($account);
- if (empty($merchant)) {
- util::fail('商家无效');
- }
- /**
- * authScope 参数的说明
- * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
- * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
- * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
- * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
- */
- $authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
- $urlEncode = stringUtil::urlSafeB64Encode($url);
- //微信授权获取code ssh 2019.11.24
- $isOpen = 1;
- wxUtil::getCode($urlEncode, $merchant, $authScope, $isOpen);
- util::end();
- }
- //微信授权获取用户信息 ssh 2019.11.20
- public function actionGetUserInfo()
- {
- $get = Yii::$app->request->get();
- $code = isset($get['code']) ? $get['code'] : '';
- if (empty($code)) {
- util::fail('没有获取用户code');
- }
- if (isset($get['state']) && $get['state'] == 'authdeny') {
- util::fail('auth fail');
- }
- $urlEncode = $get['url'];
- $url = stringUtil::urlSafeBase64Decode($urlEncode);
- $account = httpUtil::getAccount($url);
- if (empty($account)) {
- util::stop('商店ID无效!!');
- }
- $merchant = xhMerchantService::getByAccount($account);
- if (empty($merchant)) {
- util::stop('商店无效');
- }
- $sjId = $merchant['id'];
- $authScope = isset($get['authScope']) ? $get['authScope'] : '';
- if (empty($authScope)) {
- util::stop('没有授权类型');
- }
- $data = wxUtil::getOpenId($code, $merchant, 1);
- if ($data === false) {
- //微信授权获取code ssh 2019.11.24
- wxUtil::getCode($urlEncode, $merchant, $authScope, 1);
- util::end();
- }
- $openId = $data['openid'];
- $access_token = $data['access_token'];
- $user = UserService::getByOpenId($openId);
- //用户来源
- $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
- $source = $userSource['name'];
- if (empty($user)) {
- //$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
- $originalInfo = [];
- $originalInfo['openId'] = $openId;
- $originalInfo['sjId'] = $sjId;
- //没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
- if ($authScope == 'snsapi_userinfo') {
- $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
- $originalInfo = array_merge($baseInfo, $originalInfo);
- $originalInfo['isFull'] = 1;
- $originalInfo['unionId'] = $baseInfo['unionid'];
- $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
- $originalInfo['nickName'] = $baseInfo['nickName'];
- }
- $user = UserService::replaceUser($originalInfo, $source, $sjId);
- } else {
- if ($user['isFull'] == 0) {
- if ($authScope == 'snsapi_userinfo') {
- $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
- $originalInfo = $baseInfo;
- $originalInfo['isFull'] = 1;
- $originalInfo['unionId'] = $baseInfo['unionid'];
- $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
- $originalInfo['openId'] = $baseInfo['openid'];
- $originalInfo['nickName'] = $baseInfo['nickName'];
- $originalInfo['sjId'] = $sjId;
- $user = UserService::replaceUser($originalInfo, $source, $sjId);
- }
- }
- }
- //这个的基类没有设置统一的全局变量,这里进行设置一次
- $userId = $user['id'];
- $admin = AdminService::getByCondition(['userId' => $userId]);
- if (empty($admin)) {
- util::fail('您无法访问');
- }
- $adminId = $admin['id'];
- //获取token
- $token = jwt::getNewToken($adminId);
- $url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
- $this->redirect($url);
- }
- //登陆并拿到token ssh 2019.11.23
- public function actionLogin()
- {
- $get = Yii::$app->request->get();
- $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
- if (stringUtil::isMobile($mobile) == false) {
- util::fail('请填写正常的手机号');
- }
- $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
- if (empty($password)) {
- util::fail('请输入密码');
- }
- $admin = AdminService::getByCondition(['mobile' => $mobile]);
- if (empty($admin)) {
- util::fail('请先注册哦。');
- }
- if (password_verify($password, $admin['password']) == false) {
- util::fail('密码错误');
- }
- $adminId = $admin['id'];
- $openShop = $admin['openShop'] ?? 1;
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (empty($currentShopId)) {
- if ($openShop == 2) {
- util::fail('审核中');
- }
- util::fail('请先注册');
- }
- $currentShop = ShopClass::getById($currentShopId, true);
- if (empty($currentShop)) {
- util::fail('没有找到门店39');
- }
- $pfShopId = $currentShop->pfShopId ?? 0;
- if (!empty($pfShopId)) {
- //util::fail('批发店请不要在零售端登录');
- }
- $sjId = $currentShop->sjId ?? 0;
- $mainId = $currentShop->mainId ?? 0;
- $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
- if (empty($shopAdmin)) {
- util::fail('无法操作');
- }
- if ($shopAdmin->status == 0) {
- util::fail("您的账号已被冻结");
- }
- $token = jwt::getNewToken($adminId);
- $shopAdmin->lastLogin = date("Y-m-d H:i:s");
- $shopAdmin->save();
- $shopAdminId = $shopAdmin->id ?? 0;
- //是否有切换门店的权限
- $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
- $prefix = imgUtil::getPrefix();
- $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
- $admin['avatar'] = $avatar;
- $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
- if ($hdUpgrading == 1) {
- $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
- $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
- if (!in_array($shopAdminId, $allowShopAdminIds)) {
- util::fail('系统升级中,稍后再试');
- }
- }
- $apiHost = Yii::$app->params['hdHost'];
- $imgUploadApi = $apiHost . '/upload/save-file';
- util::success(['token' => $token, 'account' => $sjId, 'shopId' => $currentShopId, 'imgUploadApi' => $imgUploadApi, 'switchShop' => $switchShop,]);
- }
- /**
- * 静默获取小程序用户信息
- * 职责:通过微信小程序 code 换取 openid 和 session_key 并自动登录
- * 入参:GET 传参 code (微信临时登录凭证)
- * 返回:登录成功返回 token、用户信息、店铺 ID 等;失败返回空 token
- * 副作用:会更新管理员的最后登录时间,并将 session_key 写入 Redis 缓存
- */
- public function actionMiniInfo()
- {
- //花店平台
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
- $code = Yii::$app->request->get('code', '');
- $wxMiniBase = WxOpenService::getWxMiniBase();
- $appId = $wxMiniBase['miniAppId'];
- $appSecret = $wxMiniBase['miniAppSecret'];
- if (empty($appSecret)) {
- Yii::info('没有找到小程序的密钥');
- //没有管理店铺不允许登录
- util::success(['token' => '']);
- }
- $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
- $curl = new curl\Curl();
- $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
- // 复杂分支/关键逻辑:设置 cURL 连接和执行超时,并强制使用 IPv4,防止因微信接口卡顿或 DNS 解析慢拖垮 PHP-FPM 进程
- $curl->setOption(CURLOPT_CONNECTTIMEOUT, 2); // 连接超时限制为 2 秒,避免网络握手长时间卡死
- $curl->setOption(CURLOPT_TIMEOUT, 3); // 总执行时间限制为 3 秒,避免请求挂起时间过长
- $curl->setOption(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); // 强制 IPv4 解析,防止 IPv6 解析超时重试
- $result = $curl->get($url);
- $arr = Json::decode($result);
- $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
- $openid = $arr['openid'] ?? '';
- $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
- Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
- if (empty($openid)) {
- Yii::info(json_encode($arr));
- //没有管理店铺不允许登录
- util::success(['token' => '', 'currentMiniOpenId' => $openid, 'sn' => 1]);
- }
- $admin = AdminService::getByCondition(['miniOpenId' => $openid]);
- if (empty($admin)) {
- //没有管理店铺不允许登录
- util::success(['token' => '', 'currentMiniOpenId' => $openid, 'sn' => 2]);
- }
- $adminId = $admin['id'];
- //切换账号,多个地方要同步修改,关键词 change_account
- // if (getenv('YII_ENV') == 'production') {
- // if ($adminId == 4) {
- // $adminId = 28276;
- // $adminId = 27522;
- // $admin = AdminClass::getById($adminId);
- // }
- // } else {
- // if ($adminId == 919) {
- // $adminId = 1109;
- // $admin = AdminClass::getById($adminId);
- // }
- // }
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (empty($currentShopId)) {
- //没有管理店铺不允许登录
- util::success(['token' => '', 'currentMiniOpenId' => $openid, 'sn' => 3]);
- }
- $currentShop = ShopClass::getById($currentShopId, true);
- if (empty($currentShop)) {
- //没有管理店铺不允许登录
- util::success(['token' => '', 'currentMiniOpenId' => $openid, 'sn' => 4]);
- }
- $mainId = $currentShop->mainId ?? 0;
- $pfShopId = $currentShop->pfShopId ?? 0;
- $onlyCg = $currentShop->onlyCg ?? 1;
- $shareLogo = imgUtil::groupImg('buy_logo.jpg');
- if (isset($currentShop->shareLogo) && !empty($currentShop->shareLogo)) {
- $shareLogo = imgUtil::groupImg($currentShop->shareLogo);
- }
- $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
- if (empty($shopAdmin)) {
- //没有管理店铺不允许登录
- util::success(['token' => '', 'currentMiniOpenId' => $openid, 'sn' => 5]);
- }
- if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
- //账号冻结不再自动登录
- util::success(['token' => '', 'currentMiniOpenId' => $openid, 'sn' => 6]);
- }
- $shopAdminId = $shopAdmin->id ?? 0;
- //是否有切换门店的权限
- $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
- $prefix = imgUtil::getPrefix();
- $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
- $admin['avatar'] = $avatar;
- $token = jwt::getNewToken($adminId);
- $showDemo = 1;
- $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
- $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
- if ($hdUpgrading == 1) {
- $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
- $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
- if (!in_array($shopAdminId, $allowShopAdminIds)) {
- util::fail('系统升级中,稍后再试');
- }
- }
- $apiHost = Yii::$app->params['hdHost'];
- $imgUploadApi = $apiHost . '/upload/save-file';
- //惠雅鲜花员工不能看收入情况
- if (in_array($adminId, [2366, 2812, 4004])) {
- $shopAdmin->super = 0;
- }
- //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
- util::success([
- 'token' => $token,
- 'admin' => $admin,
- 'shopId' => $currentShopId,
- 'shopAdminId' => $shopAdminId,
- 'switchShop' => $switchShop,
- 'pfShopId' => $pfShopId,
- 'onlyCg' => $onlyCg,
- 'shareLogo' => $shareLogo,
- 'showDemo' => $showDemo,
- 'imgUploadApi' => $imgUploadApi,
- //有小程序新版本提示更新
- 'update' => $remind,
- 'currentMiniOpenId' => $openid,
- 'staff' => $shopAdmin,
- ]);
- }
- //获取收款码的二维码图片 ssh 20210602
- public function actionGatheringImgUrl()
- {
- $id = Yii::$app->request->get('id', 0);
- $shop = ShopClass::getById($id, true);
- if (empty($shop)) {
- util::fail('没有找到门店40');
- }
- $sjId = $shop->sjId;
- $imgUrl = ShopClass::generateGatheringCode($sjId, $id);
- $fileResource = file_get_contents($imgUrl);
- header('Content-type: image/jpeg');
- echo $fileResource;
- }
- //最新版本 ssh 20220211
- public function actionGetApkVersion()
- {
- $version = getenv('HD_NEW_APK_VERSION') == false ? '1.0.0' : getenv('HD_NEW_APK_VERSION');
- $mustUpdate = getenv('HD_NEW_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('HD_NEW_APK_VERSION_MUST_UPDATE');
- util::success(['version' => $version, 'mustUpdate' => $mustUpdate]);
- }
- //收银台apk更新 ssh 20220310
- public function actionGetPadApkVersion()
- {
- $version = getenv('HD_NEW_PAD_APK_VERSION') == false ? '1.0.0' : getenv('HD_NEW_PAD_APK_VERSION');
- $mustUpdate = getenv('HD_NEW_PAD_APK_VERSION_MUST_UPDATE') == false ? 0 : getenv('HD_NEW_PAD_APK_VERSION_MUST_UPDATE');
- util::success(['version' => $version, 'mustUpdate' => $mustUpdate]);
- }
- //注册使用协议 ssh 20220327
- public function actionRegister()
- {
- $html = AgreementClass::hzgRegister(1);
- util::success(['html' => $html]);
- }
- //隐私政策 ssh 20220327
- public function actionPrivacy()
- {
- $html = AgreementClass::hzgPrivacy(1);
- util::success(['html' => $html]);
- }
- /**
- * 【用途】发送登录短信验证码
- * 【为什么】供短信登录功能获取验证码,并包含防刷安全限制(单手机号60秒锁、每日上限5条)
- */
- public function actionSendLoginSms()
- {
- $getParams = Yii::$app->request->get();
- $postParams = Yii::$app->request->post();
- $allParams = array_merge($getParams, $postParams);
- $mobile = $allParams['mobile'] ?? '';
- if (!stringUtil::isMobile($mobile)) {
- util::fail('请填写正确手机号');
- }
- // 1. 安全检查:单手机号 60 秒防刷
- $lockKey = 'LOGIN_SMS_LOCK_' . $mobile;
- if (Yii::$app->redis->executeCommand('GET', [$lockKey])) {
- util::fail('发送过于频繁,请稍后再试');
- }
- // 2. 安全检查:单手机号每日上限 5 条
- $dayKey = 'LOGIN_SMS_COUNT_' . date('Ymd') . '_' . $mobile;
- $sendCount = (int)Yii::$app->redis->executeCommand('GET', [$dayKey]);
- if ($sendCount >= 5) {
- util::fail('该手机号今日获取验证码已达上限');
- }
- // 3. 生成 6 位随机验证码并保存至 Redis(有效期 5 分钟)
- $code = (string)rand(100000, 999999);
- $codeCacheKey = 'LOGIN_SMS_CODE_' . $mobile;
- Yii::$app->redis->executeCommand('SETEX', [$codeCacheKey, 300, $code]);
- // 4. 调用系统自带的限流发送组件 (内置了 IP 60秒锁和每日15条限制)
- $minute = 5;
- sms::send($mobile . ',' . $code . ',' . $minute, '登录验证码:{$var},{$var}分钟内有效');
- // 5. 写入单手机号限制锁
- Yii::$app->redis->executeCommand('SETEX', [$lockKey, 60, '1']);
- Yii::$app->redis->executeCommand('SETEX', [$dayKey, 86400, $sendCount + 1]);
- util::complete('验证码发送成功');
- }
- /**
- * 【用途】短信验证码登录
- * 【为什么】提供免密码快捷登录方式,验证通过后自动签发 JWT Token 并返回商家后台所需的所有初始化数据
- */
- public function actionSmsLogin()
- {
- $getParams = Yii::$app->request->get();
- $postParams = Yii::$app->request->post();
- $allParams = array_merge($getParams, $postParams);
- $mobile = $allParams['mobile'] ?? '';
- $code = $allParams['code'] ?? '';
- if (empty($mobile) || empty($code)) {
- util::fail('手机号和验证码不能为空');
- }
- if (!stringUtil::isMobile($mobile)) {
- util::fail('请填写正确手机号');
- }
- // 1. 校验验证码
- $codeCacheKey = 'LOGIN_SMS_CODE_' . $mobile;
- $savedCode = Yii::$app->redis->executeCommand('GET', [$codeCacheKey]);
- if (empty($savedCode) || $savedCode !== $code) {
- util::fail('验证码错误或已过期');
- }
- // 2. 验证通过,立即销毁验证码以确保一次性使用
- Yii::$app->redis->executeCommand('DEL', [$codeCacheKey]);
- // 3. 查找用户并执行登录
- $admin = AdminService::getByCondition(['mobile' => $mobile]);
- if (empty($admin)) {
- util::fail('请先注册哦...');
- }
- $openShop = $admin['openShop'] ?? 1;
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (empty($currentShopId)) {
- if ($openShop == 2) {
- util::fail('审核中');
- }
- util::fail('请先注册');
- }
- $currentShop = \bizHd\shop\classes\ShopClass::getById($currentShopId, true);
- if (empty($currentShop)) {
- util::fail('没有找到门店37');
- }
- $mainId = $currentShop->mainId ?? 0;
- $pfShopId = $currentShop->pfShopId ?? 0;
- $onlyCg = $currentShop->onlyCg ?? 1;
- $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShop->id], false, false, 'reachVip');
- $shareLogo = imgUtil::groupImg('buy_logo.jpg');
- if (isset($currentShop->shareLogo) && !empty($currentShop->shareLogo)) {
- $shareLogo = imgUtil::groupImg($currentShop->shareLogo);
- }
- $adminId = $admin['id'];
- $shopAdmin = ShopAdminService::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
- if (empty($shopAdmin)) {
- util::fail('无法操作');
- }
- if ($shopAdmin->status == 0) {
- util::fail("您的账号已被冻结");
- }
- if ($shopAdmin->delStatus == 1) {
- util::fail("您的账号已删除");
- }
- $token = jwt::getNewToken($adminId);
- $shopAdmin->lastLogin = date("Y-m-d H:i:s");
- $shopAdmin->save();
- $shopAdminId = $shopAdmin->id ?? 0;
- //是否有切换门店的权限
- $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
- $prefix = imgUtil::getPrefix();
- $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
- $admin['avatar'] = $avatar;
- $showDemo = 1;
- $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
- $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
- if ($hdUpgrading == 1) {
- $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
- $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
- if (!in_array($shopAdminId, $allowShopAdminIds)) {
- util::fail('系统升级中,稍后再试');
- }
- }
- $apiHost = Yii::$app->params['hdHost'];
- $imgUploadApi = $apiHost . '/upload/save-file';
- //惠雅鲜花员工不能看收入情况
- if (in_array($adminId, [2366, 2812, 4004])) {
- $shopAdmin->super = 0;
- }
- //充值送钱有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词recharge_sq_init ssh 20251229
- RechargeSqClass::initData($currentShop);
- //会员等级有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词member_level_init ssh 20251229
- MemberLevelClass::initData($currentShop);
- //把设备状态更新为登录
- if (isset($allParams['deviceId']) && $allParams['deviceId'] != '') {
- $device = \bizHd\device\classes\HdDeviceClass::getByCondition(['shopId' => $currentShopId, 'deviceId' => $allParams['deviceId']], true);
- if ($device) {
- $device->status = 1;
- $device->save();
- }
- }
- unset($admin['password']); //返回的用户数据删除密码字段,防止密码加密方法被反查
- //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
- util::success([
- 'token' => $token,
- 'admin' => $admin,
- 'shopId' => $currentShopId,
- 'shopAdminId' => $shopAdminId,
- 'switchShop' => $switchShop,
- 'pfShopId' => $pfShopId,
- 'onlyCg' => $onlyCg,
- 'shareLogo' => $shareLogo,
- 'imgUploadApi' => $imgUploadApi,
- 'showDemo' => $showDemo,
- //有小程序新版本提示更新
- 'update' => $remind,
- 'staff' => $shopAdmin,
- 'reachVip' => $shopExt['reachVip'] //用于判断是否开启vip
- ]);
- }
- }
|