123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 保修
- */
- class Maintain extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function addone()
- {
- $info = input('info','');
- $filedata = input('filedata','','htmlspecialchars_decode');
- $mobile = input('mobile','');
- $address = input('address','');
- //视频类型追加缩略图
- $filedata = json_decode($filedata,true);
- foreach($filedata as $key => $file){
- if($file['type'] == 'video'){
- $file_url = explode('.', $file['url']);
- unset($file_url[count($file_url) - 1]);
- $file['images_thumb'] = implode('.', $file_url) . '_0.jpg';
- }else{
- $file['images_thumb'] = $file['url'];
- }
- $filedata[$key] = $file;
- }
- $filedata = json_encode($filedata);
- //写入
- $data = [
- 'orderno' => createUniqueNo('',''),
- 'user_id' => $this->auth->id,
- 'company_id' => $this->auth->company_id,
- 'createtime' => time(),
- 'updatetime' => time(),
- 'info' => $info,
- 'filedata' => $filedata,
- 'mobile' => $mobile,
- 'address' => $address,
- 'status' => 0,
- ];
- $order_id = Db::name('maintain')->insertGetId($data);
- $this->success('保修成功请等待审核', $order_id);
- }
- public function lists(){
- $status = input('status',0); //默认待审核
- $map = [
- 'user_id' => $this->auth->id,
- 'status' => $status,
- ];
- $list = Db::name('maintain')->field('id,orderno,createtime,info,filedata,status,eva_time')
- ->where($map)->order('id desc')
- ->autopage()->select();
- if(!empty($list)){
- $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');//负责人的电话
- foreach($list as $key => $val){
- $list[$key]['header_mobile'] = $header_mobile;
- $list[$key]['status_text'] = $this->status_data($val['status']);
- }
- }
- $this->success(1,$list);
- }
- public function info(){
- $id = input('id',0);
- $map = [
- 'user_id' => $this->auth->id,
- 'id' => $id,
- ];
- $info = Db::name('maintain')
- ->where($map)
- ->find();
- $info['status_text'] = $this->status_data($info['status']);
- $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');//负责人的电话
- $info['header_mobile'] = $header_mobile;
- //追加维修师傅
- $worker = [
- 'avatar' => 'http://weibao.com/assets/img/avatar.png',
- 'truename' => '李师傅',
- 'mobile' => '17666666666',
- ];
- $info['worker_info'] = $worker;
- //追加进度
- $jindu = Db::name('maintain_jindu')->field('id,title,createtime')->where('order_id',$id)->order('id desc')->select();
- $info['jindu'] = $jindu;
- $this->success(1, $info);
- }
- //取消上报
- public function cancel(){
- $id = input('id',0);
- $map = [
- 'user_id' => $this->auth->id,
- 'id' => $id,
- ];
- $info = Db::name('maintain')
- ->where($map)
- ->find();
- if(empty($info)){
- $this->error('不存在的订单');
- }
- if($info['status'] >= 40){ //报价都审核过了,可派师傅了
- $this->error('现在已经不能取消了');
- }
- $nowtime = time();
- $update = [
- 'status' => 2,
- 'canceltime' => $nowtime, //取消时间
- 'finishtime' => $nowtime,
- 'updatetime' => $nowtime,
- ];
- $rs = Db::name('maintain')
- ->where($map)->update($update);
- $this->success('取消成功');
- }
- //报价详情
- public function baojia_info(){
- $order_id = input('order_id',0);
- //找出最新报价日志
- $baojia_log = Db::name('maintain_baojia')->where('order_id',$order_id)->where('status',30)->order('id desc')->find();
- $baojia_log['status_text'] = $this->status_data($baojia_log['status']);
- $this->success(1,$baojia_log);
- }
- //报价审核
- public function baojia_audit(){
- $id = input('order_id',0);
- $status = input('status',2);//1=通过,2=拒绝
- $reason = input('reason','','trim');
- //必填
- if($status == 2 && empty($reason)){
- $this->error('请输入拒绝原因');
- }
- //检查订单
- $map = [
- 'user_id' => $this->auth->id,
- 'id' => $id,
- ];
- $info = Db::name('maintain')->where($map)->find();
- if(empty($info)){
- $this->error('不存在的订单');
- }
- if($info['status'] != 30){ //用户待审
- $this->success('订单错误,请刷新重试');
- }
- //找出最新报价日志
- $baojia_log = Db::name('maintain_baojia')->where('order_id',$id)->where('status',30)->order('id desc')->find();
- //更新订单
- //更新报价记录
- if($status == 2){
- $update = [
- 'status' => 32, // '用户审核驳回',//等待再次报价
- 'updatetime' => time(),
- ];
- $update_baojia = [
- 'status' => 32, // '用户审核驳回',//等待再次报价
- 'updatetime' => time(),
- 'baojia_useraudit_time' => time(),
- 'baojia_useraudit_reason' => $reason,
- ];
- $remark = '报价已拒绝,即将重新报价';
- }else{
- $update = [
- 'status' => 40,
- 'updatetime' => time(),
- 'baojia_lasttime' => time(), //报价终审时间
- ];
- $update_baojia = [
- 'status' => 40,
- 'updatetime' => time(),
- 'baojia_useraudit_time' => time(),
- ];
- $remark = '报价已通过,即将指派师傅';
- }
- Db::startTrans();
- $rs1 = Db::name('maintain')->where('id',$id)->update($update);
- if($rs1 === false){
- Db::rollback();
- $this->error('审核失败');
- }
- $rs2 = Db::name('maintain_baojia')->where('id',$baojia_log['id'])->update($update_baojia);
- if($rs2 === false){
- Db::rollback();
- $this->error('审核失败');
- }
- Db::commit();
- $this->success($remark);
- }
- //验收
- public function yanshou(){
- }
- //评价
- public function evaluate(){
- $id = input('order_id',0);
- $eva_info = input('eva_info','');
- $eva_score = input('eva_score',5);
- //检查订单
- $map = [
- 'user_id' => $this->auth->id,
- 'id' => $id,
- ];
- $info = Db::name('maintain')->where($map)->find();
- if(empty($info)){
- $this->error('不存在的订单');
- }
- if($info['status'] != 100){
- $this->success('订单未验收通过,请刷新重试');
- }
- if($info['eva_time'] != 0){
- $this->success('订单已评价,无需重复评价');
- }
- //更新
- $update = [
- 'eva_info' => $eva_info,
- 'eva_score' => $eva_score,
- 'eva_time' => time(),
- ];
- $rs1 = Db::name('maintain')->where('id',$id)->update($update);
- //维保公司的平均分修改
- $this->success('评价完成');
- }
- //状态枚举
- private function status_data($status){
- $data = [
- 0 => '待报价', //等待初次报价 或 直接给指派师傅
- 2 => '已取消',
- 20 => '报价待审', //通过就去30,驳回就到22
- 22 => '报价审核驳回', //等待再次报价
- 30 => '用户待审', //通过就去40,驳回就到32
- 32 => '用户审核驳回',//等待再次报价
- 40 => '待指派', //报价都审核过了,可派师傅了
- 50 => '已选师傅',
- 60 => '材料已申请待领取',
- 70 => '材料已领取待上门', //待上门
- 80 => '已上门',
- 85 => '维修进度',
- 90 => '待验收',
- 92 => '验收驳回',//待二次上门
- 100 => '验收通过已完成',
- ];
- return $data[$status];
- }
- }
|