<?php /** * AbstractService.class.php * Service 层基类 * @author: tangxingguo * @version: $Id$ * @copyright: vchangyi.com */ namespace Common\Service; use Common\Common\Department; use Common\Common\Job; use Common\Common\User; use Common\Model\RightModel; use Common\Common\Cache; use Common\Common\Role; use Common\Common\Tag; abstract class AbstractService extends \Com\Service { protected $_d_right; // 构造方法 public function __construct() { $this->_d_right = new RightModel(); parent::__construct(); } /** * 获取格式化后的权限数据 * * @author 何岳龙 * @param array $conds 权限筛选条件 * * @return array * + array dp_list 部门信息 * + string dp_id 部门ID * + string dp_name 部门名称 * + array tag_list 标签信息 * + string tag_id 标签ID * + string tag_name 标签名称 * + array user_list 人员信息 * + string uid 用户ID * + string username 用户姓名 * + string face 头像 */ public function get_auth($conds = []) { $list = $this->_d_right->list_by_conds($conds); $rights_db = $this->format_db_data($list); $data = [ 'user_list' => [], 'dp_list' => [], 'job_list' => [], 'role_list' => [], 'tag_list' => [] ]; $dpServ = &Department::instance(); $userServ = &User::instance(); $roleServ = &Role::instance(); $jobServ = &Job::instance(); $tagServ = &Tag::instance(); foreach ($rights_db as $k => $v) { switch ($k) { // 部门 case 'dp_ids': if (!empty($v)) { sort($v); $dps = $dpServ->listById($v); foreach ($dps as $dp) { $data['dp_list'][] = [ 'dpID' => $dp['dpId'], 'dpName' => $dp['dpName'], ]; } } break; // 人员 case 'uids': if (!empty($v)) { sort($v); $users = $userServ->listAll(['memUids' => $v]); foreach ($users as $user) { $data['user_list'][] = [ 'memID' => $user['memUid'], 'memUsername' => $user['memUsername'], 'memFace' => $user['memFace'], ]; } } break; // 岗位 case 'job_ids': if (!empty($v)) { $jobs = $jobServ->listById($v); foreach ($jobs as $job) { $data['job_list'][] = [ 'jobID' => $job['jobId'], 'jobName' => $job['jobName'], ]; } } break; // 角色 case 'role_ids': if (!empty($v)) { $roles = $roleServ->listById($v); foreach ($roles as $role) { $data['role_list'][] = [ 'roleID' => $role['roleId'], 'roleName' => $role['roleName'], ]; } } break; // 标签 case 'tag_ids': sort($v); if (!empty($v)) { $tags = $tagServ->listAll($v); foreach ($tags as $tag) { $data['tag_list'][] = [ 'tagID' => $tag['tagId'], 'tagName' => $tag['tagName'], ]; } } break; } } return $data; } /** * 格式化数据库中的权限数据 * * @author houyingcai * @param array $rights 权限数据 * * @return array */ public function format_db_data($rights) { $data = []; // 数据分组 $data['uids'] = array_filter(array_column($rights, 'uid')); $data['dp_ids'] = array_filter(array_column($rights, 'cd_id')); $data['job_ids'] = array_filter(array_column($rights, 'job_id')); $data['role_ids'] = array_filter(array_column($rights, 'role_id')); $data['tag_ids'] = array_filter(array_column($rights, 'tag_id')); return $data; } }