소스 검색

[智价云] 采集品规统计更新

tangyuanwang 15 시간 전
부모
커밋
a250313195
2개의 변경된 파일100개의 추가작업 그리고 263개의 파일을 삭제
  1. 75 263
      app/Http/Controllers/Manager/Statistics/BasicPanel.php
  2. 25 0
      app/Models/Manager/Collect/ProductTask.php

+ 75 - 263
app/Http/Controllers/Manager/Statistics/BasicPanel.php

@@ -10,6 +10,7 @@ use App\Models\Manager\Process\ViolationStore as ViolationStoreModel;
 use App\Models\Manager\Collect\Product as ProductModel;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Carbon;
+use App\Models\Manager\Collect\ProductTask as ProductTaskModel;
 
 /**
  * 数据分析-基础概览面板
@@ -82,290 +83,101 @@ class BasicPanel extends Controller
             ->groupBy('store_name')
             ->select('store_name')
             ->get()->count();
+        //获取采集商品数量
+        $collect_statistics_data = $this->get_product_count($start_time, $end_time, $product_name, $is_admin, $company_id, $admin_company_id);
+        $result_data = [
+            'low_price_goods_count' => $lowPriceGoodsCount, // 低价挂网商品数量
+            'violation_product_count' => $violationProductCount, // 禁止挂网商品数量
+            'violation_store_count' => $violationStoreCount, // 违规店铺数量
+            'totle_product_count' => $lowPriceGoodsCount + $violationProductCount, // 总商品数量
+        ];
+        $result_data = array_merge($result_data, $collect_statistics_data);
 
-        //获取终端类型B端、C端、OTO,配置品规数量
-        $productModel = new ProductModel();
-        $productModel_map1 = [];
-        $productModel_map2 = [];
-        $productModel_map3 = [];
-        if ($start_time && $end_time) {
-            $productModel_map1[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map1[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map1[] = ['sampling_end_time', '<=', $end_time];
+        return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result_data]);
+    }
 
-            $productModel_map2[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map2[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map2[] = ['sampling_end_time', '>=', $end_time];
 
-            $productModel_map3[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map3[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map3[] = ['sampling_end_time', '=', '0'];
-        }
+    /**
+     * 品规数量统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2026-02-10
+     * 
+     */
+    private function get_product_count($start_time, $end_time, $product_name, $is_admin, $company_id, $admin_company_id)
+    {
+        $ProductTaskModel = new ProductTaskModel();
+        $select_company_id = 0;
         if ($is_admin != 1 && $company_id != 0) {
-            $productModel = $productModel->where('company_id', $company_id);
+            $select_company_id = $company_id;
         } else {
-            $productModel = $productModel->where('company_id', $admin_company_id);
+            $select_company_id = $admin_company_id;
         }
-
-        // 只有有查询条件时才构建复杂查询
-        $productModel = $productModel->where(function ($query) use ($productModel_map1, $productModel_map2, $productModel_map3, $start_time, $end_time) {
-            // 平台条件(固定)
-            $query->where(function ($query_li) {
-                $platforms = ['0', '5', '6', '7', '8', '9', '10'];
-                foreach ($platforms as $platform) {
-                    $query_li->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
-                }
-            });
-            $query->where('status', '0');
-            // 时间范围条件(OR)
-            if ($start_time && $end_time) {
-                $query->where(function ($subQuery) use ($productModel_map1, $productModel_map2, $productModel_map3) {
-                    if (!empty($productModel_map1)) {
-                        $subQuery->orWhere($productModel_map1);
-                    }
-                    if (!empty($productModel_map2)) {
-                        $subQuery->orWhere($productModel_map2);
-                    }
-                    if (!empty($productModel_map3)) {
-                        $subQuery->orWhere($productModel_map3);
-                    }
-                });
+        $map = [];
+        if ($start_time) $map[] = ['insert_time', '>=', $start_time];
+        if ($end_time) $map[]   = ['insert_time', '<=', $end_time];
+        if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
+        //获取B端品规数量
+        //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
+        $collect_b_product_count = 0;
+        $collect_b_product_list_data = $ProductTaskModel
+            ->where('platform', 'in', ['0', '5', '6', '7', '8', '9', '10'])//1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
+            ->where('company_id', $select_company_id)
+            ->where($map)
+            ->get()->toarray();
+        $collect_b_product_list =[];
+        if(!empty($collect_b_product_list_data)){
+            foreach ($collect_b_product_list_data as $key => $value) {
+                $collect_b_product_name = $value['product_name'];
+                $collect_b_product_specs = $value['product_specs'] !='' ? explode(',', $value['product_specs']) : [];
+                $collect_b_product_list[$collect_b_product_name][] = $collect_b_product_specs;
+                //去重$collect_b_product_list[$collect_b_product_name]数据
+                $collect_b_product_list[$collect_b_product_name] = array_unique($collect_b_product_list[$collect_b_product_name]);
             }
-        });
-
-        $productNames = $productModel
-            ->distinct('product_name')
-            ->pluck('product_name')
-            ->toArray();
-        $productModel = new ProductModel();
-        if ($is_admin != 1 && $company_id != 0) {
-            $productModel = $productModel->where('company_id', $company_id);
-        } else {
-            $productModel = $productModel->where('company_id', $admin_company_id);
-        }
-        $collect_b_product_count = $productModel
-            ->where(function ($query) use ($productModel_map1, $productModel_map2, $productModel_map3, $productNames, $start_time, $end_time) {
-                // 平台条件(固定)
-                $query->where(function ($query_li) {
-                    $platforms = ['0', '5', '6', '7', '8', '9', '10'];
-                    foreach ($platforms as $platform) {
-                        $query_li->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
-                    }
-                });
-                $query->where('status', '0');
-                $query->whereIn('product_name', $productNames);
-                // 时间范围条件(OR)
-                // 时间范围条件(OR)
-                if ($start_time && $end_time) {
-                    $query->where(function ($subQuery) use ($productModel_map1, $productModel_map2, $productModel_map3) {
-                        if (!empty($productModel_map1)) {
-                            $subQuery->orWhere($productModel_map1);
-                        }
-                        if (!empty($productModel_map2)) {
-                            $subQuery->orWhere($productModel_map2);
-                        }
-                        if (!empty($productModel_map3)) {
-                            $subQuery->orWhere($productModel_map3);
-                        }
-                    });
-                };
-            })->sum('product_specs_number');
-
-
-
-        //获取终端类型B端、C端、OTO,配置品规数量
-        $productModel = new ProductModel();
-        $productModel_map1 = [];
-        $productModel_map2 = [];
-        $productModel_map3 = [];
-        if ($start_time && $end_time) {
-            $productModel_map1[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map1[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map1[] = ['sampling_end_time', '<=', $end_time];
-
-            $productModel_map2[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map2[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map2[] = ['sampling_end_time', '>=', $end_time];
-
-            $productModel_map3[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map3[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map3[] = ['sampling_end_time', '=', '0'];
         }
-        if ($is_admin != 1 && $company_id != 0) {
-            $productModel = $productModel->where('company_id', $company_id);
-        } else {
-            $productModel = $productModel->where('company_id', $admin_company_id);
-        }
-
-        // 只有有查询条件时才构建复杂查询
-        $productModel = $productModel->where(function ($query) use ($productModel_map1, $productModel_map2, $productModel_map3, $start_time, $end_time) {
-            // 平台条件(固定)
-            $query->where(function ($query_li) {
-                $platforms = ['0', '1', '2', '3', '4', '11']; //C端:美团、拼多多、天猫、京东、药房网
-                foreach ($platforms as $platform) {
-                    $query_li->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
-                }
-            });
-            $query->where('status', '0');
-            // 时间范围条件(OR)
-            if ($start_time && $end_time) {
-                $query->where(function ($subQuery) use ($productModel_map1, $productModel_map2, $productModel_map3) {
-                    if (!empty($productModel_map1)) {
-                        $subQuery->orWhere($productModel_map1);
-                    }
-                    if (!empty($productModel_map2)) {
-                        $subQuery->orWhere($productModel_map2);
-                    }
-                    if (!empty($productModel_map3)) {
-                        $subQuery->orWhere($productModel_map3);
-                    }
-                });
+        //计算B端品规数量
+        if(!empty($collect_b_product_list)){
+            foreach ($collect_b_product_list as $key => $value) {
+                $collect_b_product_count = $collect_b_product_count + count($value);
             }
-        });
-        $productNames = $productModel
-            ->distinct('product_name')
-            ->pluck('product_name')
-            ->toArray();
-        $productModel = new ProductModel();
-        if ($is_admin != 1 && $company_id != 0) {
-            $productModel = $productModel->where('company_id', $company_id);
-        } else {
-            $productModel = $productModel->where('company_id', $admin_company_id);
         }
-        $collect_c_product_count = $productModel
-            ->where(function ($query) use ($productModel_map1, $productModel_map2, $productModel_map3, $productNames, $start_time, $end_time) {
-                // 平台条件(固定)
-                $query->where(function ($query_li) {
-                    $platforms = ['0', '1', '2', '3', '4', '11']; //C端:美团、拼多多、天猫、京东、药房网
-                    foreach ($platforms as $platform) {
-                        $query_li->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
-                    }
-                });
-                $query->where('status', '0');
-                $query->whereIn('product_name', $productNames);
-                // 时间范围条件(OR)
-                // 时间范围条件(OR)
-                if ($start_time && $end_time) {
-                    $query->where(function ($subQuery) use ($productModel_map1, $productModel_map2, $productModel_map3) {
-                        if (!empty($productModel_map1)) {
-                            $subQuery->orWhere($productModel_map1);
-                        }
-                        if (!empty($productModel_map2)) {
-                            $subQuery->orWhere($productModel_map2);
-                        }
-                        if (!empty($productModel_map3)) {
-                            $subQuery->orWhere($productModel_map3);
-                        }
-                    });
-                };
-            })->sum('product_specs_number');
-
-        //获取终端类型B端、C端、OTO,配置品规数量
-        $productModel = new ProductModel();
-        $productModel_map1 = [];
-        $productModel_map2 = [];
-        $productModel_map3 = [];
-        if ($start_time && $end_time) {
-            $productModel_map1[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map1[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map1[] = ['sampling_end_time', '<=', $end_time];
-
-            $productModel_map2[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map2[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map2[] = ['sampling_end_time', '>=', $end_time];
-
-            $productModel_map3[] = ['sampling_start_time', '>=', $start_time];
-            $productModel_map3[] = ['sampling_start_time', '<=', $end_time];
-            $productModel_map3[] = ['sampling_end_time', '=', '0'];
-        }
-        if ($is_admin != 1 && $company_id != 0) {
-            $productModel = $productModel->where('company_id', $company_id);
-        } else {
-            $productModel = $productModel->where('company_id', $admin_company_id);
+        //获取C端品规数量
+        //C端:美团、拼多多、天猫、京东、药房网
+        $collect_c_product_count = 0;
+        $collect_c_product_list_data = $ProductTaskModel
+            ->where('platform', 'in', ['0', '1', '2', '3', '4', '11'])//1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
+            ->where('company_id', $select_company_id)
+            ->where($map)
+            ->get()->toarray();
+        $collect_c_product_list =[];
+        if(!empty($collect_c_product_list_data)){
+            foreach ($collect_c_product_list_data as $key => $value) {
+                $collect_c_product_name = $value['product_name'];
+                $collect_c_product_specs = $value['product_specs'] !='' ? explode(',', $value['product_specs']) : [];
+                $collect_c_product_list[$collect_c_product_name][] = $collect_c_product_specs;
+                //去重$collect_c_product_list[$collect_c_product_name]数据
+                $collect_c_product_list[$collect_c_product_name] = array_unique($collect_c_product_list[$collect_c_product_name]);
+            }
         }
-
-        $productModel = $productModel->where(function ($query) use ($productModel_map1, $productModel_map2, $productModel_map3, $start_time, $end_time) {
-            // 平台条件(固定)
-            $query->where(function ($query_li) {
-                $platforms = ['0'];
-                foreach ($platforms as $platform) {
-                    $query_li->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
-                }
-            });
-            $query->where('status', '0');
-            // 时间范围条件(OR)
-            if ($start_time && $end_time) {
-                $query->where(function ($subQuery) use ($productModel_map1, $productModel_map2, $productModel_map3) {
-                    if (!empty($productModel_map1)) {
-                        $subQuery->orWhere($productModel_map1);
-                    }
-                    if (!empty($productModel_map2)) {
-                        $subQuery->orWhere($productModel_map2);
-                    }
-                    if (!empty($productModel_map3)) {
-                        $subQuery->orWhere($productModel_map3);
-                    }
-                });
+        //计算C端品规数量
+        if(!empty($collect_c_product_list)){
+            foreach ($collect_c_product_list as $key => $value) {
+                $collect_c_product_count = $collect_c_product_count + count($value);
             }
-        });
-        $productNames = $productModel
-            ->distinct('product_name')
-            ->pluck('product_name')
-            ->toArray();
-
-        $productModel = new ProductModel();
-        if ($is_admin != 1 && $company_id != 0) {
-            $productModel = $productModel->where('company_id', $company_id);
-        } else {
-            $productModel = $productModel->where('company_id', $admin_company_id);
         }
-        $collect_oto_product_count = $productModel
-            ->where(function ($query) use ($productModel_map1, $productModel_map2, $productModel_map3, $productNames, $start_time, $end_time) {
-                // 平台条件(固定)
-                $query->where(function ($query_li) {
-                    $platforms = ['0'];
-                    foreach ($platforms as $platform) {
-                        $query_li->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
-                    }
-                });
-                $query->where('status', '0');
-                $query->whereIn('product_name', $productNames);
-                // 时间范围条件(OR)
-                // 时间范围条件(OR)
-                if ($start_time && $end_time) {
-                    $query->where(function ($subQuery) use ($productModel_map1, $productModel_map2, $productModel_map3) {
-                        if (!empty($productModel_map1)) {
-                            $subQuery->orWhere($productModel_map1);
-                        }
-                        if (!empty($productModel_map2)) {
-                            $subQuery->orWhere($productModel_map2);
-                        }
-                        if (!empty($productModel_map3)) {
-                            $subQuery->orWhere($productModel_map3);
-                        }
-                    });
-                };
-            })->sum('product_specs_number');
-
-
-
-        // 所有终端品规数量
-        $collect_totle_product_count = $collect_b_product_count + $collect_c_product_count + $collect_oto_product_count;
+        //获取所有终端品规数量
+        $collect_totle_product_count = $collect_b_product_count + $collect_c_product_count;
 
         $result_data = [
-            'low_price_goods_count' => $lowPriceGoodsCount, // 低价挂网商品数量
-            'violation_product_count' => $violationProductCount, // 禁止挂网商品数量
-            'violation_store_count' => $violationStoreCount, // 违规店铺数量
-            'totle_product_count' => $lowPriceGoodsCount + $violationProductCount, // 总商品数量
             'collect_b_product_count' => $collect_b_product_count, // B端品规数量
             'collect_c_product_count' => $collect_c_product_count, // C端品规数量
-            'collect_oto_product_count' => $collect_oto_product_count, // OTO品规数量
+            'collect_oto_product_count' => 0, // OTO品规数量
             'collect_totle_product_count' => $collect_totle_product_count, // 所有终端品规数量
         ];
-
-        return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result_data]);
+        return $result_data;
     }
 
+
     /**
      * 禁止挂网商品数统计
      * @author 唐远望

+ 25 - 0
app/Models/Manager/Collect/ProductTask.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Models\Manager\Collect;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 采集产品任务分配模型
+ * @author: 唐远望
+ * @version: 1.0
+ * @date: 2026-04-17
+ */
+class ProductTask extends Model
+{
+    use HasFactory;
+    // 与模型关联的表名
+    protected $table = 'collect_task';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+}