123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\hander\HelpHander;
- use think\App;
- use think\Db;
- class PatrolTaskApply extends Base
- {
- public function list(){
- $page = input('page',1);
- $size = input('size',20);
- $map[] = ['org_id','=',$this->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([],'操作成功');
- }
- }
|