orgId]; $lists = Db::name('patrol_task_delay') ->where($map) ->page($page,$size) ->order('id desc') ->select(); foreach ($lists as $k=>$v){ $taskTitle = Db::name('patrol_task')->where('id',$v['task_id'])->value('title'); $lists[$k]['task_title'] = $taskTitle?$taskTitle:''; $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time'])); $lists[$k]['uname'] = Db::name('user')->where('id',$v['user_id'])->value('real_name'); $lists[$k]['deal_user'] = ''; if($v['deal_user_id'] > 0){ $lists[$k]['deal_user'] = Db::name('user')->where('id',$v['deal_user_id'])->value('real_name'); } } HelpHander::success($lists); } public function deal(){ $res = model('PatrolTaskDelay')->dealDelay($this->userId,$this->orgId); if(!$res){ HelpHander::error(model('PatrolTaskDelay')->getError()); } HelpHander::success('操作成功'); } public function add(){ $taskId = input('taskId/d',0); $endTime = input('endTime','','trim'); $reason = input('reason','','trim'); if($taskId < 0){ HelpHander::error('参数错误'); } if(!$endTime || date('Y-m-d H:i',strtotime($endTime)) != $endTime){ HelpHander::error('未选择延期时间'); } if(strtotime($endTime) <= time()){ HelpHander::error('延期时间必须大于当前时间'); } if(!$reason){ HelpHander::error('未填写延期原因'); } $task = Db::name('patrol_task')->where('org_id',$this->orgId)->where('id',$taskId)->where('del',0)->find(); if(!$task){ HelpHander::error('参数错误'); } if($task['status'] != 3){ HelpHander::error('只有未完成的任务可申请延期'); } $ret = Db::name('patrol_task_user')->where('patrol_task_id',$taskId)->where('user_id',$this->userId)->find(); if(!$ret){ HelpHander::error('无权限操作'); } // 检测是否有正在审核中的延期申请 $ret = Db::name('patrol_task_delay')->where('task_id',$taskId)->where('status',0)->find(); if($ret){ HelpHander::error('该任务已存在未处理的延期申请'); } $ret = Db::name('patrol_task_delay')->insert([ 'org_id' => $this->orgId, 'user_id' => $this->userId, 'task_id' => $taskId, 'end_time' => $endTime, 'reason' => $reason, 'status' => 0, 'create_time' => date('Y-m-d H:i:s'), 'patrol_mode' => 4 ]); if(!$ret){ HelpHander::error('操作失败'); } HelpHander::success([],'操作成功'); } public function userList(){ $page = input('page',1); $size = input('size',20); $record = Db::name('patrol_task_delay') ->where('user_id',$this->userId) ->where('org_id',$this->orgId) ->order('id desc') ->page($page,$size) ->select(); $record = $record?$record:[]; foreach ($record as $k=>$v){ $taskTitle = Db::name('patrol_task')->where('id',$v['task_id'])->value('title'); $record[$k]['task_title'] = $taskTitle?$taskTitle:''; $uname = Db::name('user')->where('id',$v['user_id'])->value('real_name'); $record[$k]['uname'] = $uname?$uname:''; $dealUser = ''; if($v['deal_user_id'] > 0){ $dealUser = Db::name('user')->where('id',$v['deal_user_id'])->value('real_name'); } $record[$k]['deal_user'] = $dealUser?$dealUser:''; $record[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time'])); $record[$k]['update_time'] = $v['update_time']?$v['update_time']:''; } HelpHander::success($record); } public function cancelDelay(){ $id = input('id/d',0); if($id < 0){ HelpHander::error('参数错误'); } $ret = Db::name('patrol_task_delay')->where('id',$id)->where('user_id',$this->userId)->find(); if(!$ret){ HelpHander::error('记录不存在'); } if($ret['status'] != 0){ HelpHander::error('申请已处理,无法取消'); } $res = Db::name('patrol_task_delay') ->where('id',$id) ->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]); if(!$res){ HelpHander::error('操作失败'); } HelpHander::success([],'操作成功'); } }