add order items table
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?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('order_items', function (Blueprint $table) {
|
||||
$table->bigIncrements('id')->comment('主键');
|
||||
$table->integer('company_id')->comment('公司 ID 与 Tools 保持一致');
|
||||
$table->integer('platform_id')->comment('平台 ID 与 Tools 保持一致');
|
||||
$table->integer('store_id')->comment('店铺 ID 与 Tools 保持一致');
|
||||
$table->integer('order_id')->comment('父订单 ID');
|
||||
$table->text('platform_order_id')->comment('平台父订单 ID');
|
||||
$table->text('sub_order_id')->nullable()->default(null)->comment('平台子订单 ID,部分平台有,如 Tmall');
|
||||
$table->integer('sub_order_type_id')->nullable()->default(null)->comment('平台子订单 类型 id,标记字段');
|
||||
$table->integer('product_id')->comment('商品 ID, 与 Tools 保持一致');
|
||||
$table->string('platform_product_id')->comment('平台商品 ID, 与 Tools 保持一致');
|
||||
$table->string('product_sku')->nullable()->default(null)->comment('商品 SKU 编码, 客户提供的内部商品编码');
|
||||
$table->string('product_barcode')->nullable()->default(null)->comment('商品 条形码 GTIN 等');
|
||||
|
||||
$table->double('unit_price', 10, 2)->default(0)->comment('单件价格');
|
||||
$table->integer('quantity')->default(0)->comment('商品子项总数量');
|
||||
$table->double('discount', 10, 2)->default(0)->comment('订单子项总的折扣金额');
|
||||
$table->double('total', 10, 2)->default(0)->comment('总金额 = 单价X数量 - 折扣');
|
||||
|
||||
$table->jsonb('ext')->nullable()->default(null)->comment('扩展字段');
|
||||
|
||||
$table->timestampsTz();
|
||||
|
||||
// 单字段索引
|
||||
$table->index('company_id');
|
||||
$table->index('platform_id');
|
||||
$table->index('store_id');
|
||||
$table->index('order_id');
|
||||
$table->index('product_id');
|
||||
|
||||
// 复合索引:支持按店铺统计 SKU 和 barcode(包含 NULL 值,支持 IS NULL 和 IS NOT NULL 查询)
|
||||
$table->index(['store_id', 'product_sku'], 'order_items_store_sku_idx');
|
||||
$table->index(['store_id', 'product_barcode'], 'order_items_store_barcode_idx');
|
||||
|
||||
// GIN 索引需要使用原生 SQL
|
||||
});
|
||||
|
||||
// 为 jsonb 字段创建 GIN 索引(PostgreSQL)
|
||||
Schema::getConnection()->statement('CREATE INDEX order_items_ext_gin_idx ON order_items USING gin (ext)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('order_items');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user