lizhen_gitee hai 7 meses
pai
achega
57deb1224c

+ 5 - 28
application/api/controller/Maintain.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use app\common\model\Maintain as Maintainmodel;
 use think\Db;
 /**
  * 保修
@@ -64,9 +65,10 @@ class Maintain extends Api
         if(!empty($list)){
             $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');//负责人的电话
 
+            $maintain_model = new Maintainmodel();
             foreach($list as $key => $val){
                 $list[$key]['header_mobile'] = $header_mobile;
-                $list[$key]['status_text'] = $this->status_data($val['status']);
+                $list[$key]['status_text'] = $maintain_model->status_data($val['status']);
             }
         }
 
@@ -85,7 +87,8 @@ class Maintain extends Api
             ->where($map)
             ->find();
 
-        $info['status_text'] = $this->status_data($info['status']);
+        $maintain_model = new Maintainmodel();
+        $info['status_text'] = $maintain_model->status_data($info['status']);
 
         $header_mobile = Db::name('user_company')->where('user_id',$this->auth->id)->value('header_mobile');//负责人的电话
         $info['header_mobile'] = $header_mobile;
@@ -144,8 +147,6 @@ class Maintain extends Api
         //找出最新报价日志
         $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);
     }
 
@@ -264,31 +265,7 @@ class Maintain extends Api
         $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];
-    }
 
 
 }

+ 187 - 23
application/api/controller/worker/Maintain.php

@@ -3,6 +3,7 @@
 namespace app\api\controller\worker;
 
 use app\common\controller\Api;
+use app\common\model\Maintain as Maintainmodel;
 use think\Db;
 /**
  * 保修
@@ -26,8 +27,9 @@ class Maintain extends Api
             ->autopage()->select();
         if(!empty($list)){
 
+            $maintain_model = new Maintainmodel();
             foreach($list as $key => $val){
-                $list[$key]['status_text'] = $this->status_data($val['status']);
+                $list[$key]['status_text'] = $maintain_model->status_data($val['status']);
             }
         }
 
@@ -46,7 +48,8 @@ class Maintain extends Api
             ->where($map)
             ->find();
 
-        $info['status_text'] = $this->status_data($info['status']);
+        $maintain_model = new Maintain();
+        $info['status_text'] = $maintain_model->status_data($info['status']);
 
 
         //追加进度
@@ -162,43 +165,204 @@ class Maintain extends Api
     //////////////////////////////循环开始///////////////////////
     //立即上门
     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'],[50,70])){
+            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' => time(),
+            'shangmen_time' => time(), //上门时间
+            'weixiu_times' => $weixiu['weixiu_times'],
+            'weixiu_id' => $weixiu_id,
+        ];
+        $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')->insertAll($jindu);
+        if(!$id){
+            $this->error('操作失败');
+        }
+
+        $this->success('操作成功');
     }
+
     //确认完成
     public function finish(){
+        $order_id = input('order_id',0);
 
-    }
-    //////////////////////////////循环结束///////////////////////
+        Db::startTrans();
 
-    //状态枚举
-    private function status_data($status){
-        $data = [
-            0  => '待报价',  //等待初次报价 或 直接给指派师傅
-                2  => '已取消',
+        //订单
+        $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, //待验收
 
-            20 => '报价待审',      //通过就去30,驳回就到22
-                22 => '报价审核驳回',   //等待再次报价
-            30 => '用户待审',   //通过就去40,驳回就到32
-                32 => '用户审核驳回',//等待再次报价
-            40 => '待指派',        //报价都审核过了,可派师傅了
-            50 => '已选师傅',
-            60 => '材料已申请待领取',
-            70 => '材料已领取待上门', //待上门
+            '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('操作失败,重试一下吧');
+        }
 
-            80 => '已上门',
-            85 => '维修进度',
-            90 => '待验收',
-                92 => '验收驳回',//待二次上门
+        //最后一个轮回,最后一个进度
+        $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('操作失败,重试一下吧');
+        }
 
-            100 => '验收通过已完成',
+        //修改订单
+        $update = [
+            'status' => 90,
+            'wancheng_time' => $nowtime,
+            'updatetime'    => $nowtime,
         ];
-        return $data[$status];
+        $rs2 = Db::name('maintain')->where('id',$order_id)->update($update);
+        if($rs2 === false){
+            Db::rollback();
+            $this->error('操作失败,重试一下吧');
+        }
+
+        Db::commit();
+        $this->success('操作成功');
     }
+    //////////////////////////////循环结束///////////////////////
+
+
 
 
 }

+ 51 - 0
application/common/model/Maintain.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 维修订单模型
+ */
+class Maintain extends Model
+{
+
+    // 表名
+    protected $name = 'maintain';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    // 追加属性
+    protected $append = [
+    ];
+
+
+    //状态枚举
+    public function status_data($status){
+        $data = [
+            0  => '待报价',  //等待初次报价 或 直接给指派师傅
+            2  => '已取消',
+
+
+            20 => '报价待审',      //通过就去30,驳回就到22
+            22 => '报价审核驳回',   //等待再次报价
+            30 => '用户待确认',   //通过就去40,没有驳回
+            40 => '待指派',        //报价都审核过了,可派师傅了
+            50 => '已选师傅',
+            60 => '材料已申请待领取',
+            70 => '材料已领取待上门', //待上门
+
+            80 => '已上门',
+            90 => '已完成待验收',
+            92 => '验收驳回',//待二次上门
+
+            100 => '验收通过已完成',
+        ];
+        return $data[$status];
+    }
+
+
+}

+ 1 - 1
application/extra/upload.php

@@ -17,7 +17,7 @@ return [
     /**
      * 最大可上传大小
      */
-    'maxsize'   => '10mb',
+    'maxsize'   => '50mb',
     /**
      * 可上传的文件类型
      */