From f7ca147e4996629fe89e037fddda1bdd8c2338aa Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 31 Oct 2024 14:10:13 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E9=80=80=E6=AC=BE=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81=E4=BC=9A?= =?UTF-8?q?=E8=A2=AB=E8=A6=86=E7=9B=96=E4=BF=AE=E5=A4=8D=202.=20=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E7=A7=AF=E5=88=86=E4=B8=8B=E5=8D=95=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/dto/shoptable/CreateOrderDTO.java | 6 ++ .../mybatis/service/MpCashierCartService.java | 9 ++ .../mybatis/service/MpOrderDetailService.java | 8 ++ .../impl/MpCashierCartServiceImpl.java | 39 +++++++-- .../impl/MpOrderDetailServiceImpl.java | 7 ++ .../ysk/cashier/pojo/order/TbOrderInfo.java | 10 +++ .../impl/shopimpl/TbShopTableServiceImpl.java | 82 +++++++++---------- 7 files changed, 111 insertions(+), 50 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/CreateOrderDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/CreateOrderDTO.java index 6cae5fd5..73dfde96 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/CreateOrderDTO.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/CreateOrderDTO.java @@ -4,6 +4,8 @@ import lombok.Data; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import java.util.ArrayList; +import java.util.List; @Data public class CreateOrderDTO { @@ -18,4 +20,8 @@ public class CreateOrderDTO { @NotEmpty private String useType; private String vipUserId; + // 使用的优惠券 + private List userCouponIds = new ArrayList<>(); + // 使用的积分抵扣数量 + private Integer pointsNum ; } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java index 43e679e2..3df120e9 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java @@ -1,6 +1,7 @@ package cn.ysk.cashier.mybatis.service; import cn.ysk.cashier.cons.TableConstant; +import cn.ysk.cashier.dto.shoptable.ShopEatTypeInfoDTO; import cn.ysk.cashier.enums.OrderStatusEnums; import cn.ysk.cashier.pojo.order.TbCashierCart; import com.baomidou.mybatisplus.extension.service.IService; @@ -55,5 +56,13 @@ public interface MpCashierCartService extends IService { * @param orderId 订单id */ boolean updateStateByOrderId(TableConstant.OrderInfo.Status status, Integer orderId); + + /** + * 根据店就餐模式查询购物车 + * @param shopEatTypeInfoDTO 就餐模式 + * @return 购物车信息 + */ + List selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId); + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderDetailService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderDetailService.java index 8d766da5..49ec5ada 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderDetailService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpOrderDetailService.java @@ -42,5 +42,13 @@ public interface MpOrderDetailService extends IService { */ List selectByOrderId(Integer orderId); + /** + * 根据购物车id和订单id查询订单详情 + * @param shopId 店铺id + * @param cartIdList 购物车id + * @param orderId 订单id + * @return 详情信息 + */ + List selectByCartIdOrOrderId(Integer shopId, ArrayList cartIdList, Integer orderId); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java index 24864521..6375f994 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java @@ -3,16 +3,16 @@ package cn.ysk.cashier.mybatis.service.impl; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.ysk.cashier.cons.TableConstant; -import cn.ysk.cashier.enums.OrderStatusEnums; -import cn.ysk.cashier.enums.OrderUseTypeEnum; -import cn.ysk.cashier.enums.ShopInfoEatModelEnum; -import cn.ysk.cashier.enums.ShopInfoRegisterlEnum; +import cn.ysk.cashier.dto.shoptable.ShopEatTypeInfoDTO; +import cn.ysk.cashier.enums.*; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.mapper.MpShopInfoMapper; +import cn.ysk.cashier.mybatis.mapper.MpShopTableMapper; import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper; import cn.ysk.cashier.mybatis.service.MpCashierCartService; import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.shop.TbShopInfo; +import cn.ysk.cashier.pojo.shop.TbShopTable; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -32,8 +32,11 @@ import java.util.List; public class MpCashierCartServiceImpl extends ServiceImpl implements MpCashierCartService { private final MpShopInfoMapper mpShopInfoMapper; - public MpCashierCartServiceImpl(MpShopInfoMapper mpShopInfoMapper) { + private final MpShopTableMapper shopTableMapper; + + public MpCashierCartServiceImpl(MpShopInfoMapper mpShopInfoMapper, MpShopTableMapper shopTableMapper) { this.mpShopInfoMapper = mpShopInfoMapper; + this.shopTableMapper = shopTableMapper; } @Override @@ -93,5 +96,31 @@ public class MpCashierCartServiceImpl extends ServiceImpl selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId()) + .eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType()) + .in(TbCashierCart::getStatus, "create", "return") + .gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime()) + .and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId)); + + // 非堂食校验台桌状态 + TbShopTable tbShopTable; + if (shopEatTypeInfoDTO.isTakeout()) { + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")) + .in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue()); + } else { + if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) { + + queryWrapper.eq(TbCashierCart::getTableId, shopEatTypeInfoDTO.getTableId()); + } else { + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")); + } + + } + return list(queryWrapper); + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderDetailServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderDetailServiceImpl.java index d6d9b89c..2db52b2f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderDetailServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpOrderDetailServiceImpl.java @@ -46,5 +46,12 @@ public class MpOrderDetailServiceImpl extends ServiceImpl() .eq(TbOrderDetail::getOrderId, orderId)); } + + @Override + public List selectByCartIdOrOrderId(Integer shopId, ArrayList cartIdList, Integer orderId) { + return list(new LambdaQueryWrapper() + .and(q -> q.in(TbOrderDetail::getCartId, cartIdList).or().eq(TbOrderDetail::getOrderId, orderId)) + .eq(TbOrderDetail::getShopId, shopId)); + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java index f685be5d..00c63939 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/order/TbOrderInfo.java @@ -240,6 +240,16 @@ public class TbOrderInfo implements Serializable { @Column(name = "`refund_remark`") private String refundRemark; + + // 积分折扣金额 + private BigDecimal pointsDiscountAmount; + // 使用的积分数量 + private Integer pointsNum; + // 用户优惠券id + private String activateInInfoList; + // 优惠券折扣金额 + private BigDecimal activateInDiscountAmount; + public void copy(TbOrderInfo source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 89c25043..c53e855d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -11,6 +11,7 @@ import cn.ysk.cashier.config.security.security.TokenProvider; import cn.ysk.cashier.cons.RedisConstant; import cn.ysk.cashier.cons.TableConstant; import cn.ysk.cashier.cons.rabbit.RabbitConstants; +import cn.ysk.cashier.dto.points.OrderDeductionPointsDTO; import cn.ysk.cashier.dto.shop.TbShopTableDto; import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria; import cn.ysk.cashier.dto.shoptable.*; @@ -18,10 +19,7 @@ import cn.ysk.cashier.enums.*; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mapper.shop.TbShopTableMapper; import cn.ysk.cashier.mybatis.mapper.*; -import cn.ysk.cashier.mybatis.service.MpCashierCartService; -import cn.ysk.cashier.mybatis.service.MpOrderDetailService; -import cn.ysk.cashier.mybatis.service.MpOrderInfoService; -import cn.ysk.cashier.mybatis.service.MpShopTableService; +import cn.ysk.cashier.mybatis.service.*; import cn.ysk.cashier.pojo.TbShopPayType; import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.order.TbOrderDetail; @@ -98,6 +96,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { private final MpShopTableService mpShopTableService; private final MpShopUnitMapper mpShopUnitMapper; private final MpProductStockDetailMapper mpProductStockDetailMapper; + private final TbMemberPointsService memberPointsService; /** @@ -1107,50 +1106,30 @@ public class TbShopTableServiceImpl implements TbShopTableService { TbShopInfo shopInfo = shopInfoRepository.findById(createOrderDTO.getShopId()).orElse(null); if (shopInfo == null) throw new BadRequestException("店铺信息不存在"); + // 非堂食校验台桌状态 + TbShopTable tbShopTable = null; + if (StrUtil.isNotBlank(createOrderDTO.getTableId())) { + tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() + .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) + .in(TbShopTable::getStatus, "idle", "using")); + } + if (tbShopTable == null) { + throw new BadRequestException("台桌未开台或不存在"); + } + // 就餐模式信息 ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(createOrderDTO.getShopId(), createOrderDTO.getTableId(), createOrderDTO.getUseType()); - // 传递orderId直接取否则取当前缓存id Integer orderId = shopEatTypeInfoDTO.isDineInAfter() ? getCurrentOrderId(shopEatTypeInfoDTO) : null; - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() - .eq(TbCashierCart::getShopId, createOrderDTO.getShopId()) - .eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType()) - .in(TbCashierCart::getStatus, "create", "return") - .gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime()) - .and(q -> q.eq(TbCashierCart::getMasterId, createOrderDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId)); - - // 非堂食校验台桌状态 - TbShopTable tbShopTable = null; - if (shopEatTypeInfoDTO.isTakeout()) { - queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")) - .in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue()); - } else { - if (StrUtil.isNotBlank(createOrderDTO.getTableId())) { - tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() - .eq(TbShopTable::getQrcode, createOrderDTO.getTableId()) - .in(TbShopTable::getStatus, "idle", "using")); - if (tbShopTable == null) { - throw new BadRequestException("台桌未开台或不存在"); - } - queryWrapper.eq(TbCashierCart::getTableId, createOrderDTO.getTableId()); - } else { - queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")); - } - - } - - List allCashierCarts = cashierCartMapper - .selectList(queryWrapper); - + List allCashierCarts = mpCashierCartService.selectByShopEatType(shopEatTypeInfoDTO, createOrderDTO.getMasterId()); List cashierCarts = new ArrayList<>(); TbCashierCart seatCart = null; for (TbCashierCart allCashierCart : allCashierCarts) { if (TableConstant.CART_SEAT_ID.equals(allCashierCart.getProductId())) { seatCart = allCashierCart; } - // if (OrderStatusEnums.CREATE.getValue().equals(allCashierCart.getStatus())) { // cashierCarts.add(allCashierCart); // } @@ -1176,12 +1155,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { cartIdList.add(tbCashierCart.getId()); } // 查询历史orderDetail - Integer finalOrderId = orderId; - LambdaQueryWrapper query = new LambdaQueryWrapper() - .and(q -> q.in(TbOrderDetail::getCartId, cartIdList).or().eq(TbOrderDetail::getOrderId, finalOrderId)) - .eq(TbOrderDetail::getShopId, createOrderDTO.getShopId()); + List oldOrderDetailList = mpOrderDetailService.selectByCartIdOrOrderId(createOrderDTO.getShopId(), cartIdList, orderId); - List oldOrderDetailList = orderDetailMapper.selectList(query); ArrayList removeOrderDetailIds = new ArrayList<>(); ArrayList removeOrderDetailList = new ArrayList<>(); HashMap oldOrderDetailMap = new HashMap<>(); @@ -1203,7 +1178,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { List orderDetails = new ArrayList<>(); List addOrderDetails = new ArrayList<>(); - boolean hasNewInfo = false; for (TbCashierCart cashierCart : cashierCarts) { if (!"return".equals(cashierCart.getStatus())) { @@ -1239,7 +1213,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderDetail.setProductName(cashierCart.getName()); orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId())); orderDetail.setPackAmount(cashierCart.getPackFee()); - orderDetail.setStatus("unpaid"); + orderDetail.setStatus(TableConstant.CashierCart.Status.RETURN.equalsVals(cashierCart.getStatus()) ? cashierCart.getStatus() : "unpaid"); orderDetail.setUseType(shopEatTypeInfoDTO.getUseType()); orderDetail.setProductImg(cashierCart.getCoverImg()); orderDetail.setCartId(cashierCart.getId()); @@ -1250,7 +1224,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderDetails.add(orderDetail); } - // 查询订单 TbOrderInfo orderInfo = null; if (orderId != null) { @@ -1275,7 +1248,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderInfo.setSettlementAmount(totalAmount); orderInfo.setAmount(totalAmount); orderInfo.setOriginAmount(totalAmount); -// orderInfo.setStatus("unpaid"); orderInfo.setOrderAmount(totalAmount); orderInfo.setRemark(createOrderDTO.getNote()); orderInfo.setFreightAmount(feeAmount); @@ -1449,6 +1421,26 @@ public class TbShopTableServiceImpl implements TbShopTableService { } + private void calculateOrderCouponAndPoints(TbOrderInfo orderInfo, List userCouponList, Integer pointsNum) { + BigDecimal shouldPayAmount = BigDecimal.ZERO; + if (pointsNum != null) { + Long memberId = Long.valueOf(orderInfo.getMemberId()); + OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount()); + if (!memberUsablePoints.getUsable()) { + throw new BadRequestException(memberUsablePoints.getUnusableReason()); + } + if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) { + throw new BadRequestException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]"); + } + + BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum); + orderInfo.setPointsNum(pointsNum); + orderInfo.setPointsDiscountAmount(discountAmount); + shouldPayAmount = shouldPayAmount.subtract(discountAmount); + memberPointsService.deductPoints(memberId, pointsNum, "霸王餐充值抵扣", Long.valueOf(orderInfo.getId())); + } + } + @Override public Object pending(PendingDTO pendingDTO) {