新增节日福利系统:①数据库表+模型 ②TriggerHolidayEventJob队列任务(在线用户筛选/金额分配/WebSocket广播) ③后台管理页面(列表/创建/手动触发) ④前台领取弹窗+WebSocket监听 ⑤定时调度每分钟扫描 ⑥CurrencySource补充HOLIDAY_BONUS

This commit is contained in:
2026-03-01 20:06:53 +08:00
parent a37b04aca0
commit c5fe9faf94
16 changed files with 1504 additions and 1 deletions

View File

@@ -0,0 +1,72 @@
<?php
/**
* 文件功能:节日福利活动表迁移
*
* 管理员可在后台创建定时发放的节日金币福利活动,
* 支持随机/定额两种分配方式,支持周期性重复。
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 创建 holiday_events 表。
*/
public function up(): void
{
Schema::create('holiday_events', function (Blueprint $table) {
$table->id();
// 活动基本信息
$table->string('name', 100)->comment('活动名称(公屏广播时显示)');
$table->text('description')->nullable()->comment('活动描述/广播文案');
// 奖励配置
$table->unsignedInteger('total_amount')->comment('总金币奖池');
$table->unsignedInteger('max_claimants')->default(0)->comment('最大领取人数0=不限)');
$table->enum('distribute_type', ['random', 'fixed'])->default('random')->comment('分配方式random=随机 fixed=定额');
$table->unsignedInteger('min_amount')->default(1)->comment('随机模式最低保底金额');
$table->unsignedInteger('max_amount')->nullable()->comment('随机模式单人上限');
$table->unsignedInteger('fixed_amount')->nullable()->comment('定额模式每人金额');
// 时间配置
$table->dateTime('send_at')->comment('触发时间');
$table->unsignedInteger('expire_minutes')->default(30)->comment('领取有效期(分钟)');
// 重复设置
$table->enum('repeat_type', ['once', 'daily', 'weekly', 'monthly', 'cron'])->default('once');
$table->string('cron_expr', 100)->nullable()->comment('自定义 CRON 表达式');
// 目标用户
$table->enum('target_type', ['all', 'vip', 'level'])->default('all')->comment('目标用户类型');
$table->string('target_value', 50)->nullable()->comment('vip级别/最低等级值');
// 状态
$table->enum('status', ['pending', 'active', 'completed', 'cancelled'])->default('pending');
$table->boolean('enabled')->default(true)->comment('是否启用');
$table->dateTime('triggered_at')->nullable()->comment('实际触发时间');
$table->dateTime('expires_at')->nullable()->comment('本次领取截止时间');
// 统计
$table->unsignedInteger('claimed_count')->default(0)->comment('已领取人数');
$table->unsignedInteger('claimed_amount')->default(0)->comment('已发出金额');
$table->timestamps();
$table->index(['status', 'send_at']);
$table->index('enabled');
});
}
/**
* 回滚迁移。
*/
public function down(): void
{
Schema::dropIfExists('holiday_events');
}
};

View File

@@ -0,0 +1,40 @@
<?php
/**
* 文件功能:节日福利领取记录表迁移
*
* 记录每个用户对每次节日福利活动的领取状态和金额。
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 创建 holiday_claims 表。
*/
public function up(): void
{
Schema::create('holiday_claims', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('event_id')->comment('关联活动 ID');
$table->unsignedBigInteger('user_id')->comment('领取用户 ID');
$table->unsignedInteger('amount')->comment('实际领取金额');
$table->dateTime('claimed_at')->comment('领取时间');
$table->foreign('event_id')->references('id')->on('holiday_events')->cascadeOnDelete();
$table->unique(['event_id', 'user_id'], 'uq_holiday_event_user');
$table->index('user_id');
});
}
/**
* 回滚迁移。
*/
public function down(): void
{
Schema::dropIfExists('holiday_claims');
}
};