2026_11_08_190000_add_agent_recharge_locks.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. /**
  6. * 入股代理充值锁定:充值到账的金额计入余额(可以立即购买股份),但 N 天内不能提现。
  7. * - agent_recharge_locks:每笔充值一条,remaining 为还锁着的金额,购买股份时优先消耗;
  8. * - agent_settings.equity_recharge_lock_days:锁定天数,默认 7,0 表示不锁定。
  9. */
  10. return new class extends Migration {
  11. public function up(): void
  12. {
  13. if (!Schema::hasTable('agent_recharge_locks')) {
  14. Schema::create('agent_recharge_locks', function (Blueprint $t) {
  15. $t->id();
  16. $t->unsignedBigInteger('agent_id');
  17. $t->unsignedBigInteger('balance_log_id')->unique()->comment('充值入账的资金流水');
  18. $t->string('reference_type', 32)->default('')->comment('agent_recharge / agent_payment_order');
  19. $t->unsignedBigInteger('reference_id')->nullable();
  20. $t->decimal('amount', 18, 4)->comment('充值金额');
  21. $t->decimal('remaining', 18, 4)->comment('仍锁定的金额(购买股份会减少)');
  22. $t->timestamp('unlock_at')->comment('到期后可提现');
  23. $t->timestamps();
  24. $t->index(['agent_id', 'unlock_at']);
  25. });
  26. }
  27. if (!Schema::hasColumn('agent_settings', 'equity_recharge_lock_days')) {
  28. Schema::table('agent_settings', fn (Blueprint $t) => $t->unsignedSmallInteger('equity_recharge_lock_days')->default(7)->comment('入股代理充值锁定天数,0 不锁定'));
  29. }
  30. }
  31. public function down(): void
  32. {
  33. if (Schema::hasColumn('agent_settings', 'equity_recharge_lock_days')) {
  34. Schema::table('agent_settings', fn (Blueprint $t) => $t->dropColumn('equity_recharge_lock_days'));
  35. }
  36. Schema::dropIfExists('agent_recharge_locks');
  37. }
  38. };