2026_10_26_160000_create_promotion_activities.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration {
  6. public function up(): void
  7. {
  8. Schema::create('promotion_activities', function (Blueprint $t) {
  9. $t->id(); $t->string('title', 140); $t->string('sub_title', 200)->nullable(); $t->unsignedTinyInteger('type');
  10. $t->boolean('status')->default(false); $t->unsignedBigInteger('start_time'); $t->unsignedBigInteger('end_time');
  11. $t->string('lang', 10)->default('zh'); $t->unsignedInteger('sort')->default(0); $t->text('params');
  12. $t->text('content')->nullable(); $t->string('image', 2048)->nullable();
  13. $t->json('publish_platforms')->nullable(); $t->json('register_platforms')->nullable();
  14. $t->boolean('register_time_limited')->default(false); $t->dateTime('register_start_time')->nullable(); $t->dateTime('register_end_time')->nullable();
  15. $t->boolean('deposit_limited')->default(false); $t->decimal('deposit_min', 24, 2)->nullable(); $t->decimal('deposit_max', 24, 2)->nullable();
  16. $t->boolean('show_ineligible')->default(true); $t->boolean('quota_enabled')->default(true);
  17. $t->unsignedInteger('reward_quota')->nullable(); $t->unsignedInteger('rewarded_count')->default(0);
  18. $t->decimal('budget', 24, 2)->nullable(); $t->decimal('budget_used', 24, 2)->default(0);
  19. $t->index(['type', 'status', 'lang']); $t->timestamps();
  20. });
  21. Schema::create('promotion_campaigns', function (Blueprint $t) {
  22. $t->unsignedBigInteger('activity_id')->primary(); $t->dateTime('first_published_at')->nullable(); $t->timestamps();
  23. });
  24. Schema::create('promotion_accounts', function (Blueprint $t) {
  25. $t->id(); $t->unsignedBigInteger('activity_id'); $t->unsignedBigInteger('user_id');
  26. $t->unsignedInteger('round_no')->default(1); $t->unsignedInteger('spins')->default(0);
  27. $t->dateTime('applied_at')->nullable(); $t->text('application_snapshot')->nullable();
  28. $t->unique(['activity_id', 'user_id']); $t->timestamps();
  29. });
  30. Schema::create('promotion_rounds', function (Blueprint $t) {
  31. $t->id(); $t->unsignedBigInteger('account_id'); $t->unsignedInteger('round_no');
  32. $t->unsignedInteger('coins_cents')->default(0); $t->string('status', 16)->default('active');
  33. $t->dateTime('started_at'); $t->unsignedBigInteger('deposit_cursor')->default(0); $t->text('bet_cursors');
  34. $t->text('completed_tasks'); $t->dateTime('claimed_at')->nullable();
  35. $t->unique(['account_id', 'round_no']); $t->timestamps();
  36. });
  37. Schema::create('promotion_task_grants', function (Blueprint $t) {
  38. $t->id(); $t->unsignedBigInteger('account_id'); $t->unsignedInteger('round_no');
  39. $t->string('task', 24); $t->string('event_key', 80); $t->text('evidence');
  40. $t->unique(['account_id', 'task', 'event_key'], 'promotion_task_event'); $t->timestamps();
  41. });
  42. Schema::create('promotion_spins', function (Blueprint $t) {
  43. $t->id(); $t->unsignedBigInteger('account_id'); $t->unsignedInteger('round_no');
  44. $t->string('request_key', 64); $t->unsignedTinyInteger('prize_index');
  45. $t->unsignedInteger('amount_cents'); $t->unsignedInteger('coins_cents');
  46. $t->boolean('conditions_complete'); $t->decimal('probability', 5, 2);
  47. $t->unique(['account_id', 'request_key']); $t->timestamps();
  48. });
  49. Schema::create('promotion_rewards', function (Blueprint $t) {
  50. $t->id(); $t->unsignedBigInteger('activity_id'); $t->unsignedBigInteger('user_id');
  51. $t->unsignedBigInteger('account_id'); $t->unsignedInteger('round_no');
  52. $t->decimal('amount', 24, 2); $t->decimal('required_flow', 24, 2)->default(0);
  53. $t->string('status', 16); $t->unsignedBigInteger('credited_log_id')->nullable();
  54. $t->unsignedBigInteger('unlocked_log_id')->nullable(); $t->text('rule_snapshot'); $t->text('flow_snapshot')->nullable();
  55. $t->dateTime('unlocked_at')->nullable(); $t->unique(['account_id', 'round_no']); $t->timestamps();
  56. });
  57. Schema::create('promotion_first_deposits', function (Blueprint $t) {
  58. $t->unsignedBigInteger('user_id')->primary(); $t->unsignedBigInteger('deposit_log_id')->unique(); $t->timestamps();
  59. });
  60. Schema::create('promotion_presence', function (Blueprint $t) {
  61. $t->id(); $t->unsignedBigInteger('user_id'); $t->string('session_hash', 64); $t->dateTime('observed_at');
  62. $t->index(['user_id', 'observed_at']); $t->unique(['user_id', 'session_hash', 'observed_at'], 'promotion_presence_dedup');
  63. });
  64. }
  65. public function down(): void
  66. {
  67. foreach (['promotion_presence', 'promotion_first_deposits', 'promotion_rewards', 'promotion_spins', 'promotion_task_grants', 'promotion_rounds', 'promotion_accounts', 'promotion_campaigns', 'promotion_activities'] as $table) Schema::dropIfExists($table);
  68. }
  69. };