KKSU
2025-01-23 20e0c1036ebc6d558e57644b770b9c9de8bcf383
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -123,14 +123,9 @@
        MallMemberCoupon mallMemberCoupon = new MallMemberCoupon();
        if(ObjectUtil.isNotEmpty(addOrderDto.getMemberCouponId())){
            Long memberCouponId = addOrderDto.getMemberCouponId();
            mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
            if(ObjectUtil.isEmpty(mallMemberCoupon)){
                throw new FebsException(mallMemberCoupon.getCouponName()+"无法使用");
            }
            Integer state = mallMemberCoupon.getState();
            if(1 != state){
                throw new FebsException(mallMemberCoupon.getCouponName()+"无法使用");
            }
            mallMemberCoupon = ValidateEntityUtils.ensureColumnReturnEntity(memberCouponId, MallMemberCoupon::getId, mallMemberCouponMapper::selectOne, "优惠券不存在");
            ValidateEntityUtils.ensureEqual(mallMemberCoupon.getState(),1, "优惠券状态异常");
            List<AddOrderItemDto> items = addOrderDto.getItems();
            couponAmountMap = getCouponAmountMap(memberCouponId, items);
        }
@@ -143,10 +138,10 @@
                    if (mallGoods.getStock() < item.getCnt()) {
                        throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                    }
                    if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                        throw new FebsException(mallGoods.getGoodsName() + "已下架");
                    }
                    ValidateEntityUtils.ensureNotEqual(mallGoods.getIsSale(),MallGoods.ISSALE_STATUS_DISABLED, "商品已下架");
//                    if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
//                        throw new FebsException(mallGoods.getGoodsName() + "已下架");
//                    }
                    BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt()));
                    orderItem.setAmount(amount);
@@ -198,9 +193,7 @@
                        }
                    }
                    if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                        throw new FebsException(mallGoods.getGoodsName() + "已下架");
                    }
                    ValidateEntityUtils.ensureNotEqual(mallGoods.getIsSale(),MallGoods.ISSALE_STATUS_DISABLED, "商品已下架");
                    //商品库存销量计算
                    Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), item.getCnt());
                    if(1 != goodsResult){
@@ -408,14 +401,13 @@
    public void cancelOrder(Long id) {
        MallMember member = LoginUserUtil.getLoginUser();
        MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), id);
        if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
        }
        ValidateEntityUtils.ensureNotEqual(orderInfo,null, "订单不存在");
        ValidateEntityUtils.ensureNotEqual(orderInfo.getDelFlag(),AppContants.DEL_FLAG_Y, "订单已删除");
        if (OrderStatusEnum.WAIT_PAY.getValue() != orderInfo.getStatus()) {
            throw new FebsException("订单不是待付款, 无法取消");
        if (OrderStatusEnum.WAIT_PAY.getValue() != orderInfo.getStatus()
                && OrderStatusEnum.WAIT_SHIPPING.getValue() != orderInfo.getStatus() ) {
            throw new FebsException("订单不是待付款或者待收货, 无法取消");
        }
        orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue());
        orderInfo.setCancelType(MallOrderInfo.CANCEL_BY_SELF);
        this.baseMapper.updateById(orderInfo);
@@ -547,7 +539,7 @@
                mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2);
                agentProducer.sendOrderCoupon(orderInfo.getId());
//                agentProducer.sendOrderCoupon(orderInfo.getId());
                break;
            case "4":
                if (orderInfo.getOrderType() != 2) {
@@ -591,14 +583,12 @@
            throw new FebsException("未设置支付密码");
        }
        if (!SecureUtil.md5(tradePwd).equals(mallMember.getTradePassword())) {
            throw new FebsException("支付密码错误");
        }
        ValidateEntityUtils.ensureEqual(SecureUtil.md5(tradePwd),mallMember.getTradePassword(),"支付密码错误");
        int reduce = memberWalletService.reduce(orderInfo.getAmount(), mallMember.getId(), field);
        if (reduce == 2) {
            throw new FebsException("余额不足");
        }
//        int reduce = memberWalletService.reduce(orderInfo.getAmount(), mallMember.getId(), field);
//        if (reduce == 2) {
//            throw new FebsException("余额不足");
//        }
        return orderInfo.getOrderNo();
    }
@@ -661,15 +651,10 @@
    @Transactional(rollbackFor = Exception.class)
    public void confirmOrder(Long id) {
        MallMember member = LoginUserUtil.getLoginUser();
        MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), id);
        if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
        }
        if (orderInfo.getStatus() != OrderStatusEnum.WAIT_FINISH.getValue()) {
            throw new FebsException("该状态不能确认收货");
        }
        MallOrderInfo orderInfo = ValidateEntityUtils.ensureColumnReturnEntity(id,MallOrderInfo::getId,this.baseMapper::selectOne,"订单不存在");
        ValidateEntityUtils.ensureEqual(member.getId(), orderInfo.getMemberId(), "订单数据异常");
        ValidateEntityUtils.ensureEqual(orderInfo.getStatus(), OrderStatusEnum.WAIT_FINISH.getValue(), "该状态不能确认收货");
//        if (orderInfo.getDeliveryState() != OrderDeliveryStateEnum.DELIVERY_FINISH.getValue()) {
//            throw new FebsException("还未送至自提点");
//        }
@@ -683,9 +668,9 @@
        orderInfo.setReceivingTime(new Date());
        this.baseMapper.updateById(orderInfo);
        //普通订单才产生积分,积分订单不产生积分
        if(1 == orderInfo.getOrderType()){
            agentProducer.sendGetScoreMsg(orderInfo.getId());
        }
//        if(1 == orderInfo.getOrderType()){
//            agentProducer.sendGetScoreMsg(orderInfo.getId());
//        }
        //生成一条团长提成记录
//        Long orderInfoId = orderInfo.getId();
//        List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfoId);
@@ -719,11 +704,8 @@
    @Override
    public void delOrder(Long id) {
        MallMember member = LoginUserUtil.getLoginUser();
        MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), id);
        if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
        }
        MallOrderInfo orderInfo = ValidateEntityUtils.ensureColumnReturnEntity(id,MallOrderInfo::getId,this.baseMapper::selectOne,"订单不存在");
        ValidateEntityUtils.ensureNotEqual(orderInfo.getDelFlag(),AppContants.DEL_FLAG_Y,"订单已删除");
        orderInfo.setDelFlag(AppContants.DEL_FLAG_Y);
        this.baseMapper.updateById(orderInfo);
    }