2026_11_04_120000_create_upgrade_invite_promotion.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Schema;
  6. /** 邀请升级奖励 (type 10): one fixed campaign; each (invitee, share level tier) pays its inviter once. */
  7. return new class extends Migration {
  8. public function up(): void
  9. {
  10. if (!Schema::hasTable('promotion_upgrade_grants')) {
  11. Schema::create('promotion_upgrade_grants', function (Blueprint $t) {
  12. $t->id(); $t->unsignedBigInteger('activity_id'); $t->unsignedBigInteger('reward_id')->index();
  13. $t->unsignedBigInteger('inviter_user_id'); $t->unsignedBigInteger('invitee_user_id');
  14. $t->unsignedInteger('level')->comment('档位:分享等级 share_levels.level');
  15. $t->decimal('amount', 24, 2); $t->unsignedInteger('invitee_level')->comment('领取时下级的分享等级');
  16. $t->unique(['activity_id', 'invitee_user_id', 'level'], 'promotion_upgrade_grant_once');
  17. $t->index(['activity_id', 'inviter_user_id']); $t->timestamps();
  18. });
  19. }
  20. DB::transaction(function () {
  21. if (DB::table('promotion_activities')->where('type', 10)->exists()) return;
  22. $now = now('Asia/Shanghai');
  23. // Content-only campaign: the title column keeps the type name for admin lists; members see only the body text.
  24. $texts = array_fill_keys(['zh', 'en', 'vi'], ['title' => '', 'content' => '']);
  25. $id = DB::table('promotion_activities')->insertGetId([
  26. 'title' => '邀请升级奖励', 'type' => 10, 'status' => 0,
  27. 'start_time' => $now->timestamp, 'end_time' => $now->copy()->addYear()->timestamp,
  28. 'lang' => 'zh', 'sort' => 0, 'params' => json_encode(['tiers' => []], JSON_THROW_ON_ERROR),
  29. 'translations' => json_encode($texts, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR),
  30. 'publish_platforms' => '[]', 'register_platforms' => '[]',
  31. 'register_time_limited' => 0, 'deposit_limited' => 0, 'show_ineligible' => 1,
  32. 'reward_quota' => null, 'budget' => null, 'created_at' => $now, 'updated_at' => $now,
  33. ]);
  34. DB::table('promotion_campaigns')->insert(['activity_id' => $id, 'first_published_at' => null, 'created_at' => $now, 'updated_at' => $now]);
  35. });
  36. }
  37. public function down(): void
  38. {
  39. // Keep the campaign and its paid grants on a code rollback.
  40. }
  41. };