灵睿积分项统计排序优化

This commit is contained in:
jiaoyukun 2026-03-27 09:33:10 +08:00
parent b70b948cdd
commit 850f0e1f98
2 changed files with 54 additions and 18 deletions

View File

@ -63,8 +63,47 @@ class Employee extends Backend
//得到查询值
$value = $opertime['value'];
list($start_time,$end_time) = explode(" - ",$value);
}
// 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'])
->where($where)
@ -72,7 +111,6 @@ class Employee extends Backend
->paginate($limit);
foreach ($list as $row) {
$row->getRelation('user')->visible(['nickname','mobile','avatar']);
$row->getRelation('team')->visible(['name']);
}
@ -81,13 +119,10 @@ class Employee extends Backend
$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);
$row['opertime'] = $start_time ? $start_time.'至'.$end_time : '';
}
unset($row);
}
$result = array("total" => $total, "rows" => $list);

View File

@ -22,6 +22,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
pageSize: 30,
fixedColumns: true,
fixedRightNumber: 1,
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) {
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){
// return "<span style='color: #0d6aad'>#请在点开【搜索栏】后选择【统计时间查询】提交查询#</span>";
// }