限时折扣商品

This commit is contained in:
wangw 2025-10-22 10:37:01 +08:00
parent 7ccdddef1e
commit c89673d4ea
9 changed files with 88 additions and 24 deletions

View File

@ -1,10 +1,16 @@
package com.czg.order.dto; package com.czg.order.dto;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data; import lombok.Data;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* 限时折扣dto * 限时折扣dto
* order专用 对应mk_limit_time_discount * order专用 对应mk_limit_time_discount
*
* @author ww * @author ww
* @description * @description
*/ */
@ -31,4 +37,16 @@ public class LimitRateDTO {
* 参与商品 * 参与商品
*/ */
private String foods; private String foods;
private Set<Long> foodIds;
public Set<Long> getFoodIds() {
if (CollUtil.isEmpty(foodIds)) {
foodIds = CollUtil.newHashSet(StrUtil.split(foods, ","))
.stream()
.map(Long::parseLong)
.collect(Collectors.toSet());
}
return foodIds;
}
} }

View File

@ -21,6 +21,8 @@ import java.math.BigDecimal;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class OrderInfoAddDTO implements Serializable { public class OrderInfoAddDTO implements Serializable {
//限时折扣部分
private LimitRateDTO limitRate;
private Long orderId; private Long orderId;
/** /**

View File

@ -84,6 +84,10 @@ public class CashierCart implements Serializable {
* 是否赠送 * 是否赠送
*/ */
private Integer isGift; private Integer isGift;
/**
* 是否参加限时折扣
*/
private Integer isTimeDiscount;
/** /**
* 是否是临时菜 * 是否是临时菜

View File

@ -136,6 +136,10 @@ public class OrderDetail implements Serializable {
* 当前下单次数 * 当前下单次数
*/ */
private Integer placeNum; private Integer placeNum;
/**
* 是否参加限时折扣
*/
private Integer isTimeDiscount;
/** /**
* 是否是临时菜品 * 是否是临时菜品
*/ */

View File

@ -50,7 +50,7 @@ public interface OrderInfoService extends IService<OrderInfo> {
OrderInfo createPayOrder(Long shopId, BigDecimal amount, String remark); OrderInfo createPayOrder(Long shopId, BigDecimal amount, String remark);
void getOrderAmount(List<OrderDetail> orderDetails, BigDecimalDTO totalAmount, BigDecimalDTO packAmount, void getOrderAmount(List<OrderDetail> orderDetails, BigDecimalDTO totalAmount, BigDecimalDTO packAmount,
BigDecimalDTO tempAmount, boolean isAllPack, Integer userAllPack, boolean isVipPrice); BigDecimalDTO tempAmount, LimitRateDTO limitRate, boolean isAllPack, Integer userAllPack, boolean isVipPrice);
Boolean printOrder(Long shopId, OrderInfoPrintDTO orderInfoPrintDTO); Boolean printOrder(Long shopId, OrderInfoPrintDTO orderInfoPrintDTO);

View File

@ -25,6 +25,7 @@ public class ShopProductVo implements Serializable {
* 商品id * 商品id
*/ */
private Long id; private Long id;
private Long syncId;
/** /**
* 商品名称 * 商品名称
*/ */

View File

@ -268,7 +268,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
UserInfo userInfo = userInfoService.getById(param.getUserId()); UserInfo userInfo = userInfoService.getById(param.getUserId());
AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在"); AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在");
} }
ShopTable table = shopTableService.getOneByTableCode(param.getShopId(), param.getTableCode()); ShopTable table = null;
if (StrUtil.isBlank(param.getTableCode())) {
param.setPayMode("no-table");
} else {
table = shopTableService.getOneByTableCode(param.getShopId(), param.getTableCode());
if (table == null) { if (table == null) {
param.setPayMode("no-table"); param.setPayMode("no-table");
} else { } else {
@ -282,9 +286,10 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
table.setStatus(ShopTableStatusEnum.UNSETTLED.getValue()); table.setStatus(ShopTableStatusEnum.UNSETTLED.getValue());
shopTableService.updateById(table); shopTableService.updateById(table);
} }
}
List<OrderDetail> orderDetails = cartService.getCartByTableCode(shopInfo.getId(), param.getTableCode(), param.getPlaceNum()); List<OrderDetail> orderDetails = cartService.getCartByTableCode(shopInfo.getId(), param.getTableCode(), param.getPlaceNum());
AssertUtil.isListEmpty(orderDetails, "下单失败 购物车为空"); AssertUtil.isListEmpty(orderDetails, "下单失败 购物车为空");
processOrderDetails(orderDetails); processOrderDetails(orderDetails, param.getLimitRate());
//生成订单 //生成订单
OrderInfo orderInfo = initOrderInfo(param, shopInfo, table); OrderInfo orderInfo = initOrderInfo(param, shopInfo, table);
orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails); orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails);
@ -394,7 +399,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
BigDecimalDTO rateAmount = new BigDecimalDTO(BigDecimal.ZERO); BigDecimalDTO rateAmount = new BigDecimalDTO(BigDecimal.ZERO);
//满减金额 //满减金额
BigDecimalDTO fullReductionAmount = new BigDecimalDTO(BigDecimal.ZERO); BigDecimalDTO fullReductionAmount = new BigDecimalDTO(BigDecimal.ZERO);
getOrderAmount(orderDetails, totalAmount, packAmount, tempAmount, getOrderAmount(orderDetails, totalAmount, packAmount, tempAmount, param.getLimitRate(),
param.isAllPack(), param.getUserAllPack(), param.isVipPrice()); param.isAllPack(), param.getUserAllPack(), param.isVipPrice());
if (totalAmount.getPrice().compareTo(param.getOriginAmount()) != 0) { if (totalAmount.getPrice().compareTo(param.getOriginAmount()) != 0) {
log.info("订单原价不正确:订单原价:{},传递为:{}", totalAmount.getPrice(), param.getOriginAmount()); log.info("订单原价不正确:订单原价:{},传递为:{}", totalAmount.getPrice(), param.getOriginAmount());
@ -805,10 +810,34 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
@Override @Override
public void getOrderAmount(List<OrderDetail> orderDetails, BigDecimalDTO totalAmount, BigDecimalDTO packAmount, public void getOrderAmount(List<OrderDetail> orderDetails, BigDecimalDTO totalAmount, BigDecimalDTO packAmount,
BigDecimalDTO tempAmount, boolean isAllPack, Integer userAllPack, boolean isVipPrice) { BigDecimalDTO tempAmount, LimitRateDTO limitRate, boolean isAllPack, Integer userAllPack, boolean isVipPrice) {
for (OrderDetail orderDetail : orderDetails) { for (OrderDetail orderDetail : orderDetails) {
if (orderDetail.getDiscountSaleAmount() != null && orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) { if (orderDetail.getDiscountSaleAmount() != null && orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
orderDetail.setUnitPrice(orderDetail.getDiscountSaleAmount()); orderDetail.setUnitPrice(orderDetail.getDiscountSaleAmount());
} else {
if (orderDetail.getIsTimeDiscount() == 1) {
if (limitRate == null || (limitRate.getFoodType() == 2 && CollUtil.isEmpty(limitRate.getFoodIds()))) {
throw new CzgException("限时折扣使用失败,商品范围不正确");
}
if (limitRate.getFoodType() == 2 && !limitRate.getFoodIds().contains(orderDetail.getProductId())) {
throw new CzgException("限时折扣使用失败,商品" + orderDetail.getProductName() + "不享受限时折扣");
}
if (!isVipPrice || "limit-time".equals(limitRate.getDiscountPriority())) {
if (orderDetail.getPrice().compareTo(BigDecimal.ZERO) == 0) {
orderDetail.setUnitPrice(orderDetail.getPrice());
} else {
// 确保最终结果保留两位小数并向上取整
orderDetail.setUnitPrice(
orderDetail.getPrice()
.multiply(new BigDecimal(limitRate.getDiscountRate()).divide(new BigDecimal("100"), 2, RoundingMode.CEILING))
.setScale(2, RoundingMode.CEILING)
);
}
} else {
orderDetail.setUnitPrice(
(orderDetail.getMemberPrice() == null || orderDetail.getMemberPrice().compareTo(BigDecimal.ZERO) <= 0)
? orderDetail.getPrice() : orderDetail.getMemberPrice());
}
} else { } else {
if (isVipPrice) { if (isVipPrice) {
orderDetail.setUnitPrice( orderDetail.setUnitPrice(
@ -818,6 +847,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderDetail.setUnitPrice(orderDetail.getPrice()); orderDetail.setUnitPrice(orderDetail.getPrice());
} }
} }
}
if (userAllPack != null) { if (userAllPack != null) {
if (userAllPack.equals(1)) { if (userAllPack.equals(1)) {
orderDetail.setPackNumber(orderDetail.getNum().subtract(orderDetail.getReturnNum())); orderDetail.setPackNumber(orderDetail.getNum().subtract(orderDetail.getReturnNum()));
@ -854,7 +884,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
* *
* @param orderDetails 订单详情 需要回填 * @param orderDetails 订单详情 需要回填
*/ */
private void processOrderDetails(List<OrderDetail> orderDetails) { private void processOrderDetails(List<OrderDetail> orderDetails, LimitRateDTO limitRate) {
for (OrderDetail detail : orderDetails) { for (OrderDetail detail : orderDetails) {
if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) { if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) {
Product product = productService.getOne(QueryWrapper.create() Product product = productService.getOne(QueryWrapper.create()
@ -869,12 +899,15 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) { if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
detail.setUnitPrice(detail.getDiscountSaleAmount()); detail.setUnitPrice(detail.getDiscountSaleAmount());
} else { } else {
if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) { if (detail.getIsTimeDiscount() == 1) {
detail.setUnitPrice(detail.getDiscountSaleAmount()); if (limitRate == null || (limitRate.getFoodType() == 2 && CollUtil.isEmpty(limitRate.getFoodIds()))) {
} else { throw new CzgException("限时折扣使用失败,商品范围不正确");
detail.setUnitPrice(detail.getPrice());
} }
if (limitRate.getFoodType() == 2 && !limitRate.getFoodIds().contains(detail.getProductId())) {
throw new CzgException("限时折扣使用失败,商品" + detail.getProductName() + "不享受限时折扣");
}
}
detail.setUnitPrice(detail.getPrice());
} }
detail.setPayAmount(detail.getNum().multiply(detail.getUnitPrice())); detail.setPayAmount(detail.getNum().multiply(detail.getUnitPrice()));
} }

View File

@ -19,6 +19,7 @@
pros.cover_img as productImg, pros.cover_img as productImg,
pros.type as productType, pros.type as productType,
cart.sku_id as skuId, cart.sku_id as skuId,
cart.is_time_discount as isTimeDiscount,
skus.spec_info as skuName, skus.spec_info as skuName,
case cart.is_gift case cart.is_gift
when 1 then 0 when 1 then 0

View File

@ -81,6 +81,7 @@
t1.images, t1.images,
t3.name as unit_name, t3.name as unit_name,
t1.is_sold_stock, t1.is_sold_stock,
t1.sync_id as syncId,
t1.stock_number, t1.stock_number,
t1.type, t1.type,
t1.group_type, t1.group_type,