From 1089e782fd467f03b85336576088e865234eb1e1 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Fri, 22 Jul 2022 16:49:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Metrics/StatisticsTotal.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/Admin/Metrics/StatisticsTotal.php b/app/Admin/Metrics/StatisticsTotal.php index 13ed1c16..cc537eff 100644 --- a/app/Admin/Metrics/StatisticsTotal.php +++ b/app/Admin/Metrics/StatisticsTotal.php @@ -6,6 +6,7 @@ use App\Models\Balance; use App\Models\Order; use App\Models\UserInfo; use App\Models\Wallet; +use Carbon\Carbon; use Dcat\Admin\Widgets\Metrics\RadialBar; use Illuminate\Http\Request; @@ -21,6 +22,12 @@ class StatisticsTotal extends RadialBar $this->title('统计预览'); $this->height(300); $this->contentWidth(12, 0); + // 设置下拉选项 + $this->dropdown([ + '1' => '当天', + '7' => '最近7天', + '30' => '最近30天', + ]); } /** @@ -32,7 +39,25 @@ class StatisticsTotal extends RadialBar */ public function handle(Request $request) { - $order = Order::whereNotIn('status', [Order::STATUS_PENDING, Order::STATUS_CANCELLED])->sum('total_amount'); + switch ($request->get('option')) { + case '30': + $start_time = Carbon::now()->subDays(29)->startOfDay(); + $end_time = Carbon::now()->endOfDay(); + + break; + case '7': + $start_time = Carbon::now()->subDays(6)->startOfDay(); + $end_time = Carbon::now()->endOfDay(); + + break; + default: + $start_time = Carbon::now()->startOfDay(); + $end_time = Carbon::now()->endOfDay(); + + break; + + } + $order = Order::whereBetween('created_at', [$start_time, $end_time])->whereNotIn('status', [Order::STATUS_PENDING, Order::STATUS_CANCELLED])->sum('total_amount'); // 卡片内容 $this->withContent([ 'total_points'=> UserInfo::sum('points'),