feat: 增强下注请求校验并调整后台钱包与接入站点权限

This commit is contained in:
2026-06-09 15:06:43 +08:00
parent 41b964a606
commit 8b1d08d3b1
3 changed files with 83 additions and 5 deletions

View File

@@ -0,0 +1,77 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('player_credit_accounts')) {
Schema::create('player_credit_accounts', function (Blueprint $table): void {
$table->unsignedBigInteger('player_id')->primary();
$table->bigInteger('credit_limit')->default(0);
$table->bigInteger('used_credit')->default(0);
$table->bigInteger('frozen_credit')->default(0);
$table->timestamps();
$table->foreign('player_id')
->references('id')
->on('players')
->cascadeOnDelete();
});
}
if (! Schema::hasTable('credit_ledger')) {
Schema::create('credit_ledger', function (Blueprint $table): void {
$table->id();
$table->string('owner_type', 16);
$table->unsignedBigInteger('owner_id');
$table->bigInteger('amount');
$table->string('reason', 64);
$table->string('ref_type', 32)->nullable();
$table->unsignedBigInteger('ref_id')->nullable();
$table->timestamps();
$table->index(['owner_type', 'owner_id', 'created_at']);
});
}
if (Schema::hasTable('players')) {
DB::table('players')
->where('funding_mode', 'credit')
->whereNotExists(function ($query): void {
$query->selectRaw('1')
->from('player_credit_accounts')
->whereColumn('player_credit_accounts.player_id', 'players.id');
})
->orderBy('id')
->select('id')
->chunkById(500, function ($players): void {
$now = now();
$rows = [];
foreach ($players as $player) {
$rows[] = [
'player_id' => (int) $player->id,
'credit_limit' => 0,
'used_credit' => 0,
'frozen_credit' => 0,
'created_at' => $now,
'updated_at' => $now,
];
}
if ($rows !== []) {
DB::table('player_credit_accounts')->insertOrIgnore($rows);
}
}, 'id');
}
}
public function down(): void
{
Schema::dropIfExists('credit_ledger');
Schema::dropIfExists('player_credit_accounts');
}
};