From 76f4a1764be7b80663409af7466916f8f1630219 Mon Sep 17 00:00:00 2001 From: v2board Date: Wed, 3 May 2023 21:34:29 +0800 Subject: [PATCH] update: statistics --- app/Console/Commands/V2boardStatistics.php | 2 + app/Http/Controllers/Admin/StatController.php | 44 +++++++++---------- app/Services/StatisticalService.php | 6 +-- database/update.sql | 12 ++--- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/app/Console/Commands/V2boardStatistics.php b/app/Console/Commands/V2boardStatistics.php index 31812fa5..a455aafd 100644 --- a/app/Console/Commands/V2boardStatistics.php +++ b/app/Console/Commands/V2boardStatistics.php @@ -117,6 +117,8 @@ class V2boardStatistics extends Command $statisticalService->setStartAt($startAt); $statisticalService->setEndAt($endAt); $data = $statisticalService->generateStatData(); + $data['record_at'] = $startAt; + $data['record_type'] = 'd'; $statistic = Stat::where('record_at', $startAt) ->where('record_type', 'd') ->first(); diff --git a/app/Http/Controllers/Admin/StatController.php b/app/Http/Controllers/Admin/StatController.php index 0b7f91e1..d0df16fc 100644 --- a/app/Http/Controllers/Admin/StatController.php +++ b/app/Http/Controllers/Admin/StatController.php @@ -36,24 +36,24 @@ class StatController extends Controller ->get() ->makeHidden(['record_at', 'created_at', 'updated_at', 'id', 'record_type']) ->toArray(); - $stats = array_reduce($stats, function($carry, $item) { - foreach($item as $key => $value) { - if(isset($carry[$key]) && $carry[$key]) { - $carry[$key] += $value; - } else { - $carry[$key] = $value; - } - } - return $carry; - }, []); - return [ - 'data' => $stats - ]; } $statisticalService = new StatisticalService(); + $stats = array_merge($stats ?? [], [$statisticalService->generateStatData()]); + + $stats = array_reduce($stats, function($carry, $item) { + foreach($item as $key => $value) { + if(isset($carry[$key]) && $carry[$key]) { + $carry[$key] += $value; + } else { + $carry[$key] = $value; + } + } + return $carry; + }, []); + return [ - 'data' => $statisticalService->generateStatData() + 'data' => $stats ]; } @@ -106,12 +106,12 @@ class StatController extends Controller $result[] = [ 'type' => '收款金额', 'date' => $date, - 'value' => $statistic['order_total'] / 100 + 'value' => $statistic['paid_total'] / 100 ]; $result[] = [ 'type' => '收款笔数', 'date' => $date, - 'value' => $statistic['order_count'] + 'value' => $statistic['paid_count'] ]; $result[] = [ 'type' => '佣金金额(已发放)', @@ -141,12 +141,12 @@ class StatController extends Controller $startAt = strtotime('-1 day', strtotime(date('Y-m-d'))); $endAt = strtotime(date('Y-m-d')); $statistics = StatServer::select([ - 'server_id', - 'server_type', - 'u', - 'd', - DB::raw('(u+d) as total') - ]) + 'server_id', + 'server_type', + 'u', + 'd', + DB::raw('(u+d) as total') + ]) ->where('record_at', '>=', $startAt) ->where('record_at', '<', $endAt) ->where('record_type', 'd') diff --git a/app/Services/StatisticalService.php b/app/Services/StatisticalService.php index 01f89518..ed1c7e44 100644 --- a/app/Services/StatisticalService.php +++ b/app/Services/StatisticalService.php @@ -52,11 +52,7 @@ class StatisticalService { $startAt = strtotime(date('Y-m-d')); $endAt = strtotime('+1 day', $startAt); } - $data = [ - 'record_type' => 'd', - 'paid_rate' => 0, - 'record_at' => $startAt - ]; + $data = []; $data['order_count'] = Order::where('created_at', '>=', $startAt) ->where('created_at', '<', $endAt) ->count(); diff --git a/database/update.sql b/database/update.sql index 68258cf2..04f8f01c 100644 --- a/database/update.sql +++ b/database/update.sql @@ -687,13 +687,13 @@ ALTER TABLE `v2_plan` ALTER TABLE `v2_stat_order` CHANGE `record_at` `record_at` int(11) NOT NULL AFTER `id`, CHANGE `record_type` `record_type` char(1) COLLATE 'utf8_general_ci' NOT NULL AFTER `record_at`, - CHANGE `order_count` `order_count` int(11) NOT NULL COMMENT '订单数量' AFTER `record_type`, - CHANGE `order_amount` `order_total` int(11) NOT NULL COMMENT '订单合计' AFTER `order_count`, - CHANGE `commission_count` `commission_count` int(11) NOT NULL AFTER `order_total`, + CHANGE `order_count` `paid_count` int(11) NOT NULL COMMENT '订单数量' AFTER `record_type`, + CHANGE `order_amount` `paid_total` int(11) NOT NULL COMMENT '订单合计' AFTER `paid_count`, + CHANGE `commission_count` `commission_count` int(11) NOT NULL AFTER `paid_total`, CHANGE `commission_amount` `commission_total` int(11) NOT NULL COMMENT '佣金合计' AFTER `commission_count`, - ADD `paid_count` int(11) NOT NULL AFTER `commission_total`, - ADD `paid_total` int(11) NOT NULL AFTER `paid_count`, - ADD `register_count` int(11) NOT NULL AFTER `paid_total`, + ADD `order_count` int(11) NOT NULL AFTER `record_type`, + ADD `order_total` int(11) NOT NULL AFTER `order_count`, + ADD `register_count` int(11) NOT NULL AFTER `order_total`, ADD `invite_count` int(11) NOT NULL AFTER `register_count`, ADD `transfer_used_total` varchar(32) NOT NULL AFTER `invite_count`, RENAME TO `v2_stat`;