统一金额分制重构
This commit is contained in:
+22
-21
@@ -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'
|
||||
|
||||
@@ -69,11 +69,11 @@ BEGIN
|
||||
AND NOT EXISTS (SELECT 1 FROM user_realname WHERE user_id = u.id);
|
||||
|
||||
-- 批量生成钱包账户
|
||||
INSERT INTO wallet_accounts (user_id, available_balance, frozen_balance, status)
|
||||
INSERT INTO wallet_accounts (user_id, available_balance_cent, frozen_balance_cent, status)
|
||||
SELECT
|
||||
u.id,
|
||||
(u.id % 10) * 100.00,
|
||||
(u.id % 5) * 50.00,
|
||||
(u.id % 10) * 10000,
|
||||
(u.id % 5) * 5000,
|
||||
'active'
|
||||
FROM users u
|
||||
WHERE NOT EXISTS (SELECT 1 FROM wallet_accounts WHERE user_id = u.id);
|
||||
@@ -159,7 +159,7 @@ BEGIN
|
||||
|
||||
-- 批量生成租号商品
|
||||
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
|
||||
)
|
||||
SELECT
|
||||
@@ -169,8 +169,8 @@ BEGIN
|
||||
) as listing_no,
|
||||
ga.id as account_id,
|
||||
ga.owner_id,
|
||||
5.00 + ((ga.id % 20) * 0.5) as price,
|
||||
100.00 + ((ga.id % 10) * 50.00) as deposit_amount,
|
||||
500 + ((ga.id % 20) * 50) as price_cent,
|
||||
10000 + ((ga.id % 10) * 5000) as deposit_amount_cent,
|
||||
CASE WHEN ga.id % 10 = 0 THEN 1 ELSE 0 END as in_transaction,
|
||||
CASE
|
||||
WHEN ga.id % 20 = 0 THEN 'offline'
|
||||
@@ -222,13 +222,13 @@ BEGIN
|
||||
id BIGINT PRIMARY KEY,
|
||||
account_id BIGINT,
|
||||
owner_id BIGINT,
|
||||
price DECIMAL(12,2),
|
||||
deposit_amount DECIMAL(12,2),
|
||||
price_cent BIGINT,
|
||||
deposit_amount_cent BIGINT,
|
||||
row_num INT
|
||||
);
|
||||
|
||||
INSERT INTO tmp_available_listings (id, account_id, owner_id, price, deposit_amount, row_num)
|
||||
SELECT id, account_id, owner_id, price, deposit_amount, (@rn := @rn + 1)
|
||||
INSERT INTO tmp_available_listings (id, account_id, owner_id, price_cent, deposit_amount_cent, row_num)
|
||||
SELECT id, account_id, owner_id, price_cent, deposit_amount_cent, (@rn := @rn + 1)
|
||||
FROM rental_listings, (SELECT @rn := 0) init
|
||||
WHERE status IN ('published', 'active') AND review_status = 'approved'
|
||||
ORDER BY id;
|
||||
@@ -255,8 +255,8 @@ BEGIN
|
||||
WHILE current_batch < batches DO
|
||||
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
|
||||
)
|
||||
SELECT
|
||||
@@ -266,10 +266,11 @@ BEGIN
|
||||
l.owner_id,
|
||||
r.id as renter_id,
|
||||
24 as estimated_duration_hours,
|
||||
l.price * 24 as rent_amount,
|
||||
l.price * 24 * 0.95 as owner_rent_amount,
|
||||
l.deposit_amount,
|
||||
l.price * 24 * 0.05 as platform_fee,
|
||||
l.price_cent * 24 as rent_amount_cent,
|
||||
ROUND(l.price_cent * 24 * 0.95) as owner_rent_amount_cent,
|
||||
l.deposit_amount_cent,
|
||||
l.deposit_amount_cent,
|
||||
ROUND(l.price_cent * 24 * 0.05) as platform_fee_cent,
|
||||
CASE (seq % 10)
|
||||
WHEN 0 THEN 'pending_payment'
|
||||
WHEN 1 THEN 'cancelled'
|
||||
@@ -360,16 +361,16 @@ BEGIN
|
||||
|
||||
WHILE current_batch < batches DO
|
||||
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
|
||||
)
|
||||
SELECT
|
||||
CONCAT('LDG', DATE_FORMAT(NOW(), '%Y%m%d%H%i%s'), LPAD(seq, 6, '0')) as ledger_no,
|
||||
u.id as user_id,
|
||||
IF(seq % 2 = 0, o.id, NULL) as order_id,
|
||||
CASE WHEN seq % 2 = 0 THEN 'in' ELSE 'out' END as direction,
|
||||
(seq % 500) + (seq * 0.01) as amount,
|
||||
1000.00 + (seq % 1000) as balance_after,
|
||||
((seq % 500) * 100) + seq as amount_cent,
|
||||
100000 + ((seq % 1000) * 100) as balance_after_cent,
|
||||
CASE WHEN seq % 5 = 0 THEN 'frozen' ELSE 'available' END as balance_type,
|
||||
CASE (seq % 6)
|
||||
WHEN 0 THEN 'rent_payment'
|
||||
|
||||
Reference in New Issue
Block a user