$this->auth->id, 'm.status' => $status, ]; if($status == 50){ $map['m.status'] = ['IN',[50,60]]; } if($status == 80){ $map['m.status'] = ['IN',[70,80,92]]; } $field = [ 'm.id','m.orderno','m.info','m.filedata','m.mobile','m.address','m.status','m.cailiao_time','m.lingqu_time','m.shangmen_time','m.wancheng_time', 'user.contactname', 'uc.projectname' ]; $list = Db::name('maintain')->alias('m')->field($field) ->join('user','m.user_id = user.id','LEFT') ->join('user_company uc','m.user_id = uc.user_id','LEFT') ->where($map)->order('m.id desc') ->autopage()->select(); if(!empty($list)){ $maintain_model = new Maintainmodel(); foreach($list as $key => $val){ $list[$key]['status_text'] = $maintain_model->status_data($val['status']); $list[$key]['filedata'] = !empty($val['filedata']) ? json_decode($val['filedata'],true) : []; } } $this->success(1,$list); } //材料清单 public function cailiao_list(){ $id = input('order_id',0); $result = []; $list = Db::name('maintain_cailiao')->field('id,order_id,name,number,danwei,images')->where('order_id',$id)->order('id desc')->select(); if(!empty($list)){ $result = list_domain_image($list,['images']); } $this->success(1, $result); } //进度列表 public function jindu_list(){ $id = input('order_id',0); $map = [ 'worker_id' => $this->auth->id, 'id' => $id, ]; $info = Db::name('maintain') ->where($map) ->find(); //追加进度 //追加多次维修+对应进度历史 $last_jindulist = []; $new_jindulist = []; $jindu_list = Db::name('maintain_jindu')->alias('jd') ->join('worker','jd.worker_id = worker.id','LEFT') ->field('jd.id,jd.worker_id,jd.weixiu_times,jd.title,jd.images,jd.createtime,worker.avatar,worker.truename') ->where('jd.order_id',$id) ->order('jd.id desc')->select(); $jindu_list = list_domain_image($jindu_list,['avatar','images']); if(!empty($jindu_list)){ for($i=$jindu_list[0]['weixiu_times'];$i>=1;$i--){ foreach($jindu_list as $key => $val){ if($i == $val['weixiu_times']){ $new_jindulist[$i][] = $val; } } } foreach($new_jindulist as $key => $val){ $last_jindulist[] = [ 'title' => '第'.$val[0]['weixiu_times'].'次', 'child' => $val ]; } } $this->success(1, $last_jindulist); } //申请材料 public function shenqingcailiao(){ $order_id = input('order_id',0); $data = input('data','','htmlspecialchars_decode'); $data = json_decode($data,true); if(empty($data)){ $this->error(); } Db::startTrans(); //订单 $map = [ 'worker_id' => $this->auth->id, 'id' => $order_id, ]; $info = Db::name('maintain')->where($map)->lock(true)->find(); if(empty($info)){ Db::rollback(); $this->error('不存在的订单'); } if($info['status'] != 50){ Db::rollback(); $this->error('状态不正确,请刷新重试'); } $nowtime = time(); //准备数据 foreach($data as $key => $val){ $val['order_id'] = $info['id']; $val['company_id'] = $info['company_id']; $val['user_id'] = $info['user_id']; $val['worker_id'] = $info['worker_id']; $val['createtime'] = $nowtime; $data[$key] = $val; } $id = Db::name('maintain_cailiao')->insertAll($data); if(!$id){ Db::rollback(); $this->error('申请失败'); } $update = [ 'status' => 60, 'updatetime' => $nowtime, 'cailiao_time' => $nowtime, //材料申请时间 ]; $rs2 = Db::name('maintain')->where('id',$order_id)->update($update); if($rs2 === false){ Db::rollback(); $this->error('申请失败'); } Db::commit(); $this->success('申请成功'); } //材料计量单位 public function cailiao_danwei(){ $data = [ '个', '把', '只', ]; $this->success(1,$data); } //领取材料 public function lingqucailiao(){ $order_id = input('order_id',0); $images = input('images','','trim'); if(empty($images)){ $this->error(); } //订单 $map = [ 'worker_id' => $this->auth->id, 'id' => $order_id, ]; $info = Db::name('maintain')->where($map)->find(); if(empty($info)){ $this->error('不存在的订单'); } if($info['status'] != 60){ $this->error('状态不正确,请刷新重试'); } $nowtime = time(); // $update = [ 'status' => 70, 'updatetime' => $nowtime, 'lingqu_time' => $nowtime, //材料申请时间 'lingqu_images' => $images, ]; $rs2 = Db::name('maintain')->where('id',$order_id)->update($update); if($rs2 === false){ $this->error('领取失败'); } $this->success('领取成功'); } //////////////////////////////循环开始/////////////////////// //立即上门 public function shangmen(){ $order_id = input('order_id',0); Db::startTrans(); //订单 $map = [ 'worker_id' => $this->auth->id, 'id' => $order_id, ]; $info = Db::name('maintain')->where($map)->lock(true)->find(); if(empty($info)){ Db::rollback(); $this->error('不存在的订单'); } if(!in_array($info['status'],[70,92])){ Db::rollback(); $this->error('状态不正确,请刷新重试'); } $nowtime = time(); //开启一个新轮回 $weixiu = [ 'order_id' => $info['id'], 'company_id' => $info['company_id'], 'user_id' => $info['user_id'], 'worker_id' => $info['worker_id'], 'weixiu_times' => $info['weixiu_times'] + 1, //次数自增1 'shangmen_time' => $nowtime, 'status' => 80, 'updatetime' => $nowtime, ]; $weixiu_id = Db::name('maintain_weixiu')->insertGetId($weixiu); if(!$weixiu_id){ Db::rollback(); $this->error('操作失败,重试一下吧'); } //新轮回第一个进度 $jindu = [ 'order_id' => $info['id'], 'company_id' => $info['company_id'], 'user_id' => $info['user_id'], 'worker_id' => $info['worker_id'], 'weixiu_times' => $weixiu['weixiu_times'], 'weixiu_id' => $weixiu_id, 'title' => '已上门', 'createtime' => $nowtime, ]; $jindu_id = Db::name('maintain_jindu')->insertGetId($jindu); if(!$jindu_id){ Db::rollback(); $this->error('操作失败,重试一下吧'); } //修改订单 $update = [ 'status' => 80, 'updatetime' => $nowtime, 'shangmen_time' => $nowtime, //上门时间 'weixiu_times' => $weixiu['weixiu_times'], 'weixiu_id' => $weixiu_id, 'wancheng_time' => 0, //清空完成时间 ]; $rs2 = Db::name('maintain')->where('id',$order_id)->update($update); if($rs2 === false){ Db::rollback(); $this->error('操作失败,重试一下吧'); } Db::commit(); $this->success('已上门'); } //新增维修进度 public function jindu_add(){ $order_id = input('order_id',0); $title = input('title',''); $images = input('images',''); if(empty($title)){ $this->error(); } //订单 $map = [ 'worker_id' => $this->auth->id, 'id' => $order_id, ]; $info = Db::name('maintain')->where($map)->find(); if(empty($info)){ $this->error('不存在的订单'); } if($info['status'] != 80){ $this->error('状态不正确,请刷新重试'); } $nowtime = time(); //准备数据 $jindu = [ 'order_id' => $info['id'], 'company_id' => $info['company_id'], 'user_id' => $info['user_id'], 'worker_id' => $info['worker_id'], 'weixiu_times' => $info['weixiu_times'], 'weixiu_id' => $info['weixiu_id'], 'title' => $title, 'images' => $images, 'createtime' => $nowtime, ]; $id = Db::name('maintain_jindu')->insertGetId($jindu); if(!$id){ $this->error('记录失败'); } $this->success('记录成功'); } //确认完成 public function wancheng(){ $order_id = input('order_id',0); Db::startTrans(); //订单 $map = [ 'worker_id' => $this->auth->id, 'id' => $order_id, ]; $info = Db::name('maintain')->where($map)->lock(true)->find(); if(empty($info)){ Db::rollback(); $this->error('不存在的订单'); } if($info['status'] != 80){ Db::rollback(); $this->error('状态不正确,请刷新重试'); } $nowtime = time(); //结束最后一个轮回 $weixiu = [ 'status' => 90, //待验收 'wancheng_time' => $nowtime, 'updatetime' => $nowtime, ]; $weixiu_rs = Db::name('maintain_weixiu')->where('id',$info['weixiu_id'])->update($weixiu); if($weixiu_rs === false){ Db::rollback(); $this->error('操作失败,重试一下吧'); } //最后一个轮回,追加完成进度 $jindu = [ 'order_id' => $info['id'], 'company_id' => $info['company_id'], 'user_id' => $info['user_id'], 'worker_id' => $info['worker_id'], 'weixiu_times' => $info['weixiu_times'], 'weixiu_id' => $info['weixiu_id'], 'title' => '已完成', 'createtime' => $nowtime, ]; $jindu_id = Db::name('maintain_jindu')->insertGetId($jindu); if(!$jindu_id){ Db::rollback(); $this->error('操作失败,重试一下吧'); } //修改订单 $update = [ 'status' => 90, 'wancheng_time' => $nowtime, 'updatetime' => $nowtime, ]; $rs2 = Db::name('maintain')->where('id',$order_id)->update($update); if($rs2 === false){ Db::rollback(); $this->error('操作失败,重试一下吧'); } Db::commit(); $this->success('操作成功'); } //////////////////////////////循环结束/////////////////////// }