diff --git a/application/api/controller/backend/AdditionAndSubtractionRecords.php b/application/api/controller/backend/AdditionAndSubtractionRecords.php index ef2d781..a7ad69c 100644 --- a/application/api/controller/backend/AdditionAndSubtractionRecords.php +++ b/application/api/controller/backend/AdditionAndSubtractionRecords.php @@ -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){ diff --git a/application/api/controller/backend/AuthGroup.php b/application/api/controller/backend/AuthGroup.php index c66f857..3b9a413 100644 --- a/application/api/controller/backend/AuthGroup.php +++ b/application/api/controller/backend/AuthGroup.php @@ -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); + } + } /** * 首页 diff --git a/application/api/controller/backend/AuthRule.php b/application/api/controller/backend/AuthRule.php index 4857dac..f9e7201 100644 --- a/application/api/controller/backend/AuthRule.php +++ b/application/api/controller/backend/AuthRule.php @@ -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); + } + } /** * 首页 * diff --git a/application/api/controller/backend/AutomaticPublicity.php b/application/api/controller/backend/AutomaticPublicity.php new file mode 100644 index 0000000..e37f4ae --- /dev/null +++ b/application/api/controller/backend/AutomaticPublicity.php @@ -0,0 +1,214 @@ +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; + } +} diff --git a/application/api/controller/backend/BasicRating.php b/application/api/controller/backend/BasicRating.php index e45dac3..5a984e4 100644 --- a/application/api/controller/backend/BasicRating.php +++ b/application/api/controller/backend/BasicRating.php @@ -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); + } + } /** * 首页 diff --git a/application/api/controller/backend/Evaluate.php b/application/api/controller/backend/Evaluate.php index 79af116..07e10ce 100644 --- a/application/api/controller/backend/Evaluate.php +++ b/application/api/controller/backend/Evaluate.php @@ -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('未查询到相关信息', []); } /** diff --git a/application/api/controller/backend/EvaluationSchedule.php b/application/api/controller/backend/EvaluationSchedule.php index 65efc8f..6e47b11 100644 --- a/application/api/controller/backend/EvaluationSchedule.php +++ b/application/api/controller/backend/EvaluationSchedule.php @@ -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); + } + } /** * 首页 * diff --git a/application/api/controller/backend/Evaluationlevel.php b/application/api/controller/backend/Evaluationlevel.php index 312d723..6ecdc5c 100644 --- a/application/api/controller/backend/Evaluationlevel.php +++ b/application/api/controller/backend/Evaluationlevel.php @@ -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); + } + } /** * 列表 diff --git a/application/api/controller/backend/ExcelController.php b/application/api/controller/backend/ExcelController.php index 67a3b75..05c2016 100644 --- a/application/api/controller/backend/ExcelController.php +++ b/application/api/controller/backend/ExcelController.php @@ -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']); diff --git a/application/api/controller/backend/Login.php b/application/api/controller/backend/Login.php index 0428d1e..359b7ef 100644 --- a/application/api/controller/backend/Login.php +++ b/application/api/controller/backend/Login.php @@ -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){ diff --git a/application/api/controller/backend/Logrecording.php b/application/api/controller/backend/Logrecording.php index f746a13..c90ac5c 100644 --- a/application/api/controller/backend/Logrecording.php +++ b/application/api/controller/backend/Logrecording.php @@ -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) { diff --git a/application/api/controller/backend/Mail.php b/application/api/controller/backend/Mail.php index 493fc97..e64b7f0 100644 --- a/application/api/controller/backend/Mail.php +++ b/application/api/controller/backend/Mail.php @@ -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); + } + } /** * 首页 * diff --git a/application/api/controller/backend/Monthly.php b/application/api/controller/backend/Monthly.php index f71dcde..fab783e 100644 --- a/application/api/controller/backend/Monthly.php +++ b/application/api/controller/backend/Monthly.php @@ -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() { diff --git a/application/api/controller/backend/PartyGroup.php b/application/api/controller/backend/PartyGroup.php index e06bdaf..f9b9689 100644 --- a/application/api/controller/backend/PartyGroup.php +++ b/application/api/controller/backend/PartyGroup.php @@ -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); + } + } /** * 首页 diff --git a/application/api/controller/backend/PartyStyle.php b/application/api/controller/backend/PartyStyle.php index 3d7e807..c15a72f 100644 --- a/application/api/controller/backend/PartyStyle.php +++ b/application/api/controller/backend/PartyStyle.php @@ -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); + } + } /** * 首页 diff --git a/application/api/controller/backend/Pdf.php b/application/api/controller/backend/Pdf.php index 197b5bf..f6f22fe 100644 --- a/application/api/controller/backend/Pdf.php +++ b/application/api/controller/backend/Pdf.php @@ -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() { diff --git a/application/api/controller/backend/PlusMinusScoring.php b/application/api/controller/backend/PlusMinusScoring.php index 388ff4c..48c9d79 100644 --- a/application/api/controller/backend/PlusMinusScoring.php +++ b/application/api/controller/backend/PlusMinusScoring.php @@ -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); + } + } /** * 首页 diff --git a/application/api/controller/backend/Politics.php b/application/api/controller/backend/Politics.php index 450130a..96797a0 100644 --- a/application/api/controller/backend/Politics.php +++ b/application/api/controller/backend/Politics.php @@ -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); + } + } /** * 首页 diff --git a/application/api/controller/backend/PublicAnnouncement.php b/application/api/controller/backend/PublicAnnouncement.php index 31cd49b..b94011d 100644 --- a/application/api/controller/backend/PublicAnnouncement.php +++ b/application/api/controller/backend/PublicAnnouncement.php @@ -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); + } + } /** * 用户列表 diff --git a/application/api/controller/backend/Quarter.php b/application/api/controller/backend/Quarter.php index 24cda66..e7d99fb 100644 --- a/application/api/controller/backend/Quarter.php +++ b/application/api/controller/backend/Quarter.php @@ -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'); diff --git a/application/api/controller/backend/Questionnaire.php b/application/api/controller/backend/Questionnaire.php index f5c215c..0486cb2 100644 --- a/application/api/controller/backend/Questionnaire.php +++ b/application/api/controller/backend/Questionnaire.php @@ -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); + } + } /** * diff --git a/application/api/controller/backend/ScoringrecordDate.php b/application/api/controller/backend/ScoringrecordDate.php index 90efd86..f8324b2 100644 --- a/application/api/controller/backend/ScoringrecordDate.php +++ b/application/api/controller/backend/ScoringrecordDate.php @@ -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 diff --git a/application/api/controller/backend/Solicitopinions.php b/application/api/controller/backend/Solicitopinions.php index 3e43283..806ab67 100644 --- a/application/api/controller/backend/Solicitopinions.php +++ b/application/api/controller/backend/Solicitopinions.php @@ -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); + } + } /** * 首页 * diff --git a/application/api/controller/backend/User.php b/application/api/controller/backend/User.php index 2c6f527..719b39e 100644 --- a/application/api/controller/backend/User.php +++ b/application/api/controller/backend/User.php @@ -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()); + } + } } diff --git a/application/api/controller/backend/UserGroup.php b/application/api/controller/backend/UserGroup.php index a34d88a..a847a4c 100644 --- a/application/api/controller/backend/UserGroup.php +++ b/application/api/controller/backend/UserGroup.php @@ -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); + } + } /** * 首页 diff --git a/application/api/controller/backend/Year.php b/application/api/controller/backend/Year.php index 62e0c2f..7dc181a 100644 --- a/application/api/controller/backend/Year.php +++ b/application/api/controller/backend/Year.php @@ -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() {