From db4824b776e87c98ccb0b92a77f2fa41d2f4e571 Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Wed, 3 Dec 2025 16:01:55 +0800 Subject: [PATCH] update store table --- backend/app/Model/Store.php | 6 +++ ...form_meta_and_timezone_to_stores_table.php | 46 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 backend/migrations/2025_12_03_155531_add_platform_meta_and_timezone_to_stores_table.php diff --git a/backend/app/Model/Store.php b/backend/app/Model/Store.php index c132a5a..81b100a 100644 --- a/backend/app/Model/Store.php +++ b/backend/app/Model/Store.php @@ -11,6 +11,8 @@ use Hyperf\DbConnection\Model\Model; * @property int $company_id 店铺所属的公司 ID * @property int $platform_id 平台 ID * @property string $platform_store_id 平台店铺 ID + * @property array $platform_meta 平台店铺扩展信息 如 店铺所属服务商 - 平台应用 id - 平台商家 id, 平台店铺名称-区域 等根据需要补充其他额外信息 + * @property int $timezone 平台店铺统计时使用的时区 默认为 +8 表示 北京时间, 如果是日本则是 +7, 填写基于 UTC 的偏移值 * @property int $warehouse_id 店铺使用的仓库 ID * @property int $currency_id 店铺的本币 ID * @property boolean $enabled 激活状态 @@ -41,6 +43,8 @@ class Store extends Model 'company_id', 'platform_id', 'platform_store_id', + 'platform_meta', + 'timezone', 'warehouse_id', 'currency_id', 'enabled', @@ -58,6 +62,8 @@ class Store extends Model 'id' => 'integer', 'company_id' => 'integer', 'platform_id' => 'integer', + 'platform_meta' => 'array', + 'timezone' => 'integer', 'warehouse_id' => 'integer', 'currency_id' => 'integer', 'enabled' => 'boolean', diff --git a/backend/migrations/2025_12_03_155531_add_platform_meta_and_timezone_to_stores_table.php b/backend/migrations/2025_12_03_155531_add_platform_meta_and_timezone_to_stores_table.php new file mode 100644 index 0000000..e91244a --- /dev/null +++ b/backend/migrations/2025_12_03_155531_add_platform_meta_and_timezone_to_stores_table.php @@ -0,0 +1,46 @@ +jsonb('platform_meta') + ->nullable() + ->after('platform_store_id') + ->comment('平台店铺扩展信息 如 店铺所属服务商 - 平台应用 id - 平台商家 id, 平台店铺名称-区域 等根据需要补充其他额外信息'); + + // 在 platform_meta 后添加 timezone 字段 + $table->tinyInteger('timezone') + ->default(8) + ->after('platform_meta') + ->comment('平台店铺统计时使用的时区 默认为 +8 表示 北京时间, 如果是日本则是 +7, 填写基于 UTC 的偏移值'); + }); + + // 为 platform_meta JSONB 字段创建 GIN 索引,支持高效的 JSON 查询 + Db::statement('CREATE INDEX idx_stores_platform_meta ON stores USING GIN (platform_meta)'); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // 删除 GIN 索引 + Db::statement('DROP INDEX IF EXISTS idx_stores_platform_meta'); + + Schema::table('stores', function (Blueprint $table) { + // 删除添加的字段 + $table->dropColumn(['platform_meta', 'timezone']); + }); + } +};