Refactor surcharge management by replacing PrcPriceSetVersionSurcharge with PrcSurchargeRel, introducing price type handling (PRODUCT, SALES, REDLINE) and updating related services, mappers, and front-end components. Enhance validation and error messaging for price type and detail ID requirements. Update database schema to support new relationships and constraints.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
-- prc_surcharge_rel: add price_type + country_code; drop version surcharge snapshot
|
||||
-- Run once on existing DB
|
||||
|
||||
-- 1) drop FK to product (SALES rows store psp_id in product_id)
|
||||
SET @fk_exists := (
|
||||
SELECT COUNT(1) FROM information_schema.TABLE_CONSTRAINTS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'prc_surcharge_rel'
|
||||
AND CONSTRAINT_NAME = 'fk_rel_product' AND CONSTRAINT_TYPE = 'FOREIGN KEY'
|
||||
);
|
||||
SET @sql := IF(@fk_exists > 0,
|
||||
'ALTER TABLE `prc_surcharge_rel` DROP FOREIGN KEY `fk_rel_product`',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 2) price_type
|
||||
SET @col_exists := (
|
||||
SELECT COUNT(1) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'prc_surcharge_rel' AND COLUMN_NAME = 'price_type'
|
||||
);
|
||||
SET @sql := IF(@col_exists = 0,
|
||||
CONCAT(
|
||||
'ALTER TABLE `prc_surcharge_rel` ',
|
||||
'ADD COLUMN `price_type` varchar(20) NOT NULL DEFAULT ''PRODUCT'' ',
|
||||
'COMMENT ''价格类型 PRODUCT产品价/SALES销售价/REDLINE红线价'' AFTER `detail_id`'
|
||||
),
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 3) country_code on rel
|
||||
SET @col_exists := (
|
||||
SELECT COUNT(1) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'prc_surcharge_rel' AND COLUMN_NAME = 'country_code'
|
||||
);
|
||||
SET @sql := IF(@col_exists = 0,
|
||||
CONCAT(
|
||||
'ALTER TABLE `prc_surcharge_rel` ',
|
||||
'ADD COLUMN `country_code` char(2) DEFAULT NULL ',
|
||||
'COMMENT ''适用国家ISO2(空=全部)'' AFTER `price_type`'
|
||||
),
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 4) backfill country from surcharge master when rel country empty
|
||||
UPDATE prc_surcharge_rel r
|
||||
INNER JOIN prc_surcharge s ON s.sc_id = r.sc_id
|
||||
SET r.country_code = s.country_code
|
||||
WHERE (r.country_code IS NULL OR r.country_code = '')
|
||||
AND s.country_code IS NOT NULL AND s.country_code <> '';
|
||||
|
||||
-- 5) rebuild unique key
|
||||
SET @uk_exists := (
|
||||
SELECT COUNT(1) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'prc_surcharge_rel' AND INDEX_NAME = 'uk_rel_scope'
|
||||
);
|
||||
SET @sql := IF(@uk_exists > 0,
|
||||
'ALTER TABLE `prc_surcharge_rel` DROP INDEX `uk_rel_scope`',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @uk_exists2 := (
|
||||
SELECT COUNT(1) FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'prc_surcharge_rel' AND INDEX_NAME = 'uk_rel_scope'
|
||||
);
|
||||
SET @sql := IF(@uk_exists2 = 0,
|
||||
'ALTER TABLE `prc_surcharge_rel` ADD UNIQUE KEY `uk_rel_scope` (`sc_id`, `product_id`, `detail_id`, `price_type`, `country_code`)',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 6) drop version surcharge snapshot table
|
||||
DROP TABLE IF EXISTS `prc_price_set_version_surcharge`;
|
||||
Reference in New Issue
Block a user