master #2

Merged
15515342911 merged 2 commits from master into main 2025-04-03 15:55:09 +08:00
26 changed files with 556 additions and 15 deletions

View File

@ -25,7 +25,7 @@ class AdditionAndSubtractionRecords extends Api
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在');
return $this->error('用户不存在','',99998);
}
$this->user_id = $user['id'];
$this->auth_group = $user['auth_group_id'];
@ -278,6 +278,7 @@ class AdditionAndSubtractionRecords extends Api
public function examine(){
$id = $this->request->post('id');
$status = $this->request->post('status');
$content = $this->request->post('content');
//获取该用户是否有审核权限
$level = Db::name('auth_group')
->where('id', $this->auth_group)
@ -293,6 +294,7 @@ class AdditionAndSubtractionRecords extends Api
];
$update = [
'status' => $status,
'content' => $content
];
$res = Db::name('addition_and_subtraction_records')->where($where)->update($update);
if($res){

View File

@ -13,6 +13,18 @@ class AuthGroup extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页

View File

@ -13,7 +13,19 @@ class AuthRule extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页
*

View File

@ -0,0 +1,214 @@
<?php
namespace app\api\controller\backend;
use app\common\controller\Api;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\Db;
/**
* 评价
*/
class AutomaticPublicity extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public function index (){
$lr_evaluation_schedule = Db::name('evaluation_schedule')
->field('id,title,start_time')
->where('evaluation_type', 1)
->order('id', 'desc')
->select();
foreach ($lr_evaluation_schedule as $key => $val) {
// 使用 DISTINCT 去重 user_id 后计算数量
$lr_evaluation_schedule[$key]['yikaopingrenshu'] = Db::name('scoringrecord')
->where('evaluation_schedule_id', $val['id'])
->distinct(true) // 添加 distinct(true) 去重
->column('user_id'); // 获取去重后的 user_id 列
$lr_evaluation_schedule[$key]['yikaopingrenshu'] = count($lr_evaluation_schedule[$key]['yikaopingrenshu']); // 计算数量
$lr_evaluation_schedule[$key]['kaopingrenshu'] = Db::name('user')
->distinct(true) // 添加 distinct(true) 去重
->column('id'); // 获取去重后的 user_id 列
$lr_evaluation_schedule[$key]['kaopingrenshu'] = count($lr_evaluation_schedule[$key]['kaopingrenshu']); // 计算数量
// $lr_evaluation_schedule[$key]['niandu'] = Db::name('scoringrecord')
// ->where('evaluation_schedule_id', $val['id'])
// ->value('term');
$lr_evaluation_schedule[$key]['niandu'] = date('Y', strtotime($val['start_time']));
}
return $this->success('添加成功', $lr_evaluation_schedule);
}
public function dailyexport()
{
$id = $this->request->get('id');
if(empty($id)) {
return $this->error('缺少用户ID参数');
}
// 获取用户数据
$users = Db::name('user')->select();
// 获取评价计划
$lr_evaluation_schedule = Db::name('evaluation_schedule')
->field('id, title, start_time')
->where('id', $id)
->order('id', 'desc')
->select();
// 提前加载用户组名称
$groupIds = array_column($users, 'group_id');
$groups = Db::name('user_group')
->whereIn('id', $groupIds)
->column('name', 'id');
// 遍历评价计划,减少重复查询
foreach ($lr_evaluation_schedule as $k => $v) {
$year = date('Y', strtotime($v['start_time']));
// 批量查询用户的评分记录和加减分记录
$scoringRecords = Db::name('scoringrecord')
->whereIn('user_id', array_column($users, 'id'))
->where('term', $year)
->where('evaluation_schedule_id', $v['id'])
->select();
$additionRecords = Db::name('addition_and_subtraction_records')
->whereIn('user_id', array_column($users, 'id'))
->where('YEAR(createtime)', $year)
->where('status', 2)
->select();
// 构建以用户ID为键的快捷查询数组
$userScoring = [];
$userAdditionSubtraction = [];
foreach ($scoringRecords as $record) {
$userId = $record['user_id'];
if (!isset($userScoring[$userId])) {
$userScoring[$userId] = [
'user_scoringrecord' => 0,
'department_score_scoringrecord' => 0,
'hospital_score_scoringrecord' => 0,
'party_score_scoringrecord' => 0,
'overall_score_scoringrecord' => 0,
];
}
$userScoring[$userId]['user_scoringrecord'] += $record['self_score'];
$userScoring[$userId]['department_score_scoringrecord'] += $record['department_score'];
$userScoring[$userId]['hospital_score_scoringrecord'] += $record['hospital_score'];
$userScoring[$userId]['party_score_scoringrecord'] += $record['party_branch_score'];
$userScoring[$userId]['overall_score_scoringrecord'] += $record['overall_party_score'];
}
foreach ($additionRecords as $record) {
$userId = $record['user_id'];
if (!isset($userAdditionSubtraction[$userId])) {
$userAdditionSubtraction[$userId] = [
'zongjiafenfenzhi' => 0,
'zongjianfenfenzhi' => 0,
];
}
if ($record['assessment_type'] == 1) {
$userAdditionSubtraction[$userId]['zongjiafenfenzhi'] += $record['score_value'];
} elseif ($record['assessment_type'] == 2) {
$userAdditionSubtraction[$userId]['zongjianfenfenzhi'] += $record['score_value'];
}
}
// 处理用户数据
foreach ($users as $key => $value) {
$groupId = $value['group_id'];
$userId = $value['id'];
// 设置组名称
$users[$key]['group_name'] = $groups[$groupId] ?? '';
// 设置评分和加减分值
$users[$key]['user_scoringrecord'] = $userScoring[$userId]['user_scoringrecord'] ?? 0;
$users[$key]['department_score_scoringrecord'] = $userScoring[$userId]['department_score_scoringrecord'] ?? 0;
$users[$key]['hospital_score_scoringrecord'] = $userScoring[$userId]['hospital_score_scoringrecord'] ?? 0;
$users[$key]['party_score_scoringrecord'] = $userScoring[$userId]['party_score_scoringrecord'] ?? 0;
$users[$key]['overall_score_scoringrecord'] = $userScoring[$userId]['overall_score_scoringrecord'] ?? 0;
$users[$key]['zongjiafenfenzhi'] = $userAdditionSubtraction[$userId]['zongjiafenfenzhi'] ?? 0;
$users[$key]['zongjianfenfenzhi'] = $userAdditionSubtraction[$userId]['zongjianfenfenzhi'] ?? 0;
// 设置年份
$users[$key]['time'] = $year;
// 计算总分
$users[$key]['zongjiafen'] = 0; // 如果需要计算其他值,可以在这里添加逻辑
$users[$key]['total_score'] =
$users[$key]['user_scoringrecord'] * 0.2 +
$users[$key]['department_score_scoringrecord'] * 0.4 +
$users[$key]['party_score_scoringrecord'] * 0.4 +
$users[$key]['zongjiafenfenzhi'] -
$users[$key]['zongjianfenfenzhi'];
}
}
// return $this->success('查询成功', $users);
// $this->success('返回成功', $date);
// 创建一个新的 Excel 文件
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 设置表头
$headers = ['年度', '考评对象', '工号', '所属科室', '自评总分', '科室评分', '党支部评分', '总党支评分', '医院评分', '总加分', '总减分', '总得分']; // 根据你的 member 表字段进行调整
$columnIndex = 1; // A = 1, B = 2, ...
foreach ($headers as $header) {
$sheet->setCellValueByColumnAndRow($columnIndex, 1, $header);
$columnIndex++;
}
// 填充数据
$rowNumber = 2; // 从第二行开始填充数据
foreach ($users as $member) {
$columnIndex = 1;
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['time']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['nickname']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['code']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['group_name']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['user_scoringrecord']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['department_score_scoringrecord']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['party_score_scoringrecord']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['overall_score_scoringrecord']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['hospital_score_scoringrecord']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['zongjiafenfenzhi']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['zongjianfenfenzhi']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['zongjiafen']);
$rowNumber++;
}
// 保存到 PHP 输出流
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . '加减分数据' . date('YmdHis') . '.xlsx"');
// header('Content-Disposition: attachment;filename="活动报名列表' . date('YmdHis') . '.xlsx"');
header('Cache-Control: max-age=0');
// 输出到浏览器供用户下载
$writer->save('php://output');
// 清理并退出
exit;
}
}

