升级节日福利年度调度与批次领取

This commit is contained in:
2026-04-21 17:53:11 +08:00
parent 5a6446b832
commit a066580014
25 changed files with 2362 additions and 536 deletions
+24 -12
View File
@@ -13,11 +13,17 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* 类功能:定义节日福利模板及其调度配置。
*/
class HolidayEvent extends Model
{
use HasFactory;
protected $fillable = [
'name',
'description',
@@ -31,6 +37,12 @@ class HolidayEvent extends Model
'expire_minutes',
'repeat_type',
'cron_expr',
'schedule_month',
'schedule_day',
'schedule_time',
'duration_days',
'daily_occurrences',
'occurrence_interval_minutes',
'target_type',
'target_value',
'status',
@@ -57,6 +69,11 @@ class HolidayEvent extends Model
'max_amount' => 'integer',
'fixed_amount' => 'integer',
'expire_minutes' => 'integer',
'schedule_month' => 'integer',
'schedule_day' => 'integer',
'duration_days' => 'integer',
'daily_occurrences' => 'integer',
'occurrence_interval_minutes' => 'integer',
'claimed_count' => 'integer',
'claimed_amount' => 'integer',
];
@@ -71,25 +88,19 @@ class HolidayEvent extends Model
}
/**
* 判断活动是否在领取有效期内
* 本模板对应的所有发放批次
*/
public function isClaimable(): bool
public function runs(): HasMany
{
return $this->status === 'active'
&& $this->expires_at
&& $this->expires_at->isFuture();
return $this->hasMany(HolidayEventRun::class, 'holiday_event_id');
}
/**
* 判断是否还有剩余领取名额
* 判断模板是否使用年度节日调度
*/
public function hasQuota(): bool
public function usesYearlySchedule(): bool
{
if ($this->max_claimants === 0) {
return true; // 不限人数
}
return $this->claimed_count < $this->max_claimants;
return $this->repeat_type === 'yearly';
}
/**
@@ -100,6 +111,7 @@ class HolidayEvent extends Model
return static::query()
->where('status', 'pending')
->where('enabled', true)
->whereNotNull('send_at')
->where('send_at', '<=', now())
->get();
}