客户等级设置
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\ProductPriceModel;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* 商品等级价格工厂(product_id / level_id 需调用方指定;无需 Faker)
|
||||
*
|
||||
* @extends Factory<ProductPriceModel>
|
||||
*/
|
||||
class ProductPriceModelFactory extends Factory
|
||||
{
|
||||
protected $model = ProductPriceModel::class;
|
||||
|
||||
private static int $sequence = 0;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$seq = ++self::$sequence;
|
||||
|
||||
return [
|
||||
'product_id' => 0,
|
||||
'level_id' => 0,
|
||||
'price' => number_format(random_int(100, 10000) / 100 + $seq * 0.01, 2, '.', ''),
|
||||
'price_type' => ProductPriceModel::PRICE_TYPE_FIXED,
|
||||
'percent' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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