|
@@ -58,7 +58,9 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
private static final Long WALLET_PAY_APP_ID = 11L;
|
|
|
|
|
|
private static final String RECHARGE_ORDER_SUBJECT = "账户充值";
|
|
|
- /** 比例倍数 1:10 **/
|
|
|
+ /**
|
|
|
+ * 比例倍数 1:10
|
|
|
+ **/
|
|
|
private static final Integer RATIO_MULTIPLE = 10;
|
|
|
@Resource
|
|
|
public SocialClientApi socialClientApi;
|
|
@@ -73,6 +75,25 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
@Resource
|
|
|
private PayCurrencyRechargePackageService payCurrencyRechargePackageService;
|
|
|
|
|
|
+ /**
|
|
|
+ * 将金额转成正确比例 1:10
|
|
|
+ *
|
|
|
+ * @return Long
|
|
|
+ **/
|
|
|
+ public static Long convertPriceRatio(Long price) {
|
|
|
+ return (price / 100) * RATIO_MULTIPLE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 逆转转换比例,将转换后的金额恢复到原始金额
|
|
|
+ *
|
|
|
+ * @param convertedPrice 转换后的金额
|
|
|
+ * @return Long 原始金额
|
|
|
+ */
|
|
|
+ public static Long revertConvertPriceRatio(Long convertedPrice) {
|
|
|
+ return (convertedPrice / RATIO_MULTIPLE) * 100;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public PayCurrencyRechargeDO createCurrencyRecharge(Long dataId, Long userId, Integer userType, String userIp,
|
|
@@ -81,7 +102,8 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
long payPrice;
|
|
|
long bonusPrice = 0;
|
|
|
if (Objects.nonNull(reqVO.getPackageId())) {
|
|
|
- PayCurrencyRechargePackageDO rechargePackage = payCurrencyRechargePackageService.validCurrencyRechargePackage(reqVO.getPackageId());
|
|
|
+ PayCurrencyRechargePackageDO rechargePackage = payCurrencyRechargePackageService
|
|
|
+ .validCurrencyRechargePackage(reqVO.getPackageId());
|
|
|
payPrice = rechargePackage.getPayPrice();
|
|
|
bonusPrice = rechargePackage.getBonusPrice();
|
|
|
} else {
|
|
@@ -89,7 +111,8 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
}
|
|
|
// 1.2 插入充值记录
|
|
|
PayCurrencyDO currency = payCurrencyService.getOrCreateCurrency(dataId, userId, userType);
|
|
|
- PayCurrencyRechargeDO recharge = PayCurrencyRechargeConvert.INSTANCE.convert(currency.getId(), payPrice, bonusPrice, reqVO.getPackageId());
|
|
|
+ PayCurrencyRechargeDO recharge = PayCurrencyRechargeConvert.INSTANCE
|
|
|
+ .convert(currency.getId(), payPrice, bonusPrice, reqVO.getPackageId());
|
|
|
currencyRechargeMapper.insert(recharge);
|
|
|
|
|
|
// 2.1 创建支付单
|
|
@@ -141,7 +164,7 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
// TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110;
|
|
|
// TODO 需要货币账户中加个可提现余额
|
|
|
payCurrencyService.addCurrencyBalance(currencyRecharge.getCurrencyId(), String.valueOf(id),
|
|
|
- PayCurrencyBizTypeEnum.RECHARGE, currencyRecharge.getTotalPrice());
|
|
|
+ PayCurrencyBizTypeEnum.RECHARGE, convertPriceRatio(currencyRecharge.getTotalPrice()));
|
|
|
|
|
|
// 4. 发送订阅消息
|
|
|
getSelf().sendCurrencyRechargerPaidMessage(payOrderId, currencyRecharge);
|
|
@@ -175,7 +198,7 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
PayCurrencyDO currency = validateCurrencyRechargeCanRefund(currencyRecharge);
|
|
|
|
|
|
// 2. 冻结退款的余额,暂时只处理赠送的余额也全部退回
|
|
|
- payCurrencyService.freezePrice(currency.getId(), currencyRecharge.getTotalPrice());
|
|
|
+ payCurrencyService.freezePrice(currency.getId(), convertPriceRatio(currencyRecharge.getTotalPrice()));
|
|
|
|
|
|
// 3. 创建退款单
|
|
|
String currencyRechargeId = String.valueOf(id);
|
|
@@ -209,7 +232,7 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
if (PayRefundStatusEnum.isSuccess(payRefund.getStatus())) {
|
|
|
// 2.1 更新货币账户余额
|
|
|
payCurrencyService.reduceCurrencyBalance(currencyRecharge.getCurrencyId(), id,
|
|
|
- PayCurrencyBizTypeEnum.RECHARGE_REFUND, currencyRecharge.getTotalPrice());
|
|
|
+ PayCurrencyBizTypeEnum.RECHARGE_REFUND, convertPriceRatio(currencyRecharge.getTotalPrice()));
|
|
|
|
|
|
updateObj.setRefundStatus(SUCCESS.getStatus()).setRefundTime(payRefund.getSuccessTime())
|
|
|
.setRefundTotalPrice(currencyRecharge.getTotalPrice()).setRefundPayPrice(currencyRecharge.getPayPrice())
|
|
@@ -218,7 +241,8 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
// 退款失败
|
|
|
if (PayRefundStatusRespEnum.isFailure(payRefund.getStatus())) {
|
|
|
// 2.2 解冻余额
|
|
|
- payCurrencyService.unfreezePrice(currencyRecharge.getCurrencyId(), currencyRecharge.getTotalPrice());
|
|
|
+ payCurrencyService.unfreezePrice(currencyRecharge.getCurrencyId(),
|
|
|
+ convertPriceRatio(currencyRecharge.getTotalPrice()));
|
|
|
|
|
|
updateObj.setRefundStatus(FAILURE.getStatus());
|
|
|
}
|
|
@@ -267,7 +291,7 @@ public class PayCurrencyRechargeServiceImpl implements PayCurrencyRechargeServic
|
|
|
// 校验货币账户余额是否足够
|
|
|
PayCurrencyDO currency = payCurrencyService.getCurrency(currencyRecharge.getCurrencyId());
|
|
|
Assert.notNull(currency, "用户货币账户({}) 不存在", currency.getId());
|
|
|
- if (currency.getBalance() < currencyRecharge.getTotalPrice()) {
|
|
|
+ if (revertConvertPriceRatio(currency.getBalance()) < currencyRecharge.getTotalPrice()) {
|
|
|
throw exception(WALLET_RECHARGE_REFUND_BALANCE_NOT_ENOUGH);
|
|
|
}
|
|
|
// TODO @芋艿:需要考虑下,赠送的金额,会不会导致提现超过;
|