PatrolTaskDelay.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\App;
  6. use think\Db;
  7. class PatrolTaskDelay extends Base
  8. {
  9. public function list(){
  10. $page = input('page',1);
  11. $size = input('size',20);
  12. $map[] = ['org_id','=',$this->orgId];
  13. $lists = Db::name('patrol_task_delay')
  14. ->where($map)
  15. ->page($page,$size)
  16. ->order('id desc')
  17. ->select();
  18. foreach ($lists as $k=>$v){
  19. $taskTitle = Db::name('patrol_task')->where('id',$v['task_id'])->value('title');
  20. $lists[$k]['task_title'] = $taskTitle?$taskTitle:'';
  21. $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
  22. $lists[$k]['uname'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  23. $lists[$k]['deal_user'] = '';
  24. if($v['deal_user_id'] > 0){
  25. $lists[$k]['deal_user'] = Db::name('user')->where('id',$v['deal_user_id'])->value('real_name');
  26. }
  27. }
  28. HelpHander::success($lists);
  29. }
  30. public function deal(){
  31. $res = model('PatrolTaskDelay')->dealDelay($this->userId,$this->orgId);
  32. if(!$res){
  33. HelpHander::error(model('PatrolTaskDelay')->getError());
  34. }
  35. HelpHander::success('操作成功');
  36. }
  37. public function add(){
  38. $taskId = input('taskId/d',0);
  39. $endTime = input('endTime','','trim');
  40. $reason = input('reason','','trim');
  41. if($taskId < 0){
  42. HelpHander::error('参数错误');
  43. }
  44. if(!$endTime || date('Y-m-d H:i',strtotime($endTime)) != $endTime){
  45. HelpHander::error('未选择延期时间');
  46. }
  47. if(strtotime($endTime) <= time()){
  48. HelpHander::error('延期时间必须大于当前时间');
  49. }
  50. if(!$reason){
  51. HelpHander::error('未填写延期原因');
  52. }
  53. $task = Db::name('patrol_task')->where('org_id',$this->orgId)->where('id',$taskId)->where('del',0)->find();
  54. if(!$task){
  55. HelpHander::error('参数错误');
  56. }
  57. if($task['status'] != 3){
  58. HelpHander::error('只有未完成的任务可申请延期');
  59. }
  60. $ret = Db::name('patrol_task_user')->where('patrol_task_id',$taskId)->where('user_id',$this->userId)->find();
  61. if(!$ret){
  62. HelpHander::error('无权限操作');
  63. }
  64. // 检测是否有正在审核中的延期申请
  65. $ret = Db::name('patrol_task_delay')->where('task_id',$taskId)->where('status',0)->find();
  66. if($ret){
  67. HelpHander::error('该任务已存在未处理的延期申请');
  68. }
  69. $ret = Db::name('patrol_task_delay')->insert([
  70. 'org_id' => $this->orgId,
  71. 'user_id' => $this->userId,
  72. 'task_id' => $taskId,
  73. 'end_time' => $endTime,
  74. 'reason' => $reason,
  75. 'status' => 0,
  76. 'create_time' => date('Y-m-d H:i:s'),
  77. 'patrol_mode' => 4
  78. ]);
  79. if(!$ret){
  80. HelpHander::error('操作失败');
  81. }
  82. HelpHander::success([],'操作成功');
  83. }
  84. public function userList(){
  85. $page = input('page',1);
  86. $size = input('size',20);
  87. $record = Db::name('patrol_task_delay')
  88. ->where('user_id',$this->userId)
  89. ->where('org_id',$this->orgId)
  90. ->order('id desc')
  91. ->page($page,$size)
  92. ->select();
  93. $record = $record?$record:[];
  94. foreach ($record as $k=>$v){
  95. $taskTitle = Db::name('patrol_task')->where('id',$v['task_id'])->value('title');
  96. $record[$k]['task_title'] = $taskTitle?$taskTitle:'';
  97. $uname = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  98. $record[$k]['uname'] = $uname?$uname:'';
  99. $dealUser = '';
  100. if($v['deal_user_id'] > 0){
  101. $dealUser = Db::name('user')->where('id',$v['deal_user_id'])->value('real_name');
  102. }
  103. $record[$k]['deal_user'] = $dealUser?$dealUser:'';
  104. $record[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
  105. $record[$k]['update_time'] = $v['update_time']?$v['update_time']:'';
  106. }
  107. HelpHander::success($record);
  108. }
  109. public function cancelDelay(){
  110. $id = input('id/d',0);
  111. if($id < 0){
  112. HelpHander::error('参数错误');
  113. }
  114. $ret = Db::name('patrol_task_delay')->where('id',$id)->where('user_id',$this->userId)->find();
  115. if(!$ret){
  116. HelpHander::error('记录不存在');
  117. }
  118. if($ret['status'] != 0){
  119. HelpHander::error('申请已处理,无法取消');
  120. }
  121. $res = Db::name('patrol_task_delay')
  122. ->where('id',$id)
  123. ->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]);
  124. if(!$res){
  125. HelpHander::error('操作失败');
  126. }
  127. HelpHander::success([],'操作成功');
  128. }
  129. }