auth->company_id == 1){ return $this->liuzhuan_index(); } $rs = [ 'status_0' => 0, 'status_20' => 0, 'status_30' => 0, 'status_40' => 0, 'status_100' => 0, 'score' => 5, ]; $list = Db::name($this->table)->field('status,count(id) as number') // ->where('status','NEQ',2) ->where('company_id',$this->auth->company_id)->group('status')->select(); if(!empty($list)){ foreach($list as $key => $val){ if($val['status'] == 0){ $rs['status_0'] = $val['number']; } if(in_array($val['status'],[20,22])){ $rs['status_20'] += $val['number']; } if($val['status'] == 30){ $rs['status_30'] = $val['number']; } if(in_array($val['status'],[40,50,60,70,80,90,92])){ $rs['status_40'] += $val['number']; } /*if($val['status'] == 100){ $rs['status_100'] = $val['number']; }*/ if(in_array($val['status'],[2,100])){ $rs['status_100'] += $val['number']; } } } //本周服务评分 $score = Db::name($this->table) ->where('status',100) ->where('company_id',$this->auth->company_id) ->whereTime('eva_time','week') /*->select(false);echo $score;exit;*/ ->avg('eva_score'); $rs['score'] = $score; $this->success(1,$rs); } //首页统计 public function liuzhuan_index(){ $rs = [ 'status_0' => 0, 'status_20' => 0, 'status_30' => 0, 'status_40' => 0, 'status_100' => 0, 'score' => 5, ]; $list = Db::name($this->table)->field('status,count(id) as number') ->where('liuzhuan_status',1)->group('status')->select(); if(!empty($list)){ foreach($list as $key => $val){ if($val['status'] == 0){ $rs['status_0'] = $val['number']; } if(in_array($val['status'],[20,22])){ $rs['status_20'] += $val['number']; } if($val['status'] == 30){ $rs['status_30'] = $val['number']; } if(in_array($val['status'],[40,50,60,70,80,90,92])){ $rs['status_40'] += $val['number']; } /*if($val['status'] == 100){ $rs['status_100'] = $val['number']; }*/ if(in_array($val['status'],[2,100])){ $rs['status_100'] += $val['number']; } } } //本周服务评分 $score = Db::name($this->table) ->where('status',100) ->where('liuzhuan_status',1) ->whereTime('eva_time','week') /*->select(false);echo $score;exit;*/ ->avg('eva_score'); $rs['score'] = $score; $this->success(1,$rs); } //列表 public function lists(){ if($this->auth->company_id == 1){ return $this->liuzhuan_lists(); } $orderno = input('orderno',''); $projectname = input('projectname',''); $header = input('header',''); $status = input('status','ALL'); //默认ALL $map = [ 'mt.company_id' => $this->auth->company_id, ]; if(!empty($orderno)){ $map['mt.orderno'] = $orderno; } if(!empty($projectname)){ $map['uc.projectname'] = ['LIKE','%'.$projectname.'%']; } if(!empty($header)){ $map['uc.header'] = ['LIKE','%'.$header.'%']; } if($status != 'ALL'){ $map['mt.status'] = $status; if($status == 20){ $map['mt.status'] = ['IN',[20,22]]; } if($status == 40){ $map['mt.status'] = ['IN',[40,50,60,70,80,90,92]]; } if($status == 100){ $map['mt.status'] = ['IN',[2,100]]; } } $field = ['mt.id','mt.orderno','uc.projectname','mt.info','uc.header','mt.status','mt.price','mt.liuzhuan_status','company.companyname']; $list = Db::name($this->table)->alias('mt') ->join('user_company uc','mt.uc_id = uc.id','LEFT') ->join('company','mt.company_id = company.id','LEFT') ->field($field) ->where($map)->order('mt.id desc') ->paginate(); $total = $list->total(); $list = $list->items(); if(!empty($list)){ $maintain_model = new Maintainmodel(); foreach($list as $key => $val){ $list[$key]['status_text'] = $maintain_model->status_data($val['status']); //pc用户,已流转订单,直接显示流转中 if($this->auth->company_id != 1 && in_array($val['status'],[0,20,22,30,40]) && $val['liuzhuan_status'] == 1){ $list[$key]['status_text'] = '流转中'; } $list[$key]['status_colorType'] = $maintain_model->status_colorType($val['status']); //假状态 $list[$key]['fake_status'] = $this->fake_status($val['status']); $list[$key]['fake_status_text'] = $this->fake_status_data($val['status']); } } $rs = [ 'list' => $list, 'total'=> $total, ]; $this->success(1,$rs); } //流转列表 public function liuzhuan_lists(){ $orderno = input('orderno',''); $projectname = input('projectname',''); $header = input('header',''); $status = input('status','ALL'); //默认ALL $map = [ 'mt.liuzhuan_status' => 1, ]; if(!empty($orderno)){ $map['mt.orderno'] = $orderno; } if(!empty($projectname)){ $map['uc.projectname'] = ['LIKE','%'.$projectname.'%']; } if(!empty($header)){ $map['uc.header'] = ['LIKE','%'.$header.'%']; } if($status != 'ALL'){ $map['mt.status'] = $status; if($status == 20){ $map['mt.status'] = ['IN',[20,22]]; } if($status == 40){ $map['mt.status'] = ['IN',[40,50,60,70,80,90,92]]; } if($status == 100){ $map['mt.status'] = ['IN',[2,100]]; } } $field = ['mt.id','mt.orderno','uc.projectname','mt.info','uc.header','mt.status','mt.price','mt.liuzhuan_status','company.companyname']; $list = Db::name($this->table)->alias('mt') ->join('user_company uc','mt.uc_id = uc.id','LEFT') ->join('company','mt.company_id = company.id','LEFT') ->field($field) ->where($map)->order('mt.id desc') ->paginate(); $total = $list->total(); $list = $list->items(); if(!empty($list)){ $maintain_model = new Maintainmodel(); foreach($list as $key => $val){ $list[$key]['status_text'] = $maintain_model->status_data($val['status']); $list[$key]['status_colorType'] = $maintain_model->status_colorType($val['status']); //假状态 $list[$key]['fake_status'] = $this->fake_status($val['status']); $list[$key]['fake_status_text'] = $this->fake_status_data($val['status']); } } $rs = [ 'list' => $list, 'total'=> $total, ]; $this->success(1,$rs); } //整合过的状态 private function fake_status_data($status){ $data = [ 0 => '待报价', 2 => '已取消', 20 => '评估报价', 22 => '评估报价', 30 => '用户待确认', 40 => '待处理', 50 => '待处理', 60 => '待处理', 70 => '待处理', 80 => '待处理', 90 => '待处理', 92 => '待处理', 100 => '已完成', ]; return isset($data[$status]) ? $data[$status] : $status; } //整合过的状态 private function fake_status($status){ $data = [ 0 => 0, 2 => 2, 20 => 20, 22 => 20, 30 => 30, 40 => 40, 50 => 40, 60 => 40, 70 => 40, 80 => 40, 90 => 40, 92 => 40, 100 => 100, ]; return isset($data[$status]) ? $data[$status] : $status; } //详情 public function info(){ $id = input('id',0); $info = Db::name($this->table)->alias('mt') ->join('user_company uc','mt.uc_id = uc.id','LEFT') ->join('user','mt.user_id = user.id','LEFT') ->join('worker','mt.worker_id = worker.id','LEFT') ->join('company','mt.company_id = company.id','LEFT') ->field('mt.*,uc.projectname,uc.header,uc.header_mobile,uc.projectaddress,user.nickname as user_nickname,user.mobile as user_mobile,worker.truename as worker_truename,worker.mobile as worker_mobile,company.companyname') ->where('mt.id',$id) ->find(); $maintain_model = new Maintainmodel(); $info['status_text'] = $maintain_model->status_data($info['status']); //pc用户,已流转订单,直接显示流转中 if($info['company_id'] != 1 && in_array($info['status'],[0,20,22,30,40]) && $info['liuzhuan_status'] == 1){ $info['status_text'] = '流转中'; } $info['status_colorType'] = $maintain_model->status_colorType($info['status']); //假状态 $info['fake_status'] = $this->fake_status($info['status']); $info['fake_status_text'] = $this->fake_status_data($info['status']); $info['filedata'] = json_decode($info['filedata'],true); //追加报价历史 $baojia = Db::name('maintain_baojia')->alias('bj') ->field('bj.*,admin.nickname as baojia_nickname,audit.nickname as baojia_audit_nickname') ->join('pc_admin admin','bj.baojia_staffid = admin.id','LEFT') ->join('pc_admin audit','bj.baojia_audit_staffid = audit.id','LEFT') ->where('order_id',$id)->order('id desc')->select(); if(!empty($baojia)){ foreach($baojia as $key => $val){ $baojia[$key]['status_text'] = $maintain_model->baojia_status_data($val['status']); } } $info['baojia_list'] = $baojia; //追加材料列表 $info['cailiao_list'] = Db::name('maintain_cailiao')->field('id,name,number,danwei,images')->where('order_id',$id)->order('id desc')->select(); //追加多次维修+对应进度历史 $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(); 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 ]; } } $info['jindu'] = $last_jindulist; $this->success(1,$info); } //提交报价 public function baojia(){ $id = input('id',0); $baojia_file = input('baojia_file',''); $baojia_filename = input('baojia_filename',''); if(empty($baojia_file) || empty($baojia_filename)){ $this->error(); } Db::startTrans(); $info = Db::name($this->table)->where('id',$id)->lock(true)->find(); if(empty($info)){ Db::rollback(); $this->error('没找到该信息,请刷新重试'); } if($info['company_id'] != $this->auth->company_id){ Db::rollback(); $this->error('没找到该信息,请刷新重试'); } if($info['status'] == 20){ Db::rollback(); $this->error('当前订单报价正在审核中'); } if($info['status'] != 22 && $info['status'] != 0){ Db::rollback(); $this->error('当前订单不能报价'); } //报价 $nowtime = time(); $baojia_data = [ 'order_id' => $info['id'], 'company_id' => $info['company_id'], 'user_id' => $info['user_id'], 'baojia_staffid' => $this->auth->id, 'baojia_time' => $nowtime, 'baojia_filename' => $baojia_filename, 'baojia_file' => $baojia_file, 'status' => 20, 'updatetime' => $nowtime, ]; $baojia_id = Db::name('maintain_baojia')->insertGetId($baojia_data); if(!$baojia_id){ Db::rollback(); $this->error('报价失败,请重试'); } // $update = [ 'status' => 20, 'updatetime' => $nowtime, ]; $rs_update = Db::name($this->table)->where('id',$id)->update($update); if($rs_update === false){ Db::rollback(); $this->error('报价失败,请重试'); } // Db::commit(); $this->success(); } //审核报价 public function baojia_audit(){ $baojia_id = input('baojia_id',0); $status = input('status',2); $reason = input('reason',''); Db::startTrans(); $nowtime = time(); $baojia_info = Db::name('maintain_baojia')->where('id',$baojia_id)->lock(true)->find(); if(empty($baojia_info)){ Db::rollback(); $this->error('没找到该信息,请刷新重试'); } $info = Db::name($this->table)->where('id',$baojia_info['order_id'])->lock(true)->find(); if(empty($info)){ Db::rollback(); $this->error('没找到该信息,请刷新重试'); } if($baojia_info['status'] != 20){ Db::rollback(); $this->error('状态错误不能审核,请刷新重试'); } if($info['status'] != 20){ Db::rollback(); $this->error('状态错误不能审核,请刷新重试'); } if($status == 1){ //通过 $baojia_update = [ 'status' => 30, 'baojia_audit_staffid' => $this->auth->id, 'baojia_audit_time' => $nowtime, 'updatetime' => $nowtime, ]; }else{ //驳回 $baojia_update = [ 'status' => 22, 'baojia_audit_staffid' => $this->auth->id, 'baojia_audit_time' => $nowtime, 'baojia_audit_reason' => $reason, 'updatetime' => $nowtime, ]; } $rs_audit = Db::name('maintain_baojia')->where('id',$baojia_id)->update($baojia_update); if($rs_audit === false){ Db::rollback(); $this->error('审核失败,请重试'); } //订单 $update = [ 'status' => $baojia_update['status'], 'updatetime' => $nowtime, ]; $rs_update = Db::name($this->table)->where('id',$baojia_info['order_id'])->update($update); if($rs_update === false){ Db::rollback(); $this->error('审核失败,请重试'); } // Db::commit(); $this->success(); } //流转到总公司 public function liuzhuan(){ $id = input('id',0); Db::startTrans(); $info = Db::name($this->table)->where('id',$id)->lock(true)->find(); if(empty($info)){ Db::rollback(); $this->error('没找到该信息,请刷新重试'); } if($info['company_id'] != $this->auth->company_id){ Db::rollback(); $this->error('没找到该信息,请刷新重试'); } if(!in_array($info['status'],[0,20,22,30,40])){ Db::rollback(); $this->error('当前订单状态,不能流转'); } if(!empty($info['worker_id'])){ Db::rollback(); $this->error('已经指派了师傅,不能流转了'); } // $update = [ 'liuzhuan_status' => 1, 'updatetime' => time(), ]; $rs_update = Db::name($this->table)->where('id',$id)->update($update); if($rs_update === false){ Db::rollback(); $this->error('流转失败,请重试'); } // Db::commit(); $this->success(); } //指派师傅 public function zhipai(){ //检查师傅 $worker_id = input('worker_id',0); $worker = Db::name('worker')->where('id',$worker_id)->where('status',1)->where('company_id',$this->auth->company_id)->find(); if(empty($worker)){ $this->error('没找到该师傅'); } //检查订单 $id = input('id',0); Db::startTrans(); $info = Db::name($this->table)->where('id',$id)->lock(true)->find(); if(empty($info)){ Db::rollback(); $this->error('没找到该信息,请刷新重试'); } if($this->auth->company_id != 1 && $info['company_id'] != $this->auth->company_id){ Db::rollback(); $this->error('没找到该信息,请刷新重试'); } /*if(in_array($info['status'],[20,22,30])){ Db::rollback(); $this->error('报价未确认,还不能指派师傅'); } if($info['status'] != 0 && $info['status'] != 40 ){ Db::rollback(); $this->error('当前订单状态,不能指派师傅'); }*/ if(!in_array($info['status'],[0,20,22,30,40])){ Db::rollback(); $this->error('当前订单状态,不能指派师傅'); } if(!empty($info['worker_id'])){ Db::rollback(); $this->error('已经指派了师傅'); } // $update = [ 'worker_id' => $worker_id, 'status' => 50, 'updatetime' => time(), ]; $rs_update = Db::name($this->table)->where('id',$id)->update($update); if($rs_update === false){ Db::rollback(); $this->error('指派失败,请重试'); } // Db::commit(); $this->success(); } //修改报价金额 public function set_price(){ $id = input('id',0); $price = input('price',0); $update = [ 'price' => $price, 'updatetime' => time(), ]; $rs_update = Db::name($this->table)->where('id',$id)->update($update); $this->success(); } }