Feat: 商店功能完整实现(单次特效卡888/周卡8888/改名卡5000,含购买、周卡覆盖、改名黑名单)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建商店商品表(shop_items)
|
||||
* 存储商店内所有可购买的商品定义
|
||||
*
|
||||
* @package Database\Migrations
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 执行迁移:创建商品表
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('shop_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 50)->comment('商品名称');
|
||||
$table->string('slug', 50)->unique()->comment('商品唯一标识');
|
||||
$table->string('description', 255)->nullable()->comment('商品描述');
|
||||
$table->string('icon', 20)->default('🛍')->comment('商品图标 emoji');
|
||||
$table->unsignedInteger('price')->comment('价格(金币)');
|
||||
// type: instant=单次立即执行, duration=有时效, one_time=一次性道具
|
||||
$table->enum('type', ['instant', 'duration', 'one_time'])->comment('商品类型');
|
||||
$table->unsignedTinyInteger('duration_days')->nullable()->comment('有效天数(duration 类型用)');
|
||||
$table->unsignedTinyInteger('sort_order')->default(0)->comment('排序');
|
||||
$table->boolean('is_active')->default(true)->comment('是否上架');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚迁移:删除商品表
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('shop_items');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建用户购买记录表(user_purchases)
|
||||
* 记录每个用户购买商店商品的流水与状态
|
||||
*
|
||||
* @package Database\Migrations
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 执行迁移:创建购买记录表
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('user_purchases', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->comment('购买用户 ID');
|
||||
$table->unsignedBigInteger('shop_item_id')->comment('商品 ID');
|
||||
// status:
|
||||
// active = 有效中(周卡 / 改名卡未使用)
|
||||
// expired = 已过期(周卡到期)
|
||||
// used = 已使用(单次卡已播 / 改名卡已用)
|
||||
// cancelled = 被新购买的周卡覆盖作废(金币不退)
|
||||
$table->enum('status', ['active', 'expired', 'used', 'cancelled'])->default('active');
|
||||
$table->unsignedInteger('price_paid')->comment('购买时实际扣除金币');
|
||||
$table->timestamp('expires_at')->nullable()->comment('到期时间(duration 类型使用)');
|
||||
$table->timestamp('used_at')->nullable()->comment('使用时间(one_time/instant 使用)');
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->foreign('shop_item_id')->references('id')->on('shop_items')->onDelete('cascade');
|
||||
$table->index(['user_id', 'status']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚迁移:删除购买记录表
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_purchases');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:创建用户名黑名单表(username_blacklist)
|
||||
* 用户使用改名卡后,旧名称写入此表保留30天,防止他人立即抢注
|
||||
*
|
||||
* @package Database\Migrations
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 执行迁移:创建用户名黑名单表
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('username_blacklist', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('username', 20)->unique()->comment('被保留的旧用户名');
|
||||
$table->timestamp('reserved_until')->comment('保留到期时间(默认30天)');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚迁移:删除黑名单表
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('username_blacklist');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user