engine = 'InnoDB'; $t->id(); $t->string('category', 32)->comment('游戏分类,与分享返佣分类标识一致'); $t->integer('level')->comment('会员等级 level.level'); $t->decimal('min_effective_amount', 20, 2)->default(0)->comment('有效投注门槛'); $t->decimal('percentage', 8, 4)->default(0)->comment('返还百分比,0.8 表示 0.8%'); $t->decimal('turnover_multiple', 8, 2)->default(0)->comment('打码量倍数,0 表示无'); $t->timestamps(); $t->unique(['category', 'level', 'min_effective_amount'], 'rebate_rules_tier_unique'); }); Schema::create('backflow_rules', function (Blueprint $t) { $t->engine = 'InnoDB'; $t->id(); $t->string('category', 32)->comment('游戏分类,与分享返佣分类标识一致'); $t->decimal('min_loss_amount', 20, 2)->default(0)->comment('亏损金额门槛'); $t->decimal('reward_amount', 20, 2)->default(0)->comment('奖励金额'); $t->decimal('turnover_multiple', 8, 2)->default(0)->comment('打码量倍数,0 表示无'); $t->timestamps(); $t->unique(['category', 'min_loss_amount'], 'backflow_rules_tier_unique'); }); Schema::table('rebates', function (Blueprint $t) { $t->json('details')->nullable()->comment('分类明细'); $t->decimal('need_flow', 20, 2)->default(0)->comment('需要打码量'); }); Schema::table('rebates', function (Blueprint $t) { $t->decimal('rebate_ratio', 12, 6)->nullable()->comment('综合返还比例')->change(); }); Schema::table('backflow', function (Blueprint $t) { $t->decimal('loss_amount', 20, 2)->default(0)->comment('分类净亏损合计'); $t->json('details')->nullable()->comment('分类明细'); $t->decimal('need_flow', 20, 2)->default(0)->comment('需要打码量'); }); if (Schema::hasTable('share_bet_facts')) { Schema::table('share_bet_facts', function (Blueprint $t) { $t->index('updated_at', 'share_bet_facts_updated_at_index'); }); } // Keep the old values in the down() path, so rollback restores what operators had. $old = DB::table('config')->whereIn('field', self::FIELDS)->get()->map(fn ($row) => (array) $row)->all(); Schema::create('reward_rule_config_backup', function (Blueprint $t) { $t->string('field', 64)->primary(); $t->json('row'); }); foreach ($old as $row) { DB::table('reward_rule_config_backup')->insert(['field' => $row['field'], 'row' => json_encode($row, JSON_UNESCAPED_UNICODE)]); } DB::table('config')->whereIn('field', self::FIELDS)->delete(); } public function down(): void { if (Schema::hasTable('reward_rule_config_backup')) { foreach (DB::table('reward_rule_config_backup')->get() as $backup) { $row = json_decode($backup->row, true); if (!DB::table('config')->where('field', $row['field'])->exists()) DB::table('config')->insert($row); } Schema::drop('reward_rule_config_backup'); } if (Schema::hasTable('share_bet_facts')) { Schema::table('share_bet_facts', function (Blueprint $t) { $t->dropIndex('share_bet_facts_updated_at_index'); }); } Schema::table('backflow', function (Blueprint $t) { $t->dropColumn(['loss_amount', 'details', 'need_flow']); }); Schema::table('rebates', function (Blueprint $t) { $t->dropColumn(['details', 'need_flow']); }); Schema::dropIfExists('backflow_rules'); Schema::dropIfExists('rebate_rules'); } };