master #2
@ -278,6 +278,7 @@ class AdditionAndSubtractionRecords extends Api
|
|||||||
public function examine(){
|
public function examine(){
|
||||||
$id = $this->request->post('id');
|
$id = $this->request->post('id');
|
||||||
$status = $this->request->post('status');
|
$status = $this->request->post('status');
|
||||||
|
$content = $this->request->post('content');
|
||||||
//获取该用户是否有审核权限
|
//获取该用户是否有审核权限
|
||||||
$level = Db::name('auth_group')
|
$level = Db::name('auth_group')
|
||||||
->where('id', $this->auth_group)
|
->where('id', $this->auth_group)
|
||||||
@ -293,6 +294,7 @@ class AdditionAndSubtractionRecords extends Api
|
|||||||
];
|
];
|
||||||
$update = [
|
$update = [
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
|
'content' => $content
|
||||||
];
|
];
|
||||||
$res = Db::name('addition_and_subtraction_records')->where($where)->update($update);
|
$res = Db::name('addition_and_subtraction_records')->where($where)->update($update);
|
||||||
if($res){
|
if($res){
|
||||||
|
200
application/api/controller/backend/AutomaticPublicity.php
Normal file
200
application/api/controller/backend/AutomaticPublicity.php
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
<?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 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;
|
||||||
|
}
|
||||||
|
}
|
@ -16,26 +16,35 @@ class Evaluate extends Api
|
|||||||
public function index (){
|
public function index (){
|
||||||
$token = $this->request->header('Token');
|
$token = $this->request->header('Token');
|
||||||
$type = $this->request->request('type',1);
|
$type = $this->request->request('type',1);
|
||||||
|
$term = $this->request->request('time',date('Y'));
|
||||||
if(!$token){
|
if(!$token){
|
||||||
return $this->error('缺少参数');
|
return $this->error('缺少参数');
|
||||||
}
|
}
|
||||||
if(!$type){
|
if(!$type){
|
||||||
return $this->error('缺少参数');
|
return $this->error('缺少参数');
|
||||||
|
}
|
||||||
|
if(!$term){
|
||||||
|
return $this->error('缺少参数');
|
||||||
}
|
}
|
||||||
$user = Db::name('user')->where('token', $token)->find();
|
$user = Db::name('user')->where('token', $token)->find();
|
||||||
if(!$user){
|
if(!$user){
|
||||||
return $this->error('该用户不存在');
|
return $this->error('该用户不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
$date = Db::name('evaluate')
|
$date = Db::name('evaluate')
|
||||||
->field('a.*,u.nickname,g.name as group_name')
|
->field('a.*,u.nickname,g.name as group_name')
|
||||||
->alias('a')
|
->alias('a')
|
||||||
->join('user u','a.user_id = u.id','LEFT')
|
->join('user u','a.user_id = u.id','LEFT')
|
||||||
->join('user_group g','a.group_id = g.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){
|
if($date){
|
||||||
return $this->success('查询成功',$date);
|
return $this->success('查询成功',$date);
|
||||||
}
|
}
|
||||||
return $this->error('未查询到相关信息');
|
return $this->error('未查询到相关信息', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,12 +152,8 @@ class ExcelController extends Api
|
|||||||
'total_subtraction' => floatval($total_subtraction)
|
'total_subtraction' => floatval($total_subtraction)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// return $this->success('评价成功', $returnData);
|
|
||||||
// $this->success('返回成功', $date);
|
|
||||||
// 创建一个新的 Excel 文件
|
|
||||||
|
|
||||||
|
// 创建一个新的 Excel 文件
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
@ -172,6 +168,7 @@ class ExcelController extends Api
|
|||||||
// 填充数据
|
// 填充数据
|
||||||
$rowNumber = 2; // 从第二行开始填充数据
|
$rowNumber = 2; // 从第二行开始填充数据
|
||||||
foreach ($returnData as $member) {
|
foreach ($returnData as $member) {
|
||||||
|
|
||||||
$columnIndex = 1;
|
$columnIndex = 1;
|
||||||
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['username']);
|
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['username']);
|
||||||
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['group_name']);
|
$sheet->setCellValueByColumnAndRow($columnIndex++, $rowNumber, $member['group_name']);
|
||||||
|
@ -62,7 +62,7 @@ class Login extends Api
|
|||||||
}
|
}
|
||||||
$user = Db::name('user')->field('auth_group_id')->where('token',$token)->find();
|
$user = Db::name('user')->field('auth_group_id')->where('token',$token)->find();
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
$this->success('请求失败');
|
$this->error('请求失败');
|
||||||
}
|
}
|
||||||
$auth = Db::name('auth_group')->field('id,name,rules')->where('id',$user['auth_group_id'])->find();
|
$auth = Db::name('auth_group')->field('id,name,rules')->where('id',$user['auth_group_id'])->find();
|
||||||
if(!$auth){
|
if(!$auth){
|
||||||
|
@ -160,7 +160,7 @@ class User extends Api
|
|||||||
public function getDoctorName()
|
public function getDoctorName()
|
||||||
{
|
{
|
||||||
$data = Db::name('user')
|
$data = Db::name('user')
|
||||||
->field('id,nickname')
|
->field('id,nickname,code')
|
||||||
->where('id', '<>', 1) // 添加条件 id 不等于 1
|
->where('id', '<>', 1) // 添加条件 id 不等于 1
|
||||||
->select();
|
->select();
|
||||||
if ($data) {
|
if ($data) {
|
||||||
@ -233,4 +233,48 @@ class User extends Api
|
|||||||
$this->error($this->auth->getError());
|
$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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user