|
|
@@ -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]);
|
|
|
+ }
|
|
|
+}
|