| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\Schema;
- /**
- * 入股代理充值锁定:充值到账的金额计入余额(可以立即购买股份),但 N 天内不能提现。
- * - agent_recharge_locks:每笔充值一条,remaining 为还锁着的金额,购买股份时优先消耗;
- * - agent_settings.equity_recharge_lock_days:锁定天数,默认 7,0 表示不锁定。
- */
- return new class extends Migration {
- public function up(): void
- {
- if (!Schema::hasTable('agent_recharge_locks')) {
- Schema::create('agent_recharge_locks', function (Blueprint $t) {
- $t->id();
- $t->unsignedBigInteger('agent_id');
- $t->unsignedBigInteger('balance_log_id')->unique()->comment('充值入账的资金流水');
- $t->string('reference_type', 32)->default('')->comment('agent_recharge / agent_payment_order');
- $t->unsignedBigInteger('reference_id')->nullable();
- $t->decimal('amount', 18, 4)->comment('充值金额');
- $t->decimal('remaining', 18, 4)->comment('仍锁定的金额(购买股份会减少)');
- $t->timestamp('unlock_at')->comment('到期后可提现');
- $t->timestamps();
- $t->index(['agent_id', 'unlock_at']);
- });
- }
- if (!Schema::hasColumn('agent_settings', 'equity_recharge_lock_days')) {
- Schema::table('agent_settings', fn (Blueprint $t) => $t->unsignedSmallInteger('equity_recharge_lock_days')->default(7)->comment('入股代理充值锁定天数,0 不锁定'));
- }
- }
- public function down(): void
- {
- if (Schema::hasColumn('agent_settings', 'equity_recharge_lock_days')) {
- Schema::table('agent_settings', fn (Blueprint $t) => $t->dropColumn('equity_recharge_lock_days'));
- }
- Schema::dropIfExists('agent_recharge_locks');
- }
- };
|