Browse Source

权限与前后端路由

shish 6 years ago
parent
commit
4f668e54b7

+ 4 - 3
app/admin/controllers/AdminController.php

@@ -2,10 +2,11 @@
 
 namespace admin\controllers;
 
+use biz\admin\services\AdminService;
 use Yii;
 use yii\web\Controller;
 
-class AdminController extends BackendController
+class AdminController extends BaseController
 {
 	
 	public $withoutLogin = [];
@@ -13,8 +14,8 @@ class AdminController extends BackendController
 	//获取登陆员工的权限 shish 2019.11.24
 	public function actionGetLoginAuth()
 	{
-		$adminId = $this->adminId;
-		
+		AdminService::getAuth();
+
 	}
 
 }

+ 42 - 0
app/admin/controllers/BaseController.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace admin\controllers;
+
+use biz\auth\services\MenuService;
+use biz\goods\services\CategoryRelateService;
+use biz\goods\services\UsageRelationService;
+use biz\merchant\services\AdminService;
+use common\components\error;
+use common\components\stringUtil;
+use common\components\validate;
+use common\services\xhUserService;
+use Yii;
+use common\services\xhWxOpenService;
+use common\services\xhMerchantAssetService;
+use common\services\xhMerchantExtendService;
+use common\services\xhMerchantService;
+use common\services\xhAdminService;
+use common\components\util;
+use common\components\weixinUtil;
+use common\components\jsSDK;
+use common\services\xhAdminToMerchantService;
+use yii\web\Cookie;
+
+class BaseController extends PublicController
+{
+	public $admin, $adminId, $adminAvatar, $account;
+	public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantAsset, $merchantLogo, $signPackage;
+	public $openMerchant, $openMerchantId;
+	public $appId;
+	public $isWeixin = false;
+	public $isLogin = false;
+	public $withoutLogin = [];//不需要登陆的方法名
+	
+	public function beforeAction($action)
+	{
+		Yii::$app->params['adminId'] = 1;
+		Yii::$app->params['merchantId'] = 1;
+		return parent::beforeAction($action);
+	}
+	
+}

+ 21 - 0
biz/admin/classes/AdminClass.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace biz\admin\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class AdminClass extends BaseClass
+{
+
+	public static $baseFile = '\biz\admin\models\Admin';
+
+	//收益通知人
+	public static $noticeAdmin = [
+		//国兰
+		'wx193341a4a80f6ea3' => ['o4c8Vs54PQh32nkgG8R3m4VuGTvw', 'o4c8VszacQJyrzu651CAu0sCsfPc'],
+		//花美灵
+		'wx84d95afcb7b594eb' => ['oTFbYvsjwgVwXggwtlM2ESAKwuN8', 'oTFbYvqP6qwdCCkdFB9GYnlzDIUg'],
+	];
+
+}

+ 13 - 0
biz/admin/classes/AdminRoleAuthClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\admin\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class AdminRoleAuthClass extends BaseClass
+{
+
+	public static $baseFile = '\biz\admin\models\AdminRoleAuth';
+
+}

+ 13 - 0
biz/admin/classes/AdminRoleClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\admin\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class AdminRoleClass extends BaseClass
+{
+
+	public static $baseFile = '\biz\admin\models\AdminRole';
+
+}

+ 13 - 0
biz/admin/models/Admin.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\admin\models;
+use biz\base\models\Base;
+
+class Admin extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhAdmin';
+	}
+
+}

+ 13 - 0
biz/admin/models/AdminRole.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\admin\models;
+use biz\base\models\Base;
+
+class AdminRole extends Base
+{
+	
+	public static function tableName()
+	{
+		return 'xhAdminRole';
+	}
+
+}

+ 13 - 0
biz/admin/models/AdminRoleAuth.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\admin\models;
+use biz\base\models\Base;
+
+class AdminRoleAuth extends Base
+{
+	
+	public static function tableName()
+	{
+		return 'xhAdminRoleAuth';
+	}
+
+}

+ 22 - 0
biz/admin/services/AdminRoleAuthService.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace biz\auth\services;
+
+use biz\base\services\BaseService;
+use Yii;
+
+class AdminRoleAuthService extends BaseService
+{
+	
+	public static $baseFile = '\biz\admin\classes\AdminRoleAuthClass';
+	
+	//角色在业务端的权限 shish 2019.11.25
+	public static function getAuthIdList($roleId, $endId)
+	{
+		$info = self::getByCondition(['roleId' => $roleId, 'endId' => $endId]);
+		$auth = isset($info['auth']) ? $info['auth'] : '';
+		$ids = !empty($auth) ? explode(',', $auth) : [];
+		return $ids;
+	}
+	
+}

+ 13 - 0
biz/admin/services/AdminRoleService.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace biz\auth\services;
+
+use biz\base\services\BaseService;
+use Yii;
+
+class AdminRoleService extends BaseService
+{
+	
+	public static $baseFile = '\biz\admin\classes\AdminRoleClass';
+
+}

