fix recharge amount calculation

This commit is contained in:
hy001 2026-05-07 18:50:32 +08:00
parent 7e4365a393
commit 895193f33c
6 changed files with 386 additions and 97 deletions

View File

@ -89,13 +89,16 @@ public enum MonthlyRechargeType {
*/
UNDEFINED;
/**
* 个人充值.
*/
public static List<MonthlyRechargeType> getPersonalRecharge() {
return List.of(UNDEFINED, HUAWEI, GOOGLE, APPLE, PAYER_MAX, SHIPPING_AGENT, STRIPE,
SALARY_EXCHANGE,
PAY_PAL, CLIPSPAY, SELLER_AGENT);
}
}
/**
* 个人充值.
*/
public static List<MonthlyRechargeType> getPersonalRecharge() {
return List.of(HUAWEI, GOOGLE, APPLE, PAYER_MAX, MIFA_PAY, AIRWALLEX, PAYNICORN,
STRIPE, PAY_PAL, CLIPSPAY, SHIPPING_AGENT, SALARY_EXCHANGE);
}
public static boolean isPersonalRecharge(MonthlyRechargeType type) {
return getPersonalRecharge().contains(type);
}
}

View File

@ -38,22 +38,28 @@ public class UserRechargeCountGatewayImpl implements UserRechargeCountGateway {
return totalRechargeUserService.listUserRechargeTotal(sysOrigin);
}
@Override
public void count(Long userId, BigDecimal amount, MonthlyRechargeType type) {
userMonthlyRechargeService.incrThisMonthAmount(userId, amount, type);
totalRechargeService.incrAmount(userId, amount, type);
monthlyRechargeUserService.incAmount(userId, amount);
totalRechargeUserService.incAmount(userId, amount);
userActivityRechargeClient.recordRecharge(userId, amount, type.name());
@Override
public void count(Long userId, BigDecimal amount, MonthlyRechargeType type) {
userMonthlyRechargeService.incrThisMonthAmount(userId, amount, type);
totalRechargeService.incrAmount(userId, amount, type);
if (!MonthlyRechargeType.isPersonalRecharge(type)) {
return;
}
monthlyRechargeUserService.incAmount(userId, amount);
totalRechargeUserService.incAmount(userId, amount);
userActivityRechargeClient.recordRecharge(userId, amount, type.name());
}
@Override
public void decr(Long userId, BigDecimal amount, MonthlyRechargeType type) {
userMonthlyRechargeService.decrThisMonthAmount(userId, amount, type);
totalRechargeService.decr(userId, amount, type);
monthlyRechargeUserService.decr(userId, amount);
totalRechargeUserService.decr(userId, amount);
public void decr(Long userId, BigDecimal amount, MonthlyRechargeType type) {
userMonthlyRechargeService.decrThisMonthAmount(userId, amount, type);
totalRechargeService.decr(userId, amount, type);
if (!MonthlyRechargeType.isPersonalRecharge(type)) {
return;
}
monthlyRechargeUserService.decr(userId, amount);
totalRechargeUserService.decr(userId, amount);
}
}

View File

@ -161,16 +161,10 @@ public class UserBankExchangeGoldCmdExe {
.setUpdateUserOrigin(OpUserType.APP.getType())
);
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "银行卡兑换");
// 记录充值金额
rechargeRecord(cmd);
userRechargeCountClient.count( cmd.getReqUserId(),
cmd.getAmount(),
MonthlyRechargeType.SHIPPING_AGENT
);
// SVip积分累计.
userSvipClient.incrIntegral(cmd.getReqUserId(), goldQuantity.longValue());
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "银行卡兑换");
// SVip积分累计.
userSvipClient.incrIntegral(cmd.getReqUserId(), goldQuantity.longValue());
redisService.unlock(key);
// 被邀请人充值邀请人获得佣金
@ -249,12 +243,12 @@ public class UserBankExchangeGoldCmdExe {
SalaryDiamondRunningWater salaryDiamondRunningWater = new SalaryDiamondRunningWater()
.setId(bankRunWaterId)
.setUserId(cmd.requiredReqUserId())
.setSysOrigin(cmd.requireReqSysOrigin())
.setType(ReceiptType.EXPENDITURE.getType())
.setAmount(cmd.getAmount())
.setSalaryEvent(UserBankWaterEvent.EXCHANGE_GOLD_COINS.name())
.setEventDesc(UserBankWaterEvent.EXCHANGE_GOLD_COINS.getDescribe())
.setRemark("Active exchange")
.setSysOrigin(cmd.requireReqSysOrigin())
.setType(ReceiptType.EXPENDITURE.getType())
.setAmount(cmd.getAmount())
.setSalaryEvent(UserBankWaterEvent.SALARY_EXCHANGE_GOLD_COINS.name())
.setEventDesc(UserBankWaterEvent.SALARY_EXCHANGE_GOLD_COINS.getDescribe())
.setRemark("Active exchange")
.setTrackId(applyId.toString())
.setBalance(decrSalaryDiamondBalance.getBalance())
.setCreateUserOrigin(OpUserType.APP.getType());
@ -283,10 +277,11 @@ public class UserBankExchangeGoldCmdExe {
.setUpdateUserOrigin(OpUserType.APP.getType())
);
sendGoldYolo(cmd, goldQuantity, bankRunWaterId);
// 记录充值金额
rechargeRecord(cmd);
return new UserBankExchangeGoldResultCO()
sendGoldYolo(cmd, goldQuantity, bankRunWaterId);
// 记录充值金额
rechargeRecord(cmd);
countSalaryExchange(cmd.requiredReqUserId(), cmd.getAmount());
return new UserBankExchangeGoldResultCO()
.setBankBalance(decrSalaryDiamondBalance.getBalance())
.setExchangeGold(Objects.toString(goldRatio));
}catch (Exception e) {
@ -346,12 +341,12 @@ public class UserBankExchangeGoldCmdExe {
SalaryDiamondRunningWater salaryDiamondRunningWater = new SalaryDiamondRunningWater()
.setId(bankRunWaterId)
.setUserId(cmd.getReqUserId())
.setSysOrigin(cmd.getReqSysOrigin().getOrigin())
.setType(ReceiptType.EXPENDITURE.getType())
.setAmount(cmd.getAmount())
.setSalaryEvent(UserBankWaterEvent.EXCHANGE_GOLD_COINS.name())
.setEventDesc(UserBankWaterEvent.EXCHANGE_GOLD_COINS.getDescribe())
.setRemark("Active exchange")
.setSysOrigin(cmd.getReqSysOrigin().getOrigin())
.setType(ReceiptType.EXPENDITURE.getType())
.setAmount(cmd.getAmount())
.setSalaryEvent(UserBankWaterEvent.SALARY_EXCHANGE_GOLD_COINS.name())
.setEventDesc(UserBankWaterEvent.SALARY_EXCHANGE_GOLD_COINS.getDescribe())
.setRemark("Active exchange")
.setTrackId(applyId.toString())
.setBalance(decrSalaryDiamondBalance.getBalance())
.setCreateUserOrigin(OpUserType.APP.getType());
@ -382,10 +377,11 @@ public class UserBankExchangeGoldCmdExe {
.setUpdateUserOrigin(OpUserType.APP.getType())
);
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "钻石兑换");
// 记录充值金额
rechargeRecord(cmd);
redisService.unlock(key);
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "钻石兑换");
// 记录充值金额
rechargeRecord(cmd);
countSalaryExchange(cmd.getReqUserId(), cmd.getAmount());
redisService.unlock(key);
return new UserBankExchangeGoldResultCO()
.setBankBalance(decrSalaryDiamondBalance.getBalance())
.setExchangeGold(Objects.toString(goldRatio));
@ -468,10 +464,11 @@ public class UserBankExchangeGoldCmdExe {
);
// 组装兑换金币信息
sendBillGold(cmd, freight, goldQuantity, bankRunWaterId, "主播工资钻石兑换");
// 记录充值金额
rechargeRecordBill(cmd);
redisService.unlock(key);
sendBillGold(cmd, freight, goldQuantity, bankRunWaterId, "主播工资钻石兑换");
// 记录充值金额
rechargeRecordBill(cmd);
countSalaryExchange(cmd.requiredReqUserId(), cmd.getAmount());
redisService.unlock(key);
return new UserBankExchangeGoldResultCO()
.setBankBalance(billDiamond.getBody().getBalance())
@ -555,25 +552,30 @@ public class UserBankExchangeGoldCmdExe {
);
// 组装兑换金币信息
sendBillGold(cmd, freight, goldQuantity, bankRunWaterId, "账单钻石兑换");
// 记录充值金额
rechargeRecordBill(cmd);
redisService.unlock(key);
sendBillGold(cmd, freight, goldQuantity, bankRunWaterId, "账单钻石兑换");
// 记录充值金额
rechargeRecordBill(cmd);
countSalaryExchange(cmd.requiredReqUserId(), cmd.getAmount());
redisService.unlock(key);
return new UserBankExchangeGoldResultCO()
.setBankBalance(billDiamond.getBody().getAgentBalance())
.setExchangeGold(Objects.toString(goldRatio));
}
private void rechargeRecord(UserBankExchangeGoldCmd cmd) {
userFreightRechargeRecordClient.inrNowMonthAmount(
cmd.getReqUserId(),
cmd.getAmount()
);
}
/**
* 账单入口-充值记录.
*/
private void rechargeRecord(UserBankExchangeGoldCmd cmd) {
userFreightRechargeRecordClient.inrNowMonthAmount(
cmd.getReqUserId(),
cmd.getAmount()
);
}
private void countSalaryExchange(Long userId, BigDecimal amount) {
userRechargeCountClient.count(userId, amount, MonthlyRechargeType.SALARY_EXCHANGE);
}
/**
* 账单入口-充值记录.
*/
private void rechargeRecordBill(UserBillExchangeGoldCmd cmd) {
userFreightRechargeRecordClient.inrNowMonthAmount(
cmd.requiredReqUserId(),

View File

@ -68,14 +68,16 @@ import org.springframework.stereotype.Component;
*
* @author pengliang on 2021/7/6
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class SendFreightShipCmdExe {
private final RedisService redisService;
private final ControlSwitch controlSwitch;
private final UserSvipClient userSvipClient;
@Slf4j
@Component
@RequiredArgsConstructor
public class SendFreightShipCmdExe {
private static final BigDecimal SHIPPING_AGENT_RECHARGE_GOLD_USD_RATIO = BigDecimal.valueOf(92000);
private final RedisService redisService;
private final ControlSwitch controlSwitch;
private final UserSvipClient userSvipClient;
private final PayAuthService payAuthService;
private final UserProfileClient userProfileClient;
private final WalletGoldGateway walletGoldGateway;
@ -313,20 +315,15 @@ public class SendFreightShipCmdExe {
}
private BigDecimal getGoldToSUD(FreightShipSendCmd cmd) {
int ratio;
if (Objects.equals(cmd.requireReqSysOriginEnum(), SysOriginPlatformEnum.YOLO) || Objects.equals(cmd.requireReqSysOriginEnum(), SysOriginPlatformEnum.TARAB)) {
ratio = 6000;
} else {
ratio = freightShipGateway
.getFreightGoldToUsdRatioCumulativeRecharge(cmd.getAcceptUserId());
}
return cmd.getQuantity().divide(BigDecimal.valueOf(ratio), 2, RoundingMode.DOWN);
}
private FreightBalanceRunningWater saveRunningWater(FreightShipSendCmd cmd, BigDecimal balance) {
private BigDecimal getGoldToSUD(FreightShipSendCmd cmd) {
if (Objects.isNull(cmd.getQuantity())) {
return BigDecimal.ZERO;
}
return cmd.getQuantity().divide(SHIPPING_AGENT_RECHARGE_GOLD_USD_RATIO, 2, RoundingMode.DOWN);
}
private FreightBalanceRunningWater saveRunningWater(FreightShipSendCmd cmd, BigDecimal balance) {
FreightBalanceRunningWater freightBalanceRunningWater = new FreightBalanceRunningWater()
.setSysOrigin(cmd.requireReqSysOrigin())
.setUserId(cmd.requiredReqUserId())

View File

@ -125,15 +125,15 @@ public class SalaryExchangeGoldCmdExe {
.setUpdateUserOrigin(OpUserType.APP.getType())
);
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "银行卡兑换");
sendGold(cmd, freight, goldQuantity, bankRunWaterId, "工资兑换");
// 记录充值金额
rechargeRecord(cmd);
userRechargeCountClient.count( cmd.getReqUserId(),
cmd.getAmount(),
MonthlyRechargeType.SHIPPING_AGENT
);
userRechargeCountClient.count( cmd.getReqUserId(),
cmd.getAmount(),
MonthlyRechargeType.SALARY_EXCHANGE
);
// 被邀请人充值邀请人获得佣金
if (!freight) {

View File

@ -0,0 +1,281 @@
-- Rebuild recharge amount with the current eligible recharge definition:
-- app/third-party payment + shipping-agent sold coins at 92000 coins/USD + salary exchange.
SET @recharge_types = 'HUAWEI,GOOGLE,APPLE,PAYER_MAX,MIFA_PAY,AIRWALLEX,PAYNICORN,STRIPE,PAY_PAL,CLIPSPAY,SHIPPING_AGENT,SALARY_EXCHANGE';
SET @activity_ids = '2006671533912581569,2006671533988298666,1235571533988298753';
CREATE TABLE IF NOT EXISTS user_monthly_recharge_v2_bak_20260507 LIKE user_monthly_recharge_v2;
INSERT IGNORE INTO user_monthly_recharge_v2_bak_20260507
SELECT *
FROM user_monthly_recharge_v2
WHERE FIND_IN_SET(type, @recharge_types);
CREATE TABLE IF NOT EXISTS user_total_recharge_bak_20260507 LIKE user_total_recharge;
INSERT IGNORE INTO user_total_recharge_bak_20260507
SELECT *
FROM user_total_recharge
WHERE FIND_IN_SET(type, @recharge_types);
CREATE TABLE IF NOT EXISTS user_monthly_recharge_user_bak_20260507 LIKE user_monthly_recharge_user;
INSERT IGNORE INTO user_monthly_recharge_user_bak_20260507
SELECT *
FROM user_monthly_recharge_user;
CREATE TABLE IF NOT EXISTS user_total_recharge_user_bak_20260507 LIKE user_total_recharge_user;
INSERT IGNORE INTO user_total_recharge_user_bak_20260507
SELECT *
FROM user_total_recharge_user;
CREATE TABLE IF NOT EXISTS user_activity_recharge_bak_20260507 LIKE user_activity_recharge;
INSERT IGNORE INTO user_activity_recharge_bak_20260507
SELECT *
FROM user_activity_recharge
WHERE FIND_IN_SET(activity_id, @activity_ids);
DROP TEMPORARY TABLE IF EXISTS tmp_recharge_monthly_20260507;
CREATE TEMPORARY TABLE tmp_recharge_monthly_20260507 (
user_id BIGINT NOT NULL,
recharge_date INT NOT NULL,
recharge_type VARCHAR(50) NOT NULL,
amount DECIMAL(12, 2) NOT NULL DEFAULT 0.00,
PRIMARY KEY (user_id, recharge_date, recharge_type)
) ENGINE=InnoDB;
DROP TEMPORARY TABLE IF EXISTS tmp_recharge_daily_20260507;
CREATE TEMPORARY TABLE tmp_recharge_daily_20260507 (
user_id BIGINT NOT NULL,
recharge_date DATE NOT NULL,
recharge_type VARCHAR(50) NOT NULL,
amount DECIMAL(12, 2) NOT NULL DEFAULT 0.00,
PRIMARY KEY (user_id, recharge_date, recharge_type)
) ENGINE=InnoDB;
INSERT INTO tmp_recharge_monthly_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.user_id,
DATE_FORMAT(t.create_time, '%Y%m') + 0 AS recharge_date,
t.pay_platform AS recharge_type,
ROUND(SUM(IFNULL(t.unit_price, 0)), 2) AS amount
FROM order_purchase_history t
WHERE t.evn = 'PROD'
AND t.is_trial_period = 0
AND t.status = 'COMPLETE'
AND t.pay_platform IN ('HUAWEI', 'GOOGLE', 'APPLE', 'PAYER_MAX', 'AIRWALLEX', 'PAYNICORN', 'STRIPE', 'PAY_PAL', 'CLIPSPAY')
GROUP BY t.user_id, recharge_date, recharge_type
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_daily_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.user_id,
DATE(DATE_SUB(t.create_time, INTERVAL 5 HOUR)) AS recharge_date,
t.pay_platform AS recharge_type,
ROUND(SUM(IFNULL(t.unit_price, 0)), 2) AS amount
FROM order_purchase_history t
WHERE t.evn = 'PROD'
AND t.is_trial_period = 0
AND t.status = 'COMPLETE'
AND t.pay_platform IN ('HUAWEI', 'GOOGLE', 'APPLE', 'PAYER_MAX', 'AIRWALLEX', 'PAYNICORN', 'STRIPE', 'PAY_PAL', 'CLIPSPAY')
GROUP BY t.user_id, recharge_date, recharge_type
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_monthly_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.user_id,
DATE_FORMAT(IFNULL(t.update_time, t.create_time), '%Y%m') + 0 AS recharge_date,
'MIFA_PAY' AS recharge_type,
ROUND(SUM(IFNULL(t.compute_usd_amount, 0)), 2) AS amount
FROM order_user_purchase_pay t
WHERE t.evn = 'PROD'
AND t.factory_code = 'MIFA_PAY'
AND t.pay_status = 'SUCCESSFUL'
AND t.receipt_type = 'PAYMENT'
AND t.refund_status = 'NONE'
GROUP BY t.user_id, recharge_date
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_daily_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.user_id,
DATE(DATE_SUB(IFNULL(t.update_time, t.create_time), INTERVAL 5 HOUR)) AS recharge_date,
'MIFA_PAY' AS recharge_type,
ROUND(SUM(IFNULL(t.compute_usd_amount, 0)), 2) AS amount
FROM order_user_purchase_pay t
WHERE t.evn = 'PROD'
AND t.factory_code = 'MIFA_PAY'
AND t.pay_status = 'SUCCESSFUL'
AND t.receipt_type = 'PAYMENT'
AND t.refund_status = 'NONE'
GROUP BY t.user_id, recharge_date
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_monthly_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.accept_user_id AS user_id,
DATE_FORMAT(t.create_time, '%Y%m') + 0 AS recharge_date,
'SHIPPING_AGENT' AS recharge_type,
SUM(TRUNCATE(IFNULL(t.quantity, 0) / 92000, 2)) AS amount
FROM likei_wallet.user_freight_balance_running_water t
WHERE t.origin = 'SHIPMENT'
AND t.type = 1
AND t.remark = '货运代理出货'
AND t.accept_user_id IS NOT NULL
AND IFNULL(t.quantity, 0) > 0
GROUP BY t.accept_user_id, recharge_date
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_daily_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.accept_user_id AS user_id,
DATE(DATE_SUB(t.create_time, INTERVAL 5 HOUR)) AS recharge_date,
'SHIPPING_AGENT' AS recharge_type,
SUM(TRUNCATE(IFNULL(t.quantity, 0) / 92000, 2)) AS amount
FROM likei_wallet.user_freight_balance_running_water t
WHERE t.origin = 'SHIPMENT'
AND t.type = 1
AND t.remark = '货运代理出货'
AND t.accept_user_id IS NOT NULL
AND IFNULL(t.quantity, 0) > 0
GROUP BY t.accept_user_id, recharge_date
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_monthly_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.user_id,
DATE_FORMAT(t.create_time, '%Y%m') + 0 AS recharge_date,
'SALARY_EXCHANGE' AS recharge_type,
ROUND(SUM(IFNULL(t.amount, 0)), 2) AS amount
FROM likei_wallet.user_salary_account_running_water t
WHERE t.type = 1
AND t.salary_event = 'SALARY_EXCHANGE'
GROUP BY t.user_id, recharge_date
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_daily_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.user_id,
DATE(DATE_SUB(t.create_time, INTERVAL 5 HOUR)) AS recharge_date,
'SALARY_EXCHANGE' AS recharge_type,
ROUND(SUM(IFNULL(t.amount, 0)), 2) AS amount
FROM likei_wallet.user_salary_account_running_water t
WHERE t.type = 1
AND t.salary_event = 'SALARY_EXCHANGE'
GROUP BY t.user_id, recharge_date
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_monthly_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.user_id,
DATE_FORMAT(t.create_time, '%Y%m') + 0 AS recharge_date,
'SALARY_EXCHANGE' AS recharge_type,
ROUND(SUM(IFNULL(t.amount, 0)), 2) AS amount
FROM likei_wallet.user_salary_diamond_running_water t
WHERE t.type = 1
AND t.salary_event IN ('SALARY_EXCHANGE_GOLD_COINS', 'EXCHANGE_GOLD_COINS', 'BILL_EXCHANGE_GOLD_COINS')
GROUP BY t.user_id, recharge_date
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
INSERT INTO tmp_recharge_daily_20260507 (user_id, recharge_date, recharge_type, amount)
SELECT
t.user_id,
DATE(DATE_SUB(t.create_time, INTERVAL 5 HOUR)) AS recharge_date,
'SALARY_EXCHANGE' AS recharge_type,
ROUND(SUM(IFNULL(t.amount, 0)), 2) AS amount
FROM likei_wallet.user_salary_diamond_running_water t
WHERE t.type = 1
AND t.salary_event IN ('SALARY_EXCHANGE_GOLD_COINS', 'EXCHANGE_GOLD_COINS', 'BILL_EXCHANGE_GOLD_COINS')
GROUP BY t.user_id, recharge_date
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount);
DELETE FROM user_monthly_recharge_v2
WHERE FIND_IN_SET(type, @recharge_types);
SET @rn := 0;
INSERT INTO user_monthly_recharge_v2 (id, user_id, type, amount, recharge_date, create_time, update_time)
SELECT
7701000000000000000 + (@rn := @rn + 1) AS id,
user_id,
recharge_type,
amount,
recharge_date,
NOW(),
NOW()
FROM tmp_recharge_monthly_20260507
WHERE amount > 0
ORDER BY user_id, recharge_date, recharge_type;
DELETE FROM user_total_recharge
WHERE FIND_IN_SET(type, @recharge_types);
SET @rn := 0;
INSERT INTO user_total_recharge (id, user_id, type, amount, create_time, update_time)
SELECT
7702000000000000000 + (@rn := @rn + 1) AS id,
user_id,
recharge_type,
ROUND(SUM(amount), 2) AS amount,
NOW(),
NOW()
FROM tmp_recharge_monthly_20260507
WHERE amount > 0
GROUP BY user_id, recharge_type
ORDER BY user_id, recharge_type;
DELETE FROM user_monthly_recharge_user;
SET @rn := 0;
INSERT INTO user_monthly_recharge_user (id, user_id, recharge_date, amount, create_time, update_time)
SELECT
7703000000000000000 + (@rn := @rn + 1) AS id,
user_id,
recharge_date,
ROUND(SUM(amount), 2) AS amount,
NOW(),
NOW()
FROM tmp_recharge_monthly_20260507
WHERE amount > 0
GROUP BY user_id, recharge_date
ORDER BY user_id, recharge_date;
DELETE FROM user_total_recharge_user;
SET @rn := 0;
INSERT INTO user_total_recharge_user (id, user_id, amount, create_time, update_time)
SELECT
7704000000000000000 + (@rn := @rn + 1) AS id,
user_id,
ROUND(SUM(amount), 2) AS amount,
NOW(),
NOW()
FROM tmp_recharge_monthly_20260507
WHERE amount > 0
GROUP BY user_id
ORDER BY user_id;
DELETE FROM user_activity_recharge
WHERE FIND_IN_SET(activity_id, @activity_ids);
INSERT INTO user_activity_recharge (user_id, activity_id, recharge_date, recharge_type, amount, create_time, update_time)
SELECT
d.user_id,
a.activity_id,
d.recharge_date,
d.recharge_type,
d.amount,
NOW(),
NOW()
FROM tmp_recharge_daily_20260507 d
JOIN (
SELECT 2006671533912581569 AS activity_id
UNION ALL SELECT 2006671533988298666
UNION ALL SELECT 1235571533988298753
) a
WHERE d.amount > 0
ORDER BY d.user_id, a.activity_id, d.recharge_date, d.recharge_type;
SELECT 'tmp_monthly_rows' AS metric, COUNT(*) AS value FROM tmp_recharge_monthly_20260507
UNION ALL SELECT 'tmp_daily_rows', COUNT(*) FROM tmp_recharge_daily_20260507
UNION ALL SELECT 'user_monthly_recharge_v2_rows', COUNT(*) FROM user_monthly_recharge_v2 WHERE FIND_IN_SET(type, @recharge_types)
UNION ALL SELECT 'user_total_recharge_rows', COUNT(*) FROM user_total_recharge WHERE FIND_IN_SET(type, @recharge_types)
UNION ALL SELECT 'user_monthly_recharge_user_rows', COUNT(*) FROM user_monthly_recharge_user
UNION ALL SELECT 'user_total_recharge_user_rows', COUNT(*) FROM user_total_recharge_user
UNION ALL SELECT 'user_activity_recharge_rows', COUNT(*) FROM user_activity_recharge WHERE FIND_IN_SET(activity_id, @activity_ids);