admin/sql/migrate_t_order_pickup_fields.sql
zzh 341a318f0b feat: 客户发件地址与揽收订单,复用小包创建全链路。
新增地址簿 CRUD、pickup/create、订单 orderSource 筛选;附带包裹商品图片上传接口。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-15 18:58:48 +08:00

76 lines
2.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 已有库增量:t_order 揽收订单字段 OrderSource / PickupTime / CustomerSenderAddressId
-- 对应功能:订单 → 揽收订单;见 oms系统设计-050801.md §4.2.1 / §4.4.4
-- 可重复执行
SET @col_exists := (
SELECT COUNT(1)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_order'
AND COLUMN_NAME = 'OrderSource'
);
SET @sql := IF(
@col_exists = 0,
'ALTER TABLE `t_order` ADD COLUMN `OrderSource` VARCHAR(32) NULL COMMENT ''订单来源:manual/pickup/upload/batch/platform'' AFTER `CustomerId`',
'SELECT ''t_order.OrderSource already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @col_exists := (
SELECT COUNT(1)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_order'
AND COLUMN_NAME = 'PickupTime'
);
SET @sql := IF(
@col_exists = 0,
'ALTER TABLE `t_order` ADD COLUMN `PickupTime` DATETIME NULL COMMENT ''预约揽收时间'' AFTER `OrderSource`',
'SELECT ''t_order.PickupTime already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @col_exists := (
SELECT COUNT(1)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_order'
AND COLUMN_NAME = 'CustomerSenderAddressId'
);
SET @sql := IF(
@col_exists = 0,
'ALTER TABLE `t_order` ADD COLUMN `CustomerSenderAddressId` INT NULL COMMENT ''发件地址簿 Id'' AFTER `PickupTime`',
'SELECT ''t_order.CustomerSenderAddressId already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
UPDATE `t_order`
SET `OrderSource` = 'manual'
WHERE `OrderSource` IS NULL OR `OrderSource` = '';
SET @idx_exists := (
SELECT COUNT(1)
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 't_order'
AND INDEX_NAME = 'idx_ord_source_ctime'
);
SET @sql := IF(
@idx_exists = 0,
'ALTER TABLE `t_order` ADD KEY `idx_ord_source_ctime` (`OrderSource`, `CreateTime`)',
'SELECT ''idx_ord_source_ctime already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;