소스 검색

[智价云] 采集更新

tangyuanwang 1 일 전
부모
커밋
597d071fe9
1개의 변경된 파일76개의 추가작업 그리고 12개의 파일을 삭제
  1. 76 12
      app/Http/Controllers/Manager/Collect/Product.php

+ 76 - 12
app/Http/Controllers/Manager/Collect/Product.php

@@ -266,6 +266,8 @@ class Product extends Controller
         $all_data['sampling_start_time'] = $sampling_start_time ? strtotime($sampling_start_time . '00:00:00') : '0';
         $all_data['sampling_end_time'] = $sampling_end_time ? strtotime($sampling_end_time . '23:59:59') : '0';
         $all_data['minimum_order_quantity'] = $minimum_order_quantity;
+        $sampling_start_time = $all_data['sampling_start_time'];
+        $sampling_end_time = $all_data['sampling_end_time'];
 
         if (is_numeric($round_number) && $round_number > 3) return json_send(['code' => 'error', 'msg' => '轮次数量不能超过3']);
         if ($all_data['sampling_start_time']  && strtotime(date('Y-m-d', $all_data['sampling_start_time']) . '23:59:59') < time()) return json_send(['code' => 'error', 'msg' => '采集开始时间必须大于当前时间']);
@@ -310,7 +312,7 @@ class Product extends Controller
             foreach ($platforms as $platform) {
                 // 修正:将 orWhereRaw 改为 orWhere,并传入闭包
                 $product_specs_log = $ProductModel
-                    ->orWhere(function ($querys) use ($product_specs, $platform, $Product) {
+                    ->orWhere(function ($querys) use ($product_specs, $platform, $Product, $sampling_start_time) {
                         $querys->whereRaw("FIND_IN_SET(?, platform)", [$platform])
                             ->where([
                                 'product_brand' => $Product->product_brand,
@@ -330,10 +332,30 @@ class Product extends Controller
                             });
                         //记录的开始跟结束时间是否在当前记录的采集开始时间结束时间之内
                         if ($Product->sampling_start_time > 0 && $Product->sampling_end_time > 0) {
-                            $querys->where(function ($query_li) use ($Product) {
-                                $query_li->where('sampling_start_time', '<=', $Product->sampling_start_time)
-                                    ->where('sampling_end_time', '>=', $Product->sampling_end_time);
+                            $querys->where('sampling_start_time', '>=', $sampling_start_time)->where('sampling_start_time', '<=', $sampling_start_time);
+                        }
+                    })
+                    ->orWhere(function ($querys) use ($product_specs, $platform, $Product, $sampling_end_time) {
+                        $querys->whereRaw("FIND_IN_SET(?, platform)", [$platform])
+                            ->where([
+                                'product_brand' => $Product->product_brand,
+                                'product_name' => $Product->product_name,
+                                'status' => '0',
+                                'company_id' => $Product->company_id
+                            ])
+                            ->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_spec)) continue;
+                                            $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
+                                        }
+                                    }
+                                });
                             });
