兼容接入订单租期字段

This commit is contained in:
yml
2026-05-24 18:24:39 +08:00
parent e69d08ca9f
commit 778e08a261
9 changed files with 211 additions and 85 deletions
+4 -1
View File
@@ -78,6 +78,8 @@ CREATE TABLE rental_orders (
account_id BIGINT UNSIGNED NOT NULL,
owner_id BIGINT UNSIGNED NOT NULL,
renter_id BIGINT UNSIGNED NOT NULL,
rented_at DATETIME NULL,
estimated_duration_hours INT NOT NULL DEFAULT 24,
rent_start_at DATETIME NULL,
rent_end_at DATETIME NULL,
rent_hours INT NOT NULL,
@@ -95,7 +97,8 @@ CREATE TABLE rental_orders (
UNIQUE KEY uk_rental_orders_order_no (order_no),
KEY idx_rental_orders_renter_status (renter_id, status),
KEY idx_rental_orders_owner_status (owner_id, status),
KEY idx_rental_orders_listing_id (listing_id)
KEY idx_rental_orders_listing_id (listing_id),
KEY idx_rental_orders_rented_at (status, rented_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE handoff_records (
@@ -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`);