cqpCow 1 year ago
parent
commit
7e666e6c6d
1 changed files with 25 additions and 0 deletions
  1. 25 0
      app/Service/ConstructionService.php

+ 25 - 0
app/Service/ConstructionService.php

@@ -12,6 +12,7 @@ use App\Model\CustomerInfo;
 use App\Model\DeliveryNote;
 use App\Model\Depart;
 use App\Model\Employee;
+use App\Model\Product;
 use App\Model\SalesOrder;
 use App\Model\SalesOrderInfo;
 use App\Model\SalesOrderProductInfo;
@@ -682,7 +683,12 @@ class ConstructionService extends Service
         //分派的总社或分社
         $dispatch = $this->getDispatchData($data['data']);
 
+        //施工产品
+        $product_map = $this->getProduct($data['data']);
+
         foreach ($data['data'] as $key => $value){
+            $product_tmp = $product_map[$value['id']] ?? [];
+            $data['data'][$key]['product_detail'] = implode(',',$product_tmp);
             if(! empty($value['address1'])) {
                 $tmp = json_decode($value['address1'],true);
                 $tmp = implode(' ',$tmp);
@@ -721,6 +727,25 @@ class ConstructionService extends Service
         return $data;
     }
 
+    public function getProduct($data){
+        $search_id = array_column($data,'id');
+        if(empty($search_id)) return [];
+
+        $product = ConstructionProductInfo::where('del_time',0)
+            ->whereIn('construction_id',$search_id)
+            ->select('product_id','construction_id')
+            ->get()->toArray();
+        $product_map = Product::whereIn('id',array_unique(array_column($product,'product_id')))->pluck('title','id')->toArray();
+
+        $return = [];
+        foreach ($product as $value){
+            $product_tmp = $product_map[$value['product_id']] ?? "";
+            if($product_tmp) $return[$value['construction_id']][] = $product_tmp;
+        }
+
+        return $return;
+    }
+
     public function getDispatchData($data){
         $search_id = [];
         foreach ($data as $value){