cqpCow 1 năm trước cách đây
mục cha
commit
6eb8fa1293
1 tập tin đã thay đổi với 26 bổ sung2 xóa
  1. 26 2
      app/Service/ProductService.php

+ 26 - 2
app/Service/ProductService.php

@@ -415,11 +415,17 @@ class ProductService extends Service
             ->first();
         if(! empty($in)) $customer['introduction'] = $in->introduction;
 
+        $model = BasicType::TopClear($user,$data);
+        $basic = $model->where('del_time',0)
+            ->where('type',22)
+            ->select('title','id','type')
+            ->orderby('id', 'asc')->get()->toArray();
+
         $detail = ProductPriceDetail::where('del_time',0)
             ->where('product_id',$data['id'])
             ->select('product_id','basic_type_id','price')
             ->get()->toArray();
-        $title_map = BasicType::whereIn('id',array_column($detail,'basic_type_id'))
+        $title_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($detail,'basic_type_id'),array_column($basic,'id'))))
             ->pluck('title','id')
             ->toArray();
         //是否总公司
@@ -434,7 +440,7 @@ class ProductService extends Service
             }else{
                 $is_show = 1;
             }
-            $customer['product_price'][] = [
+            $customer['product_price'][$value['basic_type_id']] = [
                 'basic_type_id' => $value['basic_type_id'],
                 'basic_type_title' => $title_map[$value['basic_type_id']] ?? '',
                 'price' => $value['price'],
@@ -442,6 +448,24 @@ class ProductService extends Service
             ];
         }
 
+        foreach ($basic as $value){
+            if(! $is_main && ($top_depart['basic_type_id'] != $value['basic_type_id'])) {
+                $is_show = 0;
+            }else{
+                $is_show = 1;
+            }
+            if(! isset($customer['product_price'][$value['id']])){
+                $customer['product_price'][$value['id']] = [
+                    'basic_type_id' => $value['id'],
+                    'basic_type_title' => $title_map[$value['id']] ?? '',
+                    'price' => 0,
+                    'is_show' => $is_show,
+                ];
+            }
+        }
+
+        $customer['product_price'] = array_values($customer['product_price']);
+
         //单位
         $title = BasicType::where('id',$customer['unit'])->value('title');
         $customer['unit_name'] = $title;