瀏覽代碼

[智价云] 采集规格处理更新

tangyuanwang 22 小時之前
父節點
當前提交
0599ca9790
共有 1 個文件被更改,包括 17 次插入17 次删除
  1. 17 17
      app/Http/Controllers/Manager/Collect/Product.php

+ 17 - 17
app/Http/Controllers/Manager/Collect/Product.php

@@ -47,7 +47,7 @@ class Product extends Controller
         if (is_numeric($platforms) || $platforms) {
             $ProductModel = $ProductModel
                 ->where(function ($query) use ($platforms) {
-                    $platforms = explode(',',$platforms);
+                    $platforms = explode(',', $platforms);
                     foreach ($platforms as $platform) {
                         $query->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
                     }
@@ -255,7 +255,7 @@ class Product extends Controller
         if ($all_data['sampling_end_time']  && $all_data['sampling_end_time'] < time()) return json_send(['code' => 'error', 'msg' => '采集结束时间必须大于当前时间']);
 
         $platform_string = $all_data['platform'];
-        if(empty($platform_string)) return json_send(['code' => 'error', 'msg' => '平台不能为空']);
+        if (empty($platform_string)) return json_send(['code' => 'error', 'msg' => '平台不能为空']);
         $enable_full_quantity = request('enable_full_quantity', 0); //全量,0启用,1禁用
         $all_data['enable_full_quantity'] = $enable_full_quantity;
         if (trim($product_keyword) != '') {
@@ -264,12 +264,12 @@ class Product extends Controller
                 return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
             }
         }
-        if($enable_full_quantity == 1 && $all_data['product_specs'] == ''){
+        if ($enable_full_quantity == 1 && $all_data['product_specs'] == '') {
             return json_send(['code' => 'error', 'msg' => '非全量采集,商品规格不能为空']);
         }
         //查询是否存在
         $map = ['product_name' => $all_data['product_name']];
-        if($product_brand != '') $map['product_brand'] = $product_brand;
+        if ($product_brand != '') $map['product_brand'] = $product_brand;
         if ($is_admin != 1 && $company_id != 0) {
             $map['company_id'] = $company_id;
             $all_data['company_id'] = $company_id;
@@ -284,14 +284,14 @@ class Product extends Controller
             $product_specs = $product_specs_tring ?  explode(',', $product_specs_tring) : '';
             $product_specs = $product_specs ? array_unique($product_specs) : '';
             //继续校平台是否存在
-           
+
             $platforms = $platform_string ?  explode(',', $platform_string) : '';
             $platforms = $platforms ? array_unique($platforms) : '';
 
             $platform_data = $ProductModel->platform_index_data();
-            $map_where = ['product_name' => $all_data['product_name'],'status'=>'0','company_id'=> $all_data['company_id']];
+            $map_where = ['product_name' => $all_data['product_name'], 'status' => '0', 'company_id' => $all_data['company_id']];
             if ($product_brand != '') $map_where['product_brand'] = $product_brand;
-            if (!empty($platforms) && $platforms != '')  {
+            if (!empty($platforms) && $platforms != '') {
                 foreach ($platforms as $platform) {
                     $product_specs_log = $ProductModel
                         ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
@@ -313,7 +313,6 @@ class Product extends Controller
                     }
                 }
             }
-            
         }
         // 写入数据表
         $result     =  $ProductModel->addProduct($all_data);
@@ -365,7 +364,7 @@ class Product extends Controller
         if ($all_data['sampling_end_time']  && $all_data['sampling_end_time'] < time()) return json_send(['code' => 'error', 'msg' => '采集结束时间必须大于当前时间']);
 
         $platform_string = $all_data['platform'];
-        if(empty($platform_string)) return json_send(['code' => 'error', 'msg' => '平台不能为空']);
+        if (empty($platform_string)) return json_send(['code' => 'error', 'msg' => '平台不能为空']);
         $enable_full_quantity = request('enable_full_quantity', 0); //全量,0启用,1禁用
         $all_data['enable_full_quantity'] = $enable_full_quantity;
         if (trim($product_keyword) != '') {
@@ -374,7 +373,7 @@ class Product extends Controller
                 return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
             }
         }
-        if($enable_full_quantity == 1 && $all_data['product_specs'] == ''){
+        if ($enable_full_quantity == 1 && $all_data['product_specs'] == '') {
             return json_send(['code' => 'error', 'msg' => '非全量采集,商品规格不能为空']);
         }
         //查询是否存在
@@ -498,19 +497,20 @@ class Product extends Controller
                     ->where(function ($query) use ($product_specs) {
                         // 平台条件(固定)
                         $query->where(function ($query_li) use ($product_specs) {
-
+                            if (!empty($product_specs)) {
                                 foreach ($product_specs as $product_spec) {
                                     if (empty($product_specs)) continue;
                                     $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
                                 }
-                            });
-                        })->first();
-                    $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
-                    if (!empty($product_specs_log)) {
-                        return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格启用记录']);
-                    }
+                            }
+                        });
+                    })->first();
+                $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
+                if (!empty($product_specs_log)) {
+                    return json_send(['code' => 'error', 'msg' => $platform_name . '存在重复的商品规格启用记录']);
                 }
             }
+        }
         // 执行修改
         $result            =  $ProductModel->changeStatus($Product, $status);
         // 提示新增失败