input('date', today()->toDateString()); // 各来源活动产出统计(按 source + currency 分组汇总) $stats = $this->currencyService->activityStats($date); // 按货币类型分组,方便视图展示 $statsByType = $stats->groupBy('currency')->map( fn ($rows) => $rows->keyBy('source') ); // 今日净流通量(正向增加 - 负向消耗),可判断通货膨胀 $netFlow = []; foreach (['exp', 'gold', 'charm'] as $currency) { $totalIn = UserCurrencyLog::whereDate('created_at', $date) ->where('currency', $currency)->where('amount', '>', 0) ->sum('amount'); $totalOut = UserCurrencyLog::whereDate('created_at', $date) ->where('currency', $currency)->where('amount', '<', 0) ->sum('amount'); $netFlow[$currency] = [ 'in' => $totalIn, 'out' => abs($totalOut), 'net' => $totalIn + $totalOut, // 净增量 ]; } // 所有已知来源(供视图展示缺失来源的空行) $allSources = CurrencySource::cases(); return view('admin.currency-stats.index', compact( 'date', 'stats', 'statsByType', 'netFlow', 'allSources', )); } }