5个 Job: - ExpireMarriageProposals:每5分钟扫描超时求婚(广播通知) - TriggerScheduledWeddings:每5分钟触发定时婚礼(广播庆典) - AutoExpireDivorces:每小时处理离婚超时自动解除 - ExpireWeddingEnvelopes:每小时清理过期红包 - ProcessMarriageIntimacy:每日00:05全量亲密度时间奖励 console.php 注册5个 Schedule
51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:触发定时婚礼(到时间后自动执行红包分发)
|
||
*
|
||
* 每 5 分钟执行一次,扫描 ceremony_at <= now() 且 status=pending 的婚礼,
|
||
* 调用 WeddingService::trigger() 分发红包并广播庆典事件。
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Jobs;
|
||
|
||
use App\Events\WeddingCelebration;
|
||
use App\Models\WeddingCeremony;
|
||
use App\Services\WeddingService;
|
||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
use Illuminate\Foundation\Queue\Queueable;
|
||
|
||
class TriggerScheduledWeddings implements ShouldQueue
|
||
{
|
||
use Queueable;
|
||
|
||
/**
|
||
* 执行 Job:检查并触发到时的定时婚礼。
|
||
*/
|
||
public function handle(WeddingService $wedding): void
|
||
{
|
||
WeddingCeremony::query()
|
||
->where('status', 'pending')
|
||
->where('ceremony_type', 'scheduled')
|
||
->where('ceremony_at', '<=', now())
|
||
->with('marriage')
|
||
->cursor()
|
||
->each(function (WeddingCeremony $ceremony) use ($wedding) {
|
||
if (! $ceremony->marriage) {
|
||
return;
|
||
}
|
||
|
||
$result = $wedding->trigger($ceremony);
|
||
|
||
if ($result['ok']) {
|
||
// 广播全房间婚礼庆典
|
||
broadcast(new WeddingCelebration($ceremony, $ceremony->marriage));
|
||
}
|
||
});
|
||
}
|
||
}
|