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