优化成绩查询速度

This commit is contained in:
小松树 committed 2019-07-01 12:33:09 +08:00
1 parent aeb025cf6b
commit 08532e22d4
2 files changed
+32 -77

No files matched your search

+8 -59
View File
@@ -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的值
+24 -18
View File
@@ -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']); //排序
}