cqpCow 2 роки тому
батько
коміт
05f9faeba3
1 змінених файлів з 24 додано та 3 видалено
  1. 24 3
      app/Service/FinishedOrderService.php

+ 24 - 3
app/Service/FinishedOrderService.php

@@ -181,6 +181,7 @@ class FinishedOrderService extends Service
 
             //反写数量
             $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
+            $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'));
             DB::commit();
         }catch (\Exception $e){
             DB::rollBack();
@@ -248,7 +249,7 @@ class FinishedOrderService extends Service
         if($this->isEmpty($data,'finish_id') && $this->isEmpty($data,'team_id')) return [false,'人员和班组不能都为空!'];
 
         $bool = DispatchSub::whereIn('id',$data['id'])->where('job_status',1)->exists();
-//        if($bool) return [false,'正在队列中,请不要重复操作!'];
+        if($bool) return [false,'正在队列中,请不要重复操作!'];
 
         $result = DispatchSub::whereIn('id',$data['id'])
             ->select('id','finished_num','dispatch_quantity','out_order_no_time','process_id','dispatch_no','order_product_id','sale_orders_product_id','order_no','product_no','product_title','price','customer_name','technology_material','technology_name','wood_name')
@@ -372,7 +373,7 @@ class FinishedOrderService extends Service
         return $data;
     }
 
-    //反写写完工数量
+    //反写写完工数量(根据销售订单id)
     public function writeFinishedQuantity($sale_orders_product_id){
         if(empty($sale_orders_product_id)) return;
 
@@ -392,6 +393,26 @@ class FinishedOrderService extends Service
         }
     }
 
+    //反写写完工数量(根据生产订单id)
+    public function writeFinishedQuantityByOrdersProductId($order_product_id){
+        if(empty($order_product_id)) return;
+
+        $result = DispatchSub::where('del_time',0)
+            ->whereIn('order_product_id',$order_product_id)
+            ->select(DB::raw("sum(finished_num) as finished_num"),'order_product_id')
+            ->groupby('order_product_id')
+            ->pluck('finished_num','order_product_id')
+            ->toArray();
+
+        if(empty($result)) return;
+
+        foreach ($result as $key => $value){
+            OrdersProduct::where('id',$key)->update([
+                'finished_num' => $value
+            ]);
+        }
+    }
+
     public function mobileAdd($data,$user){
         //数据校验以及填充
         list($status,$msg,$count_arr) = $this->orderMobileRule($data);
@@ -533,7 +554,7 @@ class FinishedOrderService extends Service
 
             //反写数量
             $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
-
+            $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'));
             DB::commit();
             //本地数据写入结束-----------
         }catch (\Exception $e){