统一金额分制重构

This commit is contained in:
yml
2026-06-09 19:04:11 +08:00
parent 87673288ef
commit 5cd3ead4bd
69 changed files with 886 additions and 1277 deletions
+22 -21
View File
@@ -53,11 +53,11 @@ BEGIN
END IF;
-- 为用户创建钱包
INSERT INTO wallet_accounts (user_id, available_balance, frozen_balance, status)
INSERT INTO wallet_accounts (user_id, available_balance_cent, frozen_balance_cent, status)
VALUES (
LAST_INSERT_ID(),
(i % 10) * 100.00,
(i % 5) * 50.00,
(i % 10) * 10000,
(i % 5) * 5000,
'active'
) ON DUPLICATE KEY UPDATE user_id=user_id;
@@ -83,8 +83,8 @@ BEGIN
DECLARE i INT DEFAULT 1;
DECLARE user_id_val BIGINT;
DECLARE account_id_val BIGINT;
DECLARE price_val DECIMAL(12,2);
DECLARE deposit_val DECIMAL(12,2);
DECLARE price_val BIGINT;
DECLARE deposit_val BIGINT;
DECLARE verified_user_min BIGINT;
DECLARE verified_user_max BIGINT;
DECLARE user_pick BIGINT;
@@ -146,11 +146,11 @@ BEGIN
SET account_id_val = LAST_INSERT_ID();
-- 创建租号商品
SET price_val = 5.00 + (i % 20) * 0.5;
SET deposit_val = 100.00 + (i % 10) * 50.00;
SET price_val = 500 + (i % 20) * 50;
SET deposit_val = 10000 + (i % 10) * 5000;
INSERT INTO rental_listings (
listing_no, account_id, owner_id, price, deposit_amount,
listing_no, account_id, owner_id, price_cent, deposit_amount_cent,
in_transaction, status, review_status, published_at
) VALUES (
CONCAT(
@@ -205,8 +205,8 @@ BEGIN
DECLARE owner_id_val BIGINT;
DECLARE renter_id_val BIGINT;
DECLARE order_no_val VARCHAR(64);
DECLARE rent_amount_val DECIMAL(12,2);
DECLARE deposit_val DECIMAL(12,2);
DECLARE rent_amount_val BIGINT;
DECLARE deposit_val BIGINT;
DECLARE listing_min BIGINT;
DECLARE listing_max BIGINT;
DECLARE listing_pick BIGINT;
@@ -235,7 +235,7 @@ BEGIN
-- 近似随机选择一个上架商品,避免 ORDER BY RAND() 全表排序。
SET listing_id_val = NULL;
SET listing_pick = listing_min + FLOOR(RAND() * (listing_max - listing_min + 1));
SELECT rl.id, rl.account_id, rl.owner_id, rl.price, rl.deposit_amount
SELECT rl.id, rl.account_id, rl.owner_id, rl.price_cent, rl.deposit_amount_cent
INTO listing_id_val, account_id_val, owner_id_val, rent_amount_val, deposit_val
FROM rental_listings rl
WHERE rl.id >= listing_pick
@@ -244,7 +244,7 @@ BEGIN
ORDER BY rl.id LIMIT 1;
IF listing_id_val IS NULL THEN
SELECT rl.id, rl.account_id, rl.owner_id, rl.price, rl.deposit_amount
SELECT rl.id, rl.account_id, rl.owner_id, rl.price_cent, rl.deposit_amount_cent
INTO listing_id_val, account_id_val, owner_id_val, rent_amount_val, deposit_val
FROM rental_listings rl
WHERE rl.status IN ('published', 'active')
@@ -274,8 +274,8 @@ BEGIN
INSERT INTO rental_orders (
order_no, listing_id, account_id, owner_id, renter_id,
estimated_duration_hours, rent_amount, owner_rent_amount,
deposit_amount, platform_fee, status, handoff_status,
estimated_duration_hours, rent_amount_cent, owner_rent_amount_cent,
deposit_amount_cent, deposit_original_amount_cent, platform_fee_cent, status, handoff_status,
settlement_status, rented_at, created_at
) VALUES (
order_no_val,
@@ -285,9 +285,10 @@ BEGIN
renter_id_val,
24,
rent_amount_val,
rent_amount_val * 0.95, -- 号主实得95%
ROUND(rent_amount_val * 0.95), -- 号主实得95%
deposit_val,
rent_amount_val * 0.05, -- 平台5%手续费
deposit_val,
ROUND(rent_amount_val * 0.05), -- 平台5%手续费
CASE (i % 10)
WHEN 0 THEN 'pending_payment'
WHEN 1 THEN 'cancelled'
@@ -331,7 +332,7 @@ BEGIN
DECLARE user_id_val BIGINT;
DECLARE order_id_val BIGINT;
DECLARE ledger_no_val VARCHAR(64);
DECLARE amount_val DECIMAL(12,2);
DECLARE amount_val BIGINT;
DECLARE user_min BIGINT;
DECLARE user_max BIGINT;
DECLARE order_min BIGINT;
@@ -374,18 +375,18 @@ BEGIN
END IF;
SET ledger_no_val = CONCAT('LDG', DATE_FORMAT(NOW(), '%Y%m%d%H%i%s'), LPAD(i, 6, '0'));
SET amount_val = (i % 500) + RAND() * 100;
SET amount_val = ((i % 500) * 100) + FLOOR(RAND() * 10000);
INSERT INTO wallet_ledger (
ledger_no, user_id, order_id, direction, amount,
balance_after, balance_type, biz_type, biz_no, remark, created_at
ledger_no, user_id, order_id, direction, amount_cent,
balance_after_cent, balance_type, biz_type, biz_no, remark, created_at
) VALUES (
ledger_no_val,
user_id_val,
order_id_val,
CASE WHEN i % 2 = 0 THEN 'in' ELSE 'out' END,
amount_val,
1000.00 + (i % 1000),
100000 + (i % 1000) * 100,
CASE WHEN i % 5 = 0 THEN 'frozen' ELSE 'available' END,
CASE (i % 6)
WHEN 0 THEN 'rent_payment'