diff --git a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/bank/UserBankTransferGoldCmdExe.java b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/bank/UserBankTransferGoldCmdExe.java index 5c5dfe6f..4d78c90a 100644 --- a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/bank/UserBankTransferGoldCmdExe.java +++ b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/bank/UserBankTransferGoldCmdExe.java @@ -28,12 +28,14 @@ import com.red.circle.wallet.infra.database.mongo.entity.bank.UserBankRunningWat import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankBalanceService; import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankRunningWaterService; import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankWithdrawGoldApplyService; +import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalance; import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalanceRunningWater; import com.red.circle.wallet.infra.database.rds.service.auth.PayAuthService; import com.red.circle.wallet.infra.database.rds.service.diamond.SalaryDiamondBalanceService; import com.red.circle.wallet.infra.database.rds.service.diamond.SalaryDiamondRunningWaterService; import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceRunningWaterService; import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceService; +import com.red.circle.wallet.inner.error.FreightErrorCode; import com.red.circle.wallet.inner.error.WalletErrorCode; import com.red.circle.wallet.inner.model.dto.BankBalanceDTO; import com.red.circle.wallet.inner.model.enums.FreightBalanceOrigin; @@ -46,6 +48,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -92,6 +95,14 @@ public class UserBankTransferGoldCmdExe { // 获得区域兑换比例金币比例 Double goldRatio = getExchangeGoldRatio(cmd); + BigDecimal goldQuantity = BigDecimal.valueOf(goldRatio).multiply(cmd.getAmount()).setScale(0, RoundingMode.DOWN); + + FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getAcceptUserId()); + ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance); + + long result = goldQuantity.divide(new BigDecimal(10000), RoundingMode.DOWN).setScale(0, RoundingMode.DOWN).longValue(); + ResponseAssert.isTrue(FreightErrorCode.NOT_THRESHOLD, result >= Optional.ofNullable(freightBalance.getDeliveryThreshold()).orElse(0)); + // 扣钱 BankBalanceDTO decrUserBankBalanceDTO = userBankBalanceService.decr(cmd.requiredReqUserId(), PennyAmount.ofDollar(cmd.getAmount())); @@ -118,7 +129,6 @@ public class UserBankTransferGoldCmdExe { .setCreateUserOrigin(OpUserType.APP.getType()) ); - BigDecimal goldQuantity = BigDecimal.valueOf(goldRatio).multiply(cmd.getAmount()).setScale(0, RoundingMode.DOWN); // 发送金额 sendGold(cmd, freight, goldQuantity, bankRunWaterId, "转账金币"); diff --git a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/SendFreightShipCmdExe.java b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/SendFreightShipCmdExe.java index f8693e08..23231b2a 100644 --- a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/SendFreightShipCmdExe.java +++ b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/SendFreightShipCmdExe.java @@ -102,12 +102,6 @@ public class SendFreightShipCmdExe { ResponseAssert.isTrue(WalletErrorCode.INSUFFICIENT_BALANCE, ArithmeticUtils.gte(cmd.getQuantity(), BigDecimal.ZERO)); - FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getReqUserId()); - ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance); - - long result = cmd.getQuantity().divide(new BigDecimal(10000), RoundingMode.DOWN).setScale(0, RoundingMode.DOWN).longValue(); - ResponseAssert.isTrue(FreightErrorCode.NOT_THRESHOLD, result >= Optional.ofNullable(freightBalance.getDeliveryThreshold()).orElse(0)); - // 支付密码效验 checkPayPassword(cmd); diff --git a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/salary/SalaryTransferGoldCmdExe.java b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/salary/SalaryTransferGoldCmdExe.java index 4772d4e4..f35b78d6 100644 --- a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/salary/SalaryTransferGoldCmdExe.java +++ b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/salary/SalaryTransferGoldCmdExe.java @@ -26,9 +26,11 @@ import com.red.circle.wallet.domain.wallet.WalletReceipt; import com.red.circle.wallet.infra.database.mongo.entity.bank.UserBankRunningWater; import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankBalanceService; import com.red.circle.wallet.infra.database.mongo.service.bank.UserBankRunningWaterService; +import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalance; import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalanceRunningWater; import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceRunningWaterService; import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceService; +import com.red.circle.wallet.inner.error.FreightErrorCode; import com.red.circle.wallet.inner.error.WalletErrorCode; import com.red.circle.wallet.inner.model.dto.BankBalanceDTO; import com.red.circle.wallet.inner.model.enums.FreightBalanceOrigin; @@ -41,6 +43,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -89,14 +92,20 @@ public class SalaryTransferGoldCmdExe { Double goldRatio = getExchangeGoldRatio(cmd); Long bankRunWaterId = IdWorkerUtils.getId(); + BigDecimal goldQuantity = BigDecimal.valueOf(goldRatio).multiply(cmd.getAmount()).setScale(0, RoundingMode.DOWN); + + FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getAcceptUserId()); + ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance); + + long result = goldQuantity.divide(new BigDecimal(10000), RoundingMode.DOWN).setScale(0, RoundingMode.DOWN).longValue(); + ResponseAssert.isTrue(FreightErrorCode.NOT_THRESHOLD, result >= Optional.ofNullable(freightBalance.getDeliveryThreshold()).orElse(0)); + // 扣钱 cmd.setReqTraceId(String.valueOf(bankRunWaterId)); SalaryReceipt receipt = salaryAccountConvertor.toTransferReceipt(cmd); SalaryReceiptRes salaryReceiptRes = salaryAccountGateway.changeBalance(receipt); ResponseAssert.notNull(WalletErrorCode.INSUFFICIENT_BALANCE, salaryReceiptRes); - BigDecimal goldQuantity = BigDecimal.valueOf(goldRatio).multiply(cmd.getAmount()).setScale(0, RoundingMode.DOWN); - // 发送金额 sendGold(cmd, freight, goldQuantity, bankRunWaterId, "转账金币");