ソースを参照

[智价云] 采集多规格配置

tangyuanwang 1 ヶ月 前
コミット
0b7513a26f

+ 16 - 0
app/Http/Controllers/Manager/Collect/Product.php

@@ -60,6 +60,9 @@ class Product extends Controller
         if (isset($result['data']) && count($result['data']) > 0) {
             foreach ($result['data'] as $key => $value) {
                 $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
+                $product_specs = isset($value['product_specs']) ?  explode(',', $value['product_specs']) : '';
+                //移除空数组
+                $result['data'][$key]['product_specs'] = array_filter($product_specs);
             }
         }
         // 加载模板
@@ -91,6 +94,9 @@ class Product extends Controller
         if (!$data)     return json_send(['code' => 'error', 'msg' => '记录不存在']);
 
         $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
+        $product_specs = isset($data->product_specs) ?  explode(',', $data->product_specs) : '';
+        //移除空数组
+        $data->product_specs = array_filter($product_specs);
         // 加载模板
         return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
     }
@@ -117,6 +123,11 @@ class Product extends Controller
         // 接收数据
         $all_data = request()->all();
         //采集信息配置
+        $enable_full_quantity = request('enable_full_quantity', 1);//全量,0启用,1禁用
+        $all_data['enable_full_quantity'] = $enable_full_quantity;
+        if($enable_full_quantity == 1 && !isset($all_data['product_specs'])){
+            return json_send(['code' => 'error', 'msg' => '非全量采集时,商品规格不能为空']);
+        }
         $minimum_order_quantity = request('minimum_order_quantity', 1);
         $sampling_cycle = request('sampling_cycle', '0');
         $sampling_start_time = request('sampling_start_time', '');
@@ -169,6 +180,11 @@ class Product extends Controller
         // 接收数据
         $all_data = request()->all();
         //采集信息配置
+        $enable_full_quantity = request('enable_full_quantity', 1);//全量,0启用,1禁用
+        $all_data['enable_full_quantity'] = $enable_full_quantity;
+        if($enable_full_quantity == 1 && !isset($all_data['product_specs'])){
+            return json_send(['code' => 'error', 'msg' => '非全量采集时,商品规格不能为空']);
+        }
         $minimum_order_quantity = request('minimum_order_quantity', 1);
         $sampling_cycle = request('sampling_cycle', '0');
         $sampling_start_time = request('sampling_start_time', '');

+ 2 - 2
app/Http/Requests/Manager/Collect/Product.php

@@ -43,8 +43,8 @@ class Product extends BaseRequest
     protected   $scenes         = [
         'detail'             => ['id'],
         'list'               => ['page', 'limit'],
-        'add'                      => ['platform','product_name', 'product_specs'],
-        'edit'                  => ['id','platform','product_name', 'product_specs'],
+        'add'                      => ['platform','product_name'],
+        'edit'                  => ['id','platform','product_name'],
         'set_status'              => ['id', 'status'],
         'delete'                  => ['id'],
     ];

+ 3 - 0
app/Models/Manager/Collect/Product.php

@@ -33,6 +33,7 @@ class Product extends Model
     public function addProduct_content($data)
     {
         $insert_data = [
+            'enable_full_quantity' => $data['enable_full_quantity'],
             'platform' => $data['platform'],
             'product_name' => $data['product_name'],
             'product_specs' => $data['product_specs'],
@@ -60,6 +61,7 @@ class Product extends Model
         DB::beginTransaction();
         try {
             $insert_data = [
+                'enable_full_quantity' => $data['enable_full_quantity'],
                 'platform' => $data['platform'],
                 'product_name' => $data['product_name'],
                 'product_specs' => $data['product_specs'],
@@ -94,6 +96,7 @@ class Product extends Model
     {
         DB::beginTransaction();
         try {
+            $Product->enable_full_quantity = $data['enable_full_quantity'];
             $Product->platform = $data['platform'];
             $Product->product_name = $data['product_name'];
             $Product->product_specs = $data['product_specs'];