shish 6 jaren geleden
bovenliggende
commit
5103043a9b

+ 9 - 0
app/saas/controllers/WxOpenController.php

@@ -288,6 +288,15 @@ class WxOpenController extends BaseController
             //开放平台没有小程序先绑定开放平台要用的小程序
             if (isset($open['wx_mini_base_id']) == false || empty($open['wx_mini_base_id'])) {
                 $miniData['addTime'] = $time;
+
+                //花卉宝
+                $miniAppSecret = 'f1ae43c87080da21ac631609b0dbb147';
+                if (getenv('YII_ENV') == 'dev') {
+                    //花美玲
+                    $miniAppSecret = '12f90039b1245ba6abf2e4184462fb30';
+                }
+                $miniData['miniAppSecret'] = $miniAppSecret;
+
                 $wxMiniBaseRespond = WxMiniBaseService::add($miniData);
                 $wxMiniBaseId = $wxMiniBaseRespond['id'];
                 WxOpenService::updateOpen(['wx_mini_base_id' => $wxMiniBaseId]);

+ 180 - 180
app/shop/controllers/AuthController.php

@@ -24,184 +24,184 @@ use yii\helpers\Json;
  */
 class AuthController extends PublicController
 {
-	
-	//准备授权 shish 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 shish 2019.11.24
-		wxUtil::getCode($urlEncode, $merchant, $authScope);
-		util::end();
-	}
-	
-	//微信授权获取用户信息 shish 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('商店无效');
-		}
-		$merchantId = $merchant['id'];
-		$authScope = isset($get['authScope']) ? $get['authScope'] : '';
-		if (empty($authScope)) {
-			util::stop('没有授权类型');
-		}
-		$data = wxUtil::getOpenId($code, $merchant);
-		if ($data === false) {
-			//微信授权获取code shish 2019.11.24
-			wxUtil::getCode($urlEncode, $merchant, $authScope);
-			util::end();
-		}
-		$openId = $data['openid'];
-		$access_token = $data['access_token'];
-		$user = UserService::getByOpenId($openId, $merchantId);
-		//用户来源
-		$userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
-		$source = $userSource['name'];
-		if (empty($user)) {
-			//$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
-			$originalInfo = [];
-			$originalInfo['openId'] = $openId;
-			$originalInfo['merchantId'] = $merchantId;
-			
-			//没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
-			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, $merchantId);
-		} 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['merchantId'] = $merchantId;
-					$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-				}
-			}
-		}
-		//这个的基类没有设置统一的全局变量,这里进行设置一次
-		$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 shish 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 (password_verify($password, $admin['password']) == false) {
-			util::fail('密码错误');
-		}
-		$adminId = $admin['id'];
-		//获取token
-		$token = jwt::getNewToken($adminId);
-		util::success(['token' => $token, 'account' => $admin['merchantId'], 'merchantId' => $admin['merchantId']]);
-	}
-	
-	//静默获取小程序用户信息
-	public function actionMiniInfo()
-	{
-		$code = Yii::$app->request->get('code', '');
-		if (empty($code)) {
-			util::fail('没有CODE信息');
-		}
-		$wxMiniBase = WxOpenService::getWxMiniBase();
-		$appId = $wxMiniBase['miniAppId'];
-		$appSecret = $wxMiniBase['miniAppSecret'];
-		if (empty($appSecret)) {
-			util::fail('没有找到小程序的密钥');
-		}
-		$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$arr = Json::decode($result);
-		$sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
-		$cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
-		Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-		$openid = isset($arr['openid']) ? $arr['openid'] : '';
-		if (empty($openid)) {
-			Yii::info(json_encode($arr));
-			util::fail('没有获取到小程序openId');
-		}
-		//用户来源
-		$userSource = UserClass::$userSourceId['mini']['name'];
-		$admin = AdminService::getByMiniOpenId($openid);
-		$relateId = 0;
-		if (empty($admin)) {
-			$adminInfo = ['miniOpenId' => $openid];
-			Yii::info(json_encode($adminInfo));
-			$admin = AdminService::replaceAdmin($adminInfo, $userSource);
-			$adminId = $admin['id'];
-		} else {
-			$adminId = $admin['id'];
-			$relate = AdminRelateService::getByCondition(['adminId' => $adminId]);
-			$relateId = isset($relate['id']) ? $relate['id'] : 0;
-		}
-		//管理员关联商家
-		Yii::$app->redis->executeCommand('SET', ['ADMIN_RELATION_' . $adminId, $relateId]);
-		$token = jwt::getNewToken($adminId);
-		util::success(['token' => $token, 'admin' => $admin]);
-	}
-	
+
+    //准备授权 shish 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 shish 2019.11.24
+        wxUtil::getCode($urlEncode, $merchant, $authScope);
+        util::end();
+    }
+
+    //微信授权获取用户信息 shish 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('商店无效');
+        }
+        $merchantId = $merchant['id'];
+        $authScope = isset($get['authScope']) ? $get['authScope'] : '';
+        if (empty($authScope)) {
+            util::stop('没有授权类型');
+        }
+        $data = wxUtil::getOpenId($code, $merchant);
+        if ($data === false) {
+            //微信授权获取code shish 2019.11.24
+            wxUtil::getCode($urlEncode, $merchant, $authScope);
+            util::end();
+        }
+        $openId = $data['openid'];
+        $access_token = $data['access_token'];
+        $user = UserService::getByOpenId($openId, $merchantId);
+        //用户来源
+        $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
+        $source = $userSource['name'];
+        if (empty($user)) {
+            //$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
+            $originalInfo = [];
+            $originalInfo['openId'] = $openId;
+            $originalInfo['merchantId'] = $merchantId;
+
+            //没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
+            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, $merchantId);
+        } 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['merchantId'] = $merchantId;
+                    $user = UserService::replaceUser($originalInfo, $source, $merchantId);
+                }
+            }
+        }
+        //这个的基类没有设置统一的全局变量,这里进行设置一次
+        $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 shish 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 (password_verify($password, $admin['password']) == false) {
+            util::fail('密码错误');
+        }
+        $adminId = $admin['id'];
+        //获取token
+        $token = jwt::getNewToken($adminId);
+        util::success(['token' => $token, 'account' => $admin['merchantId'], 'merchantId' => $admin['merchantId']]);
+    }
+
+    //静默获取小程序用户信息
+    public function actionMiniInfo()
+    {
+        $code = Yii::$app->request->get('code', '');
+        if (empty($code)) {
+            util::fail('没有CODE信息');
+        }
+        $wxMiniBase = WxOpenService::getWxMiniBase();
+        $appId = $wxMiniBase['miniAppId'];
+        $appSecret = $wxMiniBase['miniAppSecret'];
+        if (empty($appSecret)) {
+            util::fail('没有找到小程序的密钥');
+        }
+        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $arr = Json::decode($result);
+        $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
+        $openid = isset($arr['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::fail('没有获取到小程序openId');
+        }
+        //用户来源
+        $userSource = UserClass::$userSourceId['mini']['name'];
+        $admin = AdminService::getByMiniOpenId($openid);
+        $relateId = 0;
+        if (empty($admin)) {
+            $adminInfo = ['miniOpenId' => $openid];
+            Yii::info(json_encode($adminInfo));
+            $admin = AdminService::replaceAdmin($adminInfo, $userSource);
+            $adminId = $admin['id'];
+        } else {
+            $adminId = $admin['id'];
+            $relate = AdminRelateService::getByCondition(['adminId' => $adminId]);
+            $relateId = isset($relate['id']) ? $relate['id'] : 0;
+        }
+        //管理员关联商家
+        Yii::$app->redis->executeCommand('SET', ['ADMIN_RELATION_' . $adminId, $relateId]);
+        $token = jwt::getNewToken($adminId);
+        util::success(['token' => $token, 'admin' => $admin]);
+    }
+
 }