+ 68 - 0
biz/admin/services/AdminService.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace biz\admin\services;
+
+use biz\auth\services\AdminRoleAuthService;
+use biz\auth\services\AuthService;
+use biz\base\services\BaseService;
+use biz\merchant\services\MerchantService;
+use common\components\error;
+use common\components\stringUtil;
+use common\services\xhTMessageService;
+use Yii;
+
+class AdminService extends BaseService
+{
+	
+	public static $baseFile = '\biz\admin\classes\AdminClass';
+	
+	public static function generateSessionId($account)
+	{
+		return 'SID_HT_' . $account . '_' . date("mdHis") . '_' . stringUtil::charsShuffle(18);
+	}
+	
+	//发送到手机上 shish 2019.8.11
+	public static function sendUrlToMobile($url, $merchant)
+	{
+		$class = self::$baseFile;
+		$noticeAdminList = $class::$noticeAdmin;
+		$appId = $merchant['wxAppId'];
+		$openId = isset($noticeAdminList[$appId][0]) ? $noticeAdminList[$appId][0] : '';
+		if (empty($openId)) {
+			error::instance()->setError('没有设置通知人');
+			return false;
+		}
+		xhTMessageService::sendUrlToMobile($url, $openId, $merchant);
+		return true;
+	}
+	
+	//员工获取权限 shish 2019.11.25
+	public static function getAuth()
+	{
+		$adminId = Yii::$app->params['adminId'];
+		$merchantId = Yii::$app->params['merchantId'];
+		$admin = self::getById($adminId);
+		$roleId = isset($admin['roleId']) ? $admin['roleId'] : 0;
+		if (empty($roleId)) {
+			return [];
+		}
+		//零售端
+		$endId = 1;
+		//商家在业务端的权限
+		$merchantIdList = MerchantService::getAuthIdList($merchantId, $endId);
+		if (empty($merchantIdList)) {
+			return [['endId' => 1, 'frontUrl' => [], 'backUrl' => []]];
+		}
+		//角色在业务端的权限
+		$roleIdList = AdminRoleAuthService::getAuthIdList($roleId, $endId);
+		if (empty($roleIdList)) {
+			return [['endId' => 1, 'front' => [], 'back' => []]];
+		}
+		$commonIdList = array_intersect($roleIdList, $merchantIdList);
+		$all = AuthService::getByIds($commonIdList);
+		$front = array_column($all, 'frontUrl');
+		$back = array_column($all, 'backUrl');
+		return ['endId' => 1, 'frontUrl' => $front, 'backUrl' => $back];
+	}
+	
+}

+ 10 - 5
biz/auth/services/AuthService.php

@@ -17,6 +17,14 @@ class AuthService extends BaseService
 		return self::getAllByCondition(['endId' => $endId], null, '*');
 	}
 
+	//某业务端的权限id shish 2019.11.25
+	public static function getListId($endId)
+	{
+		$list = self::getList($endId);
+		$ids = empty($list) ? [] : array_column($list,'id');
+		return $ids;
+	}
+	
 	//获取指定业务端的权限树
 	public static function getTree($endId)
 	{
@@ -25,14 +33,11 @@ class AuthService extends BaseService
 		return $tree;
 	}
 
-	//获取业务所有权限名称 shish 2019.11.24
+	//获取业务所有权限名称 shish 2019.11.24
 	public static function getNameList($endId)
 	{
 		$list = self::getList($endId);
-		$arr = [];
-		if (!empty($list)) {
-			$arr = array_column($list, 'authName');
-		}
+		$arr = !empty($list) ? array_column($list, 'authName') : [];
 		return $arr;
 	}
 

+ 25 - 1
biz/merchant/services/MerchantService.php

@@ -1,12 +1,36 @@
 <?php
 
 namespace biz\merchant\services;
+
+use biz\auth\services\AuthService;
 use biz\base\services\BaseService;
+use biz\saas\services\SetAuthService;
 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 = array_intersect($idList, $setIdList);
 
+		return $commonIdList;
+		
+	}
+	
 }

+ 12 - 8
biz/saas/services/SetAuthService.php

@@ -1,25 +1,29 @@
 <?php
 
 namespace biz\saas\services;
+
 use biz\auth\services\AuthService;
 use biz\base\services\BaseService;
 use Yii;
 
 class SetAuthService extends BaseService
 {
-
+	
 	public static $baseFile = '\biz\saas\classes\SetAuthClass';
-
-	//获取指定套餐和业务端的权限列表
-	public static function getAuthList($setId,$endId)
+	
+	//套餐在业务端的权限列表
+	public static function getAuthIdList($setId, $endId)
 	{
-		$list = AuthService::getList($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)
+	public static function getAuthTree($setId, $endId)
 	{
 		$tree = AuthService::getTree($endId);
 	}
-
+	
 }

+ 4 - 0
sql.txt

@@ -1,3 +1,7 @@
+shish 2019.11.25
+ALTER TABLE xhAuth CHANGE front_url frontUrl VARCHAR(30) NOT NULL DEFAULT '' COMMENT '前端路由';
+ALTER TABLE xhAuth CHANGE back_url backUrl VARCHAR(30) NOT NULL DEFAULT '' COMMENT '后端路由';
+
 shish 2019.11.24
 ALTER TABLE xhAdminRoleAuth ADD endId TINYINT NOT NULL DEFAULT 0 COMMENT '业务端id' AFTER roleId;
 ALTER TABLE xhMerchant ADD setDeadline INT NOT NULL DEFAULT 0 COMMENT '套餐到期时间' AFTER `setId`;