From fea84800536d25efd8070680a2fda4be3c54cd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E6=8E=8C?= Date: Tue, 9 Nov 2021 21:48:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=90=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chengji/controller/Bjtongji.php | 6 +++-- app/chengji/controller/Index.php | 18 ++++++------- app/chengji/model/Chengji.php | 5 ++++ app/common.php | 2 +- app/kaohao/common.php | 5 ---- app/kaohao/controller/Index.php | 13 +++++---- app/kaohao/model/SearchCanYu.php | 42 +++++------------------------ app/kaohao/model/SearchMore.php | 21 ++++++++++++--- app/student/controller/Index.php | 3 ++- app/system/model/School.php | 20 ++++++++++++-- app/teach/model/Banji.php | 38 +++++++++++++++++++++++--- app/tools/controller/Index.php | 17 +++++++----- 12 files changed, 115 insertions(+), 75 deletions(-) delete mode 100755 app/kaohao/common.php diff --git a/app/chengji/controller/Bjtongji.php b/app/chengji/controller/Bjtongji.php index e6999960..9706240e 100755 --- a/app/chengji/controller/Bjtongji.php +++ b/app/chengji/controller/Bjtongji.php @@ -17,8 +17,10 @@ class Bjtongji extends AdminBase $ksinfo = $ks->where('id', $kaoshi_id) ->field('id, title') ->find(); - // 获取参与学校 - $src['kaoshi_id'] = $kaoshi_id; + $src = [ + 'kaoshi_id' => $kaoshi_id + ,'all' => true + ]; // 获取年级与学科 $ksset = new \app\kaoshi\model\KaoshiSet; $list['subject_id'] = $ksset->srcSubject($src); diff --git a/app/chengji/controller/Index.php b/app/chengji/controller/Index.php index b98a6fd8..dcfeb6c1 100755 --- a/app/chengji/controller/Index.php +++ b/app/chengji/controller/Index.php @@ -46,22 +46,22 @@ class Index extends AdminBase // 获取参数 $src = $this->request ->only([ - 'page' - ,'limit' - ,'field' => 'id' - ,'order' => 'asc' - ,'kaoshi_id' + 'kaoshi_id' ,'school_id' ,'ruxuenian' ,'banji_id' => array() ,'searchval' + ,'page' => 1 + ,'limit' => 10 + ,'field' => 'id' + ,'order' => 'asc' ], 'POST'); // 获取参与考试的班级 if (count($src['banji_id']) == 0) { $cy = new \app\kaohao\model\SearchCanYu; $src['banji_id']= array_column($cy->class($src), 'id'); - } + } $src['auth'] = event('mybanji', array()); $src['auth'] = $src['auth'][0]; @@ -69,9 +69,7 @@ class Index extends AdminBase // 实例化并查询成绩 $cj = new Chengji; $data = $cj->search($src); - $src['all'] = true; - $cnt = $data = $cj->search($src); - $data = reset_data($data, $cnt); + $data = \app\facade\Tools::reset_array($data, $src); return json($data); } @@ -779,7 +777,7 @@ class Index extends AdminBase $i++; } $newStr = $newStr . '*'; - for ($i=$cnt - $l; $i < $cnt; $i++) { + for ($i=$cnt - $l; $i < $cnt; $i++) { $newStr = $newStr . $arr[$i]; } } diff --git a/app/chengji/model/Chengji.php b/app/chengji/model/Chengji.php index 20a20056..86b24b46 100755 --- a/app/chengji/model/Chengji.php +++ b/app/chengji/model/Chengji.php @@ -257,6 +257,11 @@ class Chengji extends BaseModel 'check' => true ,'banji_id' => array() ] + ,'page' => 1 + ,'limit' => 10 + ,'field' => 'id' + ,'order' => 'asc' + ,'all' => false ); $src = array_cover($srcfrom, $src); diff --git a/app/common.php b/app/common.php index efc1af4c..07b7df86 100755 --- a/app/common.php +++ b/app/common.php @@ -95,7 +95,7 @@ */ function reset_data($data, $cnt) { - $data = \app\facade\Tools::reSetData($data, $cnt); + $data = \app\facade\Tools::reset_data($data, $cnt); return $data; } diff --git a/app/kaohao/common.php b/app/kaohao/common.php deleted file mode 100755 index 0705b1d3..00000000 --- a/app/kaohao/common.php +++ /dev/null @@ -1,5 +0,0 @@ - 1 ,'status' => 1 ]; - + $src['auth'] = event('mybanji', array()); $src['auth'] = $src['auth'][0]; $src['auth']['banji_id'] = array_intersect($src['auth']['banji_id'], $src['banji_id']); @@ -106,7 +106,7 @@ class Index extends AdminBase $check->status = 1; $check->save(); } - + $stuInfo = stu::where('id', $value->id) ->field('id, banji_id') ->with([ @@ -168,9 +168,12 @@ class Index extends AdminBase { // 获取参考年级、学科 $ksset = new ksset; - $list['data']['nianji'] = $ksset->srcGrade($kaoshi_id); + $src = [ + 'kaoshi_id' => $kaoshi_id + ,'all' => true + ]; + $list['data']['nianji'] = $ksset->srcGrade($src); $kh = new KH; - $src['kaoshi_id'] = $kaoshi_id; if(count($list['data']['nianji']) > 0){ $src['ruxuenian'] = $list['data']['nianji'][0]; } else { diff --git a/app/kaohao/model/SearchCanYu.php b/app/kaohao/model/SearchCanYu.php index c82a8dc8..89e338ed 100755 --- a/app/kaohao/model/SearchCanYu.php +++ b/app/kaohao/model/SearchCanYu.php @@ -24,9 +24,10 @@ class SearchCanyu extends BaseModel ,'all' => false ); $src = array_cover($srcfrom, $src); - $src['ruxuenian'] = str_to_array($src['ruxuenian']); + $src['ruxuenian'] = str_to_array($src['ruxuenian']); - $src['orderSql'] = $this->schPaixu($src['field']); + $sch = new \app\system\model\School; + $src['orderSql'] = $sch->schPaixu('school_id'); $kh = new kh; $schoolList = $kh->where('kaoshi_id', $src['kaoshi_id']) @@ -88,20 +89,10 @@ class SearchCanyu extends BaseModel $src['banji_id'] = str_to_array($src['banji_id']); $src['ruxuenian'] = str_to_array($src['ruxuenian']); - $src['orderSql'] = $this->schPaixu('school_id'); $ks = new \app\kaoshi\model\Kaoshi; - $bjdate = $ks->where('id', $src['kaoshi_id'])->value('bfdate'); + $bfdate = $ks->where('id', $src['kaoshi_id'])->value('bfdate'); $bj = new \app\teach\model\Banji; - $njList = $bj->gradeName($bjdate,'num'); - $bjList = $bj->where('ruxuenian', 'in', $njList) - ->order($src['orderSql']) - ->order(['ruxuenian' => 'asc']) - ->order(['paixu' => 'asc']) - ->column(['id']); - $paixuList = implode('\', \'', $bjList); - $paixuList = "field(banji_id, '". $paixuList. "')"; - $orderSql = \think\facade\Db::raw($paixuList); - + $orderSql = $bj->classPaixu($bfdate, 'banji_id'); // 通过给定参数,从考号表中获取参加考试的班级 $kh = new kh; @@ -151,25 +142,4 @@ class SearchCanyu extends BaseModel return $data; } - - /** - * 获取参加考试的班级 - * @access public - * @param number $kaoshi 考试id - * @param number $ruxuenian 入学年 - * @return array 返回班级数据模型 - */ - public function schPaixu($field) - { - $sch = new \app\system\model\School; - $schList = $sch->where('jibie_id', 10203) - ->order(['paixu' => 'asc']) - ->field('id, title, paixu') - ->column(['id']); - $paixuList = implode('\', \'', $schList); - $paixuList = "field(" . $field . ", '". $paixuList. "')"; - $orderSql = \think\facade\Db::raw($paixuList); - return $orderSql; - } - -} \ No newline at end of file +} diff --git a/app/kaohao/model/SearchMore.php b/app/kaohao/model/SearchMore.php index ccf260a1..2a91b2d5 100755 --- a/app/kaohao/model/SearchMore.php +++ b/app/kaohao/model/SearchMore.php @@ -31,6 +31,7 @@ class SearchMore extends BaseModel $src = array_cover($srcfrom, $src); $src['banji_id'] = str_to_array($src['banji_id']); + // 查询成绩 $kh = new kh(); $data = $kh->where('kaoshi_id', $src['kaoshi_id']) @@ -65,8 +66,11 @@ class SearchMore extends BaseModel $query->field('id, xingming, sex, shengri'); } ]) + ->append(['banjiTitle', 'banTitle']) ->select(); + + return $data; } @@ -82,6 +86,11 @@ class SearchMore extends BaseModel 'kaoshi_id' => '0' ,'banji_id' => array() ,'searchval' => '' + ,'page' => 1 + ,'limit' => 10 + ,'field' => 'id' + ,'order' => 'asc' + ,'all' => false ); // 用新值替换初始值 @@ -119,6 +128,11 @@ class SearchMore extends BaseModel $query->field('id, xingming, sex, shengri, xuehao'); } ]) + ->when($src['all'] == false, function ($query) use($src) { + $query + ->page($src['page'], $src['limit']); + }) + ->order([$src['field'] => $src['order']]) ->append(['banjiTitle', 'banTitle', 'xuehao']) ->select(); return $data; @@ -171,7 +185,7 @@ class SearchMore extends BaseModel $data[$key]['student_xingming'] = '被真删除'; $data[$key]['sex'] = '未知'; } - + } $data[$key]['ban_title'] = $value->banjiTitle; @@ -223,15 +237,16 @@ class SearchMore extends BaseModel } } - if($sbjcnt>0){ + if ($sbjcnt > 0) { $data[$key]['sum'] = $dfsum; $data[$key]['avg'] = round($dfsum / $sbjcnt, 1); - }else{ + } else { $data[$key]['sum'] = null; $data[$key]['avg'] = null; } } + return $data; } diff --git a/app/student/controller/Index.php b/app/student/controller/Index.php index cd80a7ed..32afdc20 100755 --- a/app/student/controller/Index.php +++ b/app/student/controller/Index.php @@ -613,8 +613,9 @@ class Index extends AdminBase ,'order' => 'desc' ],'POST'); + // 判断是否存在数据,如果没有数据则返回。 - if(strlen($str) <= 0){ + if(strlen($src['searchval']) <= 0){ $data = reset_data($data, 0); return json($data); } diff --git a/app/system/model/School.php b/app/system/model/School.php index ca926ee7..6ea19e3e 100755 --- a/app/system/model/School.php +++ b/app/system/model/School.php @@ -127,7 +127,7 @@ class School extends BaseModel $src['orderSql'] = \think\facade\Db::raw($paixuList); } else { $src['orderSql'] = array($src['field'] => $src['order']); - } + } // 查询数据 $data = $this @@ -240,7 +240,7 @@ class School extends BaseModel { $bf = true; } - + if($bf == true) { $ids[] = $value->id; @@ -261,4 +261,20 @@ class School extends BaseModel return $schlist; } + + // 学校排序 + # ziduan 生成后的字段名字 + public function schPaixu($ziduan = 'school_id', $order = 'asc') + { + $sch = new \app\system\model\School; + $schList = $sch->where('jibie_id', 10203) + ->order(['paixu' => $order]) + ->field('id, title, paixu') + ->column(['id']); + $paixuList = implode('\', \'', $schList); + $paixuList = "field(" . $ziduan . ", '". $paixuList. "')"; + $orderSql = \think\facade\Db::raw($paixuList); + return $orderSql; + } + } diff --git a/app/teach/model/Banji.php b/app/teach/model/Banji.php index b78ade02..b311a488 100755 --- a/app/teach/model/Banji.php +++ b/app/teach/model/Banji.php @@ -37,8 +37,8 @@ class Banji extends BaseModel ] ,'page' => 1 ,'limit' => 10 - ,'field' => 'id' - ,'order' => 'desc' + ,'field' => 'paixu' + ,'order' => 'asc' ,'all' => false ]; $src = array_cover($srcfrom, $src); @@ -50,6 +50,14 @@ class Banji extends BaseModel $src['ruxuenian'] = array_values($njname); } + $sch = new \app\system\model\School; + if ($src['field'] == 'paixu') { + $src['orderSql'] = $this->classPaixu(time(), 'id', $src['order']); + } else { + $src['orderSql'] = $this->classPaixu(time(), 'id'); + } + + // 查询数据 $data = $this ->when(count($src['school_id']) > 0, function($query) use($src){ @@ -80,7 +88,12 @@ class Banji extends BaseModel $query ->page($src['page'], $src['limit']); }) - ->order([$src['field'] => $src['order']]) + ->when($src['field'] == 'paixu', function ($query) use($src) { + $query->order($src['orderSql']) + ->order([$src['field'] => $src['order']]); + }, function ($query) use($src) { + $query->order([$src['field'] => $src['order']]); + }) ->append(['banjiTitle', 'banTitle', 'grade', 'bzr']) ->select(); @@ -122,6 +135,25 @@ class Banji extends BaseModel } + // 班级排序 + # ziduan 生成后的字段名称 + public function classPaixu($riqi = 0, $ziduan = 'banji_id', $order = 'asc') + { + $sch = new \app\system\model\School; + $orderSql = $sch->schPaixu('school_id');; + $njList = $this->gradeName($riqi,'num'); + $bjList = $this->where('ruxuenian', 'in', $njList) + ->order($orderSql) + ->order(['ruxuenian' => 'desc']) + ->order(['paixu' => $order]) + ->column(['id']); + $paixuList = implode('\', \'', $bjList); + $paixuList = "field(" . $ziduan . ", '". $paixuList. "')"; + $orderSql = \think\facade\Db::raw($paixuList); + return $orderSql; + } + + // 学校关联模型 public function glSchool(){ return $this->belongsTo(\app\system\model\School::class, 'school_id', 'id'); diff --git a/app/tools/controller/Index.php b/app/tools/controller/Index.php index 542e41f8..96be88ec 100755 --- a/app/tools/controller/Index.php +++ b/app/tools/controller/Index.php @@ -103,7 +103,7 @@ class Index extends BaseController * @param str或array $str 表单中获取的参数 * @return array 返回类型 */ - public function reSetData($data, $cnt) + public function reset_data($data = array(), $cnt) { $arr = [ 'code' => 0 // ajax请求次数,作为标识符 @@ -115,7 +115,7 @@ class Index extends BaseController // 整理数据 if($cnt > 0) { - + $arr = [ 'code' => 0 // ajax请求次数,作为标识符 ,'msg' => "" // 获取到的结果数(每页显示数量) @@ -127,20 +127,21 @@ class Index extends BaseController } - /** + + /** * 把重新整理从数据模型中返回的对象 * @access public * @param str或array $str 表单中获取的参数 * @return array 返回类型 */ - public function reset_data($arr = array(), $srcfrom) + public function reset_array($arr = array(), $srcfrom) { // 整理变量 $src = [ 'field' => '' ,'order' => 'desc' - ,'page' => '' - ,'limit' => '' + ,'page' => '1' + ,'limit' => '10' ]; $src = array_cover($srcfrom, $src) ; $data = [ # 数据合并 @@ -150,6 +151,7 @@ class Index extends BaseController 'data' => [], # 获取到的数据结果 ]; + // 重新整理数据 $cnt = count($arr); # 记录总数 if($cnt > 0){ @@ -159,7 +161,6 @@ class Index extends BaseController : $src['order'] = SORT_ASC; # 数据排序 $arr = $this->sortArrByManyField($arr, $src['field'], $src['order']); } - // halt($arr); if($src['page'] > 0 and $src['limit'] > 0) { $limit_start = $src['page'] * $src['limit'] - $src['limit']; # 获取当前页数据 @@ -178,6 +179,8 @@ class Index extends BaseController } + + // 加密 public function encrypt($data, $key) {