@is", "", $content); $content = preg_replace("@@is", "", $content); $content = preg_replace("@@is", "", $content); $content = preg_replace("@<(.*?)>@is", "", $content); $content = str_replace(PHP_EOL, '', $content); $space = array(" ", " ", " ", " ", " "); $go_away = array("", "", "", "", ""); $content = str_replace($space, $go_away, $content); $res = mb_substr($content, 0, $count, 'UTF-8'); if (mb_strlen($content, 'UTF-8') > $count) { $res = $res . "..."; } return $res; } /** * PHP格式化字节大小 * @param number $size 字节数 * @param string $delimiter 数字和单位分隔符 * @return string 格式化后的带单位的大小 */ function format_bytes($size, $delimiter = '') { $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); for ($i = 0; $size >= 1024 && $i < 5; $i++) { $size /= 1024; } return round($size, 2) . $delimiter . $units[$i]; } function create_tree_list($pid, $arr, $group, &$tree = []) { foreach ($arr as $key => $vo) { if ($key == 0) { $vo['spread'] = true; } if (!empty($group) and in_array($vo['id'], $group)) { $vo['checked'] = true; } else { $vo['checked'] = false; } if ($vo['pid'] == $pid) { $child = create_tree_list($vo['id'], $arr, $group); if ($child) { $vo['children'] = $child; } $tree[] = $vo; } } return $tree; } //递归排序,用于分类选择 function set_recursion($result, $pid = 0, $level = -1) { /*记录排序后的类别数组*/ static $list = array(); static $space = ['', '├─', '§§├─', '§§§§├─', '§§§§§§├─']; $level++; foreach ($result as $k => $v) { if ($v['pid'] == $pid) { if ($pid != 0) { $v['title'] = $space[$level] . $v['title']; } /*将该类别的数据放入list中*/ $list[] = $v; set_recursion($result, $v['id'], $level); } } return $list; } /** * 根据id递归返回子数据 * @param $data 数据 * @param $pid 父节点id */ function get_data_node($data = [], $pid = 0) { $dep = []; foreach ($data as $k => $v) { if ($v['pid'] == $pid) { $node = get_data_node($data, $v['id']); array_push($dep, $v); if (!empty($node)) { $dep = array_merge($dep, $node); } } } return array_values($dep); } //获取指定管理员的信息 function get_admin($id) { $admin = Db::name('Admin')->where(['id' => $id])->find(); $admin['group_id'] = Db::name('AdminGroupAccess')->where(['uid' => $id])->column('group_id'); return $admin; } //读取权限节点列表 function get_admin_rule() { $rule = Db::name('AdminRule')->where(['status' => 1])->order('sort asc,id asc')->select()->toArray(); return $rule; } //读取模块列表 function get_admin_module() { $group = Db::name('AdminModule')->order('id asc')->select()->toArray(); return $group; } //读取权限分组列表 function get_admin_group() { $group = Db::name('AdminGroup')->order('create_time asc')->select()->toArray(); return $group; } //读取指定权限分组详情 function get_admin_group_info($id) { $rule = Db::name('AdminGroup')->where(['id' => $id])->value('rules'); $rules = explode(',', $rule); return $rules; } //读取部门列表 function get_department() { $department = Db::name('Department')->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; } //读取员工所在部门的负责人 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; } //读取职位 function get_position() { $position = Db::name('Position')->where(['status' => 1])->select()->toArray(); return $position; } //读取导航列表,用于后台 function get_nav($nav_id) { $nav = Db::name('NavInfo')->where('nav_id', $nav_id)->order('sort asc')->select(); return $nav; } //读取关键字列表 function get_keywords() { $keywords = Db::name('Keywords')->where(['status' => 1])->order('create_time asc')->select(); return $keywords; } //读取文章分类列表 function get_article_cate() { $cate = Db::name('ArticleCate')->where(['delete_time' => 0])->order('create_time asc')->select()->toArray(); return $cate; } //读取图集分类列表 function get_gallery_cate() { $cate = Db::name('GalleryCate')->where(['delete_time' => 0])->order('create_time asc')->select()->toArray(); return $cate; } //读取商品分类列表 function get_goods_cate() { $cate = Db::name('GoodsCate')->where(['delete_time' => 0])->order('create_time asc')->select()->toArray(); return $cate; } //访问按小时归档统计 function hour_document($arrData) { $documents = array(); $hour = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]; foreach ($hour as $val) { $documents[$val] = 0; } foreach ($arrData as $index => $value) { $archivesTime = intval(date("H", $value['create_time'])); $documents[$archivesTime] += 1; } return $documents; } //访问按日期归档统计 function date_document($arrData) { $documents = array(); foreach ($arrData as $index => $value) { $archivesTime = date("Y-m-d", $value['create_time']); if (empty($documents[$archivesTime])) { $documents[$archivesTime] = 1; } else { $documents[$archivesTime] += 1; } } return $documents; } /** * 管理员操作日志 * @param string $type 操作类型 login add edit view delete * @param int $param_id 操作类型 * @param array $param 提交的参数 * @param subject $param 操作主题 */ function add_log($type, $param_id = '', $param = [], $subject = '') { $action = '未知操作'; $type_action = get_config('log.admin_action'); if ($type_action[$type]) { $action = $type_action[$type]; } if ($type == 'login') { $login_admin = Db::name('Admin')->where(array('id' => $param_id))->find(); } else { $session_admin = get_config('app.session_admin'); $login_admin = \think\facade\Session::get($session_admin); } $data = []; $data['title'] = ''; $data['uid'] = $login_admin['id']; $data['nickname'] = $login_admin['nickname']; $data['type'] = $type; $data['action'] = $action; $data['param_id'] = $param_id; $data['param'] = json_encode($param); $data['module'] = strtolower(app('http')->getName()); $data['controller'] = uncamelize(app('request')->controller()); $data['function'] = strtolower(app('request')->action()); $parameter = $data['module'] . '/' . $data['controller'] . '/' . $data['function']; $rule_menu = Db::name('AdminRule')->where(array('src' => $parameter))->find(); if ($rule_menu) { $data['title'] = $rule_menu['title']; $data['subject'] = $rule_menu['name']; } else { if (empty($subject)) { $data['subject'] = '系统'; } else { $data['subject'] = $subject; } } $content = $login_admin['nickname'] . '在' . date('Y-m-d H:i:s') . $data['action'] . '了' . $data['subject']; $data['content'] = $content; $data['ip'] = app('request')->ip(); $data['create_time'] = time(); Db::name('AdminLog')->strict(false)->field(true)->insert($data); } /** * 项目操作日志 * */ function add_project_log($action, $project_id, $content = '', $type = 0) { $data = array(); $session_admin = get_config('app.session_admin'); $login_admin = \think\facade\Session::get($session_admin); $data['uid'] = $login_admin['id']; $data['nickname'] = $login_admin['nickname']; $data['unit_name'] = $login_admin['unit_name']; $data['project_id'] = $project_id; $project = Db::name('CostProject')->where('id', $project_id)->field("project_name,project_status")->find(); $data['project_name'] = $project['project_name']; $data['project_status'] = $project['project_status']; $data['action'] = $action; $data['ip'] = app('request')->ip(); $data['create_time'] = time(); // halt($data); if (!empty($content)) { $data["content"] = $content; } if($type){ $arr_ids = array(); $ids = Db::name("cost_project")->where("id", $project_id)->field("entrust_maker,entrust_approver,review_head,sent_review_unit,operate_head,operate_team")->find(); $workpeople = $ids['operate_team']; foreach ($ids as $key => $value) { if($key == 'operate_team'){ $value1 = explode(',',$value); foreach ($value1 as $key => $value) { array_push($arr_ids, $value); $arr_ids = array_filter($arr_ids); } }else{ array_push($arr_ids, $value); } $arr_ids = array_filter($arr_ids); } $key = array_search(get_login_admin("id"), $arr_ids); unset($arr_ids[$key]); $key= ''; switch ($type) { case 1: $key="detail"; break; case 2: $key="comment"; break; case 3: $key="record"; break; case 4: $key="report"; break; case 5: $key="user"; break; case 6: $key="contact"; break; } // halt($arr_ids); if(!empty($key)){ Db::name("new_msg")->whereIn("uid",$arr_ids)->where("project_id",$project_id)->update([$key=>1]); } } Db::name('ProjectLog')->strict(false)->field(true)->insert($data); } /** *添加人员和项目关系 */ function add_user($uid,$project_id){ $data = [ "uid" => $uid, "project_id" => $project_id, ]; Db::name("new_msg")->insert($data); } /** *删除人员和项目关系 */ function remove_user($uid){ Db::name("new_msg")->where("uid",$uid)->delete(); } /** * * 小红点 */ function new_msg($project_id,$type) { $arr_ids = array(); $ids = Db::name("cost_project")->where("id", $project_id)->field("entrust_maker,review_head,sent_review_unit,operate_head,operate_team")->find(); foreach ($ids as $key => $value) { array_push($arr_ids, $value); $arr_ids = array_filter($arr_ids); } $aaa = [ "detail" => 0, "comment" => 0, "record" =>0, "report" =>0, "user" =>0 ]; $aaa= json_encode($aaa); $aaa = Db::name('admin_group_access')->column("uid"); $a = Db::name("admin")->column("id"); $c = array_diff($aaa,$a); dump($c,$aaa,$a); } //递归返回树形菜单数据 function get_tree($data, $pId, $open = 0, $deep = 0) { $tree = []; foreach ($data as $k => $v) { $v['checkArr'] = array('type' => 0, 'isChecked' => 0); $v['spread'] = true; $v['parentId'] = $v['pid']; if ($deep >= $open) { $v['spread'] = false; } $v['name'] = $v['title']; if ($v['pid'] == $pId) { //父亲找到儿子 $deep++; $v['children'] = get_tree($data, $v['id'], $open, $deep); $tree[] = $v; //unset($data[$k]); } } return array_values($tree); } //获取顶级部门id function get_unit($unit_id) { $unit_pid = Db::name('Department')->where("id", $unit_id)->field(["pid", "id"])->find(); for ($i = $unit_id; $i > 0;) { $unit_pid = Db::name('Department')->where("id", $i)->field(["pid", "id"])->find(); $i = $unit_pid["pid"]; if ($i == 0) { return $unit_pid["id"]; } } } /** * 附件样式 */ function fileCard($item) { $li = ''; $host = $_SERVER['HTTP_HOST']; if (count($item) > 0) { for ($a = 0; $a < count($item); $a++) { $image = ['jpg', 'jpeg', 'png', 'gif']; $doc = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'zip', 'rar', '7z']; $down = '预览'; $down1 = '下载'; // 判断元素是否在数组中 $path = '/static/home/images/icon/file.png'; if (in_array($item[$a]['fileext'], $image)) { $path = $item[$a]['filepath']; $down = '预览'; } else if (in_array($item[$a]['fileext'], $doc)) { $path = '/static/home/images/icon/' . $item[$a]['fileext'] . '.png'; } dump($item); $li .= '
  • ' . $item[$a]['name'] .
                '

    ' . $item[$a]['name'] . '

    ' . $down . $down1 . '删除' . '
  • '; } return $li; } }