灵睿积分项统计排序优化
This commit is contained in:
parent
b70b948cdd
commit
850f0e1f98
@ -63,31 +63,66 @@ class Employee extends Backend
|
|||||||
//得到查询值
|
//得到查询值
|
||||||
$value = $opertime['value'];
|
$value = $opertime['value'];
|
||||||
list($start_time,$end_time) = explode(" - ",$value);
|
list($start_time,$end_time) = explode(" - ",$value);
|
||||||
|
|
||||||
}
|
}
|
||||||
$list = $this->model
|
// var_dump($sort);
|
||||||
|
// 判断是否按 score_count 排序,该字段为PHP计算值无法直接数据库排序
|
||||||
|
$sortByScoreCount = ($sort === 'employee.score_count');
|
||||||
|
// var_dump($sortByScoreCount);
|
||||||
|
if ($sortByScoreCount) {
|
||||||
|
|
||||||
|
// 按积分统计排序:需取全量数据后在PHP层排序再手动分页
|
||||||
|
$list = $this->model
|
||||||
|
->with(['user','team'])
|
||||||
|
->where($where)
|
||||||
|
->select();
|
||||||
|
|
||||||
|
foreach ($list as $row) {
|
||||||
|
$row->getRelation('user')->visible(['nickname','mobile','avatar']);
|
||||||
|
$row->getRelation('team')->visible(['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = collection($list)->toArray();
|
||||||
|
|
||||||
|
// 为每条记录计算 score_count
|
||||||
|
foreach ($list as &$row) {
|
||||||
|
$row['score_count'] = \app\common\model\score\Employee::getPriceByCoachAndTime($row['id'], $start_time, $end_time);
|
||||||
|
$row['opertime'] = $start_time ? $start_time.'至'.$end_time : '';
|
||||||
|
}
|
||||||
|
unset($row);
|
||||||
|
|
||||||
|
// PHP层按 score_count 排序
|
||||||
|
usort($list, function($a, $b) use ($order) {
|
||||||
|
if (strtolower($order) === 'desc') {
|
||||||
|
return $b['score_count'] <=> $a['score_count'];
|
||||||
|
}
|
||||||
|
return $a['score_count'] <=> $b['score_count'];
|
||||||
|
});
|
||||||
|
|
||||||
|
$total = count($list);
|
||||||
|
// 手动分页
|
||||||
|
$list = array_slice($list, $offset, $limit);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// 常规排序:直接数据库分页
|
||||||
|
$list = $this->model
|
||||||
->with(['user','team'])
|
->with(['user','team'])
|
||||||
->where($where)
|
->where($where)
|
||||||
->order($sort, $order)
|
->order($sort, $order)
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
|
|
||||||
foreach ($list as $row) {
|
foreach ($list as $row) {
|
||||||
|
$row->getRelation('user')->visible(['nickname','mobile','avatar']);
|
||||||
$row->getRelation('user')->visible(['nickname','mobile','avatar']);
|
$row->getRelation('team')->visible(['name']);
|
||||||
$row->getRelation('team')->visible(['name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$total = $list->total();
|
|
||||||
$list = $list->items();
|
|
||||||
|
|
||||||
foreach ($list as &$row) {
|
|
||||||
$row['score_count'] = 0;
|
|
||||||
$row['opertime'] = '';
|
|
||||||
if($start_time){
|
|
||||||
$row['opertime'] = $start_time.'至'.$end_time;
|
|
||||||
}
|
}
|
||||||
$row['score_count'] = \app\common\model\score\Employee::getPriceByCoachAndTime($row['id'],$start_time,$end_time);
|
|
||||||
|
|
||||||
|
$total = $list->total();
|
||||||
|
$list = $list->items();
|
||||||
|
|
||||||
|
foreach ($list as &$row) {
|
||||||
|
$row['score_count'] = \app\common\model\score\Employee::getPriceByCoachAndTime($row['id'], $start_time, $end_time);
|
||||||
|
$row['opertime'] = $start_time ? $start_time.'至'.$end_time : '';
|
||||||
|
}
|
||||||
|
unset($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array("total" => $total, "rows" => $list);
|
$result = array("total" => $total, "rows" => $list);
|
||||||
|
|||||||
@ -22,6 +22,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
|||||||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||||||
pk: 'id',
|
pk: 'id',
|
||||||
sortName: 'id',
|
sortName: 'id',
|
||||||
|
pageSize: 30,
|
||||||
fixedColumns: true,
|
fixedColumns: true,
|
||||||
fixedRightNumber: 1,
|
fixedRightNumber: 1,
|
||||||
columns: [
|
columns: [
|
||||||
@ -36,7 +37,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
|||||||
{field: 'opertime', title: __('统计时间查询'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter:function (value, row, index) {
|
{field: 'opertime', title: __('统计时间查询'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter:function (value, row, index) {
|
||||||
return row.opertime ? row.opertime : '未查询';
|
return row.opertime ? row.opertime : '未查询';
|
||||||
}},
|
}},
|
||||||
{field: 'score_count', title: __('积分统计(根据具体统计时间筛选)'),formatter:function (value, row, index) {
|
{field: 'score_count', title: __('积分统计(根据具体统计时间筛选)'), sortable: true, formatter:function (value, row, index) {
|
||||||
// if( !row.opertime){
|
// if( !row.opertime){
|
||||||
// return "<span style='color: #0d6aad'>#请在点开【搜索栏】后选择【统计时间查询】提交查询#</span>";
|
// return "<span style='color: #0d6aad'>#请在点开【搜索栏】后选择【统计时间查询】提交查询#</span>";
|
||||||
// }
|
// }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user