fix: 修复用户侧流量明细不显示的问题

This commit is contained in:
NishinomiyaAki 2024-06-20 11:22:08 +08:00 committed by akizhwang
parent 5f3b95b699
commit d45113da7e
2 changed files with 6 additions and 7 deletions

View File

@ -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);

View File

@ -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] ?? [