Merge pull request '重复充值余额处理' (#61) from cxw into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #61
This commit is contained in:
commit
6f5f3dd8b2
@ -7,6 +7,7 @@ import cn.hutool.extra.spring.SpringUtil;
|
|||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
|
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
|
||||||
@ -149,7 +150,17 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
// 1.32 校验支付渠道是否有效
|
// 1.32 校验支付渠道是否有效
|
||||||
PayChannelDO channel = validateChannelCanSubmit(order.getAppId(), reqVO.getChannelCode());
|
PayChannelDO channel = validateChannelCanSubmit(order.getAppId(), reqVO.getChannelCode());
|
||||||
PayClient client = channelService.getPayClient(channel.getId());
|
PayClient client = channelService.getPayClient(channel.getId());
|
||||||
|
// 如果订单扩展里面已经存在该订单号的订单扩展(正在等待),则关闭已有的订单扩展,然后再创建(解决先点击微信支付,然后再使用余额支付会产生两个扩展订单的bug)
|
||||||
|
LambdaQueryWrapperX<PayOrderExtensionDO> wrapperX = new LambdaQueryWrapperX<>();
|
||||||
|
wrapperX.eq(PayOrderExtensionDO::getOrderId, order.getId()).eq(PayOrderExtensionDO::getStatus, PayOrderStatusEnum.WAITING.getStatus());
|
||||||
|
List<PayOrderExtensionDO> existOrderExtensionList = orderExtensionMapper.selectList(wrapperX);
|
||||||
|
if (existOrderExtensionList != null){
|
||||||
|
// 考虑到这种重复的扩展订单一般就一个(最大值取决与支付方式个数),所以不使用批处理插入
|
||||||
|
for (PayOrderExtensionDO payOrderExtensionDO : existOrderExtensionList) {
|
||||||
|
payOrderExtensionDO.setStatus(PayOrderStatusEnum.CLOSED.getStatus());
|
||||||
|
orderExtensionMapper.updateById(payOrderExtensionDO);
|
||||||
|
}
|
||||||
|
}
|
||||||
// 2. 插入 PayOrderExtensionDO
|
// 2. 插入 PayOrderExtensionDO
|
||||||
String no = noRedisDAO.generate(payProperties.getOrderNoPrefix());
|
String no = noRedisDAO.generate(payProperties.getOrderNoPrefix());
|
||||||
PayOrderExtensionDO orderExtension = PayOrderConvert.INSTANCE.convert(reqVO, userIp)
|
PayOrderExtensionDO orderExtension = PayOrderConvert.INSTANCE.convert(reqVO, userIp)
|
||||||
@ -262,13 +273,19 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
PayChannelDO channel = channelService.validPayChannel(channelId);
|
PayChannelDO channel = channelService.validPayChannel(channelId);
|
||||||
// 更新支付订单为已支付
|
// 更新支付订单为已支付
|
||||||
TenantUtils.execute(channel.getTenantId(), () -> getSelf().notifyOrder(channel, notify));
|
TenantUtils.execute(channel.getTenantId(), () -> getSelf().notifyOrder(channel, notify));
|
||||||
|
// 获取订单扩展
|
||||||
PayOrderExtensionDO payOrderExtensionDO = orderExtensionMapper.selectByNo(notify.getOutTradeNo());
|
PayOrderExtensionDO payOrderExtensionDO = orderExtensionMapper.selectByNo(notify.getOutTradeNo());
|
||||||
PayWalletRechargeDO walletRechargeDO = walletRechargeMapper.selectOne("pay_order_id", payOrderExtensionDO.getOrderId());
|
// 判断订单是否更新为已支付
|
||||||
if (walletRechargeDO != null){
|
if (Objects.equals(PayOrderStatusEnum.SUCCESS.getStatus(), orderMapper.selectById(payOrderExtensionDO.getOrderId()).getStatus())){
|
||||||
walletRechargeDO.setPayStatus(true);
|
|
||||||
walletRechargeDO.setPayTime(LocalDateTime.now());
|
// 充值判断
|
||||||
walletRechargeMapper.updateById(walletRechargeDO);
|
PayWalletRechargeDO walletRechargeDO = walletRechargeMapper.selectOne("pay_order_id", payOrderExtensionDO.getOrderId());
|
||||||
payWalletService.addWalletBalance(walletRechargeDO.getWalletId(),walletRechargeDO.getPayOrderId().toString(),RECHARGE,walletRechargeDO.getTotalPrice());
|
if (walletRechargeDO != null){
|
||||||
|
walletRechargeDO.setPayStatus(true);
|
||||||
|
walletRechargeDO.setPayTime(LocalDateTime.now());
|
||||||
|
walletRechargeMapper.updateById(walletRechargeDO);
|
||||||
|
payWalletService.addWalletBalance(walletRechargeDO.getWalletId(),walletRechargeDO.getPayOrderId().toString(),RECHARGE,walletRechargeDO.getTotalPrice());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user