84 lines
2.0 KiB
PHP
84 lines
2.0 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 文件功能:双色球购票记录 Model
|
|||
|
|
*
|
|||
|
|
* 每条记录对应一注彩票(一组选号),包含开奖后的中奖等级与派奖金额。
|
|||
|
|
*
|
|||
|
|
* @author ChatRoom Laravel
|
|||
|
|
*
|
|||
|
|
* @version 1.0.0
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
namespace App\Models;
|
|||
|
|
|
|||
|
|
use Illuminate\Database\Eloquent\Model;
|
|||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
|
|
|
|||
|
|
class LotteryTicket extends Model
|
|||
|
|
{
|
|||
|
|
protected $fillable = [
|
|||
|
|
'issue_id',
|
|||
|
|
'user_id',
|
|||
|
|
'red1', 'red2', 'red3', 'blue',
|
|||
|
|
'amount',
|
|||
|
|
'is_quick_pick',
|
|||
|
|
'prize_level',
|
|||
|
|
'payout',
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 字段类型转换。
|
|||
|
|
*/
|
|||
|
|
protected function casts(): array
|
|||
|
|
{
|
|||
|
|
return [
|
|||
|
|
'is_quick_pick' => 'boolean',
|
|||
|
|
'prize_level' => 'integer',
|
|||
|
|
'payout' => 'integer',
|
|||
|
|
'amount' => 'integer',
|
|||
|
|
];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ─── 关联 ──────────────────────────────────────────────────────────
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 关联的期次。
|
|||
|
|
*/
|
|||
|
|
public function issue(): BelongsTo
|
|||
|
|
{
|
|||
|
|
return $this->belongsTo(LotteryIssue::class, 'issue_id');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 关联的购票用户。
|
|||
|
|
*/
|
|||
|
|
public function user(): BelongsTo
|
|||
|
|
{
|
|||
|
|
return $this->belongsTo(User::class);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ─── 业务方法 ──────────────────────────────────────────────────────
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 返回本注选号的格式化字符串(用于备注和展示)。
|
|||
|
|
*
|
|||
|
|
* @return string 如:红03 08 12 蓝4
|
|||
|
|
*/
|
|||
|
|
public function numbersLabel(): string
|
|||
|
|
{
|
|||
|
|
return sprintf(
|
|||
|
|
'红%02d %02d %02d 蓝%d',
|
|||
|
|
$this->red1, $this->red2, $this->red3, $this->blue
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 是否已中奖。
|
|||
|
|
*/
|
|||
|
|
public function isWon(): bool
|
|||
|
|
{
|
|||
|
|
return $this->prize_level > 0;
|
|||
|
|
}
|
|||
|
|
}
|