| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace biz\admin\classes;
- use common\components\util;
- use Yii;
- use biz\base\classes\BaseClass;
- class AdminRoleClass extends BaseClass
- {
-
- public static $baseFile = '\biz\admin\models\AdminRole';
-
- //验证权限 shish 2019.12.9
- public static function valid($role, $merchantId)
- {
- if (empty($role)) {
- util::fail('角色无效');
- }
- if ($role['merchantId'] != $merchantId) {
- util::fail('没有权限操作');
- }
- }
-
- //添加角色 shish 2019.12.10
- public function addRole($data)
- {
- $roleName = $data['roleName'];
- $merchantId = $data['merchantId'];
- $nameList = self::getNameList($merchantId);
- if (in_array($roleName, $nameList)) {
- util::fail('角色已经存在');
- }
- $data['addTime'] = time();
- return self::add($data);
- }
-
- //获取商家角色列表 shish 2019.12.10
- public static function getRoleList($merchantId)
- {
- return self::getAllByCondition(['merchantId' => $merchantId], null, '*');
- }
-
- //获取商家所有的角色名称 shish 2019.12.10
- public static function getNameList($merchantId)
- {
- $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);
- }
- }
|