shish преди 6 години
родител
ревизия
89335d3b44
променени са 3 файла, в които са добавени 36 реда и са изтрити 4 реда
  1. 11 0
      app/business/controllers/AdminRoleController.php
  2. 17 2
      biz/admin/classes/AdminRoleClass.php
  3. 8 2
      biz/admin/services/AdminRoleService.php

+ 11 - 0
app/business/controllers/AdminRoleController.php

@@ -28,5 +28,16 @@ class AdminRoleController extends BaseController
 		$respond = AdminRoleService::addRole($post);
 		util::success($respond);
 	}
+	
+	//修改角色 shish 2019.12.10
+	public function actionUpdate()
+	{
+		$post = Yii::$app->request->post();
+		$id = isset($post['id']) ? $post['id'] : 0;
+		unset($post['id']);
+		$role = AdminRoleService::getById($id);
+		AdminRoleService::updateRole($role, $post);
+		util::ok('修改成功');
+	}
 
 }

+ 17 - 2
biz/admin/classes/AdminRoleClass.php

@@ -34,7 +34,7 @@ class AdminRoleClass extends BaseClass
 		$data['addTime'] = time();
 		return self::add($data);
 	}
-
+	
 	//获取商家角色列表 shish 2019.12.10
 	public static function getRoleList($merchantId)
 	{
@@ -47,5 +47,20 @@ class AdminRoleClass extends BaseClass
 		$list = self::getRoleList($merchantId);
 		return !empty($list) ? array_column($list, 'roleName') : [];
 	}
-	
+
+	//更新角色 shish 2019.12.10
+	public static function updateRole($role, $data)
+	{
+		$merchantId = $role['merchantId'];
+		if ($role['roleName'] != $data['roleName']) {
+			$name = $data['roleName'];
+			$nameList = self::getNameList($merchantId);
+			if (in_array($name, $nameList)) {
+				util::fail('名称已经存在');
+			}
+		}
+		$id = $role['id'];
+		return self::updateById($id, $data);
+	}
+
 }

+ 8 - 2
biz/admin/services/AdminRoleService.php

@@ -21,11 +21,17 @@ class AdminRoleService extends BaseService
 	{
 		return AdminRoleClass::getRoleList($merchantId);
 	}
-	
+
 	//添加角色 shish 2019.12.10
 	public static function addRole($data)
 	{
 		return AdminRoleClass::addRole($data);
 	}
-	
+
+	//修改角色 shish 2019.12.10
+	public static function updateRole($role, $data)
+	{
+		return AdminRoleClass::updateRole($role,$data);
+	}
+
 }