新增节日福利系统:①数据库表+模型 ②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

106
app/Models/HolidayEvent.php Normal file
View File

@@ -0,0 +1,106 @@
<?php
/**
* 文件功能:节日福利活动模型
*
* 管理员在后台配置的定时发放金币活动,
* 支持随机/定额两种分配方式,支持一次性或周期性重复。
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class HolidayEvent extends Model
{
protected $fillable = [
'name',
'description',
'total_amount',
'max_claimants',
'distribute_type',
'min_amount',
'max_amount',
'fixed_amount',
'send_at',
'expire_minutes',
'repeat_type',
'cron_expr',
'target_type',
'target_value',
'status',
'enabled',
'triggered_at',
'expires_at',
'claimed_count',
'claimed_amount',
];
/**
* 属性类型转换。
*/
protected function casts(): array
{
return [
'send_at' => 'datetime',
'triggered_at' => 'datetime',
'expires_at' => 'datetime',
'enabled' => 'boolean',
'total_amount' => 'integer',
'max_claimants' => 'integer',
'min_amount' => 'integer',
'max_amount' => 'integer',
'fixed_amount' => 'integer',
'expire_minutes' => 'integer',
'claimed_count' => 'integer',
'claimed_amount' => 'integer',
];
}
/**
* 本次活动的所有领取记录。
*/
public function claims(): HasMany
{
return $this->hasMany(HolidayClaim::class, 'event_id');
}
/**
* 判断活动是否在领取有效期内。
*/
public function isClaimable(): bool
{
return $this->status === 'active'
&& $this->expires_at
&& $this->expires_at->isFuture();
}
/**
* 判断是否还有剩余领取名额。
*/
public function hasQuota(): bool
{
if ($this->max_claimants === 0) {
return true; // 不限人数
}
return $this->claimed_count < $this->max_claimants;
}
/**
* 查询待触发的活动(定时任务调用)。
*/
public static function pendingToTrigger(): \Illuminate\Database\Eloquent\Collection
{
return static::query()
->where('status', 'pending')
->where('enabled', true)
->where('send_at', '<=', now())
->get();
}
}