新增:双色球彩票系统后端基础(阶段一)
📦 数据库 - 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 保护)
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:双色球期次表迁移
|
||||
*
|
||||
* 记录每期彩票的开奖状态、号码、奖池金额、派奖结果。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 lottery_issues 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('lottery_issues', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
// 期号,如 2026063(年份+当年第几期)
|
||||
$table->string('issue_no', 20)->unique()->comment('期号');
|
||||
|
||||
// 状态:open=购票中 / closed=已停售 / settled=已开奖
|
||||
$table->string('status', 20)->default('open')->comment('状态');
|
||||
|
||||
// 开奖号码(开奖后写入)
|
||||
$table->unsignedTinyInteger('red1')->nullable()->comment('开奖红球1');
|
||||
$table->unsignedTinyInteger('red2')->nullable()->comment('开奖红球2');
|
||||
$table->unsignedTinyInteger('red3')->nullable()->comment('开奖红球3');
|
||||
$table->unsignedTinyInteger('blue')->nullable()->comment('开奖蓝球');
|
||||
|
||||
// 奖池金额
|
||||
$table->unsignedBigInteger('pool_amount')->default(0)->comment('本期奖池金额(含滚存)');
|
||||
$table->unsignedBigInteger('carry_amount')->default(0)->comment('从上期滚存来的金额');
|
||||
|
||||
// 超级期标记
|
||||
$table->boolean('is_super_issue')->default(false)->comment('是否超级期');
|
||||
$table->unsignedTinyInteger('no_winner_streak')->default(0)->comment('截止本期连续无一等奖期数');
|
||||
|
||||
// 统计
|
||||
$table->unsignedInteger('total_tickets')->default(0)->comment('本期购票总注数');
|
||||
$table->unsignedBigInteger('payout_amount')->default(0)->comment('实际派奖总额');
|
||||
|
||||
// 时间
|
||||
$table->timestamp('sell_closes_at')->nullable()->comment('停售时间');
|
||||
$table->timestamp('draw_at')->nullable()->comment('开奖时间');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('status');
|
||||
$table->index('draw_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚迁移。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('lottery_issues');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:双色球奖池流水表迁移
|
||||
*
|
||||
* 透明记录每期奖池的每笔变动(售票入池、派奖扣除、滚存、系统注入)。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 lottery_pool_logs 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('lottery_pool_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignId('issue_id')->constrained('lottery_issues')->cascadeOnDelete()->comment('关联期次 ID');
|
||||
|
||||
// 变动金额(正数=增加,负数=减少)
|
||||
$table->bigInteger('change_amount')->comment('变动金额');
|
||||
|
||||
// 变动原因:ticket_sale/carry_over/admin_inject/system_inject/payout/prize_4th/prize_5th
|
||||
$table->string('reason', 30)->comment('变动原因');
|
||||
|
||||
// 变动后奖池余额快照
|
||||
$table->unsignedBigInteger('pool_after')->comment('变动后奖池金额');
|
||||
|
||||
// 备注(可选,如:第X注购票、N等奖派奖等)
|
||||
$table->string('remark', 200)->nullable()->comment('备注');
|
||||
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
$table->index(['issue_id', 'reason']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚迁移。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('lottery_pool_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:双色球购票记录表迁移
|
||||
*
|
||||
* 记录每用户每注的选号、中奖等级、派奖金额。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 lottery_tickets 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('lottery_tickets', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignId('issue_id')->constrained('lottery_issues')->cascadeOnDelete()->comment('期次 ID');
|
||||
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete()->comment('购票用户 ID');
|
||||
|
||||
// 用户选号(红球已排序存储,方便比对)
|
||||
$table->unsignedTinyInteger('red1')->comment('用户选红球1(较小)');
|
||||
$table->unsignedTinyInteger('red2')->comment('用户选红球2');
|
||||
$table->unsignedTinyInteger('red3')->comment('用户选红球3(较大)');
|
||||
$table->unsignedTinyInteger('blue')->comment('用户选蓝球');
|
||||
|
||||
// 购票信息
|
||||
$table->unsignedInteger('amount')->comment('购票金额(每注固定 ticket_price)');
|
||||
$table->boolean('is_quick_pick')->default(false)->comment('是否机选');
|
||||
|
||||
// 开奖结果(开奖后写入)
|
||||
$table->unsignedTinyInteger('prize_level')->default(0)->comment('中奖等级:0=未中 1-5=各等级');
|
||||
$table->unsignedBigInteger('payout')->default(0)->comment('实际派奖金额');
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['issue_id', 'user_id']);
|
||||
$table->index(['user_id', 'created_at']);
|
||||
$table->index('prize_level');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚迁移。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('lottery_tickets');
|
||||
}
|
||||
};
|
||||
@@ -133,6 +133,41 @@ class GameConfigSeeder extends Seeder
|
||||
'fishing_cooldown' => 300, // 收竿后冷却秒数
|
||||
],
|
||||
],
|
||||
|
||||
// ─── 双色球彩票 ──────────────────────────────────────────────
|
||||
[
|
||||
'game_key' => 'lottery',
|
||||
'name' => '双色球彩票',
|
||||
'icon' => '🎟️',
|
||||
'description' => '每日一期,选3红球(1-12)+1蓝球(1-6),按奖池比例派奖,无一等奖滚存累积。',
|
||||
'enabled' => false,
|
||||
'params' => [
|
||||
// ── 开奖时间 ──
|
||||
'draw_hour' => 20, // 每天几点开奖(24小时制)
|
||||
'draw_minute' => 0, // 几分开奖
|
||||
'stop_sell_minutes' => 2, // 开奖前几分钟停止购票
|
||||
|
||||
// ── 购票限制 ──
|
||||
'ticket_price' => 100, // 每注金币
|
||||
'max_tickets_per_user' => 50, // 每期单人最多购票注数
|
||||
'max_tickets_per_buy' => 10, // 单次最多购买注数
|
||||
|
||||
// ── 奖池分配比例(%)──
|
||||
'pool_ratio' => 70, // 购票金额进奖池比例
|
||||
'prize_1st_ratio' => 60, // 一等奖占奖池%
|
||||
'prize_2nd_ratio' => 20, // 二等奖占奖池%
|
||||
'prize_3rd_ratio' => 10, // 三等奖占奖池%
|
||||
'carry_ratio' => 10, // 强制滚存比例%
|
||||
|
||||
// ── 固定小奖 ──
|
||||
'prize_4th_fixed' => 150, // 四等奖固定金额/注
|
||||
'prize_5th_fixed' => 50, // 五等奖固定金额/注
|
||||
|
||||
// ── 超级期 ──
|
||||
'super_issue_threshold' => 3, // 连续几期无一等奖触发超级期
|
||||
'super_issue_inject' => 20000, // 超级期系统注入金额上限
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($games as $game) {
|
||||
|
||||
Reference in New Issue
Block a user