From d45113da7e26335a7e7a0eea0f9dc2ba3df78ac4 Mon Sep 17 00:00:00 2001 From: NishinomiyaAki Date: Thu, 20 Jun 2024 11:22:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BE=A7=E6=B5=81=E9=87=8F=E6=98=8E=E7=BB=86=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/V1/User/StatController.php | 10 +++++----- app/Services/StatisticalService.php | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/V1/User/StatController.php b/app/Http/Controllers/V1/User/StatController.php index a7845d4..2cca151 100644 --- a/app/Http/Controllers/V1/User/StatController.php +++ b/app/Http/Controllers/V1/User/StatController.php @@ -13,7 +13,7 @@ class StatController extends Controller { public function getTrafficLog(Request $request) { - $startDate = now()->startOfMonth(); + $startDate = strtotime(now()->startOfMonth()); $records = StatUser::query() ->where('user_id', $request->user['id']) ->where('record_at', '>=', $startDate) @@ -26,11 +26,11 @@ class StatController extends Controller $statService->setStartAt($recordAt); $todayTraffics = $statService->getStatUserByUserID($request->user['id']); if (count($todayTraffics) > 0) { - $todayTraffics = collect($todayTraffics)->map(function ($todayTraffic) { - $todayTraffic['server_rate'] = number_format($todayTraffic['server_rate'], 2); - return $todayTraffic; + $records = collect($todayTraffics)->merge($records); + $records = $records->map(function ($record) { + $record['server_rate'] = number_format($record['server_rate'], 2); + return $record; }); - $records = $todayTraffics->merge($records); } $data = TrafficLogResource::collection(collect($records)); return $this->success($data); diff --git a/app/Services/StatisticalService.php b/app/Services/StatisticalService.php index 3ec016e..1b22146 100644 --- a/app/Services/StatisticalService.php +++ b/app/Services/StatisticalService.php @@ -110,12 +110,11 @@ class StatisticalService */ public function getStatUserByUserID($userId): array { - $stats = []; $statsUser = $this->redis->zrange($this->statUserKey, 0, -1, true); foreach ($statsUser as $member => $value) { list($rate, $uid, $type) = explode('_', $member); - if ($uid !== $userId) + if (intval($uid) !== intval($userId)) continue; $key = "{$rate}_{$uid}"; $stats[$key] = $stats[$key] ?? [