From 08532e22d46aec5aabcb8635bd8d84d442c02ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9D=BE=E6=A0=91?= Date: Mon, 1 Jul 2019 12:33:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=88=90=E7=BB=A9=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 67 ++++------------------------- application/kaoshi/model/Kaohao.php | 42 ++++++++++-------- 2 files changed, 32 insertions(+), 77 deletions(-) diff --git a/application/common.php b/application/common.php index 84da807a..02f11504 100644 --- a/application/common.php +++ b/application/common.php @@ -261,76 +261,25 @@ function upload($list,$file,$isSave=false) - /** * 数组重新排序 * $array 要排序的数组 * $field 排序字段 * $sort 排序方式 SORT_DESC 降序;SORT_ASC 升序 * */ -function arraySequence($array, $field = 'id', $sort = 'desc') { +function arraySequence($data, $field = 'id', $sort = 'desc') { + // 排序方式 + $sort == 'desc' ? $sort = 'SORT_DESC' : $sort = 'SORT_ASC'; + // 获取参考列 + $column = array_column($data, $field); + // 排序 + array_multisort($column, SORT_ASC, $data); - $len = count($array)-1; - - if($sort == 'asc') - { - for($i = 0 ; $i<$len ; $i++){ - for($x=0 ; $x<($len-$i) ; $x++) - { - if(isset($array[$x][$field]) && isset($array[$x+1][$field])) - { - if($array[$x][$field] > $array[$x+1][$field]) - { - $temp = $array[$x]; - $array[$x] = $array[$x+1]; - $array[$x+1] = $temp; - } - }elseif(!isset($array[$x+1][$field])){ - $temp = $array[$x]; - $array[$x] = $array[$x+1]; - $array[$x+1] = $temp; - } - } - } - }else{ - for($i = 0 ; $i<$len ; $i++){ - for($x=0 ; $x<($len-$i) ; $x++) - { - if(isset($array[$x][$field]) && isset($array[$x+1][$field])) - { - if($array[$x][$field] < $array[$x+1][$field]) - { - $temp = $array[$x]; - $array[$x] = $array[$x+1]; - $array[$x+1] = $temp; - } - }elseif(!isset($array[$x][$field])){ - $temp = $array[$x]; - $array[$x] = $array[$x+1]; - $array[$x+1] = $temp; - } - } - } - } - return $array; + return $data; } -/** - * 数组重新排序 - * $array 要排序的数组 - * $field 排序字段 - * $sort 排序方式 SORT_DESC 降序;SORT_ASC 升序 - * */ -// function arraySequence($array, $field = 'id', $sort = 'desc') { -// $array = array(); - -// return $array; -// } - - - /** * 根据键值,用数组2的值替换数组1的值 diff --git a/application/kaoshi/model/Kaohao.php b/application/kaoshi/model/Kaohao.php index 75196748..756dd960 100644 --- a/application/kaoshi/model/Kaohao.php +++ b/application/kaoshi/model/Kaohao.php @@ -166,17 +166,17 @@ class Kaohao extends Base foreach ($khlist as $key => $value) { $data[$key]['id'] = $value->id; $data[$key]['school'] = $value->cj_school->jiancheng; - // if($value->cj_student != Null){ + if($value->cj_student != Null){ $data[$key]['student'] = $value->cj_student->xingming; $data[$key]['sex'] = $value->cj_student->sex; - // }else{ - // $stuinfo = $stu::withTrashed() - // ->where('id',$value->student) - // ->field('id,xingming,sex') - // ->find(); - // $data[$key]['student'] = $stuinfo->xingming; - // $data[$key]['sex'] = $stuinfo->sex; - // } + }else{ + $stuinfo = $stu::withTrashed() + ->where('id',$value->student) + ->field('id,xingming,sex') + ->find(); + $data[$key]['student'] = $stuinfo->xingming; + $data[$key]['sex'] = $stuinfo->sex; + } $data[$key]['nianji'] = $value->nianji; $data[$key]['banji'] = $value->cj_banji->num_title; $dfsum = 0; @@ -184,15 +184,21 @@ class Kaohao extends Base $cjarr = $this->zzcj($value->ks_chengji); + // 初始化参数 + $dfsum = 0; + $sbjcnt = 0; - // foreach ($xk as $k => $val) { - // if(array_key_exists($k,$cjarr)) - // { - // $data[$key][$val]=$cjarr[$k]; - // }else{ - // $data[$key][$val]=''; - // } - // } + foreach ($xk as $k => $val) { + // 为每个学科赋值并记录学科数 + if(array_key_exists($k,$cjarr)) + { + $data[$key][$val]=$cjarr[$k] * 1; + $sbjcnt++; + $dfsum = $dfsum + $data[$key][$val]; + }else{ + $data[$key][$val]=''; + } + } $data[$key]['sum'] = $dfsum; @@ -206,7 +212,7 @@ class Kaohao extends Base // 按条件排序 if(count($data)>0){ - // $data = arraySequence($data,$src['field'],$src['type']); //排序 + $data = arraySequence($data,$src['field'],$src['type']); //排序 }