Browse Source

权限相关

shish 6 years ago
parent
commit
0c7281ee9c

+ 130 - 138
app/business/controllers/AuthController.php

@@ -3,158 +3,150 @@
 namespace business\controllers;
 
 use biz\admin\services\AdminService;
+use biz\auth\services\AuthService;
 use common\components\httpUtil;
 use common\components\jwt;
 use common\components\util;
 use Yii;
-use yii\web\Controller;
 use common\components\stringUtil;
 use biz\merchant\services\MerchantService;
-use biz\user\classes\UserClass;
 use biz\user\services\UserService;
 use common\services\xhMerchantService;
 use common\components\wxUtil;
 
-use Lcobucci\JWT\Builder;
-use Lcobucci\JWT\Signer\Hmac\Sha256;
-use Lcobucci\JWT\Parser;
-use Lcobucci\JWT\ValidationData;
-use linslin\yii2\curl;
-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'];
-		//获取token
-		$token = jwt::getNewToken($userId);
-		$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]);
-	}
-	
+    //准备授权 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'];
+        //获取token
+        $token = jwt::getNewToken($userId);
+        $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]);
+    }
+
 }

+ 69 - 57
app/business/controllers/MerchantController.php

@@ -2,68 +2,80 @@
 
 namespace business\controllers;
 
+use biz\auth\services\AuthService;
 use biz\merchant\services\MerchantExtendService;
 use biz\merchant\services\MerchantService;
+use biz\saas\services\SetAuthService;
 use Yii;
 use common\components\util;
 
 class MerchantController extends BaseController
 {
-	
-	//运费设置 shish 2019.12.8
-	public function actionFreightSetting()
-	{
-		$get = Yii::$app->request->get();
-		$first = isset($get['first']) && is_numeric($get['first']) ? $get['first'] : 5;
-		$add = isset($get['add']) && is_numeric($get['add']) ? $get['add'] : 5;
-		MerchantExtendService::updateByCondition(['merchantId' => $this->merchantId], ['freight' => $first . '_' . $add]);
-		util::ok();
-	}
-	
-	//商家信息 shish 2019.12.8
-	public function actionDetail()
-	{
-		$merchant = MerchantService::getInfo($this->merchant, $this->merchantExtend);
-		util::success($merchant);
-	}
-	
-	//商家现有的会员等级 shish 2019.12.12
-	public function actionMemberLevel()
-	{
-		$list = MerchantExtendService::getGradeList($this->merchantExtend, false, false);
-		$extend = $this->merchantExtend;
-		$gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
-		util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
-	}
-	
-	//会员等级更新 shish 2019.12.18
-	public function actionMemberLevelUpdate()
-	{
-		$extend = $this->merchantExtend;
-		if ($extend['gradeSwitch'] == 0) {
-			util::fail('会员等级已设置不能修改');
-		}
-		$list = Yii::$app->request->post('list');
-		if (empty($list) || is_array($list) == false) {
-			util::fail('请填写会员等级');
-		}
-		$data = [];
-		foreach ($list as $key => $val) {
-			$data[] = $val[0] . '_' . $val[1] . '_' . $val[2];
-		}
-		if (empty($data)) {
-			util::fail('请填写会员等级!');
-		}
-		$string = implode('I', $data);
-		MerchantExtendService::updateByCondition(['merchantId' => $this->merchantId], ['gradeList' => $string]);
-		util::ok('提交成功');
-	}
-	
-	//常用链接
-	public function actionCommonUrl()
-	{
-		$list = MerchantService::getCommonUrlList();
-		util::success($list);
-	}
-	
+
+    //运费设置 shish 2019.12.8
+    public function actionFreightSetting()
+    {
+        $get = Yii::$app->request->get();
+        $first = isset($get['first']) && is_numeric($get['first']) ? $get['first'] : 5;
+        $add = isset($get['add']) && is_numeric($get['add']) ? $get['add'] : 5;
+        MerchantExtendService::updateByCondition(['merchantId' => $this->merchantId], ['freight' => $first . '_' . $add]);
+        util::ok();
+    }
+
+    //商家信息 shish 2019.12.8
+    public function actionDetail()
+    {
+        $merchant = MerchantService::getInfo($this->merchant, $this->merchantExtend);
+        util::success($merchant);
+    }
+
+    //商家现有的会员等级 shish 2019.12.12
+    public function actionMemberLevel()
+    {
+        $list = MerchantExtendService::getGradeList($this->merchantExtend, false, false);
+        $extend = $this->merchantExtend;
+        $gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
+        util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
+    }
+
+    //会员等级更新 shish 2019.12.18
+    public function actionMemberLevelUpdate()
+    {
+        $extend = $this->merchantExtend;
+        if ($extend['gradeSwitch'] == 0) {
+            util::fail('会员等级已设置不能修改');
+        }
+        $list = Yii::$app->request->post('list');
+        if (empty($list) || is_array($list) == false) {
+            util::fail('请填写会员等级');
+        }
+        $data = [];
+        foreach ($list as $key => $val) {
+            $data[] = $val[0] . '_' . $val[1] . '_' . $val[2];
+        }
+        if (empty($data)) {
+            util::fail('请填写会员等级!');
+        }
+        $string = implode('I', $data);
+        MerchantExtendService::updateByCondition(['merchantId' => $this->merchantId], ['gradeList' => $string]);
+        util::ok('提交成功');
+    }
+
+    //常用链接
+    public function actionCommonUrl()
+    {
+        $list = MerchantService::getCommonUrlList();
+        util::success($list);
+    }
+
+    //商家当前的权限id列表 shish 2020.1.23
+    public function actionAuth()
+    {
+        $merchant = $this->merchant;
+        $setId = $merchant['setId'];
+        $endId = 1;
+        $ids = SetAuthService::getAuthIdList($setId, $endId);
+        util::success(['ids' => $ids]);
+    }
+
 }

