feat: 霸王餐充值修改
This commit is contained in:
@@ -20,7 +20,7 @@ public class MemberInDTO {
|
||||
private BigDecimal amount;
|
||||
private Integer orderId;
|
||||
// 使用的优惠券
|
||||
private List<Integer> userCouponIds = new ArrayList<>();
|
||||
private Integer userCouponId;
|
||||
// 是否使用积分抵扣
|
||||
private Integer pointsNum ;
|
||||
}
|
||||
|
||||
@@ -1369,19 +1369,7 @@ public class CartService {
|
||||
|
||||
private void returnCoupon(TbOrderInfo orderInfo) {
|
||||
// 返还优惠券
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
PayService.returnCoupon(orderInfo, shopCouponService);
|
||||
}
|
||||
|
||||
private void consumeCoupon(List<TbActivateOutRecord> outRecordList, Integer memberId, TbOrderInfo orderInfo) {
|
||||
|
||||
@@ -236,6 +236,7 @@ public class PayService {
|
||||
|
||||
/**
|
||||
* 校验订单支付状态是否正常
|
||||
*
|
||||
* @param orderInfo 订单信息
|
||||
*/
|
||||
private void checkOrderPayState(TbOrderInfo orderInfo) {
|
||||
@@ -255,6 +256,7 @@ public class PayService {
|
||||
|
||||
/**
|
||||
* 保存订单支付详情
|
||||
*
|
||||
* @param orderInfo 订单信息
|
||||
* @param payType 支付类型
|
||||
* @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("当前店铺未开启与优惠券同享");
|
||||
}
|
||||
|
||||
@@ -414,6 +416,10 @@ public class PayService {
|
||||
if (!freeDineConfig.getUseType().contains(orderInfo.getEatModel())) {
|
||||
throw new MsgException("当前店铺未开启此就餐模式霸王餐");
|
||||
}
|
||||
|
||||
// 返还优惠券
|
||||
returnCoupon(orderInfo, shopCouponService);
|
||||
|
||||
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.setOrderId(orderInfo.getId());
|
||||
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);
|
||||
if (userCouponList.isEmpty()) {
|
||||
throw new MsgException("存在不可用优惠券");
|
||||
}
|
||||
|
||||
ArrayList<ActivateInInfoVO> activateInInfoVOS = new ArrayList<>();
|
||||
for (Integer userCouponId : payDTO.getUserCouponIds()) {
|
||||
TbUserCouponVo userCouponVo = userCouponList.stream().filter(item -> item.getId().equals(userCouponId)).findFirst().orElse(null);
|
||||
TbUserCouponVo userCouponVo = userCouponList.stream().filter(item -> item.getId().equals(payDTO.getUserCouponId())).findFirst().orElse(null);
|
||||
if (userCouponVo == null) {
|
||||
throw new MsgException("存在不可用优惠券");
|
||||
}
|
||||
|
||||
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()));
|
||||
if (tbShopCoupons.size() != payDTO.getUserCouponIds().size()) {
|
||||
TbShopCoupon tbShopCoupons = mpShopCouponMapper.selectById(userCouponVo.getCouponId());
|
||||
if (tbShopCoupons == null) {
|
||||
throw new MsgException("存在不可用优惠券");
|
||||
}
|
||||
|
||||
// 设置优惠券信息
|
||||
// orderInfo.seta(JSONObject.toJSONString(activateInInfoVOS));
|
||||
orderInfo.setUserCouponAmount(BigDecimal.valueOf(tbShopCoupons.stream().map(TbShopCoupon::getDiscountAmount).reduce(0, Integer::sum)));
|
||||
OrderCouponInfoDTO couponInfoDTO = new OrderCouponInfoDTO();
|
||||
couponInfoDTO.setFullReductionCouponMap(new HashMap<Integer, TbUserCouponVo>(){{
|
||||
put(userCouponVo.getId(), userCouponVo);
|
||||
}});
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
|
||||
orderInfo.setUserCouponAmount(userCouponVo.getDiscountAmount());
|
||||
record.setCouponInfo(JSONObject.toJSONString(userCouponList));
|
||||
}
|
||||
|
||||
@@ -485,6 +487,21 @@ public class PayService {
|
||||
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)
|
||||
public Result payOrder(String openId, OrderPayDTO payDTO, String ip) throws Exception {
|
||||
@@ -1217,6 +1234,7 @@ public class PayService {
|
||||
|
||||
/**
|
||||
* 订单支付成功修改订单和子单状态
|
||||
*
|
||||
* @param orderInfo 订单信息
|
||||
* @param payType 支付平台
|
||||
* @param payOrderNO 三方支付订单号
|
||||
@@ -1555,6 +1573,7 @@ public class PayService {
|
||||
|
||||
/**
|
||||
* 检查充值回调是否是霸王餐活动
|
||||
*
|
||||
* @param memberIn 充值记录
|
||||
* @param payType 支付平台
|
||||
* @param payOrderNo 三方交易订单号
|
||||
@@ -1573,23 +1592,22 @@ public class PayService {
|
||||
|
||||
Integer shopId = Integer.valueOf(orderInfo.getShopId());
|
||||
// 销毁使用的优惠券
|
||||
// if (StrUtil.isNotBlank(orderInfo.getActivateInInfoList())) {
|
||||
// ArrayList<TbActivateOutRecord> activateOutRecords = new ArrayList<>();
|
||||
// JSONArray activateInfoList = JSONObject.parseArray(orderInfo.getActivateInInfoList());
|
||||
// activateInfoList.forEach(item -> {
|
||||
// ActivateInInfoVO infoVO = ((JSONObject)item).toJavaObject(ActivateInInfoVO.class);
|
||||
// TbActivateOutRecord tbActivateOutRecord = new TbActivateOutRecord();
|
||||
// tbActivateOutRecord.setShopId(shopId);
|
||||
// tbActivateOutRecord.setGiveId(infoVO.getId());
|
||||
// tbActivateOutRecord.setVipUserId(Integer.valueOf(orderInfo.getMemberId()));
|
||||
// tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue());
|
||||
// tbActivateOutRecord.setUseNum(infoVO.getNum());
|
||||
// tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue());
|
||||
// tbActivateOutRecord.setCreateTime(DateUtil.date());
|
||||
// activateOutRecords.add(tbActivateOutRecord);
|
||||
// });
|
||||
// shopCouponService.use(shopId, orderInfo.getId(), Integer.valueOf(orderInfo.getUserId()), activateOutRecords);
|
||||
// }
|
||||
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList())) {
|
||||
ArrayList<TbActivateOutRecord> activateOutRecords = new ArrayList<>();
|
||||
OrderCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderCouponInfoDTO.class);
|
||||
couponInfoDTO.getFullReductionCouponMap().values().forEach(item -> {
|
||||
TbActivateOutRecord tbActivateOutRecord = new TbActivateOutRecord();
|
||||
tbActivateOutRecord.setShopId(shopId);
|
||||
tbActivateOutRecord.setGiveId(item.getId());
|
||||
tbActivateOutRecord.setVipUserId(Integer.valueOf(orderInfo.getMemberId()));
|
||||
tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue());
|
||||
tbActivateOutRecord.setUseNum(item.getCurrentUseNum());
|
||||
tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue());
|
||||
tbActivateOutRecord.setCreateTime(DateUtil.date());
|
||||
activateOutRecords.add(tbActivateOutRecord);
|
||||
});
|
||||
shopCouponService.use(shopId, orderInfo.getId(), Integer.valueOf(orderInfo.getUserId()), activateOutRecords);
|
||||
}
|
||||
// 更改订单状态
|
||||
orderSuccessPay(orderInfo, payType, payOrderNo);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user