0
0

PatrolTaskDelay.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Exception;
  5. use think\Db;
  6. class PatrolTaskDelay extends Base
  7. {
  8. public function dealDelay($userId,$orgId){
  9. $id = input('id/d',0);
  10. $status = input('status/d',0);
  11. $endTime = input('end_time','');
  12. $remark = input('remark','','trim');
  13. if(!in_array($status,[1,2]) || $id <= 0){
  14. $this->error = "参数错误";
  15. return false;
  16. }
  17. if($status == 1 && !$endTime){
  18. $this->error = "延期时间不能为空";
  19. return false;
  20. }
  21. $info = Db::name('patrol_task_delay')->where('id',$id)->where('org_id',$orgId)->find();
  22. if(!$info){
  23. $this->error = "记录不存在";
  24. return false;
  25. }
  26. if($info['status'] != 0){
  27. $this->error = "申请已处理";
  28. return false;
  29. }
  30. if($status == 1 && strtotime($endTime) <= time()){
  31. $this->error = "延期时间不能小于当前时间";
  32. // Db::name('patrol_task_delay')->where('id',$id)->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]);
  33. return false;
  34. }
  35. Db::startTrans();
  36. try{
  37. $ret = Db::name('patrol_task_delay')->where('id',$id)->update([
  38. 'deal_user_id'=>$userId,
  39. 'status'=>$status,
  40. 'remark'=>$remark,
  41. 'end_time'=>$endTime,
  42. 'update_time'=>date('Y-m-d H:i:s')
  43. ]);
  44. if(!$ret){
  45. \exception('操作失败');
  46. }
  47. if($status == 1){
  48. $task = Db::name('patrol_task')->where('id',$info['task_id'])->find();
  49. // 恢复计划任务
  50. $res = Db::name('patrol_task')->where('id',$info['task_id'])->update([
  51. 'status' => 1,
  52. 'del' => 0,
  53. 'end_time' => $info['end_time']
  54. ]);
  55. if(!$res){
  56. \exception('操作失败');
  57. }
  58. $userIds = Db::name('patrol_task_user')->where('patrol_task_id',$info['task_id'])->column('user_id');
  59. $arr = [];
  60. foreach ($userIds as $v){
  61. $arr[] = [
  62. 'org_id'=>$orgId,
  63. 'type'=>(new Task())::TASK_TYPE_PATROL,
  64. 'start_time' => $task['start_time'],
  65. 'create_time'=>getTime(),
  66. 'bus_id'=>$task['id'],
  67. 'user_id'=>$v
  68. ];
  69. }
  70. $res = Db::name('task')->insertAll($arr);
  71. if($res != count($userIds)){
  72. \exception('操作失败');
  73. }
  74. }
  75. Db::commit();
  76. }catch (Exception $e){
  77. Db::rollback();
  78. $this->error = $e->getMessage();
  79. return false;
  80. }
  81. return true;
  82. }
  83. }