功能:新增用户积分流水系统

- 新建 user_currency_logs 流水表 (Migration)
- App\Enums\CurrencySource 来源枚举(可扩展)
- App\Models\UserCurrencyLog 流水模型
- App\Services\UserCurrencyService 统一积分变更服务
- FishingController:抛竿/收竿接入流水记录
- AutoSaveExp:自动存点接入流水记录
- Admin/UserManagerController:管理员调整接入流水记录
- LeaderboardController:新增今日三榜(经验/金币/魅力)+ 个人流水日志页
- Admin/CurrencyStatsController:后台活动统计页
- views:新增个人日志页、后台统计页;排行榜新增今日榜数据传递
- routes:新增个人日志路由 /my/currency-logs、后台路由 /admin/currency-stats
This commit is contained in:
2026-02-28 12:49:26 +08:00
parent 3f5d0e9539
commit 0c5e218aa8
14 changed files with 1045 additions and 223 deletions
@@ -0,0 +1,102 @@
{{--
文件功能:后台积分活动统计页面
显示指定日期下各来源活动(钓鱼、存点等)产出的经验/金币/魅力统计,以及今日净流通量
@extends admin/layouts
--}}
@extends('layouts.admin')
@section('title', '积分流水统计')
@section('content')
<div class="p-6 max-w-6xl mx-auto">
{{-- 页头 --}}
<div class="flex items-center justify-between mb-6">
<h1 class="text-2xl font-bold text-gray-800">📊 积分流水活动统计</h1>
{{-- 日期选择器 --}}
<form method="GET" action="{{ route('admin.currency-stats.index') }}" class="flex items-center gap-3">
<label class="text-sm text-gray-600">查询日期:</label>
<input type="date" name="date" value="{{ $date }}"
class="border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-indigo-400">
<button type="submit"
class="bg-indigo-600 text-white px-4 py-2 rounded-lg text-sm hover:bg-indigo-700 transition">
查询
</button>
</form>
</div>
{{-- 净流通量摘要卡片 --}}
<div class="grid grid-cols-3 gap-4 mb-8">
@foreach (['exp' => ['label' => '经验', 'icon' => '⚡', 'color' => 'amber'], 'gold' => ['label' => '金币', 'icon' => '💰', 'color' => 'yellow'], 'charm' => ['label' => '魅力', 'icon' => '🌸', 'color' => 'pink']] as $cur => $info)
@php $flow = $netFlow[$cur] ?? ['in'=>0,'out'=>0,'net'=>0]; @endphp
<div class="bg-white rounded-xl border border-gray-200 shadow-sm p-5">
<div class="flex items-center gap-2 mb-3">
<span class="text-2xl">{{ $info['icon'] }}</span>
<span class="font-semibold text-gray-700">{{ $info['label'] }} 流通</span>
</div>
<div class="flex justify-between text-sm">
<span class="text-green-600">+{{ number_format($flow['in']) }} 流入</span>
<span class="text-red-500">-{{ number_format($flow['out']) }} 消耗</span>
</div>
<div class="mt-2 text-lg font-bold {{ $flow['net'] >= 0 ? 'text-green-700' : 'text-red-600' }}">
净增:{{ $flow['net'] >= 0 ? '+' : '' }}{{ number_format($flow['net']) }}
</div>
</div>
@endforeach
</div>
{{-- 来源活动详细统计表 --}}
<div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
<div class="px-6 py-4 border-b border-gray-200 bg-gray-50">
<h2 class="text-lg font-semibold text-gray-700">各活动来源产出明细</h2>
<p class="text-xs text-gray-400 mt-1">日期:{{ $date }}(仅统计正向增加,不含消耗)</p>
</div>
<table class="w-full text-sm">
<thead class="bg-gray-50 border-b text-gray-600">
<tr>
<th class="px-6 py-3 text-left">来源活动</th>
<th class="px-6 py-3 text-right"> 经验产出</th>
<th class="px-6 py-3 text-right">💰 金币产出</th>
<th class="px-6 py-3 text-right">🌸 魅力产出</th>
<th class="px-6 py-3 text-right">参与人次</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@foreach ($allSources as $source)
@php
$expRow = $statsByType['exp'][$source->value] ?? null;
$goldRow = $statsByType['gold'][$source->value] ?? null;
$charmRow = $statsByType['charm'][$source->value] ?? null;
$hasData = $expRow || $goldRow || $charmRow;
$maxParticipants = max(
$expRow?->participant_count ?? 0,
$goldRow?->participant_count ?? 0,
$charmRow?->participant_count ?? 0,
);
@endphp
<tr class="{{ $hasData ? '' : 'opacity-40' }} hover:bg-gray-50 transition">
<td class="px-6 py-3 font-medium text-gray-700">{{ $source->label() }}</td>
<td
class="px-6 py-3 text-right {{ $expRow?->total_amount > 0 ? 'text-amber-600 font-semibold' : 'text-gray-300' }}">
{{ $expRow ? number_format($expRow->total_amount) : '—' }}
</td>
<td
class="px-6 py-3 text-right {{ $goldRow?->total_amount > 0 ? 'text-yellow-600 font-semibold' : 'text-gray-300' }}">
{{ $goldRow ? number_format($goldRow->total_amount) : '—' }}
</td>
<td
class="px-6 py-3 text-right {{ $charmRow?->total_amount > 0 ? 'text-pink-600 font-semibold' : 'text-gray-300' }}">
{{ $charmRow ? number_format($charmRow->total_amount) : '—' }}
</td>
<td class="px-6 py-3 text-right text-gray-500">
{{ $maxParticipants > 0 ? $maxParticipants . ' 人' : '—' }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endsection
@@ -0,0 +1,103 @@
{{--
文件功能:用户个人积分流水日志页面
用户可筛选查看自己的经验、金币、魅力变动历史,按日期倒序排列
@extends layouts.app
--}}
@extends('layouts.app')
@section('title', '我的积分记录 - 飘落流星')
@section('nav-icon', '📊')
@section('nav-title', '我的积分记录')
@section('content')
<main class="p-4 sm:p-6 lg:p-8">
<div class="max-w-4xl mx-auto">
{{-- 筛选栏 --}}
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 mb-6 flex flex-wrap gap-3 items-center">
<span class="text-gray-600 text-sm font-medium">筛选:</span>
{{-- 货币类型 --}}
<div class="flex gap-2">
@foreach(['' => '全部', 'exp' => '⚡ 经验', 'gold' => '💰 金币', 'charm' => '🌸 魅力'] as $val => $label)
<a href="{{ route('currency.my-logs', array_merge(request()->query(), ['currency' => $val, 'days' => $days])) }}"
class="px-3 py-1 rounded-full text-xs font-medium transition
{{ ($currency ?? '') === $val ? 'bg-indigo-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-indigo-100' }}">
{{ $label }}
</a>
@endforeach
</div>
{{-- 日期范围 --}}
<div class="flex gap-2 ml-auto">
@foreach([7 => '7 天', 14 => '14 天', 30 => '30 天'] as $d => $label)
<a href="{{ route('currency.my-logs', array_merge(request()->query(), ['days' => $d])) }}"
class="px-3 py-1 rounded-full text-xs font-medium transition
{{ $days === $d ? 'bg-indigo-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-indigo-100' }}">
{{ $label }}
</a>
@endforeach
</div>
</div>
{{-- 流水列表 --}}
<div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
@if($logs->isEmpty())
<div class="p-12 text-center text-gray-400">
<div class="text-4xl mb-3">📭</div>
<p>暂无积分记录,快去钓鱼或挂机吧!</p>
</div>
@else
<table class="w-full text-sm">
<thead class="bg-gray-50 border-b border-gray-200 text-gray-600">
<tr>
<th class="px-4 py-3 text-left">时间</th>
<th class="px-4 py-3 text-left">类型</th>
<th class="px-4 py-3 text-left">来源</th>
<th class="px-4 py-3 text-right">变动</th>
<th class="px-4 py-3 text-right">变动后余额</th>
<th class="px-4 py-3 text-left">备注</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@foreach($logs as $log)
@php
$currencyIcons = ['exp' => '⚡', 'gold' => '💰', 'charm' => '🌸'];
$icon = $currencyIcons[$log->currency] ?? '📌';
$isPositive = $log->amount >= 0;
@endphp
<tr class="hover:bg-gray-50 transition">
<td class="px-4 py-3 text-gray-500 whitespace-nowrap">
{{ \Carbon\Carbon::parse($log->created_at)->format('m-d H:i') }}
</td>
<td class="px-4 py-3">
{{ $icon }} {{ \App\Services\UserCurrencyService::currencyLabel($log->currency) }}
</td>
<td class="px-4 py-3 text-gray-600">
@php
$sourceLabel = '';
try { $sourceLabel = \App\Enums\CurrencySource::from($log->source)->label(); } catch (\Throwable) { $sourceLabel = $log->source; }
@endphp
{{ $sourceLabel }}
</td>
<td class="px-4 py-3 text-right font-semibold {{ $isPositive ? 'text-green-600' : 'text-red-500' }}">
{{ $isPositive ? '+' : '' }}{{ number_format($log->amount) }}
</td>
<td class="px-4 py-3 text-right text-gray-500">
{{ number_format($log->balance_after) }}
</td>
<td class="px-4 py-3 text-gray-400 text-xs max-w-[160px] truncate">
{{ $log->remark ?: '—' }}
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>
<p class="text-center text-xs text-gray-400 mt-4">最多显示最近 200 条记录</p>
</div>
</main>
@endsection