feat: 霸王餐充值修改

This commit is contained in:
2024-11-05 15:00:11 +08:00
parent 917d53e2bb
commit 12a802fe49
3 changed files with 89 additions and 83 deletions

View File

@@ -20,7 +20,7 @@ public class MemberInDTO {
private BigDecimal amount; private BigDecimal amount;
private Integer orderId; private Integer orderId;
// 使用的优惠券 // 使用的优惠券
private List<Integer> userCouponIds = new ArrayList<>(); private Integer userCouponId;
// 是否使用积分抵扣 // 是否使用积分抵扣
private Integer pointsNum ; private Integer pointsNum ;
} }

View File

@@ -1369,19 +1369,7 @@ public class CartService {
private void returnCoupon(TbOrderInfo orderInfo) { private void returnCoupon(TbOrderInfo orderInfo) {
// 返还优惠券 // 返还优惠券
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList())) { PayService.returnCoupon(orderInfo, shopCouponService);
OrderCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderCouponInfoDTO.class);
// 券返还
if (!couponInfoDTO.getOutRecordList().isEmpty()) {
couponInfoDTO.getOutRecordList().forEach(item -> {
item.setRefNum(item.getUseNum());
});
shopCouponService.refund(couponInfoDTO.getOutRecordList());
couponInfoDTO.setOutRecordList(new ArrayList<>());
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
}
}
} }
private void consumeCoupon(List<TbActivateOutRecord> outRecordList, Integer memberId, TbOrderInfo orderInfo) { private void consumeCoupon(List<TbActivateOutRecord> outRecordList, Integer memberId, TbOrderInfo orderInfo) {

View File

@@ -236,6 +236,7 @@ public class PayService {
/** /**
* 校验订单支付状态是否正常 * 校验订单支付状态是否正常
*
* @param orderInfo 订单信息 * @param orderInfo 订单信息
*/ */
private void checkOrderPayState(TbOrderInfo orderInfo) { private void checkOrderPayState(TbOrderInfo orderInfo) {
@@ -255,6 +256,7 @@ public class PayService {
/** /**
* 保存订单支付详情 * 保存订单支付详情
*
* @param orderInfo 订单信息 * @param orderInfo 订单信息
* @param payType 支付类型 * @param payType 支付类型
* @return 订单支付 * @return 订单支付
@@ -402,7 +404,7 @@ public class PayService {
} }
// 校验优惠券积分同享 // 校验优惠券积分同享
if (!payDTO.getUserCouponIds().isEmpty() && freeDineConfig.getWithCoupon() == 0) { if (payDTO.getUserCouponId() != null && freeDineConfig.getWithCoupon() == 0) {
throw new MsgException("当前店铺未开启与优惠券同享"); throw new MsgException("当前店铺未开启与优惠券同享");
} }
@@ -414,6 +416,10 @@ public class PayService {
if (!freeDineConfig.getUseType().contains(orderInfo.getEatModel())) { if (!freeDineConfig.getUseType().contains(orderInfo.getEatModel())) {
throw new MsgException("当前店铺未开启此就餐模式霸王餐"); throw new MsgException("当前店铺未开启此就餐模式霸王餐");
} }
// 返还优惠券
returnCoupon(orderInfo, shopCouponService);
BigDecimal shouldPayAmount = orderInfo.getOriginAmount().multiply(BigDecimal.valueOf(freeDineConfig.getRechargeTimes())); BigDecimal shouldPayAmount = orderInfo.getOriginAmount().multiply(BigDecimal.valueOf(freeDineConfig.getRechargeTimes()));
@@ -442,35 +448,31 @@ public class PayService {
record.setState(TableConstant.FreeDineRecord.State.WAIT_PAY.getValue()); record.setState(TableConstant.FreeDineRecord.State.WAIT_PAY.getValue());
record.setOrderId(orderInfo.getId()); record.setOrderId(orderInfo.getId());
record.setOrderAmount(orderInfo.getOrderAmount()); record.setOrderAmount(orderInfo.getOrderAmount());
if (!payDTO.getUserCouponIds().isEmpty()) { if (payDTO.getUserCouponId() != null) {
List<TbUserCouponVo> userCouponList = shopCouponService.getActivateCouponByAmount(Integer.valueOf(orderInfo.getShopId()), String.valueOf(payDTO.getUserId()), shouldPayAmount); List<TbUserCouponVo> userCouponList = shopCouponService.getActivateCouponByAmount(Integer.valueOf(orderInfo.getShopId()), String.valueOf(payDTO.getUserId()), shouldPayAmount);
if (userCouponList.isEmpty()) { if (userCouponList.isEmpty()) {
throw new MsgException("存在不可用优惠券"); throw new MsgException("存在不可用优惠券");
} }
ArrayList<ActivateInInfoVO> activateInInfoVOS = new ArrayList<>(); TbUserCouponVo userCouponVo = userCouponList.stream().filter(item -> item.getId().equals(payDTO.getUserCouponId())).findFirst().orElse(null);
for (Integer userCouponId : payDTO.getUserCouponIds()) {
TbUserCouponVo userCouponVo = userCouponList.stream().filter(item -> item.getId().equals(userCouponId)).findFirst().orElse(null);
if (userCouponVo == null) { if (userCouponVo == null) {
throw new MsgException("存在不可用优惠券"); throw new MsgException("存在不可用优惠券");
} }
shouldPayAmount = shouldPayAmount.subtract(userCouponVo.getDiscountAmount()); shouldPayAmount = shouldPayAmount.subtract(userCouponVo.getDiscountAmount());
ActivateInInfoVO activateInInfoVO = new ActivateInInfoVO()
.setId(userCouponVo.getId())
.setCouponId(userCouponVo.getCouponId())
.setNum(1);
activateInInfoVOS.add(activateInInfoVO);
}
List<TbShopCoupon> tbShopCoupons = mpShopCouponMapper.selectBatchIds(activateInInfoVOS.stream().map(ActivateInInfoVO::getCouponId).collect(Collectors.toList())); TbShopCoupon tbShopCoupons = mpShopCouponMapper.selectById(userCouponVo.getCouponId());
if (tbShopCoupons.size() != payDTO.getUserCouponIds().size()) { if (tbShopCoupons == null) {
throw new MsgException("存在不可用优惠券"); throw new MsgException("存在不可用优惠券");
} }
// 设置优惠券信息 // 设置优惠券信息
// orderInfo.seta(JSONObject.toJSONString(activateInInfoVOS)); OrderCouponInfoDTO couponInfoDTO = new OrderCouponInfoDTO();
orderInfo.setUserCouponAmount(BigDecimal.valueOf(tbShopCoupons.stream().map(TbShopCoupon::getDiscountAmount).reduce(0, Integer::sum))); couponInfoDTO.setFullReductionCouponMap(new HashMap<Integer, TbUserCouponVo>(){{
put(userCouponVo.getId(), userCouponVo);
}});
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
orderInfo.setUserCouponAmount(userCouponVo.getDiscountAmount());
record.setCouponInfo(JSONObject.toJSONString(userCouponList)); record.setCouponInfo(JSONObject.toJSONString(userCouponList));
} }
@@ -485,6 +487,21 @@ public class PayService {
return shouldPayAmount; return shouldPayAmount;
} }
static void returnCoupon(TbOrderInfo orderInfo, TbShopCouponService shopCouponService) {
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList())) {
OrderCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderCouponInfoDTO.class);
// 券返还
if (!couponInfoDTO.getOutRecordList().isEmpty()) {
couponInfoDTO.getOutRecordList().forEach(item -> {
item.setRefNum(item.getUseNum());
});
shopCouponService.refund(couponInfoDTO.getOutRecordList());
couponInfoDTO.setOutRecordList(new ArrayList<>());
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
}
}
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result payOrder(String openId, OrderPayDTO payDTO, String ip) throws Exception { public Result payOrder(String openId, OrderPayDTO payDTO, String ip) throws Exception {
@@ -1217,6 +1234,7 @@ public class PayService {
/** /**
* 订单支付成功修改订单和子单状态 * 订单支付成功修改订单和子单状态
*
* @param orderInfo 订单信息 * @param orderInfo 订单信息
* @param payType 支付平台 * @param payType 支付平台
* @param payOrderNO 三方支付订单号 * @param payOrderNO 三方支付订单号
@@ -1555,6 +1573,7 @@ public class PayService {
/** /**
* 检查充值回调是否是霸王餐活动 * 检查充值回调是否是霸王餐活动
*
* @param memberIn 充值记录 * @param memberIn 充值记录
* @param payType 支付平台 * @param payType 支付平台
* @param payOrderNo 三方交易订单号 * @param payOrderNo 三方交易订单号
@@ -1573,23 +1592,22 @@ public class PayService {
Integer shopId = Integer.valueOf(orderInfo.getShopId()); Integer shopId = Integer.valueOf(orderInfo.getShopId());
// 销毁使用的优惠券 // 销毁使用的优惠券
// if (StrUtil.isNotBlank(orderInfo.getActivateInInfoList())) { if (StrUtil.isNotBlank(orderInfo.getCouponInfoList())) {
// ArrayList<TbActivateOutRecord> activateOutRecords = new ArrayList<>(); ArrayList<TbActivateOutRecord> activateOutRecords = new ArrayList<>();
// JSONArray activateInfoList = JSONObject.parseArray(orderInfo.getActivateInInfoList()); OrderCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderCouponInfoDTO.class);
// activateInfoList.forEach(item -> { couponInfoDTO.getFullReductionCouponMap().values().forEach(item -> {
// ActivateInInfoVO infoVO = ((JSONObject)item).toJavaObject(ActivateInInfoVO.class); TbActivateOutRecord tbActivateOutRecord = new TbActivateOutRecord();
// TbActivateOutRecord tbActivateOutRecord = new TbActivateOutRecord(); tbActivateOutRecord.setShopId(shopId);
// tbActivateOutRecord.setShopId(shopId); tbActivateOutRecord.setGiveId(item.getId());
// tbActivateOutRecord.setGiveId(infoVO.getId()); tbActivateOutRecord.setVipUserId(Integer.valueOf(orderInfo.getMemberId()));
// tbActivateOutRecord.setVipUserId(Integer.valueOf(orderInfo.getMemberId())); tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue());
// tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue()); tbActivateOutRecord.setUseNum(item.getCurrentUseNum());
// tbActivateOutRecord.setUseNum(infoVO.getNum()); tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue());
// tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue()); tbActivateOutRecord.setCreateTime(DateUtil.date());
// tbActivateOutRecord.setCreateTime(DateUtil.date()); activateOutRecords.add(tbActivateOutRecord);
// activateOutRecords.add(tbActivateOutRecord); });
// }); shopCouponService.use(shopId, orderInfo.getId(), Integer.valueOf(orderInfo.getUserId()), activateOutRecords);
// shopCouponService.use(shopId, orderInfo.getId(), Integer.valueOf(orderInfo.getUserId()), activateOutRecords); }
// }
// 更改订单状态 // 更改订单状态
orderSuccessPay(orderInfo, payType, payOrderNo); orderSuccessPay(orderInfo, payType, payOrderNo);