diff --git a/app/api/BaseController.php b/app/api/BaseController.php index a095869..126d3d6 100644 --- a/app/api/BaseController.php +++ b/app/api/BaseController.php @@ -97,10 +97,10 @@ abstract class BaseController $session_admin = get_config('app.session_admin'); if (!Session::has($session_admin)) { $this->apiError('请先登录'); - } else { - $this->uid = Session::get($session_admin)['id']; - View::assign('login_user', $this->uid); } + else{ + $this->uid = Session::get($session_admin); + } } /** * Api处理成功结果返回方法 diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index ffe82c6..589f952 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -83,7 +83,7 @@ class Index extends BaseController $data['action'] = app('request')->action(); $data['uploadip'] = app('request')->ip(); $data['create_time'] = time(); - $data['user_id'] = get_login_admin('id') ? get_login_admin('id') : 0; + $data['user_id'] = this->uid; if ($data['module'] = 'admin') { //通过后台上传的文件直接审核通过 $data['status'] = 1; diff --git a/app/article/view/index/view.html b/app/article/view/index/view.html index e88478b..5b64c18 100644 --- a/app/article/view/index/view.html +++ b/app/article/view/index/view.html @@ -68,7 +68,7 @@ <img src="{$vo.thumb}" alt="{vo.name}" class="comment-img"> </div> <div style="margin-left:128px;"> - <p class="comment-tips">发表于:{$vo.create_time}{$vo.update_time} {eq name="$vo.admin_id" value="$login_user"} <button class="layui-btn layui-btn-xs layui-btn-danger layui-del" data-cid="{$vo.id}">删除</button>{/eq}</p> + <p class="comment-tips">发表于:{$vo.create_time}{$vo.update_time} {eq name="$vo.admin_id" value="$login_admin"} <button class="layui-btn layui-btn-xs layui-btn-danger layui-del" data-cid="{$vo.id}">删除</button>{/eq}</p> <div class="py-2">{$vo.content|raw}</div> </div> </div> diff --git a/app/base/BaseController.php b/app/base/BaseController.php index d6c1b64..d3949a4 100644 --- a/app/base/BaseController.php +++ b/app/base/BaseController.php @@ -16,6 +16,7 @@ use think\facade\Db; use think\facade\Request; use think\facade\Session; use think\facade\View; +use systematic\Systematic; /** * 控制器基础类 @@ -68,7 +69,6 @@ abstract class BaseController { // 检测权限 $this->checkLogin(); - $this->param = $this->request->param(); } /** @@ -86,11 +86,11 @@ abstract class BaseController exit; } } else { - $this->uid = Session::get($session_admin)['id']; - $this->did = Session::get($session_admin)['did']; - View::assign('login_user', $this->uid); - $user = Db::name('Admin')->where(['id' => $this->uid])->find(); - $is_lock = $user['is_lock']; + $this->uid = Session::get($session_admin); + $login_admin = Db::name('Admin')->where(['id' => $this->uid])->find(); + $this->did = $login_admin['did']; + View::assign('login_admin', $login_admin); + $is_lock = $login_admin['is_lock']; if($is_lock==1){ redirect('/home/login/lock.html')->send(); exit; @@ -100,9 +100,9 @@ abstract class BaseController return true; } else{ - $reg_pwd = $user['reg_pwd']; + $reg_pwd = $login_admin['reg_pwd']; if($reg_pwd!==''){ - redirect('/home/api/edit_password.html')->send(); + redirect('/home/index/edit_password.html')->send(); exit; } if (!$this->checkAuth()) { @@ -127,44 +127,12 @@ abstract class BaseController protected function checkAuth() { //Cache::delete('RulesSrc' . $uid); - $uid = $this->uid; - if (!Cache::get('RulesSrc' . $uid) || !Cache::get('RulesSrc0')) { - //用户所在权限组及所拥有的权限 - // 执行查询 - $groups = []; - $position_id = Db::name('Admin')->where('id', $uid)->value('position_id'); - $groups = Db::name('PositionGroup') - ->alias('a') - ->join("AdminGroup g", "a.group_id=g.id", 'LEFT') - ->where([['a.pid', '=', $position_id], ['g.status', '=', 1]]) - ->select() - ->toArray(); - //保存用户所属用户组设置的所有权限规则id - $ids = []; - foreach ($groups as $g) { - $ids = array_merge($ids, explode(',', trim($g['rules'], ','))); - } - $ids = array_unique($ids); - //读取所有权限规则 - $rules_all = Db::name('AdminRule')->field('src')->select()->toArray(); - //读取用户组所有权限规则 - $rules = Db::name('AdminRule')->where('id', 'in', $ids)->field('src')->select()->toArray(); - //循环规则,判断结果。 - $auth_list_all = []; - $auth_list = []; - foreach ($rules_all as $rule_all) { - $auth_list_all[] = strtolower($rule_all['src']); - } - foreach ($rules as $rule) { - $auth_list[] = strtolower($rule['src']); - } - //规则列表结果保存到Cache - Cache::tag('adminRules')->set('RulesSrc0', $auth_list_all, 36000); - Cache::tag('adminRules')->set('RulesSrc' . $uid, $auth_list, 36000); - } else { - $auth_list_all = Cache::get('RulesSrc0'); - $auth_list = Cache::get('RulesSrc' . $uid); - } + $uid = $this->uid; + $GOUGU = new Systematic(); + $GOUGU->auth($uid); + $auth_list_all = Cache::get('RulesSrc0'); + $auth_list = Cache::get('RulesSrc' . $uid); + $pathUrl = $this->module . '/' . $this->controller . '/' . $this->action; if (!in_array($pathUrl, $auth_list)) { return false; @@ -172,91 +140,4 @@ abstract class BaseController return true; } } - - // - // 以下为新增,为了使用旧版TP的 success error redirect 跳转 start - // - - /** - * 操作成功跳转的快捷方法 - * @access protected - * @param mixed $msg 提示信息 - * @param string $url 跳转的URL地址 - * @param mixed $data 返回的数据 - * @param integer $wait 跳转等待时间 - * @param array $header 发送的Header信息 - * @return void - */ - protected function success($msg = '', string $url = null, $data = '', int $wait = 3, array $header = []) - { - if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) { - $url = $_SERVER["HTTP_REFERER"]; - } elseif ($url) { - $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url); - } - - $result = [ - 'code' => 0, - 'msg' => $msg, - 'data' => $data, - 'url' => $url, - 'wait' => $wait, - ]; - - $type = $this->getResponseType(); - if ($type == 'html') { - $response = view($this->app->config->get('app.dispatch_success_tmpl'), $result); - } else if ($type == 'json') { - $response = json($result); - } - throw new HttpResponseException($response); - } - - /** - * 操作错误跳转的快捷方法 - * @access protected - * @param mixed $msg 提示信息 - * @param string $url 跳转的URL地址 - * @param mixed $data 返回的数据 - * @param integer $wait 跳转等待时间 - * @param array $header 发送的Header信息 - * @return void - */ - protected function error($msg = '', string $url = null, $data = '', int $wait = 3, array $header = []) - { - if (is_null($url)) { - $url = $this->request->isAjax() ? '' : 'javascript:history.back(-1);'; - } elseif ($url) { - $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app->route->buildUrl($url); - } - - $result = [ - 'code' => 1, - 'msg' => $msg, - 'data' => $data, - 'url' => $url, - 'wait' => $wait, - ]; - - $type = $this->getResponseType(); - if ($type == 'html') { - $response = view($this->app->config->get('app.dispatch_error_tmpl'), $result); - } else if ($type == 'json') { - $response = json($result); - } - throw new HttpResponseException($response); - } - /** - * 获取当前的response 输出类型 - * @access protected - * @return string - */ - protected function getResponseType() - { - return $this->request->isJson() || $this->request->isAjax() ? 'json' : 'html'; - } - - // - // 以上为新增,为了使用旧版的 success error redirect 跳转 end - // } diff --git a/app/base/view/common/base.html b/app/base/view/common/base.html index 2716b13..d784ea9 100644 --- a/app/base/view/common/base.html +++ b/app/base/view/common/base.html @@ -20,7 +20,7 @@ {/block} {block name="style"}{/block} <script> - const login_user={$login_user}; + const login_admin={$login_admin.id}; </script> {block name="js"}{/block} </head> diff --git a/app/common.php b/app/common.php index 5c0fd1f..f3447d0 100644 --- a/app/common.php +++ b/app/common.php @@ -173,27 +173,6 @@ function get_admin($id) return $admin; } -//获取当前登录用户的信息 -function get_login_admin($key = '') -{ - $session_admin = get_config('app.session_admin'); - if (\think\facade\Session::has($session_admin)) { - $gougu_admin = \think\facade\Session::get($session_admin); - $admin = get_admin($gougu_admin['id']); - if (!empty($key)) { - if (isset($admin[$key])) { - return $admin[$key]; - } else { - return ''; - } - } else { - return $admin; - } - } else { - return ''; - } -} - /** * 节点权限判断 * @rule String @@ -423,6 +402,31 @@ function get_flow($uid,$flows) 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); + } + } +} + //读取报销类型 function get_expense_cate() { @@ -504,58 +508,149 @@ function get_file($id) } /** - * 员工操作日志 - * @param string $type 操作类型 login add edit view delete - * @param int $param_id 操作类型 - * @param array $param 提交的参数 + * 间隔时间段格式化 + * @param int $time 时间戳 + * @param string $format 格式 【d:显示到天 i显示到分钟 s显示到秒】 + * @return string */ +function time_trans($time, $format = 'd') +{ + $now = time(); + $diff = $now - $time; + if ($diff < 60) { + return '1分钟前'; + } else if ($diff < 3600) { + return floor($diff / 60) . '分钟前'; + } else if ($diff < 86400) { + return floor($diff / 3600) . '小时前'; + } + $yes_start_time = strtotime(date('Y-m-d 00:00:00', strtotime('-1 days'))); //昨天开始时间 + $yes_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-1 days'))); //昨天结束时间 + $two_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-2 days'))); //2天前结束时间 + $three_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-3 days'))); //3天前结束时间 + $four_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-4 days'))); //4天前结束时间 + $five_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-5 days'))); //5天前结束时间 + $six_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-6 days'))); //6天前结束时间 + $seven_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-7 days'))); //7天前结束时间 + + if ($time > $yes_start_time && $time < $yes_end_time) { + return '昨天'; + } + + if ($time > $yes_start_time && $time < $two_end_time) { + return '1天前'; + } + + if ($time > $yes_start_time && $time < $three_end_time) { + return '2天前'; + } + + if ($time > $yes_start_time && $time < $four_end_time) { + return '3天前'; + } + + if ($time > $yes_start_time && $time < $five_end_time) { + return '4天前'; + } + + if ($time > $yes_start_time && $time < $six_end_time) { + return '5天前'; + } + + if ($time > $yes_start_time && $time < $seven_end_time) { + return '6天前'; + } + + switch ($format) { + case 'd': + $show_time = date('Y-m-d', $time); + break; + case 'i': + $show_time = date('Y-m-d H:i', $time); + break; + case 's': + $show_time = date('Y-m-d H:i:s', $time); + break; + } + return $show_time; +} + +/** + * 计算按天数 + */ +function countDays($a, $b = 0) +{ + if ($b == 0) { + $b = date("Y-m-d"); + } + $date_1 = $a; + $date_2 = $b; + $d1 = strtotime($date_1); + $d2 = strtotime($date_2); + $days = round(($d2 - $d1) / 3600 / 24); + if ($days > 0) { + return $days; + } else { + return 0; + } +} + + +/** + * fullcalendar日历控件方法1 + */ +function parseDateTime($string, $timeZone=null) { + $date = new DateTime( + $string, + $timeZone ? $timeZone : new DateTimeZone('UTC') + ); + if ($timeZone) { + $date->setTimezone($timeZone); + } + return $date; +} + +/** + * fullcalendar日历控件方法2 + */ +function stripTime($datetime) { + return new DateTime($datetime->format('Y-m-d')); +} + + function add_log($type, $param_id = '', $param = [] ,$subject='') { - $action = '未知操作'; + $title = '操作'; + $session_admin = get_config('app.session_admin'); + $uid = \think\facade\Session::get($session_admin); $type_action = get_config('log.type_action'); if($type_action[$type]){ - $action = $type_action[$type]; + $title = $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['uid'] = $login_admin['id']; - $data['name'] = $login_admin['name']; - $data['type'] = $type; - $data['action'] = $action; - $data['param_id'] = $param_id; - $data['param'] = json_encode($param); - $data['module'] = strtolower(app('http')->getName()); - $data['controller'] = strtolower(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']; - } - elseif($type == 'upload'){ - $data['title'] = $param['name']; - $data['subject'] = '文件'; + $data = [ + 'uid' => $uid, + 'type' => $type, + 'action' => $title, + 'param_id' => $param_id, + 'param' => json_encode($param), + 'module' => strtolower(app('http')->getName()), + 'controller' => strtolower(app('request')->controller()), + 'function' => strtolower(app('request')->action()), + 'ip' => app('request')->ip(), + 'create_time' => time(), + 'subject' => '系统' + ]; + if($subject!=''){ + $data['subject'] =$subject; } else{ - $data['title'] = ''; - if($subject!=''){ - $data['subject'] =$subject; + $rule = $data['module'] . '/' . $data['controller'] . '/' . $data['function']; + $rule_menu = Db::name('AdminRule')->where(array('src' => $rule))->find(); + if($rule_menu){ + $data['subject'] = $rule_menu['name']; } - else{ - $data['subject'] ='系统'; - } } - $content = $login_admin['name'] . '在' . 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); + Db::name('AdminLog')->strict(false)->field(true)->insert($data); } /** @@ -983,10 +1078,11 @@ function date_document($arrData) * @param array $options * @return json */ -function to_assign($code = 0, $msg = "操作成功", $data = [], $url = '', $httpCode = 200, $header = [], $options = []) +function to_assign($code = 0, $msg = "操作成功", $data = [], $action = '', $url = '', $httpCode = 200, $header = [], $options = []) { $res = ['code' => $code]; $res['msg'] = $msg; + $res['action'] = $action; $res['url'] = $url; if (is_object($data)) { $data = $data->toArray(); @@ -1147,37 +1243,6 @@ function sort_select($select = array(), $field, $order = 1) } } -/** - * fullcalendar日历控件方法1 - */ -function parseDateTime($string, $timeZone=null) { - $date = new DateTime( - $string, - $timeZone ? $timeZone : new DateTimeZone('UTC') - ); - if ($timeZone) { - $date->setTimezone($timeZone); - } - return $date; -} - -/** - * fullcalendar日历控件方法2 - */ -function stripTime($datetime) { - return new DateTime($datetime->format('Y-m-d')); -} - -/** - * 根据时间戳获取星期几 - * @param $time 要转换的时间戳 - */ -function getTimeWeek($time, $i = 0) -{ - $weekarray = array("日", "一", "二", "三", "四", "五", "六"); - $oneD = 24 * 60 * 60; - return "星期" . $weekarray[date("w", $time + $oneD * $i)]; -} /** * 时间戳格式化 * @param int $time @@ -1195,462 +1260,6 @@ function time_format($time = NULL, $format = 'Y-m-d H:i:s') return $time != '' ? str_replace('x', $sec, date($format, intval($usec))) : ''; } -/** - * 将秒数转换为时间 (小时、分、秒) - * @param - */ -function getTimeBySec($time,$second=true) -{ - if (is_numeric($time)) { - $value = array( - "hours" => 0, - "minutes" => 0, "seconds" => 0, - ); - $t=''; - if ($time >= 3600) { - $value["hours"] = floor($time / 3600); - $time = ($time % 3600); - $t .= $value["hours"] . "小时"; - } - if ($time >= 60) { - $value["minutes"] = floor($time / 60); - $time = ($time % 60); - $t .= $value["minutes"] . "分钟"; - } - if ($time > 0 && $time < 60 && $second==true) { - $value["seconds"] = floor($time); - $t .= $value["seconds"] . "秒"; - } - return $t; - } else { - return (bool)FALSE; - } -} - -/** - * 将秒数转换为时间 (年、天、小时、分、秒) - * @param - */ -function getDateBySec($time,$second=false) -{ - if (is_numeric($time)) { - $value = array( - "years" => 0, "days" => 0, "hours" => 0, - "minutes" => 0, "seconds" => 0, - ); - $t=''; - if ($time >= 31556926) { - $value["years"] = floor($time / 31556926); - $time = ($time % 31556926); - $t .= $value["years"] . "年"; - } - if ($time >= 86400) { - $value["days"] = floor($time / 86400); - $time = ($time % 86400); - $t .= $value["days"] . "天"; - } - if ($time >= 3600) { - $value["hours"] = floor($time / 3600); - $time = ($time % 3600); - $t .= $value["hours"] . "小时"; - } - if ($time >= 60) { - $value["minutes"] = floor($time / 60); - $time = ($time % 60); - $t .= $value["minutes"] . "分钟"; - } - if ($time < 60 && $second==true) { - $value["seconds"] = floor($time); - $t .= $value["seconds"] . "秒"; - } - return $t; - } else { - return (bool)FALSE; - } -} - -/* - *根据年月计算有几天 - */ -function getmonthByYM($param) -{ - $month = $param['month'] ? $param['month'] : date('m', time()); - $year = $param['year'] ? $param['year'] : date('Y', time()); - if (in_array($month, array('1', '3', '5', '7', '8', '01', '03', '05', '07', '08', '10', '12'))) { - $days = '31'; - } elseif ($month == 2) { - if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 !== 0)) { - //判断是否是闰年 - $days = '29'; - } else { - $days = '28'; - } - } else { - $days = '30'; - } - return $days; -} - -/** - * 根据时间戳计算当月天数 - * @param - */ -function getmonthdays($time) -{ - $month = date('m', $time); - $year = date('Y', $time); - if (in_array($month, array('1', '3', '5', '7', '8', '01', '03', '05', '07', '08', '10', '12'))) { - $days = '31'; - } elseif ($month == 2) { - if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 !== 0)) { - //判断是否是闰年 - $days = '29'; - } else { - $days = '28'; - } - } else { - $days = '30'; - } - return $days; -} - -/** - * 生成从开始时间到结束时间的日期数组 - * @param type,默认时间戳格式 - * @param type = 1 时,date格式 - * @param type = 2 时,获取每日开始、结束时间 - */ -function dateList($start, $end, $type = 0) -{ - if (!is_numeric($start) || !is_numeric($end) || ($end <= $start)) return ''; - $i = 0; - //从开始日期到结束日期的每日时间戳数组 - $d = array(); - if ($type == 1) { - while ($start <= $end) { - $d[$i] = date('Y-m-d', $start); - $start = $start + 86400; - $i++; - } - } else { - while ($start <= $end) { - $d[$i] = $start; - $start = $start + 86400; - $i++; - } - } - if ($type == 2) { - $list = array(); - foreach ($d as $k => $v) { - $list[$k] = getDateRange($v); - } - return $list; - } else { - return $d; - } -} - -/** - * 获取指定日期开始时间与结束时间 - */ -function getDateRange($timestamp) -{ - $ret = array(); - $ret['sdate'] = strtotime(date('Y-m-d', $timestamp)); - $ret['edate'] = strtotime(date('Y-m-d', $timestamp)) + 86400; - return $ret; -} - -/** - * 生成从开始月份到结束月份的月份数组 - * @param int $start 开始时间戳 - * @param int $end 结束时间戳 - */ -function monthList($start, $end) -{ - if (!is_numeric($start) || !is_numeric($end) || ($end <= $start)) return ''; - $start = date('Y-m', $start); - $end = date('Y-m', $end); - //转为时间戳 - $start = strtotime($start . '-01'); - $end = strtotime($end . '-01'); - $i = 0; - $d = array(); - while ($start <= $end) { - //这里累加每个月的的总秒数 计算公式:上一月1号的时间戳秒数减去当前月的时间戳秒数 - $d[$i] = $start; - $start += strtotime('+1 month', $start) - $start; - $i++; - } - return $d; -} - -/** - * 等于(时间段)数据处理 - * - * @param $type - * @return array - * @since 2021-06-11 - * @author fanqi - */ -function advancedDate($type) -{ - // 本年度 - if ($type == 'year') { - $arrTime = DataTime::year(); - $start_time = date('Y-m-d 00:00:00', $arrTime[0]); - $end_time = date('Y-m-d 23:59:59', $arrTime[1]); - } - - // 上一年度 - if ($type == 'lastYear') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 year')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 year')); - } - - // 下一年度 - if ($type == 'nextYear') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 year')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 year')); - } - - // 上半年 - if ($type == 'firstHalfYear') { - $start_time = date('Y-01-01 00:00:00'); - $end_time = date('Y-06-30 23:59:59'); - } - - // 下半年 - if ($type == 'nextHalfYear') { - $start_time = date('Y-07-01 00:00:00'); - $end_time = date('Y-12-31 23:59:59'); - } - - // 本季度 - if ($type == 'quarter') { - $season = ceil((date('n')) / 3); - $start_time = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y'))); - $end_time = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); - } - - // 上一季度 - if ($type == 'lastQuarter') { - $season = ceil((date('n')) / 3) - 1; - $start_time = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y'))); - $end_time = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); - } - - // 下一季度 - if ($type == 'nextQuarter') { - $season = ceil((date('n')) / 3); - $start_time = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 + 1, 1, date('Y'))); - $end_time = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3 + 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); - } - - // 本月 - if ($type == 'month') { - $start_time = date('Y-m-01 00:00:00'); - $end_time = date('Y-m-31 23:59:59'); - } - - // 上月 - if ($type == 'lastMonth') { - $start_time = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '-1 month')); - $end_time = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '-1 month')); - } - - // 下月 - if ($type == 'nextMonth') { - $start_time = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '+1 month')); - $end_time = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '+1 month')); - } - - // 本周 - if ($type == 'week') { - $start_time = date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'))); - $end_time = date('Y-m-d 23:59:59', mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y'))); - } - - // 上周 - if ($type == 'lastWeek') { - $date = date("Y-m-d"); - $w = date("w", strtotime($date)); - $d = $w ? $w - 1 : 6; - $start = date("Y-m-d", strtotime($date . " - " . $d . " days")); - $start_time = date('Y-m-d', strtotime($start . " - 7 days")); - $end_time = date('Y-m-d', strtotime($start . " - 1 days")); - } - - // 下周 - if ($type == 'nextWeek') { - $date = date("Y-m-d"); - $w = date("w", strtotime($date)); - $d = $w ? $w - 1 : 6; - $start = date("Y-m-d", strtotime($date . " - " . $d . " days")); - $start_time = date('Y-m-d', strtotime($start . " + 7 days")); - $end_time = date('Y-m-d', strtotime($start . " + 13 days")); - } - - // 今天 - if ($type == 'today') { - $start_time = date('Y-m-d 00:00:00'); - $end_time = date('Y-m-d 23:59:59'); - } - - // 昨天 - if ($type == 'yesterday') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); - } - - // 明天 - if ($type == 'tomorrow') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 day')); - } - - // 过去3天 - if ($type == 'previous3day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-3 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); - } - - // 过去5天 - if ($type == 'previous5day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-5 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); - } - - // 过去7天 - if ($type == 'previous7day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-7 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); - } - // 过去10天 - if ($type == 'previous10day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-10 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); - } - // 过去30天 - if ($type == 'previous30day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-30 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); - } - // 未来3天 - if ($type == 'future3day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+3 day')); - } - // 未来5天 - if ($type == 'future5day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+5 day')); - } - // 未来7天 - if ($type == 'future7day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+7 day')); - } - // 未来10天 - if ($type == 'future10day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+10 day')); - } - // 未来30天 - if ($type == 'future30day') { - $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); - $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+30 day')); - } - return [$start_time,$end_time]; -} - -/** - * 计算按天数 - */ -function countDays($a, $b = 0) -{ - if ($b == 0) { - $b = date("Y-m-d"); - } - $date_1 = $a; - $date_2 = $b; - $d1 = strtotime($date_1); - $d2 = strtotime($date_2); - $days = round(($d2 - $d1) / 3600 / 24); - if ($days > 0) { - return $days; - } else { - return 0; - } -} - -/** - * 间隔时间段格式化 - * @param int $time 时间戳 - * @param string $format 格式 【d:显示到天 i显示到分钟 s显示到秒】 - * @return string - */ -function time_trans($time, $format = 'd') -{ - $now = time(); - $diff = $now - $time; - if ($diff < 60) { - return '1分钟前'; - } else if ($diff < 3600) { - return floor($diff / 60) . '分钟前'; - } else if ($diff < 86400) { - return floor($diff / 3600) . '小时前'; - } - $yes_start_time = strtotime(date('Y-m-d 00:00:00', strtotime('-1 days'))); //昨天开始时间 - $yes_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-1 days'))); //昨天结束时间 - $two_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-2 days'))); //2天前结束时间 - $three_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-3 days'))); //3天前结束时间 - $four_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-4 days'))); //4天前结束时间 - $five_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-5 days'))); //5天前结束时间 - $six_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-6 days'))); //6天前结束时间 - $seven_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-7 days'))); //7天前结束时间 - - if ($time > $yes_start_time && $time < $yes_end_time) { - return '昨天'; - } - - if ($time > $yes_start_time && $time < $two_end_time) { - return '1天前'; - } - - if ($time > $yes_start_time && $time < $three_end_time) { - return '2天前'; - } - - if ($time > $yes_start_time && $time < $four_end_time) { - return '3天前'; - } - - if ($time > $yes_start_time && $time < $five_end_time) { - return '4天前'; - } - - if ($time > $yes_start_time && $time < $six_end_time) { - return '5天前'; - } - - if ($time > $yes_start_time && $time < $seven_end_time) { - return '6天前'; - } - - switch ($format) { - case 'd': - $show_time = date('Y-m-d', $time); - break; - case 'i': - $show_time = date('Y-m-d H:i', $time); - break; - case 's': - $show_time = date('Y-m-d H:i:s', $time); - break; - } - return $show_time; -} /** diff --git a/app/contract/view/index/add.html b/app/contract/view/index/add.html index 28d95e4..cce454c 100644 --- a/app/contract/view/index/add.html +++ b/app/contract/view/index/add.html @@ -245,7 +245,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/contract/index/add", data.field, callback); diff --git a/app/contract/view/index/edit.html b/app/contract/view/index/edit.html index 899094d..82c8f5e 100644 --- a/app/contract/view/index/edit.html +++ b/app/contract/view/index/edit.html @@ -251,7 +251,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/contract/index/add", data.field, callback); diff --git a/app/contract/view/index/view_set.html b/app/contract/view/index/view_set.html index 05dec9b..723c9c9 100644 --- a/app/contract/view/index/view_set.html +++ b/app/contract/view/index/view_set.html @@ -327,7 +327,7 @@ const moduleInit = ['tool','employeepicker']; success:function(e){ layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } }) diff --git a/app/customer/controller/Index.php b/app/customer/controller/Index.php index f38a6f8..c0e8212 100644 --- a/app/customer/controller/Index.php +++ b/app/customer/controller/Index.php @@ -415,7 +415,7 @@ class Index extends BaseController else{ $sea = isset($param['sea']) ? $param['sea'] : 0; View::assign('sea', $sea); - View::assign('userinfo', get_login_admin()); + View::assign('userinfo', get_admin($this->uid)); return view(); } } diff --git a/app/customer/view/api/add_chance.html b/app/customer/view/api/add_chance.html index a04a2ce..211d64e 100644 --- a/app/customer/view/api/add_chance.html +++ b/app/customer/view/api/add_chance.html @@ -93,7 +93,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(); + tool.sideClose(); parent.layui.chanceTable.reload(); } } diff --git a/app/customer/view/api/add_trace.html b/app/customer/view/api/add_trace.html index e2e4f8b..b5d3a22 100644 --- a/app/customer/view/api/add_trace.html +++ b/app/customer/view/api/add_trace.html @@ -92,7 +92,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(); + tool.sideClose(); parent.layui.traceTable.reload(); } } diff --git a/app/customer/view/api/edit_chance.html b/app/customer/view/api/edit_chance.html index 89426b4..8f27d7d 100644 --- a/app/customer/view/api/edit_chance.html +++ b/app/customer/view/api/edit_chance.html @@ -93,7 +93,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(); + tool.sideClose(); parent.layui.chanceTable.reload(); } } diff --git a/app/customer/view/api/edit_trace.html b/app/customer/view/api/edit_trace.html index a3fffe1..6663eb7 100644 --- a/app/customer/view/api/edit_trace.html +++ b/app/customer/view/api/edit_trace.html @@ -92,7 +92,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(); + tool.sideClose(); parent.layui.traceTable.reload(); } } diff --git a/app/customer/view/contact/contact_edit.html b/app/customer/view/contact/contact_edit.html index 922f38b..1c581a0 100644 --- a/app/customer/view/contact/contact_edit.html +++ b/app/customer/view/contact/contact_edit.html @@ -85,7 +85,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(); + tool.sideClose(); parent.layui.contactTable.reload(); } } diff --git a/app/customer/view/index/index.html b/app/customer/view/index/index.html index b368f12..44e29fa 100644 --- a/app/customer/view/index/index.html +++ b/app/customer/view/index/index.html @@ -195,7 +195,7 @@ var html = '<div class="layui-btn-group">'; var btn0='<span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>'; var btn1='<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove">移入公海</span>'; - if(d.belong_uid == login_user){ + if(d.belong_uid == login_admin){ return html+btn0+btn1+'</div>'; } else{ diff --git a/app/finance/model/Expense.php b/app/finance/model/Expense.php index 13bd246..2a45768 100644 --- a/app/finance/model/Expense.php +++ b/app/finance/model/Expense.php @@ -27,23 +27,23 @@ class Expense extends Model }); } else{ - $expense = Expense::where($where) - ->order('id desc') - ->paginate($rows, false, ['query' => $param]) - ->each(function ($item, $key) { - $item->income_month = empty($item->income_month) ? '-' : date('Y-m', $item->income_month); - $item->expense_time = empty($item->expense_time) ? '-' : date('Y-m-d', $item->expense_time); - $item->admin_name = Db::name('Admin')->where(['id' => $item->admin_id])->value('name'); - $item->department = Db::name('Department')->where(['id' => $item->did])->value('title'); - $item->pay_name = Db::name('Admin')->where(['id' => $item->pay_admin_id])->value('name'); - $item->pay_time = empty($item->pay_time) ? '-' : date('Y-m-d H:i', $item->pay_time); - $item->amount = Db::name('ExpenseInterfix')->where(['exid' => $item->id])->sum('amount'); - $item['check_user'] = '-'; - if($item['check_status']==1 && !empty($item['check_admin_ids'])){ - $check_user = Db::name('Admin')->where('id','in',$item['check_admin_ids'])->column('name'); - $item['check_user'] = implode(',',$check_user); - } - }); + $expense = Expense::where($where) + ->order('id desc') + ->paginate($rows, false, ['query' => $param]) + ->each(function ($item, $key) { + $item->income_month = empty($item->income_month) ? '-' : date('Y-m', $item->income_month); + $item->expense_time = empty($item->expense_time) ? '-' : date('Y-m-d', $item->expense_time); + $item->admin_name = Db::name('Admin')->where(['id' => $item->admin_id])->value('name'); + $item->department = Db::name('Department')->where(['id' => $item->did])->value('title'); + $item->pay_name = Db::name('Admin')->where(['id' => $item->pay_admin_id])->value('name'); + $item->pay_time = empty($item->pay_time) ? '-' : date('Y-m-d H:i', $item->pay_time); + $item->amount = Db::name('ExpenseInterfix')->where(['exid' => $item->id])->sum('amount'); + $item['check_user'] = '-'; + if($item['check_status']==1 && !empty($item['check_admin_ids'])){ + $check_user = Db::name('Admin')->where('id','in',$item['check_admin_ids'])->column('name'); + $item['check_user'] = implode(',',$check_user); + } + }); } return $expense; } diff --git a/app/finance/view/expense/index.html b/app/finance/view/expense/index.html index 78b0892..dd5b6a8 100644 --- a/app/finance/view/expense/index.html +++ b/app/finance/view/expense/index.html @@ -152,7 +152,7 @@ var btn2='<span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>'; var btn3='<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>'; html+=btn1; - if(d.check_status==4 && d.admin_id==login_user){ + if(d.check_status==4 && d.admin_id==login_admin){ html+=btn2+btn3; } html+='</div>'; diff --git a/app/finance/view/invoice/add.html b/app/finance/view/invoice/add.html index f11f56d..afdf033 100644 --- a/app/finance/view/invoice/add.html +++ b/app/finance/view/invoice/add.html @@ -267,7 +267,7 @@ function gouguInit() { success:function(e){ layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } }) diff --git a/app/finance/view/invoice/index.html b/app/finance/view/invoice/index.html index 57eb36c..89f1023 100644 --- a/app/finance/view/invoice/index.html +++ b/app/finance/view/invoice/index.html @@ -180,7 +180,7 @@ var btn2='<span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>'; var btn3='<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>'; html+=btn1; - if(d.check_status==4 && d.admin_id==login_user){ + if(d.check_status==4 && d.admin_id==login_admin){ html+=btn2+btn3; } html+='</div>'; diff --git a/app/home/controller/Api.php b/app/home/controller/Api.php index 91504d3..3843493 100644 --- a/app/home/controller/Api.php +++ b/app/home/controller/Api.php @@ -8,11 +8,7 @@ declare (strict_types = 1); namespace app\home\controller; use app\api\BaseController; -use app\home\model\AdminLog; -use app\user\validate\AdminCheck; -use think\exception\ValidateException; use think\facade\Db; -use think\facade\Session; class api extends BaseController { @@ -147,13 +143,13 @@ class api extends BaseController $where = []; $where[] = ['uid','<>',1]; $where[] = ['create_time', '>', $times]; - $content = Db::name('AdminLog')->field("id,uid,name")->where($where)->select(); + $list = Db::name('AdminLog')->field("id,uid")->where($where)->select(); $logs = array(); - foreach ($content as $index => $value) { + foreach ($list as $key => $value) { $uid = $value['uid']; if (empty($logs[$uid])) { $logs[$uid]['count'] = 1; - $logs[$uid]['name'] = $value['name']; + $logs[$uid]['name'] = Db::name('Admin')->where('id',$uid)->value('name'); } else { $logs[$uid]['count'] += 1; } @@ -165,74 +161,4 @@ class api extends BaseController return to_assign(0, '', ['data_logs' => $data_logs]); } - //修改个人信息 - public function edit_personal() - { - if (request()->isAjax()) { - $param = get_params(); - $uid = $this->uid; - Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param); - $session_admin = get_config('app.session_admin'); - Session::set($session_admin, Db::name('admin')->find($uid)); - return to_assign(); - } - else{ - return view('user@user/edit_personal', [ - 'admin' => get_admin($this->uid), - ]); - } - } - - //修改密码 - public function edit_password() - { - if (request()->isAjax()) { - $param = get_params(); - try { - validate(AdminCheck::class)->scene('editPwd')->check($param); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - return to_assign(1, $e->getError()); - } - $uid = $this->uid; - - $admin = Db::name('Admin')->where(['id' => $uid])->find(); - $old_psw = set_password($param['old_pwd'], $admin['salt']); - if ($admin['pwd'] != $old_psw) { - return to_assign(1, '旧密码错误'); - } - - $salt = set_salt(20); - $new_pwd = set_password($param['pwd'], $salt); - $data = [ - 'reg_pwd' => '', - 'salt' => $salt, - 'pwd' => $new_pwd, - 'update_time' => time(), - ]; - Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($data); - $session_admin = get_config('app.session_admin'); - Session::set($session_admin, Db::name('admin')->find($uid)); - return to_assign(); - } - else{ - return view('user@user/edit_password', [ - 'admin' => get_admin($this->uid), - ]); - } - } - - //系统操作日志 - public function log_list() - { - if (request()->isAjax()) { - $param = get_params(); - $log = new AdminLog(); - $content = $log->get_log_list($param); - return table_assign(0, '', $content); - }else{ - return view('home@log/log_list'); - } - } - } diff --git a/app/home/controller/Index.php b/app/home/controller/Index.php index 338978f..2feaf58 100644 --- a/app/home/controller/Index.php +++ b/app/home/controller/Index.php @@ -10,6 +10,9 @@ declare (strict_types = 1); namespace app\home\controller; use app\base\BaseController; +use app\home\model\AdminLog; +use app\user\validate\AdminCheck; +use think\exception\ValidateException; use think\facade\Db; use think\facade\View; @@ -75,9 +78,9 @@ class Index extends BaseController } return to_assign(0, 'ok', $statistics); } else { - $admin = get_login_admin(); - if (get_cache('menu' . $admin['id'])) { - $list = get_cache('menu' . $admin['id']); + $admin = Db::name('Admin')->where('id',$this->uid)->find(); + if (get_cache('menu' . $this->uid)) { + $list = get_cache('menu' . $this->uid); } else { $adminGroup = Db::name('PositionGroup')->where(['pid' => $admin['position_id']])->column('group_id'); $adminMenu = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('rules'); @@ -88,11 +91,10 @@ class Index extends BaseController } $menu = Db::name('AdminRule')->where(['menu' => 1, 'status' => 1])->where('id', 'in', $adminMenus)->order('sort asc,id asc')->select()->toArray(); $list = list_to_tree($menu); - \think\facade\Cache::tag('adminMenu')->set('menu' . $admin['id'], $list); + \think\facade\Cache::tag('adminMenu')->set('menu' . $this->uid, $list); } View::assign('menu', $list); - $user = Db::name('Admin')->where('id',$this->uid)->find(); - View::assign('theme',$user['theme']); + View::assign('theme',$admin['theme']); return View(); } } @@ -235,22 +237,22 @@ class Index extends BaseController ); } - $admin = get_login_admin(); - $adminGroup = Db::name('PositionGroup')->where(['pid' => $admin['position_id']])->column('group_id'); - $adminLayout = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('layouts'); - $adminLayouts = []; - foreach ($adminLayout as $k => $v) { - $v = explode(',', $v); - $adminLayouts = array_merge($adminLayouts, $v); + $position_id = Db::name('Admin')->where('id',$this->uid)->value('position_id'); + $adminGroup = Db::name('PositionGroup')->where(['pid' => $position_id])->column('group_id'); + $adminLayout = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('layouts'); + $adminLayouts = []; + foreach ($adminLayout as $k => $v) { + $v = explode(',', $v); + $adminLayouts = array_merge($adminLayouts, $v); + } + $layouts = get_config('layout'); + $layout_selected = []; + foreach ($layouts as $key =>$vo) { + if (!empty($adminLayouts) and in_array($vo['id'], $adminLayouts)) { + $layout_selected[] = $vo; } - $layouts = get_config('layout'); - $layout_selected = []; - foreach ($layouts as $key =>$vo) { - if (!empty($adminLayouts) and in_array($vo['id'], $adminLayouts)) { - $layout_selected[] = $vo; - } - } - View::assign('layout_selected',$layout_selected); + } + View::assign('layout_selected',$layout_selected); View::assign('total', $total); View::assign('handle', $handle); View::assign('install', $install); @@ -290,6 +292,71 @@ class Index extends BaseController } } + + //修改个人信息 + public function edit_personal() + { + if (request()->isAjax()) { + $param = get_params(); + $uid = $this->uid; + Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param); + return to_assign(); + } + else{ + View::assign('admin',get_admin($this->uid)); + return view(); + } + } + + //修改密码 + public function edit_password() + { + if (request()->isAjax()) { + $param = get_params(); + try { + validate(AdminCheck::class)->scene('editPwd')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $uid = $this->uid; + + $admin = Db::name('Admin')->where(['id' => $uid])->find(); + $old_psw = set_password($param['old_pwd'], $admin['salt']); + if ($admin['pwd'] != $old_psw) { + return to_assign(1, '旧密码错误'); + } + + $salt = set_salt(20); + $new_pwd = set_password($param['pwd'], $salt); + $data = [ + 'reg_pwd' => '', + 'salt' => $salt, + 'pwd' => $new_pwd, + 'update_time' => time(), + ]; + Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($data); + return to_assign(); + } + else{ + View::assign('admin',get_admin($this->uid)); + return view(); + } + } + + //系统操作日志 + public function log_list() + { + if (request()->isAjax()) { + $param = get_params(); + $log = new AdminLog(); + $content = $log->get_log_list($param); + return table_assign(0, '', $content); + }else{ + return view(); + } + } + //设置theme public function set_theme() { diff --git a/app/home/controller/Log.php b/app/home/controller/Log.php index f51b9d2..063b68a 100644 --- a/app/home/controller/Log.php +++ b/app/home/controller/Log.php @@ -22,37 +22,39 @@ class Log extends BaseController $param = get_params(); $where = array(); if (!empty($param['keywords'])) { - $where[] = ['name|content|param_id|uid', 'like', '%' . $param['keywords'] . '%']; + $where[] = ['u.name|a.param_id|a.uid', 'like', '%' . $param['keywords'] . '%']; } if (!empty($param['action'])) { - $where[] = ['action','=',$param['action']]; + $where[] = ['a.action','=',$param['action']]; } $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; - $content = DB::name('AdminLog') - ->field("id,uid,name,action,title,content,rule_menu,ip,param_id,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') create_time") - ->order('create_time desc') + $list = DB::name('AdminLog') + ->field("a.*,u.name") + ->alias('a') + ->join('Admin u', 'a.uid = u.id') + ->order('a.create_time desc') ->where($where) - ->paginate($rows, false, ['query' => $param]); - $content->toArray(); - foreach ($content as $k => $v) { - $data = $v; - $param_array = json_decode($v['param'], true); - if(is_array($param_array)){ - $param_value = ''; - foreach ($param_array as $key => $value) { - if (is_array($value)) { - $value = implode(',', $value); + ->paginate($rows, false, ['query' => $param]) + ->each(function($item, $key){ + $item['content'] = $item['name']. $item['action'] . '了' . $item['subject']; + $item['create_time'] = date('Y-m-d H:i:s', $item['create_time']); + $param_array = json_decode($item['param'], true); + if(is_array($param_array)){ + $param_value = []; + foreach ($param_array as $key => $value) { + if (is_array($value)) { + $value = implode(',', $value); + } + $param_value[] = $key . ':' . $value; } - $param_value .= $key . ':' . $value . ' | '; + $item['param'] = implode(' & ',$param_value); } - $data['param'] = $param_value; - } - else{ - $data['param'] = $param_array; - } - $content->offsetSet($k, $data); - } - return table_assign(0, '', $content); + else{ + $item['param'] = $param_array; + } + return $item; + }); + return table_assign(0, '', $list); } else { $type_action = get_config('log.type_action'); View::assign('type_action', $type_action); diff --git a/app/home/controller/Login.php b/app/home/controller/Login.php index 9a9f249..1ea23b6 100644 --- a/app/home/controller/Login.php +++ b/app/home/controller/Login.php @@ -54,11 +54,21 @@ class Login ]; Db::name('admin')->where(['id' => $admin['id']])->update($data); $session_admin = get_config('app.session_admin'); - Session::set($session_admin, $admin); + Session::set($session_admin, $admin['id']); $token = make_token(); set_cache($token, $admin, 7200); $admin['token'] = $token; - add_log('login', $admin['id'], $data); + $logdata = [ + 'uid' => $admin['id'], + 'type' => 'login', + 'action' => '登录', + 'subject' => '系统', + 'param_id'=>$admin['id'], + 'param'=>'[]', + 'ip' => request()->ip(), + 'create_time' => time() + ]; + Db::name('AdminLog')->strict(false)->field(true)->insert($logdata); return to_assign(0, '登录成功', ['uid' => $admin['id']]); } diff --git a/app/home/middleware/Install.php b/app/home/middleware/Install.php index 4631983..7589b66 100644 --- a/app/home/middleware/Install.php +++ b/app/home/middleware/Install.php @@ -8,15 +8,123 @@ declare (strict_types = 1); namespace app\home\middleware; +use systematic\Systematic; +use think\facade\Db; +use think\facade\Session; class Install { + protected $module = ''; + protected $controller = ''; + protected $action = ''; public function handle($request, \Closure $next) { if (!is_installed()) { return $request->isAjax() ? to_assign(1, '请先完成系统安装引导') : redirect((string) url('/install/index')); } + $module = strtolower(app('http')->getName()); + $this->module = $module; + $param = $request->param(); + $logtype = isset($param['logtype'])?$param['logtype']:''; + $module_son = isset($param['module_son'])?$param['module_son']:''; + $module_old = []; + if($module_son!='' && ($logtype != 'add' || $logtype != 'delete')){ + $module_old = Db::name($module_son)->where('id',$param['id'])->find(); + } + //return $next($request); + //获取响应,获取响应之前的代码为前置中间件, + //do songthing + //----------以上部分为前置中间件-------------- + + $response=$next($request); + + //----------以下部分为后置中间件-------------- + //获取响应之后的为后置中间件的执行内容 + + $this->controller = strtolower($request->controller()); + $this->action = strtolower($request->action()); + //获取返回的HTTPCode + //$code = $response->getCode(); + $responseData = $response->getData(); + if(isset($responseData['code']) && $responseData['code'] == 0){ + $logData = $responseData['data']; + $log_conf = get_config('log'); + $type_action = $log_conf['type_action']; + if(isset($logData['logtype']) && isset($logData['id']) && isset($type_action[$logData['logtype']])){ + $logData['type_title'] = $type_action[$logData['logtype']]; + $moduleLogData = []; + if($module_son!='' && isset($log_conf[$this->module])){ + $log_conf_module = $log_conf[$this->module]; + $module_field_key = $log_conf_module[$module_son]; + $module_new = Db::name($module_son)->where('id',$logData['id'])->find(); + $param_id = $module_new['id']; + $param_son_id = 0; + if($module_son!=$this->module){ + $param_id = $module_new[$this->module.'_id']; + $param_son_id = $module_new['id']; + } + else{ + $module_son = ''; + } + if(isset($module_field_key)){ + $moduleLogData = [ + 'param_id'=>$param_id, + 'module_son'=>$module_son, + 'param_son_id'=>$param_son_id, + 'old'=>$module_old, + 'new'=>$module_new, + 'key'=>$module_field_key + ]; + } + } + $this->addLog($logData,$moduleLogData); + } + } - return $next($request); + //这里回调本身返回response对象 + return $response; } + /* + public function end(\think\Response $response){ + + dump($response->getData()); + exit; + + //dump($response->header()); + } + */ + + protected function addLog($logData = [],$moduleLogData=[]) + { + $session_admin = get_config('app.session_admin'); + $uid = Session::get($session_admin); + $data = [ + 'uid' => $uid, + 'type' => $logData['logtype'], + 'action' => $logData['type_title'], + 'param_id' => $logData['id'], + 'param' => json_encode($logData), + 'module' => $this->module, + 'controller' => $this->controller, + 'function' => $this->action, + 'ip' => app('request')->ip(), + 'create_time' => time(), + 'subject' => '系统' + ]; + if(isset($logData['subject']) && $logData['subject'] != ''){ + $data['subject'] = $logData['subject']; + } + else{ + $rule = $data['module'] . '/' . $data['controller'] . '/' . $data['function']; + $rule_menu = Db::name('AdminRule')->where(array('src' => $rule))->find(); + if($rule_menu){ + $data['subject'] = $rule_menu['name']; + } + } + Db::name('AdminLog')->strict(false)->field(true)->insert($data); + if(!empty($moduleLogData)){ + $GOUGU = new Systematic(); + $GOUGU->moduleLog($uid,$logData['logtype'],$this->module,$moduleLogData); + } + } } diff --git a/app/home/model/AdminLog.php b/app/home/model/AdminLog.php index 5cfcc9d..6aa9de3 100644 --- a/app/home/model/AdminLog.php +++ b/app/home/model/AdminLog.php @@ -9,37 +9,25 @@ declare (strict_types = 1); namespace app\home\model; use think\Model; +use think\facade\Db; +use dateset\Dateset; class AdminLog extends Model { public function get_log_list($param = []) { - $where = array(); - if (!empty($param['no_delete'])) { - $where['type'] = ['neq', 'delete']; //过滤删除操作 - } - if (!empty($param['no_admin'])) { - $where['uid'] = ['neq', 1]; //超级管理员删除操作 - } - if (!empty($param['uid'])) { - $where['uid'] = $param['uid']; //查询指定用户的操作 - } - $where['status'] = 1; $rows = empty($param['limit']) ? get_config('app.pages') : $param['limit']; - $content = \think\facade\Db::name('AdminLog') - ->field("id,uid,name,type,title,module,controller,function,subject,action,create_time,param") - ->order('create_time desc') - ->where($where) - ->paginate($rows, false, ['query' => $param]); - - $content->toArray(); - foreach ($content as $k => $v) { - $data = $v; - $param_array = json_decode($v['param'], true); - $data['content'] = $v['name']. $v['action'] . '了' . $v['subject']; - $data['times'] = time_trans($v['create_time']); - $content->offsetSet($k, $data); - } - return $content; + $list = Db::name('AdminLog') + ->field("a.id,a.uid,a.type,a.subject,a.action,a.create_time,u.name") + ->alias('a') + ->join('Admin u', 'a.uid = u.id') + ->order('a.create_time desc') + ->paginate($rows, false, ['query' => $param]) + ->each(function($item, $key){ + $item['content'] = $item['name']. $item['action'] . '了' . $item['subject']; + $item['times'] = (new Dateset())->time_trans($item['create_time']); + return $item; + }); + return $list; } } diff --git a/app/home/view/cate/flow_type_add.html b/app/home/view/cate/flow_type_add.html index 1536140..cb4d376 100644 --- a/app/home/view/cate/flow_type_add.html +++ b/app/home/view/cate/flow_type_add.html @@ -111,7 +111,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/home/cate/flow_type_add", data.field, callback); diff --git a/app/home/view/conf/add.html b/app/home/view/conf/add.html index 5466cc2..e5cd744 100644 --- a/app/home/view/conf/add.html +++ b/app/home/view/conf/add.html @@ -19,10 +19,8 @@ <input type="radio" name="status" value="1" title="正常" checked> <input type="radio" name="status" value="0" title="禁用"> {else/} - <input type="radio" name="status" value="1" title="正常" {eq name="$config.status" value="1" - }checked{/eq}> - <input type="radio" name="status" value="0" title="禁用" {eq name="$config.status" value="0" - }checked{/eq}> + <input type="radio" name="status" value="1" title="正常" {eq name="$config.status" value="1"} checked{/eq}> + <input type="radio" name="status" value="0" title="禁用" {eq name="$config.status" value="0"} checked{/eq}> {/if} </td> </tr> @@ -61,7 +59,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/home/conf/add", data.field, callback); diff --git a/app/home/view/conf/email.html b/app/home/view/conf/email.html index 7fbc2f0..b8a694b 100644 --- a/app/home/view/conf/email.html +++ b/app/home/view/conf/email.html @@ -101,7 +101,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/home/conf/edit", data.field, callback); diff --git a/app/home/view/conf/other.html b/app/home/view/conf/other.html index 06e178d..9d5dcb1 100644 --- a/app/home/view/conf/other.html +++ b/app/home/view/conf/other.html @@ -49,7 +49,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/home/conf/edit", data.field, callback); diff --git a/app/home/view/conf/token.html b/app/home/view/conf/token.html index a964eeb..06519ea 100644 --- a/app/home/view/conf/token.html +++ b/app/home/view/conf/token.html @@ -61,7 +61,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/home/conf/edit", data.field, callback); diff --git a/app/home/view/conf/web.html b/app/home/view/conf/web.html index 03487a0..bdfb879 100644 --- a/app/home/view/conf/web.html +++ b/app/home/view/conf/web.html @@ -111,7 +111,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/home/conf/edit", data.field, callback); diff --git a/app/home/view/flow/add.html b/app/home/view/flow/add.html index 0add05a..84f166d 100644 --- a/app/home/view/flow/add.html +++ b/app/home/view/flow/add.html @@ -390,7 +390,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/home/flow/add", data.field, callback); diff --git a/app/user/view/user/edit_password.html b/app/home/view/index/edit_password.html similarity index 100% rename from app/user/view/user/edit_password.html rename to app/home/view/index/edit_password.html diff --git a/app/user/view/user/edit_personal.html b/app/home/view/index/edit_personal.html similarity index 98% rename from app/user/view/user/edit_personal.html rename to app/home/view/index/edit_personal.html index 888ff19..e6e4d0f 100644 --- a/app/user/view/user/edit_personal.html +++ b/app/home/view/index/edit_personal.html @@ -85,7 +85,7 @@ //监听提交 form.on('submit(webform)', function (data) { $.ajax({ - url: "/home/api/edit_personal", + url: "/home/index/edit_personal", type: 'post', data: data.field, success: function (e) { diff --git a/app/home/view/index/index.html b/app/home/view/index/index.html index 26b8b6b..38a7f71 100644 --- a/app/home/view/index/index.html +++ b/app/home/view/index/index.html @@ -53,12 +53,12 @@ <ul class="layui-nav"> <li class="layui-nav-item"> <a href="javascript:;"> - <img src="{:get_login_admin('thumb')}" onerror="javascript:this.src='{__IMG__}/nonepic360x360.jpg';this.onerror=null;"> - <cite>{:get_login_admin('nickname')}</cite> + <img src="{$login_admin.thumb}" onerror="javascript:this.src='{__IMG__}/nonepic360x360.jpg';this.onerror=null;"> + <cite>{$login_admin.nickname}</cite> </a> <dl class="layui-nav-child" style="text-align: center; cursor: pointer;"> - <dd><a data-href="/home/api/edit_personal" data-id="0101" data-title="基本资料" class="side-menu-item">基本资料</a></dd> - <dd><a data-href="/home/api/edit_password" data-id="0102" data-title="修改密码" class="side-menu-item">修改密码</a></dd> + <dd><a data-href="/home/index/edit_personal" data-id="0101" data-title="基本资料" class="side-menu-item">基本资料</a></dd> + <dd><a data-href="/home/index/edit_password" data-id="0102" data-title="修改密码" class="side-menu-item">修改密码</a></dd> <hr> <dd gg-event="logout"><a>退出</a></dd> </dl> diff --git a/app/home/view/index/layout_action.html b/app/home/view/index/layout_action.html index 6850440..f4854e1 100644 --- a/app/home/view/index/layout_action.html +++ b/app/home/view/index/layout_action.html @@ -1,5 +1,5 @@ <div class="layui-card"> - <div class="layui-card-header"><h3>员工动态</h3><a data-title="员工动态" data-href="/home/api/log_list" class="pull-right tab-a">更多</a></div> + <div class="layui-card-header"><h3>员工动态</h3><a data-title="员工动态" data-href="/home/index/log_list" class="pull-right tab-a">更多</a></div> <div class="layui-card-body"> <ul class="layui-timeline" id="logs"></ul> </div> @@ -8,7 +8,7 @@ //动态 function layoutAction() { $.ajax({ - url: "/home/api/log_list", + url: "/home/index/log_list", type: 'get', data: { page: 1, diff --git a/app/home/view/log/log_list.html b/app/home/view/index/log_list.html similarity index 98% rename from app/home/view/log/log_list.html rename to app/home/view/index/log_list.html index 1dd1a89..e2b7595 100644 --- a/app/home/view/log/log_list.html +++ b/app/home/view/index/log_list.html @@ -49,7 +49,7 @@ var page=1,limit=20; function getLogs() { $.ajax({ - url: "/home/api/log_list", + url: "/home/index/log_list", type: 'post', data: { page:page, diff --git a/app/home/view/keywords/add.html b/app/home/view/keywords/add.html index 98978d6..8f1b9e0 100644 --- a/app/home/view/keywords/add.html +++ b/app/home/view/keywords/add.html @@ -53,7 +53,7 @@ layer.msg(e.msg); if (e.code == 0) { layer.msg(e.msg); - parent.layui.tool.close(1000); + tool.sideClose(1000); } } }) diff --git a/app/home/view/log/index.html b/app/home/view/log/index.html index df8c099..ca3c3ef 100644 --- a/app/home/view/log/index.html +++ b/app/home/view/log/index.html @@ -4,7 +4,7 @@ <div class="p-3"> <form class="layui-form gg-form-bar border-t border-x"> <div class="layui-input-inline" style="width:300px;"> - <input type="text" name="keywords" placeholder="昵称/操作数据id/操作描述" class="layui-input" autocomplete="off" /> + <input type="text" name="keywords" placeholder="昵称/操作数据id" class="layui-input" autocomplete="off" /> </div> <div class="layui-input-inline"> <select name="action"> @@ -46,17 +46,16 @@ width: 80 }, { field: 'content', - title: '操作描述' + title: '操作描述', + width: 200 }, { field: 'param_id', title: '操作数据ID', align: 'center', width: 100 },{ - field: 'name', - title: '操作用户', - align: 'center', - width: 100 + field: 'param', + title: '操作详细数据信息', }, { field: 'ip', title: 'IP地址', diff --git a/app/home/view/role/add.html b/app/home/view/role/add.html index ce6e89e..7c44b08 100644 --- a/app/home/view/role/add.html +++ b/app/home/view/role/add.html @@ -126,7 +126,7 @@ success: function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } }); diff --git a/app/install/data/gouguoa.sql b/app/install/data/gouguoa.sql index 5de7e8d..3232d42 100644 --- a/app/install/data/gouguoa.sql +++ b/app/install/data/gouguoa.sql @@ -63,20 +63,15 @@ DROP TABLE IF EXISTS `oa_admin_log`; CREATE TABLE `oa_admin_log` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID', `uid` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '用户ID', - `name` varchar(255) NOT NULL DEFAULT '' COMMENT '姓名', `type` varchar(80) NOT NULL DEFAULT '' COMMENT '操作类型', `action` varchar(80) NOT NULL DEFAULT '' COMMENT '操作动作', `subject` varchar(80) NOT NULL DEFAULT '' COMMENT '操作主体', - `title` varchar(255) NOT NULL DEFAULT '' COMMENT '操作标题', - `content` text NULL COMMENT '操作描述', `module` varchar(32) NOT NULL DEFAULT '' COMMENT '模块', `controller` varchar(32) NOT NULL DEFAULT '' COMMENT '控制器', `function` varchar(32) NOT NULL DEFAULT '' COMMENT '方法', - `rule_menu` varchar(255) NOT NULL DEFAULT '' COMMENT '节点权限路径', `ip` varchar(64) NOT NULL DEFAULT '' COMMENT '登录ip', `param_id` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '操作数据id', `param` text NULL COMMENT '参数json格式', - `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '0删除 1正常', `create_time` int(11) NOT NULL DEFAULT 0 COMMENT '创建时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '员工操作日志表'; diff --git a/app/note/view/index/add.html b/app/note/view/index/add.html index c85bc0e..76e9f3d 100644 --- a/app/note/view/index/add.html +++ b/app/note/view/index/add.html @@ -111,7 +111,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/note/index/add", data.field, callback); diff --git a/app/oa/view/plan/index.html b/app/oa/view/plan/index.html index c050ff4..0e0ae05 100644 --- a/app/oa/view/plan/index.html +++ b/app/oa/view/plan/index.html @@ -118,11 +118,12 @@ }} ,{field: 'title', title: '日程安排内容'} ,{field: 'remind_time', title: '提醒时间', align:'center',width:136} - ,{field: 'right', title: '操作',fixed:'right', width:100, align:'center',templet:function(d){ + ,{field: 'right', title: '操作',fixed:'right', width:150, align:'center',templet:function(d){ var html='<div class="layui-btn-group">'; html+='<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">查看</button>'; - if(d.admin_id==login_user){ + if(d.admin_id==login_admin){ html+='<button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>'; + html+='<button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>'; } html+='</div>'; return html; @@ -185,6 +186,22 @@ }) return; } + else if(obj.event === 'del'){ + layer.confirm('您确定要删除该日程', { + icon: 3, + title: '提示' + }, function (index) { + let callback = function (e) { + layer.msg(e.msg); + if (e.code == 0) { + layui.pageTable.reload(); + } + } + tool.delete("/oa/plan/delete", { id: obj.data.id }, callback); + layer.close(index); + }); + return; + } }); //查看日程记录 diff --git a/app/oa/view/schedule/index.html b/app/oa/view/schedule/index.html index a24c71c..30ad2d5 100644 --- a/app/oa/view/schedule/index.html +++ b/app/oa/view/schedule/index.html @@ -116,7 +116,7 @@ ,{field: 'right', title: '操作',fixed:'right', width:150, align:'center',templet:function(d){ var html='<div class="layui-btn-group">'; html+='<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="time">调整工时</button><button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">查看</button>'; - if(d.admin_id==login_user){ + if(d.admin_id==login_admin){ html+='<button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>'; } html+='</div>'; diff --git a/app/oa/view/work/add.html b/app/oa/view/work/add.html index 1e8019e..6a67d1f 100644 --- a/app/oa/view/work/add.html +++ b/app/oa/view/work/add.html @@ -191,7 +191,7 @@ const moduleInit = ['tool','formSelects','employeepicker']; var form = layui.form,tool=layui.tool, table = layui.table, employeepicker = layui.employeepicker,dtree = layui.dtree,upload = layui.upload; //监听发送 form.on('submit(webform)', function(data){ - if(data.field.uids==login_user){ + if(data.field.uids==login_admin){ layer.msg('接收人不能是自己'); return false; } diff --git a/app/project/controller/Index.php b/app/project/controller/Index.php index 6a74e15..6fc27ad 100644 --- a/app/project/controller/Index.php +++ b/app/project/controller/Index.php @@ -210,7 +210,7 @@ class Index extends BaseController $section = explode('|', $section_conf); } View::assign('section', $section); - View::assign('user_info', get_login_admin()); + View::assign('user_info', $login_admin); View::assign('id', $id); return view(); } diff --git a/app/project/view/document/add.html b/app/project/view/document/add.html index c00bf03..dd80d21 100644 --- a/app/project/view/document/add.html +++ b/app/project/view/document/add.html @@ -90,7 +90,7 @@ layer.msg(e.msg); parent.layui.documentTable.reload(); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/project/document/add", data.field, callback); diff --git a/app/project/view/index/add.html b/app/project/view/index/add.html index bc61c32..d016884 100644 --- a/app/project/view/index/add.html +++ b/app/project/view/index/add.html @@ -330,7 +330,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/project/index/add",data.field,callback); diff --git a/app/project/view/index/edit.html b/app/project/view/index/edit.html index 2908d2e..7f1e79f 100644 --- a/app/project/view/index/edit.html +++ b/app/project/view/index/edit.html @@ -207,7 +207,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/project/api/reset_check",data.field,callback); diff --git a/app/project/view/index/view.html b/app/project/view/index/view.html index d625517..d88ab40 100644 --- a/app/project/view/index/view.html +++ b/app/project/view/index/view.html @@ -70,7 +70,7 @@ <span class="mx-2">{$detail.admin_name}</span> <span class="gray">创建于{$detail.times}<span id="editTips">{gt name="$detail.update_time" value="0"},最近更新于 {:time_trans($detail.update_time)}{/gt}</span></span> - {eq name="$detail.admin_id" value="$login_user"} + {eq name="$detail.admin_id" value="$login_admin"} <span class="layui-btn layui-btn-xs layui-btn-danger ml-4" id="delProject"><i class="layui-icon"></i>删除</span> {/eq} diff --git a/app/project/view/index/view_overview.html b/app/project/view/index/view_overview.html index a8594d6..d900ee5 100644 --- a/app/project/view/index/view_overview.html +++ b/app/project/view/index/view_overview.html @@ -48,7 +48,7 @@ <span class="gray" style="margin-left:20px">负责人:</span>{$step.check_name} <span class="gray" style="margin-left:20px">成员:</span>{$step.flow_names} <span class="gray" style="margin-left:20px">周期:</span>{$step.start_time|time_format=###,'Y-m-d'} 到 {$step.end_time|time_format=###,'Y-m-d'} - {eq name="$step.flow_uid" value="$login_user"} + {eq name="$step.flow_uid" value="$login_admin"} <div class="pt-3"> <span class="layui-btn layui-btn-normal layui-btn-sm" data-event="step" data-check="1">确认</span> {gt name="$detail.step_sort" value="0"} diff --git a/app/project/view/task/add.html b/app/project/view/task/add.html index 0fc4361..9e0db03 100644 --- a/app/project/view/task/add.html +++ b/app/project/view/task/add.html @@ -116,7 +116,7 @@ layer.msg(e.msg); parent.layui.taskTable.reload(); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/project/task/add", data.field, callback); diff --git a/app/project/view/task/task_time.html b/app/project/view/task/task_time.html index 95a73cb..92b375c 100644 --- a/app/project/view/task/task_time.html +++ b/app/project/view/task/task_time.html @@ -113,7 +113,7 @@ ,{field: 'right', title: '操作',fixed:'right', width:150, align:'center',templet:function(d){ var html='<div class="layui-btn-group">'; html+='<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="time">调整工时</button><button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">查看</button>'; - if(d.admin_id==login_user){ + if(d.admin_id==login_admin){ html+='<button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>'; } html+='</div>'; diff --git a/app/project/view/task/view.html b/app/project/view/task/view.html index 382a34a..82d3310 100644 --- a/app/project/view/task/view.html +++ b/app/project/view/task/view.html @@ -32,7 +32,7 @@ <span class="layui-badge layui-bg-gray">#P{$detail.id}</span> <span class="mx-2">{$detail.admin_name}</span> <span class="gray">创建于{$detail.times}<span id="editTips">{gt name="$detail.update_time" value="0"},最近更新于 {:time_trans($detail.update_time)}{/gt}</span></span> - {eq name="$detail.admin_id" value="$login_user"} + {eq name="$detail.admin_id" value="$login_admin"} <span class="layui-btn layui-btn-xs layui-btn-danger ml-4" id="delBtn"><i class="layui-icon"></i>删除</span> {/eq} </div> @@ -232,7 +232,7 @@ layer.msg(e.msg); parent.layui.taskTable.reload(); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } let postData = { "id": detail_id }; @@ -269,7 +269,7 @@ $('#flieList').on('click', '.file-delete', function () { let id = $(this).data('id'); let uid = $(this).data('uid'); - if (uid != login_user) { + if (uid != login_admin) { layer.msg('你不是该文件的上传人,无权限删除'); return false; } @@ -346,7 +346,7 @@ edit.text(id, name, real_txt, editPost); } if (name == "end_time") { - if (admin_id == login_user) { + if (admin_id == login_admin) { edit.date(id, name, real_txt, editPost); } else { layer.msg('您没权限修改,请联系创建人修改'); @@ -370,7 +370,7 @@ }); } if (name == "project_id") { - if (admin_id == login_user) { + if (admin_id == login_admin) { edit.select_table(id, name, real_txt, "/project/api/get_project", editPost, 1); } else { layer.msg('您没权限修改,请联系创建人或负责人修改'); diff --git a/app/user/view/personal/change_add.html b/app/user/view/personal/change_add.html index 96abcb4..3f0b6f4 100644 --- a/app/user/view/personal/change_add.html +++ b/app/user/view/personal/change_add.html @@ -133,7 +133,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/user/personal/change_add", data.field, callback); diff --git a/app/user/view/personal/leave_add.html b/app/user/view/personal/leave_add.html index 814d369..92505c5 100644 --- a/app/user/view/personal/leave_add.html +++ b/app/user/view/personal/leave_add.html @@ -137,7 +137,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/user/personal/leave_add", data.field, callback); diff --git a/app/user/view/position/add.html b/app/user/view/position/add.html index a9faea5..7cc3e78 100644 --- a/app/user/view/position/add.html +++ b/app/user/view/position/add.html @@ -104,7 +104,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/user/position/add", data.field, callback); diff --git a/app/user/view/user/add.html b/app/user/view/user/add.html index 94e76ce..f0a6200 100644 --- a/app/user/view/user/add.html +++ b/app/user/view/user/add.html @@ -227,7 +227,7 @@ let callback = function (e) { layer.msg(e.msg); if (e.code == 0) { - parent.layui.tool.close(1000); + tool.sideClose(1000); } } tool.post("/user/user/add", data.field, callback); diff --git a/extend/dateset/Dateset.php b/extend/dateset/Dateset.php new file mode 100644 index 0000000..9001207 --- /dev/null +++ b/extend/dateset/Dateset.php @@ -0,0 +1,545 @@ +<?php +declare (strict_types = 1); + +namespace dateset; + +/** + * 日期时间处理类 + */ +class Dateset +{ + const YEAR = 31536000; + const MONTH = 2592000; + const WEEK = 604800; + const DAY = 86400; + const HOUR = 3600; + const MINUTE = 60; + + /** + * 间隔时间段格式化 + * @param int $time 时间戳 + * @param string $format 格式 【d:显示到天 i显示到分钟 s显示到秒】 + * @return string + */ + function time_trans($time, $format = 'd') + { + $now = time(); + $diff = $now - $time; + if ($diff < self::MINUTE) { + return '1分钟前'; + } else if ($diff < self::HOUR) { + return floor($diff / self::MINUTE) . '分钟前'; + } else if ($diff < self::DAY) { + return floor($diff / self::HOUR) . '小时前'; + } + $yes_start_time = strtotime(date('Y-m-d 00:00:00', strtotime('-1 days'))); //昨天开始时间 + $yes_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-1 days'))); //昨天结束时间 + $two_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-2 days'))); //2天前结束时间 + $three_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-3 days'))); //3天前结束时间 + $four_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-4 days'))); //4天前结束时间 + $five_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-5 days'))); //5天前结束时间 + $six_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-6 days'))); //6天前结束时间 + $seven_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('-7 days'))); //7天前结束时间 + + if ($time > $yes_start_time && $time < $yes_end_time) { + return '昨天'; + } + + if ($time > $yes_start_time && $time < $two_end_time) { + return '1天前'; + } + + if ($time > $yes_start_time && $time < $three_end_time) { + return '2天前'; + } + + if ($time > $yes_start_time && $time < $four_end_time) { + return '3天前'; + } + + if ($time > $yes_start_time && $time < $five_end_time) { + return '4天前'; + } + + if ($time > $yes_start_time && $time < $six_end_time) { + return '5天前'; + } + + if ($time > $yes_start_time && $time < $seven_end_time) { + return '6天前'; + } + + switch ($format) { + case 'd': + $show_time = date('Y-m-d', $time); + break; + case 'i': + $show_time = date('Y-m-d H:i', $time); + break; + case 's': + $show_time = date('Y-m-d H:i:s', $time); + break; + } + return $show_time; + } + + + /** + * 计算两个时间戳之间相差的时间 + * + * $differ = self::differ(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2) + * $differ = self::differ(60, 182, 'minutes'); // 2 + * + * @param int $remote timestamp to find the span of + * @param int $local timestamp to use as the baseline + * @param string $output formatting string + * @return string when only a single output is requested + * @return array associative list of all outputs requested + * @from https://github.com/kohana/ohanzee-helpers/blob/master/src/Date.php + */ + public static function differ($remote, $local = null, $output = 'years,months,weeks,days,hours,minutes,seconds') + { + // Normalize output + $output = trim(strtolower((string)$output)); + if (!$output) { + // Invalid output + return false; + } + // Array with the output formats + $output = preg_split('/[^a-z]+/', $output); + // Convert the list of outputs to an associative array + $output = array_combine($output, array_fill(0, count($output), 0)); + // Make the output values into keys + extract(array_flip($output), EXTR_SKIP); + if ($local === null) { + // Calculate the span from the current time + $local = time(); + } + // Calculate timespan (seconds) + $timespan = abs($remote - $local); + if (isset($output['years'])) { + $timespan -= self::YEAR * ($output['years'] = (int)floor($timespan / self::YEAR)); + } + if (isset($output['months'])) { + $timespan -= self::MONTH * ($output['months'] = (int)floor($timespan / self::MONTH)); + } + if (isset($output['weeks'])) { + $timespan -= self::WEEK * ($output['weeks'] = (int)floor($timespan / self::WEEK)); + } + if (isset($output['days'])) { + $timespan -= self::DAY * ($output['days'] = (int)floor($timespan / self::DAY)); + } + if (isset($output['hours'])) { + $timespan -= self::HOUR * ($output['hours'] = (int)floor($timespan / self::HOUR)); + } + if (isset($output['minutes'])) { + $timespan -= self::MINUTE * ($output['minutes'] = (int)floor($timespan / self::MINUTE)); + } + // Seconds ago, 1 + if (isset($output['seconds'])) { + $output['seconds'] = $timespan; + } + if (count($output) === 1) { + // Only a single output was requested, return it + return array_pop($output); + } + // Return array + return $output; + } + + /** + * 获取指定年月拥有的天数 + * @param int $month + * @param int $year + * @return false|int|string + */ + public static function days_in_month($month, $year) + { + if (function_exists("cal_days_in_month")) { + return cal_days_in_month(CAL_GREGORIAN, $month, $year); + } else { + return date('t', mktime(0, 0, 0, $month, 1, $year)); + } + } + + + /** + * 将秒数转换为时间 (小时、分、秒) + * @param + */ + function getTimeBySec($time,$second=true) + { + if (is_numeric($time)) { + $value = array( + "hours" => 0, + "minutes" => 0, "seconds" => 0, + ); + $t=''; + if ($time >= 3600) { + $value["hours"] = floor($time / 3600); + $time = ($time % 3600); + $t .= $value["hours"] . "小时"; + } + if ($time >= 60) { + $value["minutes"] = floor($time / 60); + $time = ($time % 60); + $t .= $value["minutes"] . "分钟"; + } + if ($time > 0 && $time < 60 && $second==true) { + $value["seconds"] = floor($time); + $t .= $value["seconds"] . "秒"; + } + return $t; + } else { + return (bool)FALSE; + } + } + + /** + * 将秒数转换为时间 (年、天、小时、分、秒) + * @param + */ + function getDateBySec($time,$second=false) + { + if (is_numeric($time)) { + $value = array( + "years" => 0, "days" => 0, "hours" => 0, + "minutes" => 0, "seconds" => 0, + ); + $t=''; + if ($time >= 31556926) { + $value["years"] = floor($time / 31556926); + $time = ($time % 31556926); + $t .= $value["years"] . "年"; + } + if ($time >= 86400) { + $value["days"] = floor($time / 86400); + $time = ($time % 86400); + $t .= $value["days"] . "天"; + } + if ($time >= 3600) { + $value["hours"] = floor($time / 3600); + $time = ($time % 3600); + $t .= $value["hours"] . "小时"; + } + if ($time >= 60) { + $value["minutes"] = floor($time / 60); + $time = ($time % 60); + $t .= $value["minutes"] . "分钟"; + } + if ($time < 60 && $second==true) { + $value["seconds"] = floor($time); + $t .= $value["seconds"] . "秒"; + } + return $t; + } else { + return (bool)FALSE; + } + } + + /* + *根据年月计算有几天 + */ + function getmonthByYM($param) + { + $month = $param['month'] ? $param['month'] : date('m', time()); + $year = $param['year'] ? $param['year'] : date('Y', time()); + if (in_array($month, array('1', '3', '5', '7', '8', '01', '03', '05', '07', '08', '10', '12'))) { + $days = '31'; + } elseif ($month == 2) { + if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 !== 0)) { + //判断是否是闰年 + $days = '29'; + } else { + $days = '28'; + } + } else { + $days = '30'; + } + return $days; + } + + /** + * 根据时间戳计算当月天数 + * @param + */ + function getmonthdays($time) + { + $month = date('m', $time); + $year = date('Y', $time); + if (in_array($month, array('1', '3', '5', '7', '8', '01', '03', '05', '07', '08', '10', '12'))) { + $days = '31'; + } elseif ($month == 2) { + if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 !== 0)) { + //判断是否是闰年 + $days = '29'; + } else { + $days = '28'; + } + } else { + $days = '30'; + } + return $days; + } + + /** + * 生成从开始时间到结束时间的日期数组 + * @param type,默认时间戳格式 + * @param type = 1 时,date格式 + * @param type = 2 时,获取每日开始、结束时间 + */ + function dateList($start, $end, $type = 0) + { + if (!is_numeric($start) || !is_numeric($end) || ($end <= $start)) return ''; + $i = 0; + //从开始日期到结束日期的每日时间戳数组 + $d = array(); + if ($type == 1) { + while ($start <= $end) { + $d[$i] = date('Y-m-d', $start); + $start = $start + 86400; + $i++; + } + } else { + while ($start <= $end) { + $d[$i] = $start; + $start = $start + 86400; + $i++; + } + } + if ($type == 2) { + $list = array(); + foreach ($d as $k => $v) { + $list[$k] = $this->getDateRange($v); + } + return $list; + } else { + return $d; + } + } + + /** + * 获取指定日期开始时间与结束时间 + */ + function getDateRange($timestamp) + { + $ret = array(); + $ret['sdate'] = strtotime(date('Y-m-d', $timestamp)); + $ret['edate'] = strtotime(date('Y-m-d', $timestamp)) + 86400; + return $ret; + } + + /** + * 生成从开始月份到结束月份的月份数组 + * @param int $start 开始时间戳 + * @param int $end 结束时间戳 + */ + function monthList($start, $end) + { + if (!is_numeric($start) || !is_numeric($end) || ($end <= $start)) return ''; + $start = date('Y-m', $start); + $end = date('Y-m', $end); + //转为时间戳 + $start = strtotime($start . '-01'); + $end = strtotime($end . '-01'); + $i = 0; + $d = array(); + while ($start <= $end) { + //这里累加每个月的的总秒数 计算公式:上一月1号的时间戳秒数减去当前月的时间戳秒数 + $d[$i] = $start; + $start += strtotime('+1 month', $start) - $start; + $i++; + } + return $d; + } + + /** + * 等于(时间段)数据处理 + * + * @param $type + * @return array + * @since 2021-06-11 + * @author fanqi + */ + function advancedDate($type) + { + // 本年度 + if ($type == 'year') { + $arrTime = DataTime::year(); + $start_time = date('Y-m-d 00:00:00', $arrTime[0]); + $end_time = date('Y-m-d 23:59:59', $arrTime[1]); + } + + // 上一年度 + if ($type == 'lastYear') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 year')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 year')); + } + + // 下一年度 + if ($type == 'nextYear') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 year')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 year')); + } + + // 上半年 + if ($type == 'firstHalfYear') { + $start_time = date('Y-01-01 00:00:00'); + $end_time = date('Y-06-30 23:59:59'); + } + + // 下半年 + if ($type == 'nextHalfYear') { + $start_time = date('Y-07-01 00:00:00'); + $end_time = date('Y-12-31 23:59:59'); + } + + // 本季度 + if ($type == 'quarter') { + $season = ceil((date('n')) / 3); + $start_time = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y'))); + $end_time = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); + } + + // 上一季度 + if ($type == 'lastQuarter') { + $season = ceil((date('n')) / 3) - 1; + $start_time = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y'))); + $end_time = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); + } + + // 下一季度 + if ($type == 'nextQuarter') { + $season = ceil((date('n')) / 3); + $start_time = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 + 1, 1, date('Y'))); + $end_time = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3 + 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); + } + + // 本月 + if ($type == 'month') { + $start_time = date('Y-m-01 00:00:00'); + $end_time = date('Y-m-31 23:59:59'); + } + + // 上月 + if ($type == 'lastMonth') { + $start_time = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '-1 month')); + $end_time = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '-1 month')); + } + + // 下月 + if ($type == 'nextMonth') { + $start_time = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '+1 month')); + $end_time = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '+1 month')); + } + + // 本周 + if ($type == 'week') { + $start_time = date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'))); + $end_time = date('Y-m-d 23:59:59', mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y'))); + } + + // 上周 + if ($type == 'lastWeek') { + $date = date("Y-m-d"); + $w = date("w", strtotime($date)); + $d = $w ? $w - 1 : 6; + $start = date("Y-m-d", strtotime($date . " - " . $d . " days")); + $start_time = date('Y-m-d', strtotime($start . " - 7 days")); + $end_time = date('Y-m-d', strtotime($start . " - 1 days")); + } + + // 下周 + if ($type == 'nextWeek') { + $date = date("Y-m-d"); + $w = date("w", strtotime($date)); + $d = $w ? $w - 1 : 6; + $start = date("Y-m-d", strtotime($date . " - " . $d . " days")); + $start_time = date('Y-m-d', strtotime($start . " + 7 days")); + $end_time = date('Y-m-d', strtotime($start . " + 13 days")); + } + + // 今天 + if ($type == 'today') { + $start_time = date('Y-m-d 00:00:00'); + $end_time = date('Y-m-d 23:59:59'); + } + + // 昨天 + if ($type == 'yesterday') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); + } + + // 明天 + if ($type == 'tomorrow') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 day')); + } + + // 过去3天 + if ($type == 'previous3day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-3 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); + } + + // 过去5天 + if ($type == 'previous5day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-5 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); + } + + // 过去7天 + if ($type == 'previous7day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-7 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); + } + // 过去10天 + if ($type == 'previous10day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-10 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); + } + // 过去30天 + if ($type == 'previous30day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-30 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); + } + // 未来3天 + if ($type == 'future3day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+3 day')); + } + // 未来5天 + if ($type == 'future5day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+5 day')); + } + // 未来7天 + if ($type == 'future7day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+7 day')); + } + // 未来10天 + if ($type == 'future10day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+10 day')); + } + // 未来30天 + if ($type == 'future30day') { + $start_time = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); + $end_time = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+30 day')); + } + return [$start_time,$end_time]; + } + + /** + * 根据时间戳获取星期几 + * @param $time 要转换的时间戳 + */ + function getTimeWeek($time, $i = 0) + { + $weekarray = array("日", "一", "二", "三", "四", "五", "六"); + $oneD = 24 * 60 * 60; + return "星期" . $weekarray[date("w", $time + $oneD * $i)]; + } +} diff --git a/extend/systematic/Systematic.php b/extend/systematic/Systematic.php new file mode 100644 index 0000000..9477d04 --- /dev/null +++ b/extend/systematic/Systematic.php @@ -0,0 +1,53 @@ +<?php +declare (strict_types = 1); +namespace systematic; +use think\facade\Config; +use think\facade\Cache; +use think\facade\Db; +/** + * 系统类 + */ +class Systematic +{ + public function auth($uid) + { + if (!Cache::get('RulesSrc' . $uid) || !Cache::get('RulesSrc0')) { + //用户所在权限组及所拥有的权限 + $groups = []; + $position_id = Db::name('Admin')->where('id', $uid)->value('position_id'); + $groups = Db::name('PositionGroup') + ->alias('a') + ->join("AdminGroup g", "a.group_id=g.id", 'LEFT') + ->where([['a.pid', '=', $position_id], ['g.status', '=', 1]]) + ->select()->toArray(); + //保存用户所属用户组设置的所有权限规则id + $ids = []; + foreach ($groups as $g) { + $ids = array_merge($ids, explode(',', trim($g['rules'], ','))); + } + $ids = array_unique($ids); + //读取所有权限规则 + $rules_all = Db::name('AdminRule')->field('src')->select()->toArray(); + //读取用户组所有权限规则 + $rules = Db::name('AdminRule')->where('id', 'in', $ids)->field('src')->select()->toArray(); + //循环规则,判断结果。 + $auth_list_all = []; + $auth_list = []; + foreach ($rules_all as $rule_all) { + $auth_list_all[] = strtolower($rule_all['src']); + } + foreach ($rules as $rule) { + $auth_list[] = strtolower($rule['src']); + } + //规则列表结果保存到Cache + Cache::tag('adminRules')->set('RulesSrc0', $auth_list_all, 36000); + Cache::tag('adminRules')->set('RulesSrc' . $uid, $auth_list, 36000); + } + } + + //读取文件配置 + public function getConfig($key) + { + return Config::get($key); + } +} diff --git a/public/static/assets/gougu/module/oaComment.js b/public/static/assets/gougu/module/oaComment.js index f362650..c810877 100644 --- a/public/static/assets/gougu/module/oaComment.js +++ b/public/static/assets/gougu/module/oaComment.js @@ -118,7 +118,7 @@ layui.define(['tool'], function (exports) { if (item.padmin_id > 0) { pAdmin = '<span class="blue">@' + item.pname + '</span>'; } - if (item.admin_id == login_user) { + if (item.admin_id == login_admin) { ops = '<a class="mr-4" data-event="edit" data-id="' + item.id + '">编辑</a><a class="mr-4" data-event="del" data-id="' + item.id + '">删除</a>'; } itemComment += ` diff --git a/public/static/assets/gougu/module/oaSchedule.js b/public/static/assets/gougu/module/oaSchedule.js index 5fa3cd4..0fb2bd3 100644 --- a/public/static/assets/gougu/module/oaSchedule.js +++ b/public/static/assets/gougu/module/oaSchedule.js @@ -108,7 +108,7 @@ layui.define(['tool'], function (exports) { that.loading = true; let html_time = ''; if (schedule['id'] > 0) { - if(schedule['admin_id'] != login_user){ + if(schedule['admin_id'] != login_admin){ layer.msg('不能编辑他人的工作记录'); return false; }