diff --git a/app/common.php b/app/common.php index c677b8fc..5d68a5c0 100755 --- a/app/common.php +++ b/app/common.php @@ -121,12 +121,12 @@ } - // 多字段排序 - function sort_arr_by_many_field($arr, $srcfrom) - { - $data = \app\facade\Tools::sortArrByManyField($arr, $srcfrom); - return $data; - } + // // 多字段排序 + // function sort_arr_by_many_field($arr, $srcfrom) + // { + // $data = \app\facade\Tools::sortArrByManyField($arr, $srcfrom); + // return $data; + // } // 已知密码进行验证 diff --git a/app/kaoshi/controller/TongjiXiangmu.php b/app/kaoshi/controller/TongjiXiangmu.php index b653df0c..f929fb17 100755 --- a/app/kaoshi/controller/TongjiXiangmu.php +++ b/app/kaoshi/controller/TongjiXiangmu.php @@ -36,7 +36,7 @@ class TongjiXiangmu extends AdminBase // 获取参数 $src = $this->request ->only([ - 'page' => '1' + 'page' => 1 ,'limit' => '10' ,'field' => 'id' ,'order' => 'desc' @@ -56,7 +56,9 @@ class TongjiXiangmu extends AdminBase ,'tjxmCategory' ,'update_time' ]); - $data = reSetObject($data, $src); + $src['all'] = true; + $cnt = $tjxm->search($src)->count(); + $data = reset_data($data, $cnt); return json($data); } diff --git a/app/kaoshi/model/TongjiXiangmu.php b/app/kaoshi/model/TongjiXiangmu.php index e3113291..6db32786 100755 --- a/app/kaoshi/model/TongjiXiangmu.php +++ b/app/kaoshi/model/TongjiXiangmu.php @@ -1,5 +1,4 @@ '' ,'category_id' => array() + ,'page' => 1 + ,'limit' => 10 + ,'field' => 'id' + ,'order' => 'desc' + ,'all' => false ]; // 用新值替换初始值 $src = array_cover($srcfrom, $src); - $src['category_id'] = strToarray($src['category_id']); + $src['category_id'] = str_to_array($src['category_id']); // 查询数据 $data = $this @@ -35,6 +39,10 @@ class TongjiXiangmu extends BaseModel $q->field('id,title'); } ]) + ->when($src['all'] == false, function ($query) use($src) { + $query->page($src['page'], $src['limit']); + }) + ->order([$src['field'] => $src['order']]) ->select(); return $data; @@ -72,6 +80,6 @@ class TongjiXiangmu extends BaseModel // 类别关联 public function tjxmCategory() { - return $this->belongsTo('\app\system\model\Category', 'category_id', 'id'); + return $this->belongsTo(\app\system\model\Category::class, 'category_id', 'id'); } } diff --git a/app/system/controller/BackUp.php b/app/system/controller/BackUp.php index 34ccb230..d8605a4e 100755 --- a/app/system/controller/BackUp.php +++ b/app/system/controller/BackUp.php @@ -36,23 +36,31 @@ class BackUp extends AdminBase { // 获取参数 $src = $this->request - ->only([ - 'page' => '1' - ,'limit' => '10' - ,'field' => 'time' - ,'order' => 'desc' - ],'POST'); + ->only([ + 'page' => '1' + ,'limit' => '10' + ,'field' => 'time' + ,'order' => 'desc' + ],'POST'); + $src['order'] == 'desc' ? $src['order'] = SORT_DESC + : $src['order'] = SORT_ASC; # 数据排序 + $start = $src['page'] * $src['limit'] - $src['limit']; $db= new up($this->upcnf); $data = $db->fileList(); + + $cnt = count($data); + $data = \app\facade\Tools::sortArrByManyField($data, $src['field'], $src['order']); + $data = array_slice($data, $start, $src['limit']); + foreach ($data as $key => $value) { - $data[$key]['ltime'] = date('Y-m-d H:i:s', $value['time']); - $data[$key]['lsize'] = format_bytes($value['size']); - $data[$key]['juan'] = $value['part']; - $data[$key]['yasuo'] = $value['compress']; + $data[$key]['ltime'] = $value['time']; + $data[$key]['time'] = date('Y-m-d H:i:s', $value['time']); + $data[$key]['size'] = format_bytes($value['size']); + $data[$key]['part'] = $value['part']; + $data[$key]['compress'] = $value['compress']; $data[$key]['status'] = '正常'; } - $cnt = count($data); $data = reset_data($data, $cnt); return json($data); @@ -250,13 +258,13 @@ class BackUp extends AdminBase * 下载备份文件 */ public function down($time = 0){ - $db= new up($this->upcnf); - $list = $db->getFile('timeverif', $time); - $url = $list['1']['1']; - $l = strripos($url, '\\', 0) + 1; - $title = substr($url, $l, strlen($url) - $l); - $title = str_replace('-', '', $title); - return download($url, $title); + $db= new up($this->upcnf); + $list = $db->getFile('timeverif', $time); + $url = $list['1']['1']; + $l = strripos($url, '\\', 0) + 1; + $title = substr($url, $l, strlen($url) - $l); + $title = str_replace('-', '', $title); + return download($url, $title); } diff --git a/app/system/controller/Category.php b/app/system/controller/Category.php index 5784a93e..33a4d271 100755 --- a/app/system/controller/Category.php +++ b/app/system/controller/Category.php @@ -53,7 +53,9 @@ class Category extends AdminBase ,'status' ,'update_time' ]); - $data = reSetObject($data, $src); + $src['all'] = true; + $cnt = $cg->search($src)->count(); + $data = reset_data($data, $cnt); return json($data); } diff --git a/app/system/controller/Fields.php b/app/system/controller/Fields.php index daae862a..086e506f 100755 --- a/app/system/controller/Fields.php +++ b/app/system/controller/Fields.php @@ -53,7 +53,9 @@ class Fields extends AdminBase ,'update_time' ,'flAdmin' ]); - $data = reSetObject($data, $src); + $src['all'] = true; + $cnt = $fl->search($src)->count(); + $data = reset_data($data, $cnt); return json($data); } @@ -82,8 +84,6 @@ class Fields extends AdminBase } else { return $this->error('文件不存在!'); } - - } @@ -97,12 +97,30 @@ class Fields extends AdminBase { $id = request()->delete('id'); $id = explode(',', $id); - + $fl = new FL(); + $err = array(); + + $list = $fl->where('id', 'in', $id)->select(); # 查询要删除的信息 + $id = array(); + $fengefu = DIRECTORY_SEPARATOR; + foreach ($list as $key => $value) { + $url = public_path() . 'uploads' . $fengefu . $value->url; + if (file_exists($url)) { + @$temp = unlink($url); + $temp === true ? $id[] = $value->id : $err[] = $value->create_time . '上传的' . $value->oldname; + } else { + $id[] = $value->id; + } + } $data = FL::destroy($id); + if (count($err) > 0) { + $msg = implode('、', $err) . '删除失败'; + } else { + $msg = '删除成功!'; + } // 根据更新结果设置返回提示信息 - $data ? $data = ['msg' => '删除成功', 'val' => 1] - : $data = ['msg' => '数据处理错误', 'val' => 0]; + $data = ['msg' => $msg, 'val' => 1]; // 返回信息 return json($data); diff --git a/app/system/model/Category.php b/app/system/model/Category.php index 3bdda98c..e48eefc5 100755 --- a/app/system/model/Category.php +++ b/app/system/model/Category.php @@ -12,14 +12,14 @@ class Category extends BaseModel // 父级类型关联 public function glPid() { - return $this->belongsTo('Category', 'p_id', 'id'); + return $this->belongsTo(Category::class, 'p_id', 'id'); } // 子类型关联 public function glCid() { - return $this->hasMany('Category', 'p_id', 'id'); + return $this->hasMany(Category::class, 'p_id', 'id'); } @@ -29,6 +29,11 @@ class Category extends BaseModel $src = [ 'p_id'=>'' ,'searchval'=>'' + ,'page' => 1 + ,'limit' => 10 + ,'field' => 'id' + ,'order' => 'desc' + ,'all' => false ]; // 用新值替换初始值 @@ -49,11 +54,17 @@ class Category extends BaseModel } ] ) - // ->cache(true, 60) + ->when($src['all'] == false, function ($query) use($src) { + $query + ->page($src['page'], $src['limit']); + }) + ->order([$src['field'] => $src['order']]) ->select(); + return $data; } + // 查询子类别 public function srcChild($srcfrom) { @@ -62,11 +73,13 @@ class Category extends BaseModel ,'order' => 'asc' ]; $src = array_cover($srcfrom, $src); # 新值替换旧值 + $child = self::where('p_id', $src['p_id']) ->where('status', 1) ->field('id, title, p_id, status, paixu, isupdate') ->order(['paixu' => $src['order']]) ->select(); + return $child; } @@ -79,6 +92,7 @@ class Category extends BaseModel ->where('status', 1) ->field('id, title') ->select(); + return $data; } } diff --git a/app/system/model/Fields.php b/app/system/model/Fields.php index 62e58ea5..1f8630e6 100755 --- a/app/system/model/Fields.php +++ b/app/system/model/Fields.php @@ -25,14 +25,19 @@ class Fields extends BaseModel } - // 查询所有单位 + // 查询所有文件 public function search($srcfrom) { // 整理条件 $src = [ 'searchval' => '' + ,'page' => 1 + ,'limit' => 10 + ,'field' => 'id' + ,'order' => 'desc' + ,'all' => false ]; - $src = array_cover($srcfrom, $src) ; + $src = array_cover($srcfrom, $src); // 查询数据 $data = $this @@ -52,6 +57,10 @@ class Fields extends BaseModel ]); } ]) + ->when($src['all'] == false, function ($query) use($src) { + $query->page($src['page'], $src['limit']); + }) + ->order([$src['field'] => $src['order']]) ->select(); return $data; @@ -60,60 +69,13 @@ class Fields extends BaseModel // 上传人数据关联 public function flAdmin() { - return $this->belongsTo('\app\admin\model\Admin', 'user_id', 'id'); + return $this->belongsTo(\app\admin\model\Admin::class, 'user_id', 'id'); } - // 文件种类数模型关联 public function flCategory() { - return $this->belongsTo('\app\system\model\Category', 'category_id', 'id'); + return $this->belongsTo(\app\system\model\Category::class, 'category_id', 'id'); } - - - // 上传人信息获取器 - public function getUserInfoAttr($value, $data) - { - // halt($data); - $xm = ''; - if($data['user_group'] === 'admin') - { - if($this->flAdmin) - { - $xm = $this->flAdmin->xingming; - if($this->flAdmin->adSchool) - { - $xm = $xm . '(' . $this->flAdmin->adSchool->jiancheng . ')'; - } - } - }elseif ($data['user_group'] === 'teacher') { - if($this->flTeacher) - { - $xm = $this->flTeacher->xingming; - if($this->flTeacher->jsDanwei) - { - $xm = $xm . '(' . $this->flTeacher->jsDanwei->jiancheng . ')'; - } - } - }else{ - $xm = ''; - } - - $arr = [ - 'admin' => '管理员' - ,'teacher' => '教师' - ,'student' => '学生' - ]; - - if(isset($arr[$data['user_group']])) - { - $str = $arr[$data['user_group']] . ' ' . $xm; - }else{ - $str = ''; - } - - return $str; - } - } diff --git a/app/system/model/School.php b/app/system/model/School.php index fb220a6e..73bd09d5 100755 --- a/app/system/model/School.php +++ b/app/system/model/School.php @@ -176,7 +176,7 @@ class School extends BaseModel $src = array_cover($srcfrom, $src); - $data = $this->where('kaoshi&&status', 1) + $data = $this->where('kaoshi', 1) ->where('status', 1) ->order(['jibie_id', 'paixu']) ->field('id, title, jiancheng, jibie_id') diff --git a/app/system/view/back_up/index.html b/app/system/view/back_up/index.html index f61e200e..8f5fba9a 100755 --- a/app/system/view/back_up/index.html +++ b/app/system/view/back_up/index.html @@ -39,12 +39,12 @@ layui.use(['table', 'backUp', 'form'], function() { // 设置列 options.cols = [ [ //表头 - { field: 'time', type: 'checkbox', fixed: 'left' }, - { field: 'ltime', title: '时间', sort: true, minWidth: 100, fixed: 'left'}, - { field: 'juan', title: '卷数', sort: true, minWidth: 100 }, - { field: 'yasuo', title: '压缩', sort: true, minWidth: 100 }, - { field: 'lsize', title: '文件大小', minWidth: 100, sort: true }, - { field: 'status', title: '状态', minWidth: 100, sort: true }, + { field: 'ltime', type: 'checkbox', fixed: 'left' }, + { field: 'time', title: '时间', sort: true, minWidth: 100, fixed: 'left'}, + { field: 'part', title: '卷数', sort: true, minWidth: 100 }, + { field: 'compress', title: '压缩', sort: true, minWidth: 100 }, + { field: 'size', title: '文件大小', minWidth: 100, sort: true }, + { field: 'status', title: '状态', minWidth: 100 }, { field: 'id', title: '操作', toolbar: '#barDemo', minWidth: 90} ] ]; @@ -69,13 +69,13 @@ layui.use(['table', 'backUp', 'form'], function() { var tr = obj.tr; //获得当前行 tr 的DOM对象 switch (layEvent) { case 'del': // 删除 - backUp.del('/system/backup/delete/' + obj.data.time); + backUp.del('/system/backup/delete/' + obj.data.ltime); break; case 'huifu': // 删除 - backUp.back('/system/backup/import', this, obj.data.time); + backUp.back('/system/backup/import', this, obj.data.ltime); break; case 'down': // 删除 - window.open("/system/backup/down/" + obj.data.time); + window.open("/system/backup/down/" + obj.data.ltime); break; }; });