+ 23 - 0
app/business/controllers/PermissionController.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace business\controllers;
+
+use biz\auth\services\AuthService;
+use common\components\util;
+use Yii;
+
+/**
+ * 权限
+ */
+class PermissionController extends PublicController
+{
+
+    //权限树 shish 2020.1.23
+    public function actionTree()
+    {
+        $endId = Yii::$app->request->get('id', 1);
+        $tree = AuthService::getTree($endId);
+        util::success($tree);
+    }
+
+}

+ 4 - 4
biz/auth/services/AuthService.php

@@ -12,7 +12,7 @@ class AuthService extends BaseService
 	public static $baseFile = '\biz\auth\classes\AuthClass';
 	
 	//获取指定业务端的权限列表 shish 2019.11.24
-	public static function getAuthList($endId)
+	public static function getEndAuth($endId)
 	{
 		return self::getAllByCondition(['endId' => $endId], null, '*');
 	}
@@ -20,7 +20,7 @@ class AuthService extends BaseService
 	//某业务端的权限id shish 2019.11.25
 	public static function getListId($endId)
 	{
-		$list = self::getAuthList($endId);
+		$list = self::getEndAuth($endId);
 		$ids = empty($list) ? [] : array_column($list,'id');
 		return $ids;
 	}
@@ -28,7 +28,7 @@ class AuthService extends BaseService
 	//获取指定业务端的权限树
 	public static function getTree($endId)
 	{
-		$data = self::getAuthList($endId);
+		$data = self::getEndAuth($endId);
 		if(empty($data)){
 			return [];
 		}
@@ -39,7 +39,7 @@ class AuthService extends BaseService
 	//获取业务端所有权限名称 shish 2019.11.24
 	public static function getNameList($endId)
 	{
-		$list = self::getAuthList($endId);
+		$list = self::getEndAuth($endId);
 		$arr = !empty($list) ? array_column($list, 'authName') : [];
 		return $arr;
 	}

+ 39 - 39
biz/merchant/classes/MerchantClass.php

@@ -8,44 +8,44 @@ use biz\base\classes\BaseClass;
 
 class MerchantClass extends BaseClass
 {
-	
-	public static $baseFile = '\biz\merchant\models\Merchant';
-	
-	//常用链接
-	public static $commonUrl = [
-		1 => ['id' => 1, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '商城'],
-		2 => ['id' => 2, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '申请会员'],
-		3 => ['id' => 3, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '点我付款'],
-	];
-	
-	//商家信息组合 shish 2019.12.20
-	public static function groupMerchantBaseInfo($list)
-	{
-		return $list;
-	}
-	
-	public static function getMerchantByIds($ids)
-	{
-		return self::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
-	}
-	
-	public static function getMerchantById($id)
-	{
-		$merchant = self::getById($id);
-		if (empty($merchant)) {
-			return $merchant;
-		}
-		$list = self::groupBaseInfo([$merchant]);
-		return current($list);
-	}
-	
-	public static function groupBaseInfo($list)
-	{
-		foreach ($list as $key => $val) {
-			$list[$key] = business::formatMerchantLogo($list[$key]);
-			$list[$key]['address'] = '福建省厦门市思明区上湖社1017号';
-		}
-		return $list;
-	}
+
+    public static $baseFile = '\biz\merchant\models\Merchant';
+
+    //常用链接
+    public static $commonUrl = [
+        1 => ['id' => 1, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '商城'],
+        2 => ['id' => 2, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '申请会员'],
+        3 => ['id' => 3, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '点我付款'],
+    ];
+
+    //商家信息组合 shish 2019.12.20
+    public static function groupMerchantBaseInfo($list)
+    {
+        return $list;
+    }
+
+    public static function getMerchantByIds($ids)
+    {
+        return self::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
+    }
+
+    public static function getMerchantById($id)
+    {
+        $merchant = self::getById($id);
+        if (empty($merchant)) {
+            return $merchant;
+        }
+        $list = self::groupBaseInfo([$merchant]);
+        return current($list);
+    }
+
+    public static function groupBaseInfo($list)
+    {
+        foreach ($list as $key => $val) {
+            $list[$key] = business::formatMerchantLogo($list[$key]);
+            $list[$key]['address'] = '福建省厦门市思明区上湖社1017号';
+        }
+        return $list;
+    }
 
 }

+ 121 - 114
biz/merchant/services/MerchantService.php

@@ -8,122 +8,129 @@ use biz\merchant\classes\MerchantClass;
 use biz\saas\services\SetAuthService;
 use biz\saas\services\SetMealService;
 use common\components\business;
+use common\components\util;
 use Yii;
 
 class MerchantService extends BaseService
 {
-	
-	public static $baseFile = '\biz\merchant\classes\MerchantClass';
-	
-	//商家在业务端的权限 shish 2019.11.25
-	public static function getAuthIdList($merchantId, $endId)
-	{
-		$merchant = self::getById($merchantId);
-		$setId = time() > $merchant['setDeadline'] ? 0 : $merchant['setId'];
-		if (empty($endId)) {
-			return [];
-		}
-		
-		//业务端总共有哪些权限
-		$idList = AuthService::getListId($endId);
-		
-		//套餐在业务端有哪些权限
-		$setIdList = SetAuthService::getAuthIdList($setId, $endId);
-		
-		//有*号表示有所有的权限
-		$commonIdList = in_array('*', $setIdList) ? $idList : array_intersect($idList, $setIdList);
-		
-		return $commonIdList;
-		
-	}
-	
-	//获取默认门店
-	public static function getDefaultShopId($merchant)
-	{
-		$defaultShopId = isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
-		return $defaultShopId;
-	}
-	
-	//商家基本信息,去除敏感信息 shish 2019.12.8
-	public static function getInfo($merchant, $extend)
-	{
-		$delete = ['miniAppId', 'miniAppSecret', 'wxAppId', 'wxAppSecret', 'openAppId', 'wxToken', 'wxJsApiTicket', 'wxAccessToken', 'wxRefreshToken'];
-		foreach ($delete as $del) {
-			unset($merchant[$del]);
-		}
-		$deleteExtend = ['miniAppId', 'miniAccessToken', 'miniRefreshToken', 'wxPayKey', 'wxPayMerchantId', 'wxAppId'];
-		foreach ($deleteExtend as $delExtend) {
-			unset($extend[$delExtend]);
-		}
-		
-		//设置计算方式
-		$freight = $extend['freight'];
-		$freightList = explode('_', $freight);
-		$extend['freightFirst'] = isset($freightList[0]) && is_numeric($freightList[0]) ? $freightList[0] : 5;
-		$extend['freightAdd'] = isset($freightList[1]) && is_numeric($freightList[1]) ? $freightList[1] : 2;
-		$merchant['extend'] = $extend;
-		$merchant['logoUrl'] = 'http://a.huahb.com/images/avatar.jpg';
-		return $merchant;
-	}
-	
-	//常用链接 shish 2019.12.19
-	public static function getCommonUrlList()
-	{
-		$list = MerchantClass::$commonUrl;
-		return array_values($list);
-	}
-	
-	//取指定常用链接 shish 2019.12.28
-	public static function getCommonUrl($id)
-	{
-		$list = MerchantClass::$commonUrl;
-		return isset($list[$id]) ? $list[$id] : [];
-	}
-	
-	//取平台下的商家 shish 2019.12.20
-	public static function getSaasMerchant($where)
-	{
-		$data = MerchantClass::getList('*', $where, 'addTime DESC');
-		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
-		if (empty($list)) {
-			return $data;
-		}
-		
-		//管理员
-		$adminIdList = array_column($list, 'adminId');
-		$admin = AdminService::getAdminByIds($adminIdList, null, 'id');
-		//商家资产
-		$merchantIdList = array_column($list, 'id');
-		$asset = MerchantAssetService::getAssetByMerchantIds($merchantIdList);
-		//套餐
-		$setIdList = array_column($list, 'setId');
-		$set = SetMealService::getSetByIds($setIdList);
-		//拓展
-		$ext = MerchantExtendService::getExtendByMerchantIds($merchantIdList);
-		foreach ($list as $key => $val) {
-			$adminId = $val['adminId'];
-			$merchantId = $val['id'];
-			$setId = $val['setId'];
-			$val['adminName'] = isset($admin[$adminId]['adminName']) ? $admin[$adminId]['adminName'] : '';
-			$val['merchantAsset'] = isset($asset[$merchantId]) ? $asset[$merchantId] : [];
-			$val['setMealName'] = isset($set[$setId]) ? $set[$setId]['name'] : '';
-			$val['extend'] = isset($ext[$merchantId]) ? $ext[$merchantId] : [];
-			$list[$key] = business::formatMerchantLogo($val);
-		}
-		$data['list'] = $list;
-		return $data;
-	}
-	
-	//根据id批量取商家 shish 2019.12.20
-	public static function getMerchantByIds($ids)
-	{
-		return MerchantClass::getMerchantByIds($ids);
-	}
-	
-	//获取商家 shish 2019.12.30
-	public static function getMerchantById($id)
-	{
-		return MerchantClass::getMerchantById($id);
-	}
-	
+
+    public static $baseFile = '\biz\merchant\classes\MerchantClass';
+
+    //商家在业务端的权限 shish 2019.11.25
+    public static function getAuthIdList($merchantId, $endId)
+    {
+        $merchant = self::getById($merchantId);
+        $setId = $merchant['setId'];
+        if (empty($setId)) {
+            util::fail('没有找到商家的套餐');
+        }
+
+        //业务端总共有哪些权限
+        $idList = AuthService::getListId($endId);
+
+        //套餐在业务端有哪些权限
+        $setIdList = SetAuthService::getAuthIdList($setId, $endId);
+
+        //有*号表示有所有的权限
+        $commonIdList = in_array('*', $setIdList) ? $idList : array_intersect($idList, $setIdList);
+
+        return $commonIdList;
+
+    }
+
+    //获取默认门店
+    public static function getDefaultShopId($merchant)
+    {
+        $defaultShopId = isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
+        return $defaultShopId;
+    }
+
+    //商家基本信息,去除敏感信息 shish 2019.12.8
+    public static function getInfo($merchant, $extend)
+    {
+        $delete = ['miniAppId', 'miniAppSecret', 'wxAppId', 'wxAppSecret', 'openAppId', 'wxToken', 'wxJsApiTicket', 'wxAccessToken', 'wxRefreshToken'];
+        foreach ($delete as $del) {
+            unset($merchant[$del]);
+        }
+        $deleteExtend = ['miniAppId', 'miniAccessToken', 'miniRefreshToken', 'wxPayKey', 'wxPayMerchantId', 'wxAppId'];
+        foreach ($deleteExtend as $delExtend) {
+            unset($extend[$delExtend]);
+        }
+
+        //设置计算方式
+        $freight = $extend['freight'];
+        $freightList = explode('_', $freight);
+        $extend['freightFirst'] = isset($freightList[0]) && is_numeric($freightList[0]) ? $freightList[0] : 5;
+        $extend['freightAdd'] = isset($freightList[1]) && is_numeric($freightList[1]) ? $freightList[1] : 2;
+        $merchant['extend'] = $extend;
+        $merchant['logoUrl'] = 'http://a.huahb.com/images/avatar.jpg';
+        return $merchant;
+    }
+
+    //常用链接 shish 2019.12.19
+    public static function getCommonUrlList()
+    {
+        $list = MerchantClass::$commonUrl;
+        return array_values($list);
+    }
+
+    //取指定常用链接 shish 2019.12.28
+    public static function getCommonUrl($id)
+    {
+        $list = MerchantClass::$commonUrl;
+        return isset($list[$id]) ? $list[$id] : [];
+    }
+
+    //取平台下的商家 shish 2019.12.20
+    public static function getSaasMerchant($where)
+    {
+        $data = MerchantClass::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+
+        //管理员
+        $adminIdList = array_column($list, 'adminId');
+        $admin = AdminService::getAdminByIds($adminIdList, null, 'id');
+        //商家资产
+        $merchantIdList = array_column($list, 'id');
+        $asset = MerchantAssetService::getAssetByMerchantIds($merchantIdList);
+        //套餐
+        $setIdList = array_column($list, 'setId');
+        $set = SetMealService::getSetByIds($setIdList);
+        //拓展
+        $ext = MerchantExtendService::getExtendByMerchantIds($merchantIdList);
+        foreach ($list as $key => $val) {
+            $adminId = $val['adminId'];
+            $merchantId = $val['id'];
+            $setId = $val['setId'];
+            $val['adminName'] = isset($admin[$adminId]['adminName']) ? $admin[$adminId]['adminName'] : '';
+            $val['merchantAsset'] = isset($asset[$merchantId]) ? $asset[$merchantId] : [];
+            $val['setMealName'] = isset($set[$setId]) ? $set[$setId]['name'] : '';
+            $val['extend'] = isset($ext[$merchantId]) ? $ext[$merchantId] : [];
+            $list[$key] = business::formatMerchantLogo($val);
+        }
+        $data['list'] = $list;
+        return $data;
+    }
+
+    //根据id批量取商家 shish 2019.12.20
+    public static function getMerchantByIds($ids)
+    {
+        return MerchantClass::getMerchantByIds($ids);
+    }
+
+    //获取商家 shish 2019.12.30
+    public static function getMerchantById($id)
+    {
+        return MerchantClass::getMerchantById($id);
+    }
+
+    public static function getCurrentSetId($id)
+    {
+        return MerchantClass::getCurrentSetId($id);
+    }
+
+
 }

+ 14 - 18
biz/saas/services/SetAuthService.php

@@ -4,26 +4,22 @@ namespace biz\saas\services;
 
 use biz\auth\services\AuthService;
 use biz\base\services\BaseService;
+use biz\saas\classes\SetAuthClass;
+use common\components\tree;
 use Yii;
 
 class SetAuthService extends BaseService
 {
-	
-	public static $baseFile = '\biz\saas\classes\SetAuthClass';
-	
-	//套餐在业务端的权限列表
-	public static function getAuthIdList($setId, $endId)
-	{
-		$info = self::getByCondition(['setId' => $setId, 'endId' => $endId]);
-		$auth = isset($info['auth']) ? $info['auth'] : '';
-		$ids = !empty($auth) ? explode(',', $auth) : [];
-		return $ids;
-	}
-	
-	//获取指定套餐和业务端的权限树
-	public static function getAuthTree($setId, $endId)
-	{
-		$tree = AuthService::getTree($endId);
-	}
-	
+
+    public static $baseFile = '\biz\saas\classes\SetAuthClass';
+
+    //套餐在业务端的权限列表
+    public static function getAuthIdList($setId, $endId)
+    {
+        $info = self::getByCondition(['setId' => $setId, 'endId' => $endId]);
+        $auth = isset($info['auth']) ? $info['auth'] : '';
+        $ids = !empty($auth) ? explode(',', $auth) : [];
+        return $ids;
+    }
+
 }