满减活动金额字段
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.czg.service.order.dto;
|
||||
|
||||
import com.czg.order.dto.CheckOrderPay;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -19,6 +18,7 @@ public class OrderPayParamDTO {
|
||||
// @NotNull(message = "店铺不能为空")
|
||||
private Long shopId;
|
||||
private Long shopUserId;
|
||||
//挂账人
|
||||
private Long creditBuyerId;
|
||||
private String buyerRemark;
|
||||
private String returnUrl;
|
||||
@@ -26,9 +26,12 @@ public class OrderPayParamDTO {
|
||||
private String openId;
|
||||
private String authCode;
|
||||
private String pwd;
|
||||
|
||||
//充值id
|
||||
private Long rechargeId;
|
||||
//充值配置详情id
|
||||
private Long rechargeDetailId;
|
||||
//满减活动id
|
||||
private Long discountActId;
|
||||
private BigDecimal amount;
|
||||
|
||||
}
|
||||
|
||||
@@ -22,14 +22,21 @@ import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.exception.OrderCancelException;
|
||||
import com.czg.market.entity.MemberOrder;
|
||||
import com.czg.market.dto.MkDiscountActivityDTO;
|
||||
import com.czg.market.entity.MkDiscountThreshold;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.*;
|
||||
import com.czg.order.dto.*;
|
||||
import com.czg.order.entity.*;
|
||||
import com.czg.order.entity.CashierCart;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.enums.PayEnums;
|
||||
import com.czg.order.service.*;
|
||||
import com.czg.order.service.CashierCartService;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.order.vo.*;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProductRpcService;
|
||||
@@ -123,6 +130,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
@Resource
|
||||
private MemberOrderService memberOrderService;
|
||||
@Resource
|
||||
private MkDiscountActivityService discountActService;
|
||||
@Resource
|
||||
private MkShopRechargeService shopRechargeService;
|
||||
// 延迟 5 秒
|
||||
private static final long DELAY = 5;
|
||||
@@ -325,6 +334,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
log.info("订单信息:{},优惠信息:{}", JSONObject.toJSONString(orderInfo), JSONObject.toJSONString(param));
|
||||
Long shopId = orderInfo.getShopId();
|
||||
AssertUtil.isNull(shopId, "生成支付订单失败,订单信息异常");
|
||||
//检查满减活动是否开启
|
||||
MkDiscountActivityDTO discountAct = discountActService.checkDiscountAct(orderInfo.getShopId(),
|
||||
CollUtil.isNotEmpty(param.getCouponList()), param.isVipPrice(), param.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0);
|
||||
orderInfo.setSeatNum(param.getSeatNum());
|
||||
if (shopInfo.getIsTableFee() != 1 && shopInfo.getTableFee().compareTo(BigDecimal.ZERO) != 0) {
|
||||
orderInfo.setSeatAmount(new BigDecimal(param.getSeatNum()).multiply(shopInfo.getTableFee()));
|
||||
@@ -482,16 +494,20 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
}
|
||||
//优惠券金额结束 (商品金额+打包费+餐位费)
|
||||
newTotalAmount = newTotalAmount.add(packAmount.getPrice()).add(orderInfo.getSeatAmount());
|
||||
|
||||
//新客立减
|
||||
if (shopUser != null) {
|
||||
newTotalAmount = newTotalAmount.subtract(param.getNewCustomerDiscountAmount());
|
||||
} else {
|
||||
param.setNewCustomerDiscountAmount(BigDecimal.ZERO);
|
||||
}
|
||||
//折扣金额
|
||||
if (param.getDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
newTotalAmount = newTotalAmount.subtract(param.getDiscountAmount());
|
||||
//满减活动
|
||||
BigDecimal discountActAmount = calculateDiscountActAmount(discountAct, newTotalAmount);
|
||||
if (discountActAmount.compareTo(param.getDiscountActAmount()) != 0) {
|
||||
log.info("满减活动金额不正确:传递为:{},计算为:{}", param.getDiscountActAmount(), discountActAmount);
|
||||
throw new ValidateException("生成支付订单失败,满减活动金额不正确");
|
||||
}
|
||||
newTotalAmount = newTotalAmount.subtract(discountActAmount);
|
||||
//积分抵扣 金额范围校验 抵扣金额校验
|
||||
if (param.getPointsNum() > 0) {
|
||||
if (pointSetting.getMinPaymentAmount().compareTo(newTotalAmount) > 0) {
|
||||
@@ -506,6 +522,10 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
}
|
||||
}
|
||||
newTotalAmount = newTotalAmount.subtract(param.getPointsDiscountAmount());
|
||||
//商家最终改价
|
||||
if (param.getDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
newTotalAmount = newTotalAmount.subtract(param.getDiscountAmount());
|
||||
}
|
||||
//抹零
|
||||
newTotalAmount = newTotalAmount.subtract(param.getRoundAmount());
|
||||
if (newTotalAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
@@ -614,7 +634,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用时段校验
|
||||
* 使用优惠券时段校验
|
||||
*/
|
||||
private void isUseTime(ShopCoupon coupon) {
|
||||
if (!coupon.getUseDays().contains(CzgStrUtils.getStrWeek())) {
|
||||
@@ -747,6 +767,21 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减活动 校验门槛获取减免金额
|
||||
*/
|
||||
private BigDecimal calculateDiscountActAmount(MkDiscountActivityDTO discountAct, BigDecimal originalPrice) {
|
||||
if (discountAct == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
for (MkDiscountThreshold threshold : discountAct.getThresholds()) {
|
||||
if (originalPrice.compareTo(threshold.getFullAmount()) >= 0) {
|
||||
return threshold.getDiscountAmount();
|
||||
}
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getOrderAmount(List<OrderDetail> orderDetails, BigDecimalDTO totalAmount, BigDecimalDTO packAmount,
|
||||
BigDecimalDTO tempAmount, boolean isAllPack, Integer userAllPack, boolean isVipPrice) {
|
||||
@@ -875,7 +910,6 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
bizEnum = ShopUserFlowBizEnum.CASH_IN;
|
||||
}
|
||||
if (isFree) {
|
||||
bizEnum = ShopUserFlowBizEnum.CASH_IN;
|
||||
updateChain().eq(OrderInfo::getId, payment.getRelatedId())
|
||||
.set(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())
|
||||
.set(OrderInfo::getIsFreeDine, 1)
|
||||
@@ -883,7 +917,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
.update();
|
||||
} else {
|
||||
shopRechargeService.recharge(payment.getShopId(), payment.getSourceId(), payment.getRelatedId(),
|
||||
BigDecimal.valueOf(czgCallBackDto.getAmount()).divide(BigDecimal.valueOf(100)), payment.getId(), payment.getPayType(), bizEnum);
|
||||
BigDecimal.valueOf(czgCallBackDto.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN), payment.getId(), payment.getPayType(), bizEnum);
|
||||
//充值并支付 ↓
|
||||
OrderInfo orderInfo = getOne(new QueryWrapper()
|
||||
.eq(OrderInfo::getPayOrderId, payment.getId())
|
||||
@@ -904,7 +938,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
|
||||
// 发放成长值
|
||||
// 会员消费赠送成长值
|
||||
memberConfigService.deliver(orderInfo.getShopId(), orderInfo.getUserId(), TableValueConstant.MemberExpFlow.Type.RECHARGE, BigDecimal.valueOf(czgCallBackDto.getAmount()).divide(BigDecimal.valueOf(100)), null, orderInfo.getId());
|
||||
memberConfigService.deliver(orderInfo.getShopId(), orderInfo.getUserId(),
|
||||
TableValueConstant.MemberExpFlow.Type.RECHARGE,
|
||||
BigDecimal.valueOf(czgCallBackDto.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN), null, orderInfo.getId());
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
@@ -1209,12 +1245,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
orderInfo.setCouponInfoList(CollUtil.isEmpty(param.getCouponList()) ? "" : JSONObject.toJSONString(param.getCouponList()));
|
||||
//折扣信息
|
||||
orderInfo.setDiscountInfo(buildDiscountInfo(orderInfo));
|
||||
//最终折扣
|
||||
if (param.getOrderAmount().compareTo(BigDecimal.ZERO) != 0) {
|
||||
orderInfo.setDiscountRatio(orderInfo.getOrderAmount().divide(orderInfo.getOriginAmount(), 2, RoundingMode.UP));
|
||||
} else {
|
||||
orderInfo.setDiscountRatio(BigDecimal.ZERO);
|
||||
}
|
||||
//满减活动抵扣金额
|
||||
orderInfo.setDiscountActAmount(param.getDiscountActAmount());
|
||||
//0元按照现金支付处理
|
||||
if (orderInfo.getOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
|
||||
orderInfo.setStatus(OrderStatusEnums.DONE.getCode());
|
||||
@@ -1268,8 +1300,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
if (orderInfo.getDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
jsonObject.put("打折优惠", orderInfo.getDiscountAmount());
|
||||
}
|
||||
if (orderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
jsonObject.put("满减券抵扣", orderInfo.getFullCouponDiscountAmount());
|
||||
if (orderInfo.getDiscountActAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
jsonObject.put("满减活动抵扣", orderInfo.getDiscountActAmount());
|
||||
}
|
||||
if (orderInfo.getOtherCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
jsonObject.put("其它优惠券折扣", orderInfo.getOtherCouponDiscountAmount());
|
||||
|
||||
Reference in New Issue
Block a user