Files
chatroom/app/Models/LotteryTicket.php
lkddi 27371fe321 新增:双色球彩票系统后端基础(阶段一)
📦 数据库
  - lottery_issues(期次表)
  - lottery_tickets(购票记录表)
  - lottery_pool_logs(奖池流水表,透明展示)

🔩 核心组件
  - LotteryIssue / LotteryTicket / LotteryPoolLog 完整 Model
  - LotteryService:购票/机选/开奖/奖池派发/滚存/超级期预热/公屏广播
  - LotteryController:current/buy/quickPick/history/my 五个接口
  - DrawLotteryJob(每日定时开奖)/ OpenLotteryIssueJob(初始化首期)

💰 货币日志
  - CurrencySource 新增 LOTTERY_BUY / LOTTERY_WIN
  - 所有金币变动均通过 UserCurrencyService::change() 记录流水

🗓️ 调度器
  - 每分钟检查停售/开奖时机
  - 每日 18:00 超级期预热广播

🔧 配置
  - GameConfigSeeder 追加 lottery 默认配置(默认关闭)
  - /games/enabled 接口追加 lottery 开关状态
  - 新增 /lottery/* 路由组(auth 保护)
2026-03-04 15:38:02 +08:00

84 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;
}
}