123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Exception;
- use think\Db;
- class PatrolTaskDelay extends Base
- {
- public function dealDelay($userId,$orgId){
- $id = input('id/d',0);
- $status = input('status/d',0);
- $endTime = input('end_time','');
- $remark = input('remark','','trim');
- if(!in_array($status,[1,2]) || $id <= 0){
- $this->error = "参数错误";
- return false;
- }
- if($status == 1 && !$endTime){
- $this->error = "延期时间不能为空";
- return false;
- }
- $info = Db::name('patrol_task_delay')->where('id',$id)->where('org_id',$orgId)->find();
- if(!$info){
- $this->error = "记录不存在";
- return false;
- }
- if($info['status'] != 0){
- $this->error = "申请已处理";
- return false;
- }
- if($status == 1 && strtotime($endTime) <= time()){
- $this->error = "延期时间不能小于当前时间";
- // Db::name('patrol_task_delay')->where('id',$id)->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]);
- return false;
- }
- Db::startTrans();
- try{
- $ret = Db::name('patrol_task_delay')->where('id',$id)->update([
- 'deal_user_id'=>$userId,
- 'status'=>$status,
- 'remark'=>$remark,
- 'end_time'=>$endTime,
- 'update_time'=>date('Y-m-d H:i:s')
- ]);
- if(!$ret){
- \exception('操作失败');
- }
- if($status == 1){
- $task = Db::name('patrol_task')->where('id',$info['task_id'])->find();
- // 恢复计划任务
- $res = Db::name('patrol_task')->where('id',$info['task_id'])->update([
- 'status' => 1,
- 'del' => 0,
- 'end_time' => $info['end_time']
- ]);
- if(!$res){
- \exception('操作失败');
- }
- $userIds = Db::name('patrol_task_user')->where('patrol_task_id',$info['task_id'])->column('user_id');
- $arr = [];
- foreach ($userIds as $v){
- $arr[] = [
- 'org_id'=>$orgId,
- 'type'=>(new Task())::TASK_TYPE_PATROL,
- 'start_time' => $task['start_time'],
- 'create_time'=>getTime(),
- 'bus_id'=>$task['id'],
- 'user_id'=>$v
- ];
- }
- $res = Db::name('task')->insertAll($arr);
- if($res != count($userIds)){
- \exception('操作失败');
- }
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- return true;
- }
- }
|