统一金额分制重构
This commit is contained in:
@@ -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