* @version : HUOSDK 8.0 */ namespace huo\model\user; use huo\model\common\CommonModel; use huolib\constant\AgentConst; use huolib\constant\CommonConst; use think\Cache; class RoleModel extends CommonModel { protected $name = 'role'; protected $cache_tag = 'role_id_key'; public function getRoleLevelAttr($value) { } /** * 获取角色类型说明 * * @param $value * * @return string */ public function getRoleTypeTextAttr($value) { if (AgentConst::ROLE_TYPE_ADMIN == $value) { return '超级管理员'; } elseif (AgentConst::ROLE_TYPE_MANAGER == $value) { return '管理员'; } elseif (AgentConst::ROLE_TYPE_GROUP == $value) { return '一级渠道'; } elseif (AgentConst::ROLE_TYPE_AGENT == $value) { return '二级渠道'; } elseif (AgentConst::ROLE_TYPE_MEMBER == $value) { return '玩家渠道'; } elseif (AgentConst::ROLE_TYPE_PC == $value) { return '渠道专员'; } elseif (AgentConst::ROLE_TYPE_CP == $value) { return 'CP'; } return ''; } /** * 获取角色名称 * * @param $where * @param bool $inc_type * * @return array */ public function getIdNames($where = [], $inc_type = false) { $_tag = $this->cache_tag; $_cache_key = md5($_tag.json_encode($where)); $_field = 'name'; if ($inc_type) { $_cache_key = 'inc_type'.$_cache_key; $_field = "name,role_type,role_type role_type_text"; } $_roles = $this->where($where) ->cache($_cache_key, CommonConst::CONST_DAY_SECONDS, $_tag) ->column($_field, 'id'); if ($inc_type) { foreach ($_roles as $_k => $_v) { $_roles[$_k]['role_type_text'] = $this->getRoleTypeTextAttr($_v['role_type']); } } return $_roles; } /** * * @param $role_id * * @return bool|mixed */ public function getRoleTypeById($role_id) { if (empty($role_id)) { return false; } $_map['id'] = $role_id; $_key = 'role_type_'.$role_id; $_tag = $this->cache_tag; $_role_type = $this->where($_map)->cache($_key, CommonConst::CONST_DAY_SECONDS, $_tag)->value('role_type'); if (empty($_role_type)) { return false; } return intval($_role_type); } /** * 通过角色类型获取角色ID * * @param $role_type * * @return array */ public function getIdsByRoleType($role_type) { $_map = []; $_role_type = $role_type; if (is_numeric($role_type) && !empty($role_type)) { $_role_type = [$role_type]; } if (!empty($role_type)) { $_map['role_type'] = ['in', $_role_type]; } $_id_arr = $this->where($_map)->column('id'); return $_id_arr; } public function addRole($data) { $_rs = $this->insert($data); if ($_rs != false) { Cache::clear($_tag = $this->cache_tag); } return $_rs; } public function updateRole($data) { $_rs = $this->update($data); if ($_rs != false) { Cache::clear($_tag = $this->cache_tag); } return $_rs; } public function deleteRole($id) { $_rs = $this->where(['id' => $id])->delete(); if ($_rs != false) { Cache::clear($_tag = $this->cache_tag); } return $_rs; } }