Compare commits

..

2 Commits

Author SHA1 Message Date
qinzexin
9b599993af Initial commit 2025-04-01 18:11:54 +08:00
qinzexin
418bf4c1e6 feat(backend): 新增多个后台功能接口
- 新增考评级别相关接口
- 新增站内信相关接口
- 新增党风教育相关接口
- 新增加减分记录导出功能
- 新增月度自评审核通知功能
- 优化月度自评数据插入逻辑
2025-04-01 18:09:26 +08:00
2 changed files with 115 additions and 27 deletions

View File

@ -301,4 +301,58 @@ class AdditionAndSubtractionRecords extends Api
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('审核操作失败');
}
}

View File

@ -174,47 +174,81 @@ class Evaluate extends Api
$group_id = $this->request->param('group_id', 0, 'intval');
$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)) {
$this->error('月份参数格式错误');
}
if ($page < 1 || $limit < 1) {
$this->error('分页参数错误');
}
// 计算月末日期
$firstDay = $searchMonth . '-01';
$lastDay = date('Y-m-d', strtotime("last day of $searchMonth"));
// 计算时间范围
$firstDay = $searchMonth . '-01 00:00:00';
$lastDay = date('Y-m-d 23:59:59', strtotime("last day of $searchMonth"));
$result = Db::name('user')
// 获取用户总数(用于分页)
$totalUsers = Db::name('user')
->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')
->where('u.group_id', $group_id)
->whereTime('r.fsdate', 'between', [$firstDay, $lastDay]) // 修正后的时间查询
->group('u.id')
->count();
// 分页查询用户
$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();
// 构建返回数据
$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[] = [
'username' => $item['username'],
'group_name' => $item['group_name'], // 需要根据实际科室表字段替换
'month' => date('Y-m'),
'total_addition' => $item['total_addition'],
'total_subtraction' => $item['total_subtraction'],
'user_id' => $user['id'],
'username' => $user['username'],
'group_name' => $user['group_name'],
'month' => $searchMonth,
'total_addition' => floatval($total_addition),
'total_subtraction' => floatval($total_subtraction)
];
}
// 分页信息
$totalPages = ceil($totalUsers / $limit);
$returnData = [
'data' => $returnData,
'count' => $totalUsers,
];
return $this->success('评价成功', $returnData);
}
public function groupIndexrecordsList(){
// 接收参数
$userId = $this->request->param('user_id', 0, 'intval');