客户等级设置
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?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) / 100,product_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');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user