数据库迁移修改

This commit is contained in:
liu
2026-08-20 14:09:20 +08:00
parent c1d490134e
commit 52ab195432
3 changed files with 2 additions and 70 deletions
@@ -18,6 +18,7 @@ return new class extends Migration
$table->increments('id')->comment('等级ID'); $table->increments('id')->comment('等级ID');
$table->integer('icon_id')->nullable()->comment('等级图标ID'); $table->integer('icon_id')->nullable()->comment('等级图标ID');
$table->string('name', 50)->comment('等级名称(如:一级客户、二级客户)'); $table->string('name', 50)->comment('等级名称(如:一级客户、二级客户)');
$table->decimal('percent', 5, 2)->default(0)->comment('价格上浮比例(%,如 30 = 成本价上浮30%');
$table->integer('sort')->default(0)->comment('排序'); $table->integer('sort')->default(0)->comment('排序');
$table->integer('status')->default(1)->comment('状态(1正常 0停用)'); $table->integer('status')->default(1)->comment('状态(1正常 0停用)');
$table->timestamps(); $table->timestamps();
@@ -8,7 +8,7 @@ return new class extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
* 商品中心(A1-A3):商品分类、商品档案、客户等级价格体系 * 商品中心(A1-A3):商品分类、商品档案等级价格 = 成本价 × customer_level.percent 上浮)
*/ */
public function up(): void public function up(): void
{ {
@@ -50,21 +50,6 @@ return new class extends Migration
$table->comment('商品表'); $table->comment('商品表');
}); });
} }
// 商品等级价格表
if (! Schema::hasTable('product_price')) {
Schema::create('product_price', function (Blueprint $table) {
$table->increments('id')->comment('价格ID');
$table->integer('product_id')->comment('商品ID');
$table->integer('level_id')->comment('客户等级ID');
$table->decimal('price', 10, 2)->default(0)->comment('该等级下的商品单价(固定价=实际单价;百分比=等价固定价)');
$table->unsignedTinyInteger('price_type')->default(0)->comment('计价类型(0固定价 1成本百分比)');
$table->decimal('percent', 5, 2)->default(0)->comment('成本上浮百分点(如 30 = 上浮30%,仅 price_type=1 生效)');
$table->timestamps();
$table->unique(['product_id', 'level_id'], 'product_price_product_level_unique');
$table->comment('商品等级价格表');
});
}
} }
/** /**
@@ -74,6 +59,5 @@ return new class extends Migration
{ {
Schema::dropIfExists('product_category'); Schema::dropIfExists('product_category');
Schema::dropIfExists('product'); Schema::dropIfExists('product');
Schema::dropIfExists('product_price');
} }
}; };
@@ -1,53 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
* 价格体系重构:商品等级价格表 → 客户等级固定上浮比例
* (售价 = 成本价 × (100 + percent) / 100product_price 表废弃删除)
*/
public function up(): void
{
// 客户等级表加价格上浮比例(全守卫幂等:开发库若已手工加列则跳过)
if (! Schema::hasColumn('customer_level', 'percent')) {
Schema::table('customer_level', function (Blueprint $table) {
$table->decimal('percent', 5, 2)->default(0)->after('name')->comment('价格上浮比例(%,如 30 = 成本价上浮30%');
});
}
// 商品等级价格表废弃(历史数据随表删除)
Schema::dropIfExists('product_price');
}
/**
* Reverse the migrations.
*/
public function down(): void
{
// 恢复商品等级价格表(结构回滚,历史数据不恢复)
if (! Schema::hasTable('product_price')) {
Schema::create('product_price', function (Blueprint $table) {
$table->increments('id')->comment('价格ID');
$table->integer('product_id')->comment('商品ID');
$table->integer('level_id')->comment('客户等级ID');
$table->decimal('price', 10, 2)->default(0)->comment('该等级下的商品单价(固定价=实际单价;百分比=等价固定价)');
$table->unsignedTinyInteger('price_type')->default(0)->comment('计价类型(0固定价 1成本百分比)');
$table->decimal('percent', 5, 2)->default(0)->comment('成本上浮百分点(如 30 = 上浮30%,仅 price_type=1 生效)');
$table->timestamps();
$table->unique(['product_id', 'level_id'], 'product_price_product_level_unique');
$table->comment('商品等级价格表');
});
}
if (Schema::hasColumn('customer_level', 'percent')) {
Schema::table('customer_level', function (Blueprint $table) {
$table->dropColumn('percent');
});
}
}
};