View File

@ -13,6 +13,18 @@ class BasicRating extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页

View File

@ -12,30 +12,51 @@ class Evaluate extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public function index (){
$token = $this->request->header('Token');
$type = $this->request->request('type',1);
$term = $this->request->request('time',date('Y'));
if(!$token){
return $this->error('缺少参数');
}
if(!$type){
return $this->error('缺少参数');
}
if(!$term){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $token)->find();
if(!$user){
return $this->error('该用户不存在');
}
$date = Db::name('evaluate')
->field('a.*,u.nickname,g.name as group_name')
->alias('a')
->join('user u','a.user_id = u.id','LEFT')
->join('user_group g','a.group_id = g.id','LEFT')
->where('a.user_id', $user['id'])->where('a.type',$type)->order('a.id', 'desc')->select();
->where('a.user_id', $user['id'])
->where('a.type',$type)
->where('a.term','like',"%$term%")
->order('a.id', 'desc')
->select();
if($date){
return $this->success('查询成功',$date);
}
return $this->error('未查询到相关信息');
return $this->error('未查询到相关信息', []);
}
/**

View File

@ -13,7 +13,18 @@ class EvaluationSchedule extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页
*

View File

@ -17,6 +17,18 @@ class Evaluationlevel extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 列表

View File

@ -10,6 +10,18 @@ use think\Db;
class ExcelController extends Api
{
protected $noNeedLogin = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public function dailyexport()
@ -152,12 +164,8 @@ class ExcelController extends Api
'total_subtraction' => floatval($total_subtraction)
];
}
// return $this->success('评价成功', $returnData);
// $this->success('返回成功', $date);
// 创建一个新的 Excel 文件
// 创建一个新的 Excel 文件
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
@ -172,6 +180,7 @@ class ExcelController extends Api
// 填充数据
$rowNumber = 2; // 从第二行开始填充数据
foreach ($returnData as $member) {
$columnIndex = 1;
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['username']);
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['group_name']);

View File

@ -62,7 +62,7 @@ class Login extends Api
}
$user = Db::name('user')->field('auth_group_id')->where('token',$token)->find();
if (!$user) {
$this->success('请求失败');
$this->error('请求失败');
}
$auth = Db::name('auth_group')->field('id,name,rules')->where('id',$user['auth_group_id'])->find();
if(!$auth){

View File

@ -17,6 +17,18 @@ class Logrecording extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public static function addLogrecordingData($user_id = 0, $content = null)
{

View File

@ -12,7 +12,18 @@ class Mail extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页
*

View File

@ -14,6 +14,18 @@ class Monthly extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public function getEvaluation()
{

View File

@ -13,6 +13,18 @@ class PartyGroup extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页

View File

@ -13,6 +13,18 @@ class PartyStyle extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页

View File

@ -15,6 +15,18 @@ class Pdf extends Api
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public function exportPdf()
{

View File

@ -13,6 +13,18 @@ class PlusMinusScoring extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页

View File

@ -13,6 +13,18 @@ class Politics extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页

View File

@ -17,6 +17,18 @@ class PublicAnnouncement extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 用户列表

View File

@ -13,7 +13,18 @@ class Quarter extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public function getEvaluation()
{
$id = $this->request->header('Token');

View File

@ -26,6 +26,18 @@ class Questionnaire extends Api
protected $noNeedRight = ['test2'];
protected $dataLimit = 'personal';
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
*

View File

@ -13,6 +13,18 @@ class ScoringrecordDate extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* Undocumented function

View File

@ -13,7 +13,18 @@ class Solicitopinions extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页
*

View File

@ -18,6 +18,19 @@ class User extends Api
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public function getEvaluation()
{
$id = $this->request->header('Token');
@ -160,7 +173,7 @@ class User extends Api
public function getDoctorName()
{
$data = Db::name('user')
->field('id,nickname')
->field('id,nickname,code')
->where('id', '<>', 1) // 添加条件 id 不等于 1
->select();
if ($data) {
@ -233,4 +246,48 @@ class User extends Api
$this->error($this->auth->getError());
}
}
//修改密码
public function updatePassword()
{
$id = $this->request->post('id');
$old_password = $this->request->post('old_password');
$new_password = $this->request->post('new_password');
$confirm_password = $this->request->post('confirm_password');
if (!$id) {
$this->error(__('Invalid parameters'));
}
if (!$old_password) {
$this->error(__('Invalid parameters'));
}
if (!$new_password) {
$this->error(__('Invalid parameters'));
}
if (!$confirm_password) {
$this->error(__('Invalid parameters'));
}
if($new_password != $confirm_password){
$this->error(__('两次输入密码不一致'));
}
$ret = Db::name('user')
->where('id',$id)
->where('password', md5($old_password))
->find();
if(!$ret){
$this->error(__('该用户不存在'));
}
if($ret['password'] == md5($new_password)){
$this->error(__('新旧密码不能一致'));
}
$data = [
'password' => md5($new_password),
];
$update = $result = Db::name('user')->where('id', $id)->strict(false)->update($data);
if ($update) {
$this->success(__('修改成功'), $update);
} else {
$this->error($this->auth->getError());
}
}
}

View File

@ -13,6 +13,19 @@ class UserGroup extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
/**
* 首页

View File

@ -13,6 +13,19 @@ class Year extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
$id = $this->request->header('Token');
if(!$id){
return $this->error('缺少参数');
}
$user = Db::name('user')->where('token', $id)->find();
if(!$user){
return $this->error('用户不存在','',99998);
}
}
public function getEvaluation()
{