限时折扣商品
This commit is contained in:
parent
7ccdddef1e
commit
c89673d4ea
|
|
@ -1,10 +1,16 @@
|
|||
package com.czg.order.dto;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 限时折扣dto
|
||||
* order专用 对应mk_limit_time_discount
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
|
|
@ -31,4 +37,16 @@ public class LimitRateDTO {
|
|||
* 参与商品
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ import java.math.BigDecimal;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OrderInfoAddDTO implements Serializable {
|
||||
//限时折扣部分
|
||||
private LimitRateDTO limitRate;
|
||||
|
||||
private Long orderId;
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -84,6 +84,10 @@ public class CashierCart implements Serializable {
|
|||
* 是否赠送
|
||||
*/
|
||||
private Integer isGift;
|
||||
/**
|
||||
* 是否参加限时折扣
|
||||
*/
|
||||
private Integer isTimeDiscount;
|
||||
|
||||
/**
|
||||
* 是否是临时菜
|
||||
|
|
|
|||
|
|
@ -136,6 +136,10 @@ public class OrderDetail implements Serializable {
|
|||
* 当前下单次数
|
||||
*/
|
||||
private Integer placeNum;
|
||||
/**
|
||||
* 是否参加限时折扣
|
||||
*/
|
||||
private Integer isTimeDiscount;
|
||||
/**
|
||||
* 是否是临时菜品
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public interface OrderInfoService extends IService<OrderInfo> {
|
|||
|
||||
OrderInfo createPayOrder(Long shopId, BigDecimal amount, String remark);
|
||||
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);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public class ShopProductVo implements Serializable {
|
|||
* 商品id
|
||||
*/
|
||||
private Long id;
|
||||
private Long syncId;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -268,23 +268,28 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
UserInfo userInfo = userInfoService.getById(param.getUserId());
|
||||
AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在");
|
||||
}
|
||||
ShopTable table = shopTableService.getOneByTableCode(param.getShopId(), param.getTableCode());
|
||||
if (table == null) {
|
||||
ShopTable table = null;
|
||||
if (StrUtil.isBlank(param.getTableCode())) {
|
||||
param.setPayMode("no-table");
|
||||
} else {
|
||||
if ("before".equals(shopInfo.getRegisterType())) {
|
||||
param.setPayMode("before-pay");
|
||||
} else if ("after".equals(shopInfo.getRegisterType())) {
|
||||
param.setPayMode("after-pay");
|
||||
table = shopTableService.getOneByTableCode(param.getShopId(), param.getTableCode());
|
||||
if (table == null) {
|
||||
param.setPayMode("no-table");
|
||||
} else {
|
||||
param.setPayMode("未知");
|
||||
if ("before".equals(shopInfo.getRegisterType())) {
|
||||
param.setPayMode("before-pay");
|
||||
} else if ("after".equals(shopInfo.getRegisterType())) {
|
||||
param.setPayMode("after-pay");
|
||||
} else {
|
||||
param.setPayMode("未知");
|
||||
}
|
||||
table.setStatus(ShopTableStatusEnum.UNSETTLED.getValue());
|
||||
shopTableService.updateById(table);
|
||||
}
|
||||
table.setStatus(ShopTableStatusEnum.UNSETTLED.getValue());
|
||||
shopTableService.updateById(table);
|
||||
}
|
||||
List<OrderDetail> orderDetails = cartService.getCartByTableCode(shopInfo.getId(), param.getTableCode(), param.getPlaceNum());
|
||||
AssertUtil.isListEmpty(orderDetails, "下单失败 购物车为空");
|
||||
processOrderDetails(orderDetails);
|
||||
processOrderDetails(orderDetails, param.getLimitRate());
|
||||
//生成订单
|
||||
OrderInfo orderInfo = initOrderInfo(param, shopInfo, table);
|
||||
orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails);
|
||||
|
|
@ -394,7 +399,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
BigDecimalDTO rateAmount = 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());
|
||||
if (totalAmount.getPrice().compareTo(param.getOriginAmount()) != 0) {
|
||||
log.info("订单原价不正确:订单原价:{},传递为:{}", totalAmount.getPrice(), param.getOriginAmount());
|
||||
|
|
@ -805,17 +810,42 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
|
||||
@Override
|
||||
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) {
|
||||
if (orderDetail.getDiscountSaleAmount() != null && orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
orderDetail.setUnitPrice(orderDetail.getDiscountSaleAmount());
|
||||
} else {
|
||||
if (isVipPrice) {
|
||||
orderDetail.setUnitPrice(
|
||||
(orderDetail.getMemberPrice() == null || orderDetail.getMemberPrice().compareTo(BigDecimal.ZERO) <= 0)
|
||||
? orderDetail.getPrice() : orderDetail.getMemberPrice());
|
||||
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 {
|
||||
orderDetail.setUnitPrice(orderDetail.getPrice());
|
||||
if (isVipPrice) {
|
||||
orderDetail.setUnitPrice(
|
||||
(orderDetail.getMemberPrice() == null || orderDetail.getMemberPrice().compareTo(BigDecimal.ZERO) <= 0)
|
||||
? orderDetail.getPrice() : orderDetail.getMemberPrice());
|
||||
} else {
|
||||
orderDetail.setUnitPrice(orderDetail.getPrice());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (userAllPack != null) {
|
||||
|
|
@ -854,7 +884,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
*
|
||||
* @param orderDetails 订单详情 需要回填
|
||||
*/
|
||||
private void processOrderDetails(List<OrderDetail> orderDetails) {
|
||||
private void processOrderDetails(List<OrderDetail> orderDetails, LimitRateDTO limitRate) {
|
||||
for (OrderDetail detail : orderDetails) {
|
||||
if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) {
|
||||
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) {
|
||||
detail.setUnitPrice(detail.getDiscountSaleAmount());
|
||||
} else {
|
||||
if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
detail.setUnitPrice(detail.getDiscountSaleAmount());
|
||||
} else {
|
||||
detail.setUnitPrice(detail.getPrice());
|
||||
|
||||
if (detail.getIsTimeDiscount() == 1) {
|
||||
if (limitRate == null || (limitRate.getFoodType() == 2 && CollUtil.isEmpty(limitRate.getFoodIds()))) {
|
||||
throw new CzgException("限时折扣使用失败,商品范围不正确");
|
||||
}
|
||||
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()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
pros.cover_img as productImg,
|
||||
pros.type as productType,
|
||||
cart.sku_id as skuId,
|
||||
cart.is_time_discount as isTimeDiscount,
|
||||
skus.spec_info as skuName,
|
||||
case cart.is_gift
|
||||
when 1 then 0
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@
|
|||
t1.images,
|
||||
t3.name as unit_name,
|
||||
t1.is_sold_stock,
|
||||
t1.sync_id as syncId,
|
||||
t1.stock_number,
|
||||
t1.type,
|
||||
t1.group_type,
|
||||
|
|
|
|||
Loading…
Reference in New Issue