0
0

PatrolTaskApply.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Exception;
  5. use think\Db;
  6. class PatrolTaskApply extends Base
  7. {
  8. public function dealApply($userId,$orgId){
  9. $id = input('id/d',0);
  10. $status = input('status/d',0);
  11. $remark = input('remark','','trim');
  12. if(!in_array($status,[1,2]) || $id <= 0){
  13. $this->error = "参数错误";
  14. return false;
  15. }
  16. $info = Db::name('patrol_task_apply')->where('id',$id)->where('org_id',$orgId)->find();
  17. if(!$info){
  18. $this->error = "记录不存在";
  19. return false;
  20. }
  21. if($info['status'] != 0){
  22. $this->error = "申请已处理";
  23. return false;
  24. }
  25. // if(strtotime($info['end_time']) <= time()){
  26. // $this->error = "延期时间已失效";
  27. // Db::name('patrol_task_delay')->where('id',$id)->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]);
  28. // return false;
  29. // }
  30. Db::startTrans();
  31. try{
  32. $ret = Db::name('patrol_task_apply')->where('id',$id)->update([
  33. 'deal_user_id'=>$userId,
  34. 'status'=>$status,
  35. 'remark'=>$remark,
  36. 'update_time'=>date('Y-m-d H:i:s')
  37. ]);
  38. if(!$ret){
  39. \exception('操作失败');
  40. }
  41. if($status == 1){
  42. // 恢复计划任务
  43. $res = Db::name('patrol_task')->where('id',$info['task_id'])->update([
  44. 'status' => 2,
  45. 'del' => 0,
  46. 'update_time' => date('Y-m-d H:i:s')
  47. ]);
  48. if(!$res){
  49. \exception('操作失败');
  50. }
  51. }
  52. Db::commit();
  53. }catch (Exception $e){
  54. Db::rollback();
  55. $this->error = $e->getMessage();
  56. return false;
  57. }
  58. return true;
  59. }
  60. }