fix:优惠券扣减问题

This commit is contained in:
dzc committed 2026-07-30 10:01:37 +08:00
1 parent dbf20d66d4
commit a1c466b18b
3 files changed
+17 -7

No files matched your search

@@ -13,7 +13,8 @@ import lombok.Getter;
@AllArgsConstructor
public enum YesNoEnum {
YES("1", "是"), NO("0", "否");
YES("1", "是"),
NO("0", "否");
/**
* 编码
@@ -67,6 +67,7 @@ import com.bsd.pjcloud.hard.mapper.HardThirdMiOrderMapper;
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.service.*;
import com.bsd.pjcloud.hard.utils.RemoteBatchQueryUtil;
import com.bsd.pjcloud.supermarket.api.feign.RemoteMallProductService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteShopSkuService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketSpuService;
@@ -1781,7 +1782,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
RequestContextHolder.setRequestAttributes(requestAttributes);
List<Long> walletIds = list.stream().map(HardOrderVo::getWalletId).filter(ObjectUtil::isNotEmpty).distinct().toList();
if (ObjectUtil.isNotEmpty(walletIds)) {
List<WalletManageVo> walletList = remoteWalletService.getWalletByIds(walletIds).getData();
List<WalletManageVo> walletList = getWalletListByIds(walletIds);
Map<Long, WalletManageVo> walletMap = CollectionUtils.convertMap(walletList, WalletManageVo::getId);
for (HardOrderVo v : list) {
WalletManageVo target = walletMap.get(v.getWalletId());
@@ -1801,4 +1802,8 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
}
CompletableFuture.allOf(deptFuture, mchFuture, deviceFuture, currentDeptFuture, walletFuture).join();
}
}
private List<WalletManageVo> getWalletListByIds(List<Long> walletIds) {
return RemoteBatchQueryUtil.queryByIds(walletIds, ids -> remoteWalletService.getWalletByIds(ids).getData());
}
}
@@ -99,10 +99,14 @@ public class ActCouponComUtilService implements ActCouponLifecycleService {
*/
@Override
public void afterReceive(ActCouponEntity coupon, ActCouponRecordEntity record, SysUser sysUser) {
// 使用原子更新操作,避免并发问题
int rows = actCouponMapper.deductStock(coupon.getId());
if (rows == 0) {
throw new RuntimeException("优惠券库存不足或已被领完");
if (ObjectUtil.isNotEmpty(coupon.getTotalCount()) && coupon.getTotalCount() > 0) {
if (ObjectUtil.isNotEmpty(coupon.getSurplusCount())) {
// 使用原子更新操作,避免并发问题
int rows = actCouponMapper.deductStock(coupon.getId());
if (rows == 0) {
throw new RuntimeException("优惠券库存不足或已被领完");
}
}
}
}