where('name', $name)->find(); if (isset($conf['content'])) { $config = unserialize($conf['content']); } set_cache('system_config' . $name, $config); } if ($key == '') { return $config; } else { if (isset($config[$key])) { return $config[$key]; } else{ return ''; } } } //设置系统配置 function set_system_config($name, $key, $value='') { $config = []; $conf = Db::name('config')->where('name', $name)->find(); if ($conf['content']) { $config = unserialize($conf['content']); } $config[$key] = $value; set_cache('system_config' . $name, $config); $content = serialize($config); Db::name('config')->where('name', $name)->update(['content'=>$content]); } //读取文件配置 function get_config($key) { return Config::get($key); } //判断cms是否完成安装 function is_installed() { static $isInstalled; if (empty($isInstalled)) { $isInstalled = file_exists(CMS_ROOT . 'config/install.lock'); } return $isInstalled; } //判断cms是否存在模板 function isTemplate($url='') { static $isTemplate; if (empty($isTemplate)) { $isTemplate = file_exists(CMS_ROOT . 'app/'.$url); } return $isTemplate; } //判断模块是否存在 function isModule($name) { $map = []; $map[] = ['name', '=', $name]; $count = Db::name('AdminModule')->where($map)->count(); return $count; } //是否是某数据权限,count>1即有权限 function isAuth($uid,$name) { if($uid == 1){ return 1; } $map = []; $map[] = ['name', '=', $name]; $map[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',uids)")]; $count = Db::name('DataAuth')->where($map)->count(); return $count; } //获取服务器信息 function get_system_info($key) { $system = [ 'os' => PHP_OS, 'php' => PHP_VERSION, 'upload_max_filesize' => get_cfg_var("upload_max_filesize") ? get_cfg_var("upload_max_filesize") : "不允许上传附件", 'max_execution_time' => get_cfg_var("max_execution_time") . "秒 ", ]; if (empty($key)) { return $system; } else { return $system[$key]; } } //获取url参数 function get_params($key = "") { return Request::instance()->param($key); } //生成一个不会重复的字符串 function make_token() { $str = md5(uniqid(md5(microtime(true)), true)); $str = sha1($str); //加密 return $str; } //随机字符串,默认长度10 function set_salt($num = 10) { $str = 'qwertyuiopasdfghjklzxcvbnm1234567890'; $salt = substr(str_shuffle($str), 10, $num); return $salt; } //密码加密 function set_password($pwd, $salt) { return md5(md5($pwd . $salt) . $salt); } //获取指定管理员的信息 function get_admin($id) { $admin = Db::name('Admin') ->alias('a') ->field('a.*,d.title as department,p.title as position') ->leftJoin ('Department d ','d.id= a.did') ->leftJoin ('Position p ','p.id= a.position_id') ->where(['a.id' => $id]) ->cache(true,60) ->find(); $admin['last_login_time'] = empty($admin['last_login_time']) ? '-' : date('Y-m-d H:i', $admin['last_login_time']); return $admin; } /** * 节点权限判断 * @rule String * @uid Int * @return bool */ function check_auth($rule, $uid) { $auth_list = Cache::get('RulesSrc' . $uid); if (!in_array($rule, $auth_list)) { return false; } else { return true; } } //读取部门列表 function get_department() { $department = Db::name('Department')->order('sort desc,id asc')->where(['status' => 1])->select()->toArray(); return $department; } //获取某部门的子部门id.$is_self时候包含自己 function get_department_son($did = 0, $is_self = 1) { $department = get_department(); $department_list = get_data_node($department, $did); $department_array = array_column($department_list, 'id'); if ($is_self == 1) { //包括自己部门在内 $department_array[] = $did; } return $department_array; } //读取员工所在部门的分管领导(pid=1,上一级负责人) function get_department_leader($uid=0,$pid=0) { $did = get_admin($uid)['did']; if($pid==0){ $leader = Db::name('Department')->where(['id' => $did])->value('leader_id'); } else{ $pdid = Db::name('Department')->where(['id' => $did])->value('pid'); if($pdid == 0){ $leader = 0; } else{ $leader = Db::name('Department')->where(['id' => $pdid])->value('leader_id'); } } return $leader; } //读取员工所在部门的负责人(pid=1,上一级负责人) function get_department_manager($uid=0,$pid=0) { $did = get_admin($uid)['did']; if($pid==0){ $manager = Db::name('Department')->where(['id' => $did])->value('manager_id'); } else{ $pdid = Db::name('Department')->where(['id' => $did])->value('pid'); if($pdid == 0){ $manager = 0; } else{ $manager = Db::name('Department')->where(['id' => $pdid])->value('manager_id'); } } return $manager; } //读取部门负责人所在部门的数据权限【包括员工所在部门+其子部门】 function get_department_role($uid = 0) { $did = get_admin($uid)['did']; //判断是否是部门负责人 $is_leader = Db::name('Department')->where(['id' => $did,'leader_id'=>$uid])->count(); if($is_leader==0){ return []; } else{ //获取子部门 $department = get_department(); $department_list = get_data_node($department, $did); $department_array = array_column($department_list, 'id'); //包括自己部门在内 $department_array[] = $did; return $department_array; } } //读取是否是某员工的上级领导 function get_user_role($leader_id=0,$uid = 0) { $did = get_admin($uid)['did']; //获取子部门 $department = get_department(); $department_list = get_data_node($department, $did); $department_array = array_column($department_list, 'id'); //包括自己部门在内 $department_array[] = $did; //判断是否是部门负责人 $is_leader = Db::name('Department')->where([['id','in',$did],['leader_id','=',$leader_id]])->count(); return $is_leader; } //读取根据uid返回所在部门和所管理的子部门did function get_user_dids($uid = 0) { $did = get_admin($uid)['did']; $department_array = []; //判断是否是部门负责人 $is_leader = Db::name('Department')->where(['id'=>$did,'leader_id'=>$uid])->count(); if($is_leader > 0 || $uid == 1){ //获取子部门 $department = get_department(); $department_list = get_data_node($department, $did); $department_array = array_column($department_list, 'id'); //包括自己部门在内 $department_array[] = $did; } else{ //包括自己部门在内 $department_array[] = $did; } return $department_array; } //读取职位 function get_position() { $position = Db::name('Position')->where(['status' => 1])->select()->toArray(); return $position; } //根据流程类型读取某部门某模块的审核流程 function get_cate_department_flows($cate=1,$department=0) { $map1 = []; $map2 = []; $map1[] = ['status', '=', 1]; $map1[] = ['flow_cate', '=', $cate]; $map1[] = ['department_ids', '=', '']; $map2[] = ['status', '=', 1]; $map2[] = ['flow_cate', '=', $cate]; $map2[] = ['', 'exp', Db::raw("FIND_IN_SET('{$department}',department_ids)")]; $list = Db::name('Flow')->field('id,name,check_type')->whereOr([$map1,$map2])->order('id desc')->select()->toArray(); return $list; } //根据流程所属模块读取某部门某模块的审核流程 function get_type_department_flows($type=6,$department=0) { $map1 = []; $map2 = []; $map1[] = ['status', '=', 1]; $map1[] = ['type', '=', $type]; $map1[] = ['department_ids', '=', '']; $map2[] = ['status', '=', 1]; $map2[] = ['type', '=', $type]; $map2[] = ['', 'exp', Db::raw("FIND_IN_SET('{$department}',department_ids)")]; $list = Db::name('Flow')->field('id,name,check_type')->whereOr([$map1,$map2])->order('id desc')->select()->toArray(); return $list; } /** * 初始化审批流程数据 * @param $flow_id 审批流程id * @return */ function set_flow($flow_id,$check_admin_ids,$uid) { $flow_detail = Db::name('Flow')->where('id',$flow_id)->find(); $check_type = $flow_detail['check_type']; $flow = unserialize($flow_detail['flow_list']); if ($check_type == 1) { if($flow[0]['flow_type'] == 1){ //部门负责人 $manager = get_department_manager($uid); if($manager == 0){ return to_assign(1,'审批流程设置有问题:当前部门负责人还未设置,请联系HR或者管理员'); } else{ $check_admin_ids = $manager; } } else if($flow[0]['flow_type'] == 2){ //上级部门负责人 $manager = get_department_manager($uid,1); if($manager == 0){ return to_assign(1,'审批流程设置有问题:上级部门负责人还未设置,请联系HR或者管理员'); } else{ $check_admin_ids = $manager; } } else if($flow[0]['flow_type'] == 7){ //部门分管领导 $leader = get_department_leader($uid); if($leader == 0){ return to_assign(1,'审批流程设置有问题:部门分管领导还未设置,请联系HR或者管理员'); } else{ $check_admin_ids = $leader; } } else if($flow[0]['flow_type'] == 6){ //上级部门分管领导 $leader = get_department_leader($uid,1); if($leader == 0){ return to_assign(1,'审批流程设置有问题:上级部门分管领导还未设置,请联系HR或者管理员'); } else{ $check_admin_ids = $leader; } } else{ $check_admin_ids = $flow[0]['flow_uids']; } } else if ($check_type == 3) { $check_admin_ids = $flow[0]['flow_uids']; } $flow_data = array( 'check_type' => $check_type, 'flow' => $flow, 'check_admin_ids' => $check_admin_ids ); return $flow_data; } /** * 获取审批流程数据 * @param $uid 当前登录用户 * @param $flows 当前步骤内容 * @return */ function get_flow($uid,$flows) { $check_user = ''; $check_user_ids = []; if($flows['flow_type']==1){ $check_user = '部门负责人-'; $check_user_ids[]=get_department_manager($uid); } else if($flows['flow_type']==2){ $check_user = '上级部门负责人-'; $check_user_ids[]=get_department_manager($uid,1); } else if($flows['flow_type']==7){ $check_user = '部门分管领导-'; $check_user_ids[]=get_department_leader($uid); } else if($flows['flow_type']==6){ $check_user = '上级部门分管领导-'; $check_user_ids[]=get_department_leader($uid,1); } else{ $check_user_ids = explode(',',$flows['flow_uids']); } $check_user_array = Db::name('Admin')->where('id','in',$check_user_ids)->column('name'); $res = array( 'check_user' => $check_user.implode(',',$check_user_array), 'check_user_ids' => $check_user_ids ); return $res; } /** * 隐藏电话号码中间4位和邮箱 */ function hidetel($phone) { //隐藏邮箱 if (strpos($phone, '@')) { $email_array = explode("@", $phone); $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($phone, 0, 3); //邮箱前缀 $count = 0; $str = preg_replace('/([\d\w+_-]{0,100})@/', '***@', $phone, -1, $count); $rs = $prevfix . $str; return $rs; } else { //隐藏联系方式中间4位 $Istelephone = preg_match('/(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)/i', $phone); //固定电话 if ($Istelephone) { return preg_replace('/(0[0-9]{2,3}[\-]?[2-9])[0-9]{3,4}([0-9]{3}[\-]?[0-9]?)/i', '$1****$2', $phone); } else { return preg_replace('/(1[0-9]{1}[0-9])[0-9]{4}([0-9]{4})/i', '$1****$2', $phone); } } } /** * @Method: 文件格式大小 * @param[type] $file_size [文件大小] */ function to_size($file_size){ $file_size = $file_size-1; if ($file_size >= 1099511627776){ $show_filesize = number_format(($file_size / 1099511627776),2) . " TB"; } elseif ($file_size >= 1073741824) { $show_filesize = number_format(($file_size / 1073741824),2) . " GB"; } elseif ($file_size >= 1048576) { $show_filesize = number_format(($file_size / 1048576),2) . " MB"; } elseif ($file_size >= 1024) { $show_filesize = number_format(($file_size / 1024),2) . " KB"; } elseif ($file_size > 0) { $show_filesize = $file_size . " b"; } elseif ($file_size == 0 || $file_size == -1) { $show_filesize = "0 b"; } return $show_filesize; } //格式化附件展示 function file_card($file,$view=''){ $image=['jpg','jpeg','png','gif']; $type_icon = 'icon-sucaiziyuan'; $view_btn = ''; if($file['fileext'] == 'pdf'){ $type_icon = 'icon-lunwenguanli'; $view_btn = ''; } if(in_array($file['fileext'], $image)){ $type_icon = 'icon-sucaiguanli'; $view_btn = ''; } $file_del=''; if(!empty($file['delete_time'])){ $file_del = 'file-hasdelete'; } $item = '