Explorar el Código

总后台权限修改

shish hace 6 años
padre
commit
e14525a65b
Se han modificado 2 ficheros con 47 adiciones y 1 borrados
  1. 30 1
      app/platform/controllers/AuthController.php
  2. 17 0
      biz/auth/services/AuthService.php

+ 30 - 1
app/platform/controllers/AuthController.php

@@ -9,6 +9,8 @@ use Yii;
 class AuthController extends BaseController
 {
 	
+	public $enableCsrfValidation = false;
+
 	//获取权限树 shish 2019.11.24
 	public function actionTree()
 	{
@@ -17,5 +19,32 @@ class AuthController extends BaseController
 		$tree = AuthService::getTree($endId);
 		util::success($tree);
 	}
-	
+
+	//添加权限 shish 2019.11.24
+	public function actionAdd()
+	{
+		$post = Yii::$app->request->post();
+		$endId = isset($post['endId']) ? $post['endId'] : 1;
+		$authName = isset($post['authName']) ? $post['authName'] : '';
+		$list = AuthService::getNameList($endId);
+		if (in_array($authName, $list)) {
+			util::fail('名称已经存在');
+		}
+		AuthService::add($_POST);
+		util::ok();
+	}
+
+	public function actionModify()
+	{
+		$post = Yii::$app->request->post();
+		$endId = isset($post['endId']) ? $post['endId'] : 1;
+		$authName = isset($post['authName']) ? $post['authName'] : '';
+		$list = AuthService::getNameList($endId);
+		if (in_array($authName, $list)) {
+			util::fail('名称已经存在');
+		}
+		AuthService::add($_POST);
+		util::ok();
+	}
+
 }

+ 17 - 0
biz/auth/services/AuthService.php

@@ -18,5 +18,22 @@ class AuthService extends BaseService
 		$tree = tree::makeTree($data, ['primary_key' => 'id', 'parent_key' => 'parentId', 'children_key' => 'children',]);
 		return $tree;
 	}
+	
+	//取出业务端所有的权限 shish 2019.11.24
+	public static function getAuthData($endId)
+	{
+		return self::getAllByCondition(['endId' => $endId], null, '*');
+	}
+
+	//获取业务商所有权限名称 shish 2019.11.24
+	public static function getNameList($endId)
+	{
+		$list = self::getAuthData($endId);
+		$arr = [];
+		if (!empty($list)) {
+			$arr = array_column($list, 'authName');
+		}
+		return $arr;
+	}
 
 }