Ver Fonte

更新师傅的进行工单数量

whitefang há 1 ano atrás
pai
commit
d868639c27

+ 3 - 1
app/api/logic/ServiceOrderLogic.php

@@ -370,7 +370,6 @@ class ServiceOrderLogic extends BaseLogic
                 throw new Exception('订单不存在');
             }
 
-            //更新工单状态为已取消
             $service_work = ServiceWork::find($work_id);
             if($service_work->user_confirm_status!=3){
                 throw new Exception('请勿重复操作');
@@ -398,6 +397,9 @@ class ServiceOrderLogic extends BaseLogic
             }
             $service_work->save();
 
+            //更新师傅的进行工单数量
+            MasterWorker::setWorktotal('dec',$service_work->master_worker_id);
+
             $work_log = [
                 'work_id'=>$work_id,
                 'master_worker_id'=>$service_work->master_worker_id,

+ 19 - 0
app/common/model/master_worker/MasterWorker.php

@@ -60,4 +60,23 @@ class MasterWorker extends BaseModel
 
     }
 
+    /**
+     * @param $type [inc=新增,dec=减少]
+     * @param $worker_id
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function setWorktotal($type,$worker_id)
+    {
+        $worker = MasterWorker::find($worker_id);
+        if($type == 'inc'){
+            $worker->inc('work_total',1)->save();
+        }else{
+            $work_total = $worker->work_total == 0?0:1;
+            $worker->dec('work_total',$work_total)->save();
+        }
+    }
+
 }