Compare commits
2 Commits
e396a59403
...
9b599993af
Author | SHA1 | Date | |
---|---|---|---|
|
9b599993af | ||
|
418bf4c1e6 |
@ -301,4 +301,58 @@ class AdditionAndSubtractionRecords extends Api
|
|||||||
return $this->error('审核失败');
|
return $this->error('审核失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function plexamine()
|
||||||
|
{
|
||||||
|
// 接收原始参数
|
||||||
|
$idsParam = $this->request->post('ids');
|
||||||
|
$status = $this->request->post('status');
|
||||||
|
|
||||||
|
// 权限验证
|
||||||
|
$level = Db::name('auth_group')
|
||||||
|
->where('id', $this->auth_group)
|
||||||
|
->value('level');
|
||||||
|
if ($level == 2) {
|
||||||
|
return $this->error('您没有审核权限');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数预处理
|
||||||
|
$ids = [];
|
||||||
|
if (!empty($idsParam)) {
|
||||||
|
// 将字符串转换为数组并过滤无效ID
|
||||||
|
$ids = array_filter(explode(',', $idsParam), function($id) {
|
||||||
|
return is_numeric($id) && $id > 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 参数校验
|
||||||
|
if (empty($ids) || !$status) {
|
||||||
|
return $this->error('缺少必要参数或包含无效ID');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造批量更新条件
|
||||||
|
$where = [
|
||||||
|
'id' => ['in', $ids]
|
||||||
|
];
|
||||||
|
|
||||||
|
$update = [
|
||||||
|
'status' => $status,
|
||||||
|
// 'updatetime' => time()
|
||||||
|
];
|
||||||
|
|
||||||
|
// 执行批量更新
|
||||||
|
$affectedRows = Db::name('addition_and_subtraction_records')
|
||||||
|
->where($where)
|
||||||
|
->update($update);
|
||||||
|
|
||||||
|
// 结果处理
|
||||||
|
if ($affectedRows !== false) {
|
||||||
|
if ($affectedRows > 0) {
|
||||||
|
return $this->success("成功更新{$affectedRows}条记录");
|
||||||
|
}
|
||||||
|
return $this->error('未找到可更新的记录');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->error('审核操作失败');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -174,47 +174,81 @@ class Evaluate extends Api
|
|||||||
$group_id = $this->request->param('group_id', 0, 'intval');
|
$group_id = $this->request->param('group_id', 0, 'intval');
|
||||||
$searchMonth = $this->request->param('month', date('Y-m'));
|
$searchMonth = $this->request->param('month', date('Y-m'));
|
||||||
|
|
||||||
// 验证月份格式
|
// 新增分页参数
|
||||||
|
$page = $this->request->param('page', 1, 'intval');
|
||||||
|
$limit = $this->request->param('limit', 10, 'intval');
|
||||||
|
$offset = ($page - 1) * $limit;
|
||||||
|
|
||||||
|
// 参数验证
|
||||||
|
if ($group_id <= 0) {
|
||||||
|
$this->error('无效的group_id');
|
||||||
|
}
|
||||||
if (!preg_match('/^\d{4}-\d{2}$/', $searchMonth)) {
|
if (!preg_match('/^\d{4}-\d{2}$/', $searchMonth)) {
|
||||||
$this->error('月份参数格式错误');
|
$this->error('月份参数格式错误');
|
||||||
}
|
}
|
||||||
|
if ($page < 1 || $limit < 1) {
|
||||||
|
$this->error('分页参数错误');
|
||||||
|
}
|
||||||
|
|
||||||
// 计算月末日期
|
// 计算时间范围
|
||||||
$firstDay = $searchMonth . '-01';
|
$firstDay = $searchMonth . '-01 00:00:00';
|
||||||
$lastDay = date('Y-m-d', strtotime("last day of $searchMonth"));
|
$lastDay = date('Y-m-d 23:59:59', strtotime("last day of $searchMonth"));
|
||||||
|
|
||||||
$result = Db::name('user')
|
// 获取用户总数(用于分页)
|
||||||
|
$totalUsers = Db::name('user')
|
||||||
->alias('u')
|
->alias('u')
|
||||||
->field([
|
|
||||||
'u.id',
|
|
||||||
'u.nickname AS username',
|
|
||||||
'u.group_id',
|
|
||||||
'g.name AS group_name',
|
|
||||||
'SUM(CASE WHEN r.assessment_type = 1 THEN r.score_value ELSE 0 END) AS total_addition',
|
|
||||||
'SUM(CASE WHEN r.assessment_type = 2 THEN r.score_value ELSE 0 END) AS total_subtraction'
|
|
||||||
])
|
|
||||||
->join('addition_and_subtraction_records r', 'u.id = r.user_id')
|
|
||||||
->join('user_group g', 'u.group_id = g.id')
|
->join('user_group g', 'u.group_id = g.id')
|
||||||
->where('u.group_id', $group_id)
|
->where('u.group_id', $group_id)
|
||||||
->whereTime('r.fsdate', 'between', [$firstDay, $lastDay]) // 修正后的时间查询
|
->count();
|
||||||
->group('u.id')
|
|
||||||
|
// 分页查询用户
|
||||||
|
$users = Db::name('user')
|
||||||
|
->alias('u')
|
||||||
|
->field(['u.id', 'u.nickname AS username', 'g.name AS group_name'])
|
||||||
|
->join('user_group g', 'u.group_id = g.id')
|
||||||
|
->where('u.group_id', $group_id)
|
||||||
|
->limit($offset, $limit)
|
||||||
|
->select();
|
||||||
|
|
||||||
|
// 统计分数(使用子查询优化)
|
||||||
|
$scores = Db::name('addition_and_subtraction_records')
|
||||||
|
->field([
|
||||||
|
'user_id',
|
||||||
|
'SUM(CASE WHEN assessment_type = 1 THEN score_value ELSE 0 END) AS total_addition',
|
||||||
|
'SUM(CASE WHEN assessment_type = 2 THEN score_value ELSE 0 END) AS total_subtraction'
|
||||||
|
])
|
||||||
|
->whereTime('fsdate', 'between', [$firstDay, $lastDay])
|
||||||
|
->group('user_id')
|
||||||
->select();
|
->select();
|
||||||
|
|
||||||
// 构建返回数据
|
// 构建返回数据
|
||||||
$returnData = [];
|
$returnData = [];
|
||||||
foreach ($result as $item) {
|
foreach ($users as $user) {
|
||||||
|
$scoreArray = array_column($scores, null, 'user_id');
|
||||||
|
$total_addition = $scoreArray[$user['id']]['total_addition'] ?? 0;
|
||||||
|
$total_subtraction = $scoreArray[$user['id']]['total_subtraction'] ?? 0;
|
||||||
|
|
||||||
$returnData[] = [
|
$returnData[] = [
|
||||||
'username' => $item['username'],
|
'user_id' => $user['id'],
|
||||||
'group_name' => $item['group_name'], // 需要根据实际科室表字段替换
|
'username' => $user['username'],
|
||||||
'month' => date('Y-m'),
|
'group_name' => $user['group_name'],
|
||||||
'total_addition' => $item['total_addition'],
|
'month' => $searchMonth,
|
||||||
'total_subtraction' => $item['total_subtraction'],
|
'total_addition' => floatval($total_addition),
|
||||||
|
'total_subtraction' => floatval($total_subtraction)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分页信息
|
||||||
|
$totalPages = ceil($totalUsers / $limit);
|
||||||
|
$returnData = [
|
||||||
|
'data' => $returnData,
|
||||||
|
'count' => $totalUsers,
|
||||||
|
];
|
||||||
|
|
||||||
return $this->success('评价成功', $returnData);
|
return $this->success('评价成功', $returnData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function groupIndexrecordsList(){
|
public function groupIndexrecordsList(){
|
||||||
// 接收参数
|
// 接收参数
|
||||||
$userId = $this->request->param('user_id', 0, 'intval');
|
$userId = $this->request->param('user_id', 0, 'intval');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user