120 lines
3.0 KiB
PHP
120 lines
3.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 文件功能:百家乐买单活动模型
|
|
*
|
|
* 负责描述一次完整的“你玩游戏我买单”活动,
|
|
* 包含时间窗口、当前状态、统计汇总以及开启/结束操作者信息。
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class BaccaratLossCoverEvent extends Model
|
|
{
|
|
/** @use HasFactory<\Database\Factories\BaccaratLossCoverEventFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* 允许批量赋值的字段。
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'title',
|
|
'description',
|
|
'status',
|
|
'starts_at',
|
|
'ends_at',
|
|
'claim_deadline_at',
|
|
'created_by_user_id',
|
|
'closed_by_user_id',
|
|
'started_notice_sent_at',
|
|
'ended_notice_sent_at',
|
|
'participant_count',
|
|
'compensable_user_count',
|
|
'total_loss_amount',
|
|
'total_claimed_amount',
|
|
];
|
|
|
|
/**
|
|
* 字段类型转换。
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'starts_at' => 'datetime',
|
|
'ends_at' => 'datetime',
|
|
'claim_deadline_at' => 'datetime',
|
|
'started_notice_sent_at' => 'datetime',
|
|
'ended_notice_sent_at' => 'datetime',
|
|
'participant_count' => 'integer',
|
|
'compensable_user_count' => 'integer',
|
|
'total_loss_amount' => 'integer',
|
|
'total_claimed_amount' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 关联:开启活动的用户。
|
|
*/
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by_user_id');
|
|
}
|
|
|
|
/**
|
|
* 关联:结束活动的用户。
|
|
*/
|
|
public function closer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'closed_by_user_id');
|
|
}
|
|
|
|
/**
|
|
* 关联:活动下的用户聚合记录。
|
|
*/
|
|
public function records(): HasMany
|
|
{
|
|
return $this->hasMany(BaccaratLossCoverRecord::class, 'event_id');
|
|
}
|
|
|
|
/**
|
|
* 关联:活动下的百家乐下注记录。
|
|
*/
|
|
public function bets(): HasMany
|
|
{
|
|
return $this->hasMany(BaccaratBet::class, 'loss_cover_event_id');
|
|
}
|
|
|
|
/**
|
|
* 判断活动当前是否允许领取补偿。
|
|
*/
|
|
public function isClaimable(): bool
|
|
{
|
|
return $this->status === 'claimable'
|
|
&& $this->claim_deadline_at !== null
|
|
&& $this->claim_deadline_at->isFuture();
|
|
}
|
|
|
|
/**
|
|
* 返回活动状态中文标签。
|
|
*/
|
|
public function statusLabel(): string
|
|
{
|
|
return match ($this->status) {
|
|
'scheduled' => '未开始',
|
|
'active' => '进行中',
|
|
'settlement_pending' => '等待结算',
|
|
'claimable' => '可领取',
|
|
'completed' => '已结束',
|
|
'cancelled' => '已取消',
|
|
default => '未知状态',
|
|
};
|
|
}
|
|
}
|