功能:婚姻系统第1-3步(枚举/迁移/Seeder)
Step 1 - 枚举扩展: - 新增 IntimacySource 枚举(7种亲密度来源) - CurrencySource 追加7个婚姻相关来源 Step 2 - 数据库迁移(6张表): - marriage_configs(约30条可配置参数) - marriage_intimacy_logs(亲密度变更日志) - wedding_tiers(5档婚礼配置) - wedding_ceremonies(婚礼仪式记录) - wedding_envelope_claims(红包领取记录) - marriages 表改良(新增全部业务字段) - users.frozen_jjb(定时婚礼金币冻结) - shop_items.type 枚举添加 ring 类型 Step 3 - Seeder: - 28条婚姻参数默认配置 - 5个婚礼档位 - 3种戒指道具(银/金/钻)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建婚姻系统参数配置表 marriage_configs
|
||||
*
|
||||
* 键值对型配置表,存储所有婚姻系统的可调参数(魅力/亲密度/惩罚等)。
|
||||
* 管理员可在后台「婚姻管理 → 参数配置」页面修改,不需要修改代码。
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 marriage_configs 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('marriage_configs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('group', 30)->index()->comment('配置分组(用于后台分组展示)');
|
||||
$table->string('key', 60)->unique()->comment('配置键名(系统内部使用)');
|
||||
$table->integer('value')->comment('配置值(均为整数)');
|
||||
$table->string('label', 60)->comment('中文名称(后台显示)');
|
||||
$table->string('description', 120)->nullable()->comment('说明(提示管理员含义)');
|
||||
$table->integer('min')->nullable()->comment('允许最小值');
|
||||
$table->integer('max')->nullable()->comment('允许最大值');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚:删除 marriage_configs 表。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('marriage_configs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建婚姻亲密度日志表 marriage_intimacy_logs
|
||||
*
|
||||
* 记录婚姻亲密度的每一次变更,包括来源、变更量、变更后余额。
|
||||
* 亲密度属于婚姻对(而非个人),独立于 user_currency_logs 存储。
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 marriage_intimacy_logs 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('marriage_intimacy_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('marriage_id')->index()->comment('所属婚姻记录 ID');
|
||||
$table->integer('amount')->comment('变更量(正数增加,负数减少)');
|
||||
$table->integer('balance_after')->comment('变更后亲密度总值');
|
||||
$table->string('source', 50)->comment('来源(对应 IntimacySource 枚举值)');
|
||||
$table->string('remark', 100)->nullable()->comment('备注说明');
|
||||
$table->timestamp('created_at')->nullable()->comment('记录时间');
|
||||
|
||||
$table->foreign('marriage_id')->references('id')->on('marriages')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚:删除亲密度日志表。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('marriage_intimacy_logs');
|
||||
}
|
||||
};
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:改良 marriages 表,添加婚姻系统所需新字段
|
||||
* 同时为 users 表添加 frozen_jjb(定时婚礼金币冻结)字段
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 执行迁移:改良 marriages 表,扩展 user_purchases.status,新增 users.frozen_jjb。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// ── marriages 表:新增所有业务字段 ─────────────────────────
|
||||
Schema::table('marriages', function (Blueprint $table) {
|
||||
// 关联用户(将旧字符串字段升级为 FK)
|
||||
$table->unsignedBigInteger('user_id')->nullable()->after('id')->index()->comment('求婚发起方 user.id');
|
||||
$table->unsignedBigInteger('partner_id')->nullable()->after('user_id')->index()->comment('被求婚方 user.id');
|
||||
|
||||
// 使用的戒指
|
||||
$table->unsignedBigInteger('ring_item_id')->nullable()->after('partner_id')->comment('使用的戒指 shop_items.id');
|
||||
$table->unsignedBigInteger('ring_purchase_id')->nullable()->after('ring_item_id')->comment('消耗的购买记录 user_purchases.id');
|
||||
|
||||
// 婚姻状态
|
||||
$table->enum('status', ['pending', 'married', 'divorced', 'rejected', 'expired'])
|
||||
->default('pending')->after('ring_purchase_id')->comment('婚姻状态');
|
||||
|
||||
// 关键时间节点
|
||||
$table->timestamp('proposed_at')->nullable()->after('status')->comment('求婚时间');
|
||||
$table->timestamp('expires_at')->nullable()->after('proposed_at')->comment('求婚48h后过期时间');
|
||||
$table->timestamp('married_at')->nullable()->after('expires_at')->comment('结婚时间');
|
||||
$table->timestamp('divorced_at')->nullable()->after('married_at')->comment('离婚时间');
|
||||
|
||||
// 离婚相关
|
||||
$table->enum('divorce_type', ['mutual', 'forced', 'auto', 'admin'])
|
||||
->nullable()->after('divorced_at')->comment('离婚类型');
|
||||
$table->unsignedBigInteger('divorcer_id')->nullable()->after('divorce_type')->comment('强制离婚发起方 user.id');
|
||||
$table->timestamp('divorce_requested_at')->nullable()->after('divorcer_id')->comment('协议离婚申请时间(用于72h超时检测)');
|
||||
|
||||
// 亲密度
|
||||
$table->integer('intimacy')->default(0)->after('divorce_requested_at')->comment('当前亲密度积分');
|
||||
$table->tinyInteger('level')->unsigned()->default(1)->after('intimacy')->comment('婚姻等级(1-4)');
|
||||
|
||||
// 统计字段
|
||||
$table->integer('online_minutes')->default(0)->after('level')->comment('双方同时在线累计分钟数');
|
||||
$table->integer('flower_count')->default(0)->after('online_minutes')->comment('相互送花累计次数');
|
||||
$table->integer('chat_count')->default(0)->after('flower_count')->comment('私聊消息累计条数');
|
||||
|
||||
// 管理员备注
|
||||
$table->string('admin_note', 200)->nullable()->after('chat_count')->comment('管理员操作备注');
|
||||
});
|
||||
|
||||
// ── users 表:新增定时婚礼冻结金币字段 ──────────────────────
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->integer('frozen_jjb')->default(0)->after('jjb')->comment('定时婚礼预冻结金币(待婚礼触发后正式扣除)');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚:移除新增字段。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('marriages', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'user_id', 'partner_id', 'ring_item_id', 'ring_purchase_id',
|
||||
'status', 'proposed_at', 'expires_at', 'married_at', 'divorced_at',
|
||||
'divorce_type', 'divorcer_id', 'divorce_requested_at',
|
||||
'intimacy', 'level', 'online_minutes', 'flower_count', 'chat_count',
|
||||
'admin_note',
|
||||
]);
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('frozen_jjb');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建婚礼档位配置表 wedding_tiers
|
||||
*
|
||||
* 固定5个档位,存储普天同庆的金额/名称/描述。
|
||||
* 管理员可在后台修改各档位的名称和金额,但不能增删档位。
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 wedding_tiers 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('wedding_tiers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->tinyInteger('tier')->unsigned()->unique()->comment('档位编号(1-5,固定)');
|
||||
$table->string('name', 30)->comment('档位名称(可改,如:小小祝福)');
|
||||
$table->string('icon', 20)->comment('档位图标(如:⭐⭐⭐)');
|
||||
$table->integer('amount')->comment('该档位总金币数');
|
||||
$table->string('description', 100)->nullable()->comment('前台展示描述');
|
||||
$table->boolean('is_active')->default(true)->comment('是否启用(关闭则前台不显示该档位)');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚:删除婚礼档位表。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('wedding_tiers');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建婚礼仪式记录表 wedding_ceremonies
|
||||
*
|
||||
* 记录每一场婚礼的档位、支付方式、举办时间及红包分发情况。
|
||||
* 一段婚姻最多同时有一场 pending/active 状态的婚礼。
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 wedding_ceremonies 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('wedding_ceremonies', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('marriage_id')->index()->comment('关联婚姻 ID');
|
||||
$table->unsignedBigInteger('tier_id')->nullable()->index()->comment('关联婚礼档位 ID(NULL=不举办红包)');
|
||||
// 快照金额:防止档位金额被修改后影响历史记录
|
||||
$table->integer('total_amount')->default(0)->comment('婚礼红包总金额(快照值)');
|
||||
$table->enum('payer_type', ['groom', 'joint'])->comment('支付方式:groom=男方全付,joint=双方各半');
|
||||
$table->integer('groom_amount')->default(0)->comment('男方实际扣除金额');
|
||||
$table->integer('partner_amount')->default(0)->comment('女方实际扣除金额(joint时各半)');
|
||||
$table->enum('ceremony_type', ['immediate', 'scheduled'])->comment('婚礼类型:immediate=立即,scheduled=定时');
|
||||
$table->timestamp('ceremony_at')->nullable()->comment('实际或计划举办时间');
|
||||
$table->enum('status', ['pending', 'active', 'completed', 'cancelled', 'expired'])
|
||||
->default('pending')->comment('婚礼状态');
|
||||
$table->integer('online_count')->nullable()->comment('触发时在线用户数(分发后记录)');
|
||||
$table->integer('claimed_count')->default(0)->comment('已领取人数');
|
||||
$table->integer('claimed_amount')->default(0)->comment('已领取金额合计');
|
||||
$table->timestamp('expires_at')->nullable()->comment('红包领取截止时间(24h后过期)');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('marriage_id')->references('id')->on('marriages')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚:删除婚礼仪式表。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('wedding_ceremonies');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建婚礼红包领取记录表 wedding_envelope_claims
|
||||
*
|
||||
* 婚礼触发时,给当时所有在线用户预分配随机金额并写入此表。
|
||||
* 用户点击领取后标记 claimed=true,24h 后未领取的自动过期。
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 创建 wedding_envelope_claims 表。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('wedding_envelope_claims', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('ceremony_id')->index()->comment('关联婚礼仪式 ID');
|
||||
$table->unsignedBigInteger('user_id')->index()->comment('领取用户 ID');
|
||||
$table->integer('amount')->comment('预分配金额(随机红包算法计算)');
|
||||
$table->boolean('claimed')->default(false)->index()->comment('是否已领取');
|
||||
$table->timestamp('claimed_at')->nullable()->comment('领取时间');
|
||||
$table->timestamp('created_at')->nullable()->comment('分配时间');
|
||||
|
||||
$table->unique(['ceremony_id', 'user_id'], 'unique_ceremony_user');
|
||||
$table->foreign('ceremony_id')->references('id')->on('wedding_ceremonies')->onDelete('cascade');
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚:删除红包领取记录表。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('wedding_envelope_claims');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:为 shop_items.type 枚举添加 ring(戒指)类型
|
||||
*
|
||||
* 戒指道具是婚姻系统专用的一次性消耗品,与普通 one_time 类型语义不同,
|
||||
* 单独用 ring 类型区分,方便后续过滤查询。
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 为 type 枚举新增 ring 值。
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::statement("ALTER TABLE `shop_items` MODIFY `type` ENUM('instant','duration','one_time','ring') NOT NULL COMMENT '道具类型'");
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚:删除 ring 枚举值(先将已有 ring 类型记录改为 one_time 以防报错)。
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
DB::statement("UPDATE `shop_items` SET `type` = 'one_time' WHERE `type` = 'ring'");
|
||||
DB::statement("ALTER TABLE `shop_items` MODIFY `type` ENUM('instant','duration','one_time') NOT NULL COMMENT '道具类型'");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user