Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -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;
|
||||
/**
|
||||
|
||||
@@ -170,6 +170,11 @@ public class OrderInfoDTO implements Serializable {
|
||||
*/
|
||||
private String discountInfo;
|
||||
|
||||
/**
|
||||
* 限时折扣信息 json
|
||||
*/
|
||||
private String limitRate;
|
||||
|
||||
/**
|
||||
* 是否支持退款,1支持退单, 0不支持退单
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
/**
|
||||
* 是否是临时菜品
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.czg.order.entity;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.order.dto.LimitRateDTO;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
@@ -189,6 +190,15 @@ public class OrderInfo implements Serializable {
|
||||
* 折扣信息 json
|
||||
*/
|
||||
private String discountInfo;
|
||||
/**
|
||||
* 限时折扣信息 json
|
||||
*/
|
||||
private String limitRateJson;
|
||||
/**
|
||||
* 限时折扣信息 json
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private LimitRateDTO limitRate;
|
||||
|
||||
/**
|
||||
* 是否支持退款,1支持退单, 0不支持退单
|
||||
|
||||
@@ -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;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.*;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
@@ -240,6 +241,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
if (historyOrderVo == null || historyOrderVo.getId() == null) {
|
||||
return null;
|
||||
}
|
||||
if (StrUtil.isNotBlank(historyOrderVo.getLimitRateJson())) {
|
||||
historyOrderVo.setLimitRate(JSONUtil.toBean(historyOrderVo.getLimitRateJson(), LimitRateDTO.class));
|
||||
}
|
||||
List<OrderDetail> orderDetails = orderDetailService.queryChain().select()
|
||||
.eq(OrderDetail::getOrderId, historyOrderVo.getId())
|
||||
.list();
|
||||
@@ -268,23 +272,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 +403,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 +814,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 +888,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 +903,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()));
|
||||
}
|
||||
@@ -1243,6 +1280,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
orderInfo.setIsWaitCall(param.isWaitCall() ? 1 : 0);
|
||||
orderInfo.setCreditBuyerId(param.getCreditBuyerId());
|
||||
orderInfo.setIsDel(0);
|
||||
if (param.getLimitRate() != null) {
|
||||
orderInfo.setLimitRateJson(JSONObject.toJSONString(param.getLimitRate()));
|
||||
}
|
||||
//取餐码 多端一致
|
||||
orderInfo.setTakeCode(getCode(shopInfo.getId()));
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user