Răsfoiți Sursa

[智价云] 基础报表统计

tangyuanwang 1 lună în urmă
părinte
comite
191c84c061

+ 277 - 0
app/Http/Controllers/Manager/Statistics/BasicPanel.php

@@ -0,0 +1,277 @@
+<?php
+
+namespace App\Http\Controllers\manager\Statistics;
+
+use App\Http\Controllers\Controller;
+use App\Http\Requests\Manager\Statistics\BasicPanel as request;
+use App\Models\Manager\Process\LowPriceGoods as LowPriceGoodsModel;
+use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
+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;
+
+/**
+ * 报表统计-基础概览面板
+ * @author 唐远望
+ * @version   1.0
+ * @date      2026-02-10
+ * 
+ */
+class BasicPanel extends Controller
+{
+
+    /*
+     * 挂网数据统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2026-02-10
+     * 
+     */
+    public function get_online_goods_count(request $request, LowPriceGoodsModel $lowPriceGoodsModel, ViolationProductModel $violationProductModel, ViolationStoreModel $violationStoreModel, ProductModel $productModel)
+    {
+        $request->scene('get_online_goods_count')->validate();
+        $admin_company_id = request('admin_company_id', '0');
+        $company_id = request('access_token.company_id', '0');
+        $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
+        $start_time_string = request('start_time', '');
+        $end_time_string = request('end_time', '');
+        $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
+        $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
+        $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
+        if ($start_time > $todayStart || $end_time > $todayStart) return  json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
+
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', $start_time];
+        if ($end_time) $map[]   = ['insert_time', '<=', $end_time];
+
+        // 统计挂网商品数量=低价挂网商品数量(去重)+ 禁止挂网商品数量(去重)
+        $lowPriceGoodsModel = $lowPriceGoodsModel->query();
+        $violationProductModel = $violationProductModel->query();
+
+        if ($is_admin != 1 && $company_id != 0) {
+            $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $company_id);
+            $violationProductModel = $violationProductModel->where('company_id', $company_id);
+        } else {
+            $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $admin_company_id);
+            $violationProductModel = $violationProductModel->where('company_id', $admin_company_id);
+        }
+
+        // 低价挂网商品数量查询
+        $lowPriceGoodsCount = $lowPriceGoodsModel->where($map)
+            ->where('status', 0)
+            ->groupBy('product_name')
+            ->count(DB::raw('DISTINCT product_name'));
+
+        // 禁止挂网商品数量查询
+        $violationProductCount = $violationProductModel->where($map)
+            ->where('status', 0)
+            ->groupBy('product_name')
+            ->count(DB::raw('DISTINCT product_name'));
+
+        // 违规店铺数量查询
+        $violationStoreCount = $violationStoreModel->where($map)
+            ->where('status', 0)
+            ->groupBy('company_name')
+            ->count(DB::raw('DISTINCT company_name'));
+
+        //获取终端类型B端、C端、OTO,配置品规数量
+        $collect_b_product_count = $productModel->whereIn('platform', ['5', '6', '7', '8', '9', '10'])->where('status', 0)->count();
+        $collect_c_product_count = $productModel->whereIn('platform', ['1', '2', '3', '4'])->where('status', 0)->count();
+        $collect_oto_product_count = $productModel->whereIn('platform', [])->where('status', 0)->count();
+
+        // 所有终端品规数量
+        $collect_totle_product_count = $collect_b_product_count + $collect_c_product_count + $collect_oto_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_totle_product_count' => $collect_totle_product_count, // 所有终端品规数量
+        ];
+
+        return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result_data]);
+    }
+
+    /**
+     * 禁止挂网商品数统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2026-02-10
+     * 
+     */
+    public function get_violation_product_count(request $request, ViolationProductModel $violationProductModel)
+    {
+        $request->scene('get_violation_product_count')->validate();
+        $admin_company_id = request('admin_company_id', '0');
+        //终端类型B端、C端、OTO
+        $terminal_type = request('terminal_type', '');
+        $company_id = request('access_token.company_id', '0');
+        $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
+        $limit = request('limit', config('page_num', 10));
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
+        $start_time_string = request('start_time', '');
+        $end_time_string = request('end_time', '');
+        $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
+        $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
+        $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
+        if ($start_time > $todayStart || $end_time > $todayStart) return  json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', $start_time];
+        if ($end_time) $map[]   = ['insert_time', '<=', $end_time];
+        // 权限判断
+        if ($is_admin != 1 && $company_id != 0) {
+            $map[] = ['company_id', '=', $company_id];
+        } else {
+            $map[] = ['company_id', '=', $admin_company_id];
+        }
+        $violationProductModel = $violationProductModel->query();
+        if ($terminal_type) {
+            $platform = [];
+            switch ($terminal_type) {
+                case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
+                    $platform = ['5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
+                    break;
+                case '2': //C端:美团、拼多多、天猫、京东
+                    $platform = ['1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
+                    break;
+                case '3': //OTO:美团买药、淘宝闪送、京东秒送
+                    $platform = [];
+                    break;
+                default:
+                    # code...
+                    break;
+            }
+            $violationProductModel = $violationProductModel->whereIn('platform_id', $platform);
+        }
+        $result = $violationProductModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
+            ->groupby('company_name')->paginate($limit);
+        return  json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+    /**
+     * 禁止挂网公司数统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2026-02-10
+     * 
+     */
+    public function get_violation_company_count(request $request, ViolationProductModel $violationProductModel)
+    {
+        $request->scene('get_violation_company_count')->validate();
+        $admin_company_id = request('admin_company_id', '0');
+        $company_id = request('access_token.company_id', '0');
+        $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
+        $limit = request('limit', config('page_num', 10));
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
+        $start_time_string = request('start_time', '');
+        $end_time_string = request('end_time', '');
+        $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
+        $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
+        $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
+        if ($start_time > $todayStart || $end_time > $todayStart) return  json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', $start_time];
+        if ($end_time) $map[]   = ['insert_time', '<=', $end_time];
+        // 权限判断
+        if ($is_admin != 1 && $company_id != 0) {
+            $map[] = ['company_id', '=', $company_id];
+        } else {
+            $map[] = ['company_id', '=', $admin_company_id];
+        }
+        $result = $violationProductModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
+            ->paginate($limit);
+        return  json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+
+
+    /*
+     * 低价违规商品数统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2026-02-10
+     * 
+     */
+    public function get_low_price_product_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
+    {
+        $request->scene('get_low_price_product_count')->validate();
+        $admin_company_id = request('admin_company_id', '0');
+        $company_id = request('access_token.company_id', '0');
+        $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
+        $limit = request('limit', config('page_num', 10));
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
+        $start_time_string = request('start_time', '');
+        $end_time_string = request('end_time', '');
+        $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
+        $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
+        $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
+        if ($start_time > $todayStart || $end_time > $todayStart) return  json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', $start_time];
+        if ($end_time) $map[]   = ['insert_time', '<=', $end_time];
+        // 权限判断
+        if ($is_admin != 1 && $company_id != 0) {
+            $map[] = ['company_id', '=', $company_id];
+        } else {
+            $map[] = ['company_id', '=', $admin_company_id];
+        }
+        $result = $LowPriceGoodsModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
+            ->groupby('company_name')->paginate($limit);
+        return  json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+    /*
+     * 低价违规公司数统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2026-02-10
+     * 
+     */
+    public function get_low_price_company_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
+    {
+        $request->scene('get_low_price_company_count')->validate();
+        $admin_company_id = request('admin_company_id', '0');
+        $company_id = request('access_token.company_id', '0');
+        $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
+        $limit = request('limit', config('page_num', 10));
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
+        $start_time_string = request('start_time', '');
+        $end_time_string = request('end_time', '');
+        $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
+        $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
+        $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
+        if ($start_time > $todayStart || $end_time > $todayStart) return  json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', $start_time];
+        if ($end_time) $map[]   = ['insert_time', '<=', $end_time];
+        // 权限判断
+        if ($is_admin != 1 && $company_id != 0) {
+            $map[] = ['company_id', '=', $company_id];
+        } else {
+            $map[] = ['company_id', '=', $admin_company_id];
+        }
+        $result = $LowPriceGoodsModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
+            ->paginate($limit);
+        return  json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+}

+ 81 - 0
app/Http/Requests/Manager/Statistics/BasicPanel.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace App\Http\Requests\Manager\Statistics;
+
+use App\Http\Requests\BaseRequest;
+
+/**
+ * 报表统计-概览面板
+ * @author 唐远望
+ * @version 1.0
+ * @date 2026-02-10
+ * 
+ */
+class BasicPanel extends BaseRequest
+{
+    /**
+     * 获取应用于请求的规则
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        // 返回结果
+        return      [
+            'name'                 => 'required',
+            'id'                => 'required|integer|gt:0',
+            'status'            => 'required|integer|in:0,1',
+            'page'              => 'integer|min:1',
+            'limit'             => 'integer|min:1',
+            'image_url'         => 'required',
+            'link_url'          => 'required',
+            'sort'              => 'required|integer|min:0',
+        ];
+    }
+
+
+    // 场景列表
+    protected   $scenes         = [
+        'detail'             => ['id'],
+        'list'               => ['page', 'limit'],
+        'add'                      => [''],
+        'edit'                      => [''],
+        'set_status'              => ['id', 'status'],
+        'delete'                  => ['id'],
+        'data_cleaning'           => [''],
+        'export_excel'            => [''],
+
+        'get_online_goods_count'   => [],
+        'get_violation_product_count'   => ['page','limit'],
+        'get_violation_company_count' => ['page','limit'],
+        'get_low_price_product_count' => ['page','limit'],
+        'get_low_price_company_count' => ['page','limit'],
+    ];
+
+    /**
+     * 获取已定义验证规则的错误消息
+     *
+     * @return array
+     */
+    public function messages()
+    {
+        return [
+            'name.required'     => '名称必填',
+            'id.required'       => 'ID未知',
+            'id.integer'        => 'ID格式错误',
+            'id.gt'               => 'ID格式错误',
+            'status.required'   => '状态未知',
+            'status.integer'    => '状态格式错误',
+            'status.in'         => '状态格式错误',
+            'page.integer'      => '页码格式错误',
+            'page.min'          => '页码格式错误',
+            'limit.integer'     => '每页数量格式错误',
+            'limit.min'         => '每页数量格式错误',
+            'image_url.required'    => '图片链接未知',
+            'link_url.required'     => '链接地址未知',
+            'sort.required'         => '排序未知',
+            'sort.integer'          => '排序格式错误',
+            'sort.min'              => '排序格式错误',
+        ];
+    }
+}

+ 12 - 1
routes/manager.php

@@ -326,4 +326,15 @@ Route::any('collect_sync/product/data_ysbang_sync', [App\Http\Controllers\Manage
 //采集数据同步-医药城
 Route::any('collect_sync/product/data_yycheng_sync', [App\Http\Controllers\Manager\CollectSync\Product::class, 'data_yycheng_sync']);
 //采集数据同步-京东天猫
-Route::any('collect_sync/product/data_jd_tmall_sync', [App\Http\Controllers\Manager\CollectSync\Product::class, 'data_jd_tmall_sync']);
+Route::any('collect_sync/product/data_jd_tmall_sync', [App\Http\Controllers\Manager\CollectSync\Product::class, 'data_jd_tmall_sync']);
+
+//基础报表统计-挂网数据统计
+Route::any('statistics/basic_panel/get_online_goods_count', [App\Http\Controllers\manager\Statistics\BasicPanel::class, 'get_online_goods_count']);
+//基础报表统计-禁止挂网商品数统计排行
+Route::any('statistics/basic_panel/get_violation_product_count', [App\Http\Controllers\manager\Statistics\BasicPanel::class, 'get_violation_product_count']);
+//基础报表统计-禁止挂网公司数统计排行
+Route::any('statistics/basic_panel/get_violation_company_count', [App\Http\Controllers\manager\Statistics\BasicPanel::class, 'get_violation_company_count']);
+//基础报表统计-低价违规商品数统计排行
+Route::any('statistics/basic_panel/get_low_price_product_count', [App\Http\Controllers\manager\Statistics\BasicPanel::class, 'get_low_price_product_count']);
+//基础报表统计-低价违规公司数统计排行
+Route::any('statistics/basic_panel/get_low_price_company_count', [App\Http\Controllers\manager\Statistics\BasicPanel::class, 'get_low_price_company_count']);