功能:新增用户积分流水系统
- 新建 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:
@@ -12,7 +12,9 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Models\User;
|
||||
use App\Services\UserCurrencyService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -22,6 +24,12 @@ use Illuminate\View\View;
|
||||
|
||||
class UserManagerController extends Controller
|
||||
{
|
||||
/**
|
||||
* 注入统一积分服务(用于管理员调整经验/金币/魅力时记录流水)
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
) {}
|
||||
/**
|
||||
* 显示用户列表及搜索(支持按等级/经验/金币/魅力排序)
|
||||
*/
|
||||
@@ -90,13 +98,35 @@ class UserManagerController extends Controller
|
||||
$targetUser->sex = $validated['sex'];
|
||||
}
|
||||
if (isset($validated['exp_num'])) {
|
||||
$targetUser->exp_num = $validated['exp_num'];
|
||||
// 计算差值并通过统一服务记录流水(管理员手动调整)
|
||||
$expDiff = $validated['exp_num'] - ($targetUser->exp_num ?? 0);
|
||||
if ($expDiff !== 0) {
|
||||
$this->currencyService->change(
|
||||
$targetUser, 'exp', $expDiff, CurrencySource::ADMIN_ADJUST,
|
||||
"管理员 {$currentUser->username} 手动调整经验",
|
||||
);
|
||||
$targetUser->refresh();
|
||||
}
|
||||
}
|
||||
if (isset($validated['jjb'])) {
|
||||
$targetUser->jjb = $validated['jjb'];
|
||||
$jjbDiff = $validated['jjb'] - ($targetUser->jjb ?? 0);
|
||||
if ($jjbDiff !== 0) {
|
||||
$this->currencyService->change(
|
||||
$targetUser, 'gold', $jjbDiff, CurrencySource::ADMIN_ADJUST,
|
||||
"管理员 {$currentUser->username} 手动调整金币",
|
||||
);
|
||||
$targetUser->refresh();
|
||||
}
|
||||
}
|
||||
if (isset($validated['meili'])) {
|
||||
$targetUser->meili = $validated['meili'];
|
||||
$meiliDiff = $validated['meili'] - ($targetUser->meili ?? 0);
|
||||
if ($meiliDiff !== 0) {
|
||||
$this->currencyService->change(
|
||||
$targetUser, 'charm', $meiliDiff, CurrencySource::ADMIN_ADJUST,
|
||||
"管理员 {$currentUser->username} 手动调整魅力",
|
||||
);
|
||||
$targetUser->refresh();
|
||||
}
|
||||
}
|
||||
if (array_key_exists('qianming', $validated)) {
|
||||
$targetUser->qianming = $validated['qianming'];
|
||||
|
||||
Reference in New Issue
Block a user