update 订单详情完成后,待结算金额,未扣除,已支付金额未增加问题修复

This commit is contained in:
yyb
2026-01-20 17:08:55 +08:00
parent d8d8a3da15
commit 6681a33940
3 changed files with 68 additions and 30 deletions

View File

@@ -140,8 +140,8 @@ public class OrderAndPayTask {
}
@Scheduled(cron = "0 0/30 * * * ? ")
//@Scheduled(cron = "0 40 2 * * ? ")
@Scheduled(cron = "0 0/1 * * * ? ")
//@Scheduled(cron = "0 0/30 * * * ? ")
@Async("scheduledTaskExecutor")
@DSTransactional
public void paymentTaskV2(){
@@ -252,6 +252,7 @@ public class OrderAndPayTask {
//已支付金额 和实际待支付金额
item.setAlreadyPayAmount(item.getAlreadyPayAmount().add(item.getPrice().multiply(BigDecimal.valueOf(item.getNumbers()))));
item.setSettlePayRealAmount(item.getSettlePayRealAmount().add(realPayAmount));
item.setAlreadyPayRealAmount(item.getAlreadyPayRealAmount().add(realPayAmount));
//设置理论支付金额 和 冻结金额 额 (冻结金额 = 理论支付金额)
build.setBlockAmount(build.getBlockAmount().add(item.getPrice().multiply(BigDecimal.valueOf(item.getNumbers()))));
build.setAmount(build.getAmount().add(item.getPrice().multiply(BigDecimal.valueOf(item.getNumbers()))));
@@ -302,10 +303,10 @@ public class OrderAndPayTask {
for (LeaseOrderItem orderTimeInfoDto : oneDayApartOrder) {
orderCompleteMap.putIfAbsent(orderTimeInfoDto.getOrderId(), true);
// 计算订单结束时间startTime + leaseTime天
LocalDateTime endTime = orderTimeInfoDto.getCreateTime().plusDays(orderTimeInfoDto.getLeaseTime());
//LocalDateTime endTime = orderTimeInfoDto.getCreateTime().plusDays(orderTimeInfoDto.getLeaseTime());
// 开发环境 测试用1分钟当一天 差值改为差1分钟
//LocalDateTime endTime = orderTimeInfoDto.getCreateTime().plusMinutes(orderTimeInfoDto.getLeaseTime());
LocalDateTime endTime = orderTimeInfoDto.getCreateTime().plusMinutes(orderTimeInfoDto.getLeaseTime() * 30);
// 获取订单完成的订单详情:比较 now 和 endTime 的年月日时分秒差值是否小于30分
long minuteTime = Duration.between(now, endTime).toMinutes();
if (minuteTime <= 0) {
@@ -326,14 +327,16 @@ public class OrderAndPayTask {
LocalDate nowDate = now.toLocalDate();
LocalDate startDate = orderTimeInfoDto.getCreateTime().toLocalDate();
long minuteDate = Duration.between(startTime, nowTime).toMinutes();
if (!nowDate.equals(startDate) && minuteDate <= 30 && minuteDate >= 0) {
//if (!nowDate.equals(startDate) && minuteDate <= 30 && minuteDate >= 0) {
// needPayIds.add(orderTimeInfoDto.getId());
// needPayInfos.add(orderTimeInfoDto);
//}
//开发环境
if ( minuteDate >= 30) {
needPayIds.add(orderTimeInfoDto.getId());
needPayInfos.add(orderTimeInfoDto);
}
//开发环境
// needPayIds.add(orderTimeInfoDto.getId());
// needPayInfos.add(orderTimeInfoDto);
//记录某个订单下所有子项目是否都完成
orderCompleteMap.put(orderTimeInfoDto.getOrderId(), false);
}
@@ -346,6 +349,7 @@ public class OrderAndPayTask {
);
}
private static Integer dataPoints = 6;
/**
* 获取各orderItemId 所需支付的金额
@@ -369,19 +373,19 @@ public class OrderAndPayTask {
.collect(Collectors.toList());
// 补零到48个数据点
while (ratios.size() < 48) {
while (ratios.size() < dataPoints) {
ratios.add(BigDecimal.ZERO);
}
// 计算总和并除以48
BigDecimal finalValue = ratios.stream()
.reduce(BigDecimal.ZERO, BigDecimal::add)
.divide(BigDecimal.valueOf(48), 2, RoundingMode.HALF_UP);
.divide(BigDecimal.valueOf(dataPoints), 2, RoundingMode.HALF_UP);
BigDecimal payAmount = itemInfo.getPrice()
.multiply(BigDecimal.valueOf(itemInfo.getNumbers()));
if (finalValue.compareTo(BigDecimal.valueOf(0.95)) <= 0){
payAmount = payAmount.multiply(finalValue);
}
@@ -888,9 +892,10 @@ public class OrderAndPayTask {
// 合并相同查询条件的记录,避免 SQL CASE WHEN 只执行第一条的问题
List<LeasePayRecordMessage> mergedRecordList = mergePayRecordMessages(reocrdList);
//订单详情结算待结算金额
leaseOrderItemMapper.updateSettleAmount(mergedRecordList);
int buyerUpdate = leaseUserWalletDataMapper.updateBalanceAndBlockBalance(mergedRecordList);
int sellerUpdate = leaseShopConfigMapper.updateBalance(mergedRecordList);
if (buyerUpdate > 0 || sellerUpdate > 0){
for (LeasePayRecordMessage item : reocrdList) {
recordLog(item);