- 在 earnings_line 表添加唯一约束 (tenant_id, order_id, clerk_id, earning_type, deleted) - 重排提现创建流程:先预留收益行,成功后才创建提现请求 - 在收益行预留时添加状态验证,检测并发修改 - 使用临时提现ID进行预留,创建请求后替换为真实ID - 添加唯一约束前先清理重复的收益记录(V10 迁移) 此修复解决了关键的竞态条件问题:并发提现可能创建没有资金支持的孤儿请求记录。 修复后确保快速失败行为 - 如果收益行已被占用,提现请求永远不会被创建。
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
-- Remove duplicate earnings lines per tenant/order/clerk/type and add unique constraint
|
||||
|
||||
DELETE FROM `play_earnings_line`
|
||||
WHERE `id` IN (
|
||||
SELECT dup_id FROM (
|
||||
SELECT id AS dup_id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY tenant_id, order_id, clerk_id, earning_type
|
||||
ORDER BY created_time, id
|
||||
) AS rn
|
||||
FROM `play_earnings_line`
|
||||
WHERE deleted = 0
|
||||
) ranked
|
||||
WHERE ranked.rn > 1
|
||||
);
|
||||
|
||||
ALTER TABLE `play_earnings_line`
|
||||
ADD UNIQUE KEY `uk_tenant_order_clerk_type` (`tenant_id`, `order_id`, `clerk_id`, `earning_type`, `deleted`);
|
||||
Reference in New Issue
Block a user