ソースを参照

[智价云] 状态校验更新

tangyuanwang 1 日 前
コミット
1c7cb5747e
1 ファイル変更35 行追加2 行削除
  1. 35 2
      app/Http/Controllers/Manager/Collect/Product.php

+ 35 - 2
app/Http/Controllers/Manager/Collect/Product.php

@@ -287,7 +287,7 @@ class Product extends Controller
             foreach ($platforms as $platform) {
                 $product_specs_log = $ProductModel
                     ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
-                    ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name']])
+                    ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name'],'status'=>'0'])
                     ->where(function ($query) use ($product_specs) {
                         // 平台条件(固定)
                         $query->where(function ($query_li) use ($product_specs) {
@@ -385,7 +385,7 @@ class Product extends Controller
             foreach ($platforms as $platform) {
                 $product_specs_log = $ProductModel
                     ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
-                    ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name']])
+                    ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name'],'status'=>'0'])
                     ->where('id', '!=', $id)
                     ->where(function ($query) use ($product_specs) {
                         // 平台条件(固定)
@@ -460,6 +460,39 @@ class Product extends Controller
         }
         $Product = $ProductModel->where($where)->first();
         if (!$Product) return json_send(['code' => 'error', 'msg' => '记录不存在']);
+        if (!empty($Product)) {
+            //继续校验规格是否存在
+            $product_specs_tring = $Product->product_specs;
+            $product_specs = $product_specs_tring ?  explode(',', $product_specs_tring) : '';
+            $product_specs = $product_specs ? array_unique($product_specs) : '';
+            //继续校平台是否存在
+
+            $platform_string = $Product->platform;
+            $platforms = $platform_string ?  explode(',', $platform_string) : '';
+            $platforms = $platforms ? array_unique($platforms) : '';
+
+            $platform_data = $ProductModel->platform_data();
+            foreach ($platforms as $platform) {
+                $product_specs_log = $ProductModel
+                    ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
+                    ->where(['product_brand' => $Product->product_brand, 'product_name' => $Product->product_name,'status'=>'0'])
+                    ->where('id', '!=', $id)
+                    ->where(function ($query) use ($product_specs) {
+                        // 平台条件(固定)
+                        $query->where(function ($query_li) use ($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.'存在重复的商品规格启用记录']);
+                }
+            }
+        }
         // 执行修改
         $result            =  $ProductModel->changeStatus($Product, $status);
         // 提示新增失败