+ 54 - 110
app/shop/controllers/BaseController.php

@@ -2,6 +2,7 @@
 
 namespace shop\controllers;
 
+use biz\admin\services\AdminRelateService;
 use biz\merchant\services\AdminService;
 use biz\merchant\services\MerchantExtendService;
 use biz\merchant\services\MerchantService;
@@ -11,115 +12,58 @@ use common\components\util;
 
 class BaseController extends PublicController
 {
-	public $admin, $adminId, $adminAvatar, $account;
-	public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantLogo, $signPackage;
-	public $openMerchant, $openMerchantId;
-	public $appId;
-	public $isWx = false;
-	public $isLogin = false;
-	public $withoutLogin = [];//不需要登陆的方法名
-	public $validate = true;
-	
-	//shish 2020.3.8
-	public function beforeAction($action)
-	{
-		//token验证
-		$adminId = jwt::getLoginId();
-		$merchantId = 0;
-		if (empty($adminId)) {
-			$this->validate = false;
-		} else {
-			$admin = AdminService::getById($adminId);
-			if (empty($admin)) {
-				util::fail('帐号无效');
-			}
-			$adminId = $admin['id'];
-			$relateId = Yii::$app->redis->executeCommand('GET', ['ADMIN_RELATION_' . $adminId]);
-			//不是数字可能被清缓存,需要重新登陆,$relateId = 0 表示没有关联商家
-			if (is_numeric($relateId) == false) {
-				util::notLogin();
-			}
-			$merchantId = $admin['merchantId'];
-			if (empty($merchantId)) {
-				util::fail('没有找到商家信息');
-			}
-		}
-		//游客可以访问的方法
-		if (in_array($action->id, $this->withoutLogin)) {
-			$this->validate = true;
-		}
-		if ($this->validate == false) {
-			util::notLogin();
-		}
-		$merchant = MerchantService::getMerchantById($merchantId);
-		$merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
-		$this->admin = $admin;
-		$this->adminId = $adminId;
-		$this->merchantId = $merchantId;
-		$this->merchant = $merchant;
-		$this->merchantExtend = $merchantExtend;
-		return parent::beforeAction($action);
-	}
-	
-	//shisq
-	public function actionList()
-	{
-		$numargs = func_num_args();
-		$select = $numargs >= 1 ? func_get_arg(0) : '*';
-		$where = $numargs >= 2 ? func_get_arg(1) : null;
-		$order = $numargs >= 3 ? func_get_arg(2) : '';
-		$with = $numargs >= 4 ? func_get_arg(3) : '';
-		
-		$service = $this->service;
-		$list = $service::getList($select, $where, $order, $with);
-		util::success($list);
-	}
-	
-	//shisq
-	public function actionAdd()
-	{
-		$data = Yii::$app->request->post();
-		$service = $this->service;
-		$re = $service::add($data);
-		util::success($re);
-	}
-	
-	//shisq
-	public function actionDetail()
-	{
-		$id = Yii::$app->request->get('id');
-		$service = $this->service;
-		$data = $service::getById($id);
-		if (isset($data['merchantId']) == false || $this->merchantId != $data['merchantId']) {
-			util::fail('没有权限');
-		}
-		if (!empty($data)) {
-			util::success($data);
-		}
-		util::fail('');
-	}
-	
-	//shisq
-	public function actionUpdate()
-	{
-		$data = Yii::$app->request->post();
-		$id = $data['id'];
-		$service = $this->service;
-		$re = $service::updateById($id, $data);
-		if ($re['status'] === true) {
-			util::success($re);
-		}
-		util::fail();
-	}
-	
-	//shisq
-	public function actionDelete()
-	{
-		$id = Yii::$app->request->get('id');
-		$service = $this->service;
-		$service::deleteById($id);
-		util::success([], '删除成功');
-	}
-	
+    public $admin, $adminId, $adminAvatar, $account;
+    public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantLogo, $signPackage;
+    public $openMerchant, $openMerchantId;
+    public $appId;
+    public $isWx = false;
+    public $isLogin = false;
+    public $withoutLogin = [];//不需要登陆的方法名
+    public $validate = true;
+
+    //shish 2020.3.8
+    public function beforeAction($action)
+    {
+        //token验证
+        $adminId = jwt::getLoginId();
+        $merchantId = 0;
+        $merchant = [];
+        $merchantExtend = [];
+        $admin = [];
+        if (empty($adminId)) {
+            $this->validate = false;
+        } else {
+            $admin = AdminService::getById($adminId);
+            if (empty($admin)) {
+                util::fail('帐号无效');
+            }
+            $adminId = $admin['id'];
+            $relateId = Yii::$app->redis->executeCommand('GET', ['ADMIN_RELATION_' . $adminId]);
+            //不是数字可能被清缓存,需要重新登陆,$relateId = 0 表示没有关联的商家
+            if (is_numeric($relateId) == false) {
+                util::notLogin();
+            }
+            if (!empty($relateId)) {
+                $relate = AdminRelateService::getById($relateId);
+                $merchantId = $relate['merchantId'];
+                $merchant = MerchantService::getMerchantById($merchantId);
+                $merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
+            }
+        }
+        //游客可以访问的方法
+        if (in_array($action->id, $this->withoutLogin)) {
+            $this->validate = true;
+        }
+        if ($this->validate == false) {
+            util::notLogin();
+        }
+        $this->admin = $admin;
+        $this->adminId = $adminId;
+        $this->merchantId = $merchantId;
+        $this->merchant = $merchant;
+        $this->merchantExtend = $merchantExtend;
+        return parent::beforeAction($action);
+    }
+
 }
 

+ 4 - 1
console/controllers/UpgradeController.php

@@ -1366,10 +1366,13 @@ ALTER TABLE `xhAdmin` DROP COLUMN `currentShopId`;";
 
         //修改总后台员工登陆密码
         StaffService::updateById(1,['password'=>password_hash('123456', PASSWORD_BCRYPT)]);
-	
+
 	    $sql = "ALTER TABLE `xhAdminRelate` ADD `adminId` INT NOT NULL DEFAULT 0 COMMENT '管理员id' AFTER `id`;";
 	    Yii::$app->db->createCommand($sql)->execute($sql);
 
+	    $sql = "ALTER TABLE `xhWxMiniBase` ADD `miniAppSecret` VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'appSecret' AFTER `miniAppId`;";
+        Yii::$app->db->createCommand($sql)->execute($sql);
+
     }
 
     //数据迁移 shish 2020.1.12