|
|
@@ -7,7 +7,6 @@ use biz\shop\classes\ShopClass;
|
|
|
use bizHd\admin\classes\ShopAdminClass;
|
|
|
use bizGhs\shop\services\ShopAdminService;
|
|
|
use bizGhs\admin\services\AdminService;
|
|
|
-use bizHd\user\classes\UserClass;
|
|
|
use bizHd\wx\classes\WxOpenClass;
|
|
|
use common\components\dict;
|
|
|
use common\components\httpUtil;
|
|
|
@@ -27,6 +26,99 @@ use yii\helpers\Json;
|
|
|
class AuthController extends PublicController
|
|
|
{
|
|
|
|
|
|
+ //微信手机号一键登录 shish 20210121
|
|
|
+ public function actionWxMobileLogin()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $iv = $post['iv'];
|
|
|
+ $encryptedData = $post['encryptedData'];
|
|
|
+ $merchant = WxOpenClass::getGhsWxInfo();
|
|
|
+ $appId = $merchant['miniAppId'];
|
|
|
+ $miniOpenId = $post['miniOpenId'] ?? '';
|
|
|
+ if (empty($miniOpenId)) {
|
|
|
+ util::fail('登录失败...');
|
|
|
+ }
|
|
|
+ $cacheKey = 'GHS_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);
|
|
|
+ $phoneNumber = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
|
|
|
+ if (empty($phoneNumber)) {
|
|
|
+ util::fail('登录失败了');
|
|
|
+ }
|
|
|
+ $ptStyle = dict::getDict('ptStyle', 'ghs');
|
|
|
+ $admin = AdminClass::getByCondition(['mobile' => $phoneNumber, 'style' => $ptStyle]);
|
|
|
+ $currentShopId = $admin['currentShopId'] ?? 0;
|
|
|
+ $openShop = $admin['openShop'] ?? 1;
|
|
|
+ if (empty($currentShopId)) {
|
|
|
+ if ($openShop == 2) {
|
|
|
+ util::fail('审核中');
|
|
|
+ }
|
|
|
+ util::fail('请先注册');
|
|
|
+ }
|
|
|
+ $adminId = $admin['id'] ?? 0;
|
|
|
+ //1没有开店 2已申请待审核 3已开店
|
|
|
+ $openShop = $admin['openShop'] ?? 1;
|
|
|
+ if ($openShop == 2) {
|
|
|
+ util::fail('帐号审核中');
|
|
|
+ }
|
|
|
+ $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
|
|
|
+ if (empty($shopAdmin)) {
|
|
|
+ util::fail('请先注册');
|
|
|
+ }
|
|
|
+ $shopAdmin->lastLogin = date("Y-m-d H:i:s");
|
|
|
+ $shopAdmin->save();
|
|
|
+ $shopAdminId = $shopAdmin->id ?? 0;
|
|
|
+ //是否有切换门店的权限
|
|
|
+ $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
|
|
|
+
|
|
|
+ $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
|
|
|
+ $token = jwt::getNewToken($adminId);
|
|
|
+ $showDemo = 1;
|
|
|
+ $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
|
|
|
+ $shop = ShopClass::getById($currentShopId, true);
|
|
|
+ $skCustomId = $shop->skCustomId ?? 0;
|
|
|
+ $apiHost = Yii::$app->params['ghsHost'];
|
|
|
+ $imgUploadApi = $apiHost . '/upload/save-file';
|
|
|
+ //使用手册
|
|
|
+ $cacheKey = 'close_book_' . $shopAdminId;
|
|
|
+ $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
|
|
|
+ $showBook = !empty($hasClose) ? 0 : 1;
|
|
|
+
|
|
|
+ $cacheKey = 'has_hit_navigate_' . $shopAdminId;
|
|
|
+ $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
|
|
|
+ $hasHitNavigate = !empty($hasHit) ? 1 : 0;
|
|
|
+
|
|
|
+ //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
|
|
|
+ util::success([
|
|
|
+ 'token' => $token,
|
|
|
+ 'admin' => $admin,
|
|
|
+ 'shopAdminId' => $shopAdminId,
|
|
|
+ 'shopId' => $currentShopId,
|
|
|
+ 'switchShop' => $switchShop,
|
|
|
+ 'openShop' => $openShop,
|
|
|
+ 'showDemo' => $showDemo,
|
|
|
+ //有小程序新版本提示更新
|
|
|
+ 'update' => $remind,
|
|
|
+ 'skCustomId' => $skCustomId,
|
|
|
+ 'apiHost' => $apiHost,
|
|
|
+ 'imgUploadApi' => $imgUploadApi,
|
|
|
+ 'showBook' => $showBook,
|
|
|
+ 'hasHitNavigate' => $hasHitNavigate,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ util::success(['admin' => $admin]);
|
|
|
+ }
|
|
|
+
|
|
|
//本机号码一键登录 shish 20210117
|
|
|
public function actionPhoneLogin()
|
|
|
{
|
|
|
@@ -285,7 +377,7 @@ class AuthController extends PublicController
|
|
|
$appSecret = $wxMiniBase['miniAppSecret'];
|
|
|
if (empty($appSecret)) {
|
|
|
//没有管理店铺不允许登录
|
|
|
- util::success(['token' => '','number'=>1]);
|
|
|
+ util::success(['token' => '', 'number' => 1]);
|
|
|
}
|
|
|
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
|
|
|
$curl = new curl\Curl();
|
|
|
@@ -296,26 +388,26 @@ class AuthController extends PublicController
|
|
|
$openid = $arr['openid'] ?? '';
|
|
|
if (empty($openid)) {
|
|
|
//没有管理店铺不允许登录
|
|
|
- util::success(['token' => '', 'currentMiniOpenId' => $openid,'number'=>2]);
|
|
|
+ util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 2]);
|
|
|
}
|
|
|
$cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
|
|
|
Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
|
|
|
$admin = AdminService::getByMiniOpenId($openid);
|
|
|
if (empty($admin)) {
|
|
|
//没有管理店铺不允许登录
|
|
|
- util::success(['token' => '', 'currentMiniOpenId' => $openid,'number'=>3]);
|
|
|
+ util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 3]);
|
|
|
}
|
|
|
$adminId = $admin['id'];
|
|
|
$openShop = $admin['openShop'] ?? 1;
|
|
|
$currentShopId = $admin['currentShopId'] ?? 0;
|
|
|
if (empty($currentShopId)) {
|
|
|
//没有管理店铺不允许登录
|
|
|
- util::success(['token' => '', 'currentMiniOpenId' => $openid,'number'=>4]);
|
|
|
+ util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 4]);
|
|
|
}
|
|
|
$shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
|
|
|
if (empty($shopAdmin)) {
|
|
|
//没有管理店铺不允许登录
|
|
|
- util::success(['token' => '', 'currentMiniOpenId' => $openid,'number'=>5]);
|
|
|
+ util::success(['token' => '', 'currentMiniOpenId' => $openid, 'number' => 5]);
|
|
|
}
|
|
|
$shopAdmin->lastLogin = date("Y-m-d H:i:s");
|
|
|
$shopAdmin->save();
|