兼容接入订单租期字段
This commit is contained in:
@@ -41,6 +41,67 @@ SET price = CASE
|
||||
END
|
||||
WHERE price <= 0;
|
||||
|
||||
SET @order_rented_at_exists := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'rental_orders'
|
||||
AND column_name = 'rented_at'
|
||||
);
|
||||
|
||||
SET @add_order_rented_at_sql := IF(
|
||||
@order_rented_at_exists = 0,
|
||||
'ALTER TABLE rental_orders ADD COLUMN rented_at DATETIME NULL AFTER renter_id',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE add_order_rented_at_stmt FROM @add_order_rented_at_sql;
|
||||
EXECUTE add_order_rented_at_stmt;
|
||||
DEALLOCATE PREPARE add_order_rented_at_stmt;
|
||||
|
||||
SET @order_estimated_duration_exists := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'rental_orders'
|
||||
AND column_name = 'estimated_duration_hours'
|
||||
);
|
||||
|
||||
SET @add_order_estimated_duration_sql := IF(
|
||||
@order_estimated_duration_exists = 0,
|
||||
'ALTER TABLE rental_orders ADD COLUMN estimated_duration_hours INT NOT NULL DEFAULT 24 AFTER rented_at',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE add_order_estimated_duration_stmt FROM @add_order_estimated_duration_sql;
|
||||
EXECUTE add_order_estimated_duration_stmt;
|
||||
DEALLOCATE PREPARE add_order_estimated_duration_stmt;
|
||||
|
||||
UPDATE rental_orders
|
||||
SET
|
||||
rented_at = COALESCE(rented_at, rent_start_at),
|
||||
estimated_duration_hours = CASE
|
||||
WHEN estimated_duration_hours > 0 THEN estimated_duration_hours
|
||||
WHEN rent_hours > 0 THEN rent_hours
|
||||
ELSE 24
|
||||
END
|
||||
WHERE rented_at IS NULL OR estimated_duration_hours <= 0;
|
||||
|
||||
SET @order_rented_at_index_exists := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'rental_orders'
|
||||
AND index_name = 'idx_rental_orders_rented_at'
|
||||
);
|
||||
|
||||
SET @add_order_rented_at_index_sql := IF(
|
||||
@order_rented_at_index_exists = 0,
|
||||
'ALTER TABLE rental_orders ADD KEY idx_rental_orders_rented_at (status, rented_at)',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE add_order_rented_at_index_stmt FROM @add_order_rented_at_index_sql;
|
||||
EXECUTE add_order_rented_at_index_stmt;
|
||||
DEALLOCATE PREPARE add_order_rented_at_index_stmt;
|
||||
|
||||
INSERT INTO system_configs (`key`, `value`, description)
|
||||
VALUES ('order.pending_payment_timeout_minutes', '15', '订单待支付超时取消分钟数')
|
||||
ON DUPLICATE KEY UPDATE `key` = VALUES(`key`);
|
||||
|
||||
Reference in New Issue
Block a user