| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- <?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=否
- $product_name = request('product_name', ''); //商品名称
- $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 ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- // 统计挂网商品数量=低价挂网商品数量(去重)+ 禁止挂网商品数量(去重)
- $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)->sum('product_specs_number');
- $collect_c_product_count = $productModel->whereIn('platform', ['1', '2', '3', '4'])->where('status', 0)->sum('product_specs_number');
- $collect_oto_product_count = $productModel->whereIn('platform', [])->where('status', 0)->sum('product_specs_number');
- // 所有终端品规数量
- $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');
- $company_id = request('access_token.company_id', '0');
- //终端类型B端、C端、OTO
- $terminal_type = request('terminal_type', '');
- $product_name = request('product_name', ''); //商品名称
- $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];
- }
- if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- $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', $platform);
- }
- $result = $violationProductModel->where($map)->where('status', 0)
- ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
- ->groupby('product_name')->paginate($limit);
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
- }
- /**
- * 禁止挂网省份统计
- * @author 唐远望
- * @version 1.0
- * @date 2026-02-10
- *
- */
- public function get_violation_province_count(request $request, ViolationProductModel $violationProductModel)
- {
- $request->scene('get_violation_province_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=否
- //终端类型B端、C端、OTO
- $terminal_type = request('terminal_type', '');
- $product_name = request('product_name', ''); //商品名称
- $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];
- }
- if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- // 禁止挂网省份统计
- $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', $platform);
- }
- try {
- // 假设 ViolationProductModel 中有 province 字段,表示省份信息
- // 查询指定时间范围内的数据,并按 province 分组统计数量
- $result = $violationProductModel->where($map)->where('status', 0)
- ->select(['province_name', DB::raw('count(province_name) as count')])
- ->groupby('province_name')
- ->orderby('count', 'desc')
- ->get();
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
- } catch (\Exception $e) {
- return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
- }
- }
- /**
- * 禁止挂网城市统计
- * @author 唐远望
- * @version 1.0
- * @date 2026-02-10
- *
- */
- public function get_violation_city_count(request $request, ViolationProductModel $violationProductModel)
- {
- $request->scene('get_violation_city_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=否
- //终端类型B端、C端、OTO
- $terminal_type = request('terminal_type', '');
- $product_name = request('product_name', ''); //商品名称
- $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];
- }
- if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- // 禁止挂网城市统计
- $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', $platform);
- }
- try {
- // 假设 ViolationProductModel 中有 city 字段,表示城市信息
- // 查询指定时间范围内的数据,并按 city 分组统计数量
- $result = $violationProductModel->where($map)->where('status', 0)
- ->select(['city_name', DB::raw('count(city_name) as count')])
- ->groupby('city_name')
- ->orderby('count', 'desc')
- ->get();
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
- } catch (\Exception $e) {
- return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
- }
- }
- /**
- * 禁止挂网公司数统计
- * @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=否
- //终端类型B端、C端、OTO
- $terminal_type = request('terminal_type', '');
- $limit = request('limit', config('page_num', 10));
- $product_name = request('product_name', ''); //商品名称
- $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 ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- // 权限判断
- 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', $platform);
- }
- $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=否
- //终端类型B端、C端、OTO
- $terminal_type = request('terminal_type', '');
- $limit = request('limit', config('page_num', 10));
- $product_name = request('product_name', ''); //商品名称
- $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];
- }
- if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- $LowPriceGoodsModel = $LowPriceGoodsModel->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;
- }
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
- }
- $result = $LowPriceGoodsModel->where($map)->where('status', 0)
- ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
- ->groupby('product_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=否
- //终端类型B端、C端、OTO
- $terminal_type = request('terminal_type', '');
- $limit = request('limit', config('page_num', 10));
- $product_name = request('product_name', ''); //商品名称
- $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];
- }
- $LowPriceGoodsModel = $LowPriceGoodsModel->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;
- }
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
- }
- if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- $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]);
- }
- /**
- * 低价挂网省份统计
- * @author 唐远望
- * @version 1.0
- * @date 2026-02-10
- *
- */
- public function get_low_price_province_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
- {
- $request->scene('get_low_price_province_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=否
- //终端类型B端、C端、OTO
- $terminal_type = request('terminal_type', '');
- $product_name = request('product_name', ''); //商品名称
- $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];
- }
- if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- // 禁止挂网省份统计
- $LowPriceGoodsModel = $LowPriceGoodsModel->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;
- }
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
- }
- try {
- // 假设 LowPriceGoodsModel 中有 province 字段,表示省份信息
- // 查询指定时间范围内的数据,并按 province 分组统计数量
- $result = $LowPriceGoodsModel->where($map)->where('status', 0)
- ->select(['province_name', DB::raw('count(province_name) as count')])
- ->groupby('province_name')
- ->orderby('count', 'desc')
- ->get();
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
- } catch (\Exception $e) {
- return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
- }
- }
- /**
- * 低价挂网城市统计
- * @author 唐远望
- * @version 1.0
- * @date 2026-02-10
- *
- */
- public function get_low_price_city_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
- {
- $request->scene('get_low_price_city_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=否
- //终端类型B端、C端、OTO
- $terminal_type = request('terminal_type', '');
- $product_name = request('product_name', ''); //商品名称
- $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];
- }
- if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
- // 禁止挂网城市统计
- $LowPriceGoodsModel = $LowPriceGoodsModel->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;
- }
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
- }
- try {
- // 假设 LowPriceGoodsModel 中有 city 字段,表示城市信息
- // 查询指定时间范围内的数据,并按 city 分组统计数量
- $result = $LowPriceGoodsModel->where($map)->where('status', 0)
- ->select(['city_name', DB::raw('count(city_name) as count')])
- ->groupby('city_name')
- ->orderby('count', 'desc')
- ->get();
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
- } catch (\Exception $e) {
- return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
- }
- }
- }
|