霸王餐修改

This commit is contained in:
张松 2025-10-16 14:20:28 +08:00
parent be6ce13888
commit 9000ee1a22
3 changed files with 21 additions and 33 deletions

View File

@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
@ -17,10 +18,16 @@ import java.util.List;
* @since 2025-02-13
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CheckOrderPay implements Serializable {
/**
* 是否霸王餐
*/
private boolean isFreeDine;
private boolean withCoupon = true;
private boolean withPoints = true;
@NotNull(message = "订单id不可为空")
private Long orderId;

View File

@ -335,7 +335,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
Long shopId = orderInfo.getShopId();
AssertUtil.isNull(shopId, "生成支付订单失败,订单信息异常");
MkDiscountActivityDTO discountAct = null;
if (param.getDiscountActAmount().compareTo(BigDecimal.ZERO) > 0) {
// 满减活动校验 不为霸王餐 霸王餐不参与满减
if (!param.isFreeDine() && param.getDiscountActAmount().compareTo(BigDecimal.ZERO) > 0) {
//检查满减活动是否开启
discountAct = discountActService.checkDiscountAct(orderInfo.getShopId(),
CollUtil.isNotEmpty(param.getCouponList()), param.isVipPrice(),
@ -347,8 +348,10 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
} else {
orderInfo.setSeatAmount(BigDecimal.ZERO);
}
// 积分校验
PointsBasicSetting pointSetting = pointsBasicService.getById(shopId);
if (param.getPointsNum() > 0) {
if ((param.isFreeDine() && param.isWithPoints()) || (!param.isFreeDine() && param.getPointsNum() > 0)) {
if (pointSetting == null || !pointSetting.getEnableDeduction().equals(1)) {
throw new ValidateException("生成支付订单失败,该店铺未开启积分抵扣");
}
@ -392,8 +395,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
log.info("订单原价不正确:订单原价:{},传递为:{}", totalAmount.getPrice(), param.getOriginAmount());
throw new ValidateException("生成支付订单失败,订单原金额不正确");
}
//优惠券部分 目前规则 每个券只能用一张
if (CollUtil.isNotEmpty(param.getCouponList())) {
if ((param.isFreeDine() && param.isWithCoupon()) || (!param.isFreeDine() && CollUtil.isNotEmpty(param.getCouponList()))){
QueryWrapper couponRecordQuery = new QueryWrapper();
couponRecordQuery.in(MkShopCouponRecord::getId, param.getCouponList());
couponRecordQuery.le(MkShopCouponRecord::getUseStartTime, LocalDateTime.now());

View File

@ -1,5 +1,6 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.exceptions.ValidateException;
@ -135,6 +136,7 @@ public class PayServiceImpl implements PayService {
* @return 是否是霸王餐充值
*/
private boolean checkPayVip(VipPayParamDTO payParam) {
if (payParam.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
throw new ValidateException("充值金额不正确");
}
@ -144,35 +146,9 @@ public class PayServiceImpl implements PayService {
if (!freeConfig.getEnable()) {
throw new CzgException("该店铺未启用霸王餐");
}
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
orderInfo.setSeatNum(payParam.getSeatNum());
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
if (shopInfo.getIsTableFee() != 1 && shopInfo.getTableFee().compareTo(BigDecimal.ZERO) != 0) {
orderInfo.setSeatAmount(new BigDecimal(orderInfo.getSeatNum()).multiply(shopInfo.getTableFee()));
} else {
orderInfo.setSeatAmount(BigDecimal.ZERO);
}
//获取商品信息 计算金额 需要传入优惠券 减去优惠券
List<OrderDetail> orderDetails = orderDetailService.queryChain().eq(OrderDetail::getOrderId, orderInfo.getId()).select().list();
//总商品支付金额 不包含打包费 用来计算后续
BigDecimalDTO totalAmount = new BigDecimalDTO(BigDecimal.ZERO);
//最终打包费
BigDecimalDTO packAmount = new BigDecimalDTO(BigDecimal.ZERO);
BigDecimalDTO tempAmount = new BigDecimalDTO(BigDecimal.ZERO);
orderInfoService.getOrderAmount(orderDetails, totalAmount, packAmount, tempAmount, payParam.isAllPack(), payParam.getUserAllPack(), false);
BigDecimal total = totalAmount.getPrice().add(packAmount.getPrice());
if (total.compareTo(freeConfig.getRechargeThreshold()) < 0) {
throw new CzgException("霸王餐满" + freeConfig.getRechargeThreshold() + "可用,当前订单金额为" + total);
}
BigDecimal payAmount = (totalAmount.getPrice().add(packAmount.getPrice()).add(orderInfo.getSeatAmount()))
.multiply(new BigDecimal(freeConfig.getMultiple())).setScale(2, RoundingMode.HALF_UP);
if (payAmount.compareTo(payParam.getAmount()) != 0) {
log.info("霸王餐应支付金额:{} 其中 打包费{} 餐位费{},充值金额为:{}",
payAmount, packAmount.getPrice(), orderInfo.getSeatAmount(), payParam.getAmount());
throw new ValidateException("霸王餐支付金额不正确");
}
orderDetailService.updateBatch(orderDetails);
CheckOrderPay checkOrderPay = BeanUtil.copyProperties(payParam, CheckOrderPay.class);
orderInfoService.checkOrderPay(checkOrderPay.setFreeDine(true).setWithCoupon(freeConfig.getWithCoupon()).setWithPoints(freeConfig.getWithPoints()));
return true;
}
return false;
@ -493,6 +469,7 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<Map<String, Object>> ltPayVip(String clintIp, VipPayParamDTO payParam) {
// 霸王餐校验
boolean isFree = checkPayVip(payParam);
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");