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); $violationStoreModel = $violationStoreModel->where('company_id', $company_id); } else { $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $admin_company_id); $violationProductModel = $violationProductModel->where('company_id', $admin_company_id); $violationStoreModel = $violationStoreModel->where('company_id', $admin_company_id); } // 低价挂网商品数量查询 $lowPriceGoodsCount = $lowPriceGoodsModel->where($map) ->where('status', 0) ->groupBy('product_name') ->select('product_name') ->get()->count(); // 禁止挂网商品数量查询 $violationProductCount = $violationProductModel->where($map) ->where('status', 0) ->groupBy('product_name') ->select('product_name') ->get()->count(); $store_map = []; if ($start_time) $store_map[] = ['insert_time', '>=', $start_time]; if ($end_time) $store_map[] = ['insert_time', '<=', $end_time]; // 违规店铺数量查询 $violationStoreCount = $violationStoreModel->where($store_map) ->where('status', 0) ->groupBy('company_name') ->select('company_name') ->get()->count(); //获取终端类型B端、C端、OTO,配置品规数量 $collect_b_product_count = $productModel->where(function ($query) { $platforms = ['0', '5', '6', '7', '8', '9', '10']; foreach ($platforms as $platform) { $query->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]); } })->where('status', 0)->sum('product_specs_number'); $collect_c_product_count = $productModel->where(function ($query) { $platforms = ['0', '1', '2', '3', '4']; foreach ($platforms as $platform) { $query->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]); } })->where('status', 0)->sum('product_specs_number'); $collect_oto_product_count = $productModel->where(function ($query) { $platforms = ['0']; foreach ($platforms as $platform) { $query->orWhereRaw("FIND_IN_SET(?, platform)", [$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 = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '2': //C端:美团、拼多多、天猫、京东 $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '3': //OTO:美团买药、淘宝闪送、京东秒送 $platform = ['0']; 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 = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '2': //C端:美团、拼多多、天猫、京东 $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '3': //OTO:美团买药、淘宝闪送、京东秒送 $platform = ['0']; 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 = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '2': //C端:美团、拼多多、天猫、京东 $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '3': //OTO:美团买药、淘宝闪送、京东秒送 $platform = ['0']; 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 = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '2': //C端:美团、拼多多、天猫、京东 $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '3': //OTO:美团买药、淘宝闪送、京东秒送 $platform = ['0']; 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 = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '2': //C端:美团、拼多多、天猫、京东 $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '3': //OTO:美团买药、淘宝闪送、京东秒送 $platform = ['0']; 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 = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '2': //C端:美团、拼多多、天猫、京东 $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '3': //OTO:美团买药、淘宝闪送、京东秒送 $platform = ['0']; 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 = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '2': //C端:美团、拼多多、天猫、京东 $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '3': //OTO:美团买药、淘宝闪送、京东秒送 $platform = ['0']; 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 = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '2': //C端:美团、拼多多、天猫、京东 $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药 break; case '3': //OTO:美团买药、淘宝闪送、京东秒送 $platform = ['0']; 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()]); } } }