orgId]; $lists = Db::name('patrol_task_apply') ->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('PatrolTaskApply')->dealApply($this->userId,$this->orgId); if(!$res){ HelpHander::error(model('PatrolTaskApply')->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(!$reason){ HelpHander::error('未填写原因'); } $task = Db::name('patrol_task')->where('org_id',$this->orgId)->where('id',$taskId)->where('del',0)->find(); if(!$task || $task['patrol_mode'] != 1){ 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_apply')->where('task_id',$taskId)->where('status',0)->find(); if($ret){ HelpHander::error('该任务已存在未处理的申请'); } $ret = Db::name('patrol_task_apply')->insert([ 'org_id' => $this->orgId, 'user_id' => $this->userId, 'task_id' => $taskId, 'reason' => $reason, 'status' => 0, 'create_time' => date('Y-m-d H:i:s'), 'patrol_mode' => 1 ]); if(!$ret){ HelpHander::error('操作失败'); } HelpHander::success([],'操作成功'); } public function userList(){ $page = input('page',1); $size = input('size',20); $record = Db::name('patrol_task_apply') ->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 cancelApply(){ $id = input('id/d',0); if($id < 0){ HelpHander::error('参数错误'); } $ret = Db::name('patrol_task_apply')->where('id',$id)->where('user_id',$this->userId)->find(); if(!$ret){ HelpHander::error('记录不存在'); } if($ret['status'] != 0){ HelpHander::error('申请已处理,无法取消'); } $res = Db::name('patrol_task_apply') ->where('id',$id) ->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]); if(!$res){ HelpHander::error('操作失败'); } HelpHander::success([],'操作成功'); } }