+                        //记录的开始跟结束时间是否在当前记录的采集开始时间结束时间之内
+                        if ($Product->sampling_start_time > 0 && $Product->sampling_end_time > 0) {
+                            $querys->where('sampling_end_time', '>=', $sampling_end_time)->where('sampling_end_time', '<=', $sampling_end_time);
                         }
                     })
                     ->orWhere(function ($querys) use ($product_specs, $platform, $Product) {
@@ -421,6 +443,8 @@ class Product extends Controller
         $all_data['sampling_start_time'] = $sampling_start_time ? strtotime($sampling_start_time . '00:00:00') : '0';
         $all_data['sampling_end_time'] = $sampling_end_time ? strtotime($sampling_end_time . '23:59:59') : '0';
         $all_data['minimum_order_quantity'] = $minimum_order_quantity;
+        $sampling_start_time = $all_data['sampling_start_time'];
+        $sampling_end_time = $all_data['sampling_end_time'];
 
         if (is_numeric($round_number) && $round_number > 3) return json_send(['code' => 'error', 'msg' => '轮次数量不能超过3']);
         if ($all_data['sampling_start_time']  && strtotime(date('Y-m-d', $all_data['sampling_start_time']) . '23:59:59') < time()) return json_send(['code' => 'error', 'msg' => '采集开始时间必须大于当前时间']);
@@ -463,7 +487,7 @@ class Product extends Controller
             foreach ($platforms as $platform) {
                 // 修正:将 orWhereRaw 改为 orWhere,并传入闭包
                 $product_specs_log = $ProductModel
-                    ->orWhere(function ($querys) use ($product_specs, $platform, $Product) {
+                    ->orWhere(function ($querys) use ($product_specs, $platform, $Product, $sampling_start_time) {
                         $querys->whereRaw("FIND_IN_SET(?, platform)", [$platform])
                             ->where([
                                 'product_brand' => $Product->product_brand,
@@ -471,7 +495,6 @@ class Product extends Controller
                                 'status' => '0',
                                 'company_id' => $Product->company_id
                             ])
-                            ->where('id', '!=', $Product->id)
                             ->where(function ($query) use ($product_specs) {
                                 $query->where(function ($query_li) use ($product_specs) {
                                     if (!empty($product_specs)) {
@@ -484,10 +507,30 @@ class Product extends Controller
                             });
                         //记录的开始跟结束时间是否在当前记录的采集开始时间结束时间之内
                         if ($Product->sampling_start_time > 0 && $Product->sampling_end_time > 0) {
-                            $querys->where(function ($query_li) use ($Product) {
-                                $query_li->where('sampling_start_time', '<=', $Product->sampling_start_time)
-                                    ->where('sampling_end_time', '>=', $Product->sampling_end_time);
+                            $querys->where('sampling_start_time', '>=', $sampling_start_time)->where('sampling_start_time', '<=', $sampling_start_time);
+                        }
+                    })
+                    ->orWhere(function ($querys) use ($product_specs, $platform, $Product, $sampling_end_time) {
+                        $querys->whereRaw("FIND_IN_SET(?, platform)", [$platform])
+                            ->where([
+                                'product_brand' => $Product->product_brand,
+                                'product_name' => $Product->product_name,
+                                'status' => '0',
+                                'company_id' => $Product->company_id
+                            ])
+                            ->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_spec)) continue;
+                                            $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
+                                        }
+                                    }
+                                });
                             });
+                        //记录的开始跟结束时间是否在当前记录的采集开始时间结束时间之内
+                        if ($Product->sampling_start_time > 0 && $Product->sampling_end_time > 0) {
+                            $querys->where('sampling_end_time', '>=', $sampling_end_time)->where('sampling_end_time', '<=', $sampling_end_time);
                         }
                     })
                     ->orWhere(function ($querys) use ($product_specs, $platform, $Product) {
@@ -617,10 +660,31 @@ class Product extends Controller
                             });
                         //记录的开始跟结束时间是否在当前记录的采集开始时间结束时间之内
                         if ($Product->sampling_start_time > 0 && $Product->sampling_end_time > 0) {
-                            $querys->where(function ($query_li) use ($Product) {
-                                $query_li->where('sampling_start_time', '<=', $Product->sampling_start_time)
-                                    ->where('sampling_end_time', '>=', $Product->sampling_end_time);
+                            $querys->where('sampling_start_time', '>=', $Product->sampling_start_time)->where('sampling_end_time', '<=', $Product->sampling_start_time);
+                        }
+                    })
+                    ->orWhere(function ($querys) use ($product_specs, $platform, $Product) {
+                        $querys->whereRaw("FIND_IN_SET(?, platform)", [$platform])
+                            ->where([
+                                'product_brand' => $Product->product_brand,
+                                'product_name' => $Product->product_name,
+                                'status' => '0',
+                                'company_id' => $Product->company_id
+                            ])
+                            ->where('id', '!=', $Product->id)
+                            ->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_spec)) continue;
+                                            $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
+                                        }
+                                    }
+                                });
                             });
+                        //记录的开始跟结束时间是否在当前记录的采集开始时间结束时间之内
+                        if ($Product->sampling_start_time > 0 && $Product->sampling_end_time > 0) {
+                            $querys->where('sampling_end_time', '>=', $Product->sampling_end_time)->where('sampling_end_time', '<=', $Product->sampling_end_time);
                         }
                     })
                     ->orWhere(function ($querys) use ($product_specs, $platform, $Product) {