From c57304bad2b2a74ea3e9d2e144b082c3230a4ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=BB=BA=E7=82=8A?= <924182103@qq.com> Date: Mon, 19 Aug 2024 16:04:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=B2=9C=E8=8A=B12.0-=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E8=BD=AF=E5=88=A0=E9=99=A4+=E7=BB=9F=E8=AE=A1=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/DailyStockRecordReport.php | 3 +- .../Commands/KttOrderAfterSaleQuery.php | 2 +- app/Services/Statistic/SaleDataService.php | 33 ++++++++++++------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/Console/Commands/DailyStockRecordReport.php b/app/Console/Commands/DailyStockRecordReport.php index 9c27e44..758125c 100644 --- a/app/Console/Commands/DailyStockRecordReport.php +++ b/app/Console/Commands/DailyStockRecordReport.php @@ -55,7 +55,8 @@ class DailyStockRecordReport extends Command ->select("business_order_items.external_sku_id" , DB::raw("sum(goods_number-already_cancel_number) as goods_total") , DB::raw("ROUND(sum(goods_amount) / 100,2) as order_total_amount")) - ->whereBetween("business_order_items.created_at", [$startDateTime, $endDateTime]) + ->where('b.confirm_at', '>=', Carbon::parse($startDateTime)->getPreciseTimestamp(3)) + ->where('b.confirm_at', '<=', Carbon::parse($endDateTime)->getPreciseTimestamp(3)) ->where("business_order_items.cancel_status", "=", 0) ->groupBy('external_sku_id')->get()->pluck(null, "external_sku_id")->toArray(); diff --git a/app/Console/Commands/KttOrderAfterSaleQuery.php b/app/Console/Commands/KttOrderAfterSaleQuery.php index 68a4c08..654429c 100644 --- a/app/Console/Commands/KttOrderAfterSaleQuery.php +++ b/app/Console/Commands/KttOrderAfterSaleQuery.php @@ -44,7 +44,7 @@ class KttOrderAfterSaleQuery extends Command { $shops = Shop::query()->where('plat_id', Shop::$PLAT_KTT)->where('status', Shop::$STATUS_AUTHORIZED)->get(); $endTime = DateTimeUtils::getMicroTime(); - $beginTime = $endTime - (15 * 60 * 1000)-1000;//售后单每15min查询一次 多查询一次 + $beginTime = $endTime - (15 * 60 * 1000)-1000;//售后单每15min查询一次 多查询一秒 foreach ($shops as $shop) { BusinessFactory::init()->make($shop->plat_id)->setShop($shop)->downloadAfterSaleOrdersAndSave($beginTime, $endTime); } diff --git a/app/Services/Statistic/SaleDataService.php b/app/Services/Statistic/SaleDataService.php index 305b296..1dd9dc2 100644 --- a/app/Services/Statistic/SaleDataService.php +++ b/app/Services/Statistic/SaleDataService.php @@ -20,7 +20,9 @@ use Illuminate\Support\Facades\Validator; class SaleDataService { - + /** + * sku维度的统计数据 + */ public static function saleStatistics(Request $request) { if (StaticTypeEnum::TODAY == $request->type) { @@ -31,7 +33,9 @@ class SaleDataService return static::skuSaleStatisticsByHistory($request); } } - + /** + * sku维度 今日实时统计 + */ public static function skuSaleStatisticsByToday(Request $request) { [$startTime, $endTime] = static::getTimeRange($request); @@ -170,8 +174,7 @@ class SaleDataService return [$startTime, $endTime]; } - public - static function spuSaleStatisticsByToday(Request $request) + public static function spuSaleStatisticsByToday(Request $request) { [$startTime, $endTime] = static::getTimeRange($request); //实时统计 sku维度 @@ -182,7 +185,8 @@ class SaleDataService , DB::raw("sum(CASE WHEN b.shipping_status=0 THEN goods_number-already_cancel_number ELSE 0 END) as unshipping_num") , DB::raw("sum(goods_number-already_cancel_number) as goods_total") , DB::raw("ROUND(sum(goods_amount) / 100,2) as goods_total_amount")) - ->whereBetween("business_order_items.created_at", [$startTime, $endTime]) + ->where('b.confirm_at', '>=', Carbon::parse($startTime)->getPreciseTimestamp(3)) + ->where('b.confirm_at', '<=', Carbon::parse($endTime)->getPreciseTimestamp(3)) ->where("external_sku_id", "!=", "") ->where("business_order_items.cancel_status", "=", 0) ->groupBy('external_sku_id')->get()->toArray(); @@ -235,8 +239,7 @@ class SaleDataService * @param $endTime * @return array */ - public - static function spuSaleStatisticsByHistory($startTime, $endTime) + public static function spuSaleStatisticsByHistory($startTime, $endTime) { $dailyAllRecord = DailyStockRecord::query() ->select("sku_id", DB::raw("sum(order_goods_num) as goods_total") @@ -269,8 +272,12 @@ class SaleDataService })->values()->toArray(); } - public - static function gmvStatistics(Request $request) + /** + * gmv 统计 + * @param Request $request + * @return array + */ + public static function gmvStatistics(Request $request) { if (StaticTypeEnum::TODAY == $request->type) { [$startTime, $endTime] = static::getTimeRange($request); @@ -319,8 +326,12 @@ class SaleDataService } - public - static function lossRecordStatistics(Request $request) + /** + * 报损统计 + * @param Request $request + * @return array + */ + public static function lossRecordStatistics(Request $request) { $startTime = Carbon::parse($request->input("start_time"))->toDateTimeString(); $endTime = Carbon::parse($request->input("end_time"))->toDateTimeString();