Files
datahub/backend/migrations/2025_11_13_068522_create_skus_mapping.php
T

47 lines
2.1 KiB
PHP
Raw Normal View History

2025-11-13 16:27:32 +08:00
<?php
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('skus_mapping', function (Blueprint $table) {
2025-11-14 10:58:26 +08:00
$table->comment('存储 业务侧 SKU 到 客户原始 SKU 的映射信息, 当平台绑定异常时使用。如果原始 SKU 中没有平台对应的组合商品,则有两种解决思路。1. 为了统计 sku 销售数量的准确性,对组合商品进行拆单 (推荐的做法)。2. 与客户侧沟通在原始数据侧创建新的 SKU 用来标记组合商品。 运营类特殊商品如 补差价/锁价券等,原则上不应该参与热卖统计。');
2025-11-13 16:27:32 +08:00
2025-11-14 10:58:26 +08:00
$table->bigIncrements('id')->comment('主键');
2025-11-13 16:27:32 +08:00
$table->integer('company_id')->comment('公司 ID 与 Tools 保持一致');
$table->integer('platform_id')->comment('平台 ID 与 Tools 保持一致');
$table->text('platform_product_id')->comment('平台 商品 ID 与 电商平台 保持一致');
$table->text('origin_sku')->comment('客户侧匹配的 SKU 编码, 组合商品需要拆分');
$table->integer('store_id')->nullable()->comment('店铺 ID 与 Tools 保持一致, 建议填写以方便核对');
$table->integer('warehouse_id')->nullable()->comment('店铺绑定仓库 ID 与 Tools 保持一致,建议填写,建议填写以方便核对');
$table->boolean('enabled')->default(true)->comment('是否启用映射规则,默认为启用');
$table->text('note')->nullable()->default(null)->comment('备注信息');
$table->timestampsTz();
2025-11-13 16:41:56 +08:00
// 创建联合唯一索引:确保同一平台的同一产品只能有一条映射记录
// 原始 SKU 的约束由业务侧实现
$table->unique(['platform_id', 'platform_product_id'], 'uk_platform_product');
2025-11-13 16:27:32 +08:00
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('skus_mapping');
}
};