request->header('Token'); if(!$id){ return $this->error('缺少参数'); } $user = Db::name('user')->where('token', $id)->find(); if(!$user){ return $this->error('用户不存在'); } $this->user_id = $user['id']; $this->group_id = $user['group_id']; $this->auth_id = $user['auth_group_id']; $this->level = Db::name('auth_group')->where('id', $user['auth_group_id'])->value('level'); } /** * Undocumented function *列表 * @return void */ public function index() { $page = $this->request->post('page', 1); $limit = $this->request->post('size', 10); $group= $this->request->post('group_id'); $status= $this->request->post('status'); $time= $this->request->post('fsdate'); $user_id= $this->request->post('user_id'); // var_dump($group);die(); $where = []; //判断该用户有没有权限审核 if($this->level == 2){ $where['a.user_id'] = $this->user_id; if ($status) { $where['a.status'] = $status; } if ($time) { $where['a.fsdate'] = $time; } // return $this->success('查询成功1',$where); } if($this->level == 1){ $where['a.group_id'] = $this->group_id; if ($status) { $where['a.status'] = $status; } if ($time) { $where['a.fsdate'] = $time; } if ($user_id) { $where['a.user_id'] = $user_id; } // return $this->success('查询成功2',$where); } if($this->auth_id == 1 && $group){ $where['a.group_id'] = $group; if ($status) { $where['a.status'] = $status; } if ($time) { $where['a.fsdate'] = $time; } if ($user_id) { $where['a.user_id'] = $user_id; } // return $this->success('查询成功3',$where); } // 获取指定科室及其子科室的ID $groupIds = $this->getGroupAndSubGroupIds($group); if (!empty($groupIds)) { $where['a.group_id'] = ['in', $groupIds]; } // return $this->success('查询成功',$where); $date = Db::name('reject_red_envelopes') ->field('a.*,u.nickname,g.name as group_name,w.nickname as zm_nickname') ->alias('a') ->join('user u','a.user_id = u.id','LEFT') ->join('user_group g','a.group_id = g.id','LEFT') ->join('user w','a.zm_user_id = w.id','LEFT') ->where($where) ->order('a.id', 'desc') ->page($page, $limit) ->select(); $count = Db::name('reject_red_envelopes') ->field('a.*,u.nickname,g.name as group_name,w.nickname as zm_nickname') ->alias('a') ->join('user u','a.user_id = u.id','LEFT') ->join('user_group g','a.group_id = g.id','LEFT') ->join('user w','a.zm_user_id = w.id','LEFT') ->where($where) ->count(); foreach($date as $k => $v){ $date[$k]['level'] = $this->level; } $res = [ 'count' => $count, 'data' => $date ]; return $this->success('查询成功',$res); } // 获取指定科室及其子科室的ID private function getGroupAndSubGroupIds($groupId) { if (!$groupId) { return []; } // 获取指定科室及其子科室的ID $groupIds = Db::name('user_group') ->where('id', $groupId) ->whereOr('pid', $groupId) ->column('id'); return $groupIds; } /** * 详情查询 * @return void */ public function find(){ $id = $this->request->request('id'); if(!$id){ return $this->error('缺少参数'); } $date = Db::name('reject_red_envelopes') ->field('a.*,u.nickname,g.name as group_name,w.nickname as zm_nickname') ->alias('a') ->join('user u','a.user_id = u.id','LEFT') ->join('user_group g','a.group_id = g.id','LEFT') ->join('user w','a.zm_user_id = w.id','LEFT') ->where('a.id', $id) ->find(); if($date){ return $this->success('查询成功',$date); } return $this->error('查询失败'); } /** * 审核 */ public function examine() { // 1. 参数接收与基础验证 $id = $this->request->post('id'); $status = $this->request->post('status'); $reason = $this->request->post('reason', ''); // 设置默认值避免未定义警告 // 2. 权限验证(前置检查) if ($this->level == 2) { return $this->error('您没有审核权限'); } // 3. 参数有效性验证 if (empty($id) || !is_numeric($id)) { return $this->error('缺少有效的红包记录ID'); } if (!in_array($status, [1, 2, 3])) { // 假设状态值只能是1/2/3 return $this->error('无效的审核状态值'); } // 4. 构建更新数据 $updateData = [ 'status' => $status, // 'audit_time' => date('Y-m-d H:i:s') // 添加审核时间记录 ]; // 5. 状态为驳回时的特殊处理 if ($status == 3) { if (empty(trim($reason))) { return $this->error('驳回时必须填写原因'); } $updateData['reason'] = htmlspecialchars($reason); // 防止XSS攻击 } $where = ['id' => $id]; $result = Db::name('reject_red_envelopes') ->where($where) ->update($updateData); if($result){ $this->success('审核成功'); } return $this->error('操作失败,请重试'); } /** * 新增记录 */ public function create() { $data = $this->request->post(); $data['createtime'] = date('Y-m-d H:i:s'); $result = Db::name('reject_red_envelopes')->strict(false)->insert($data); if ($result) { return $this->success('添加成功',$result); } else { return $this->error('添加失败',$result); } } }