Administrator
2025-07-03 ba11b8586b1f3a6b072d787719083a792e1d1671
src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java
@@ -14,14 +14,14 @@
import cc.mrbird.febs.mall.service.ApiClothesOrderService;
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.vo.clothes.ApiClothesOrderInfoVo;
import cc.mrbird.febs.mall.vo.clothes.ApiClothesOrderPayVo;
import cc.mrbird.febs.mall.vo.clothes.ApiMyDraftVo;
import cc.mrbird.febs.mall.vo.clothes.*;
import cc.mrbird.febs.pay.model.BrandWCPayRequestData;
import cc.mrbird.febs.pay.service.IPayService;
import cc.mrbird.febs.pay.service.IXcxPayService;
import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
@@ -65,6 +65,7 @@
    private final MallAddressInfoMapper mallAddressInfoMapper;
    private final MallMemberCouponMapper mallMemberCouponMapper;
    private final MallGoodsCouponMapper mallGoodsCouponMapper;
    private final MallExpressInfoMapper mallExpressInfoMapper;
    private final AgentProducer agentProducer;
    private final IXcxPayService iXcxPayService;
@@ -460,9 +461,13 @@
                throw new FebsException("详情参数错误");
            }
        }
        /**
         *  计算优惠金额、运费和实际支付金额
         */
        total = total.multiply(new BigDecimal(orderInfo.getGoodsCnt())).setScale(2, RoundingMode.DOWN);
        orderInfo.setAmount(total);
                /**
                 *  计算优惠金额、运费和实际支付金额
                 */
        BigDecimal discountAmount = BigDecimal.ZERO;
        MallMemberCoupon mallMemberCoupon = new MallMemberCoupon();
        if(ObjectUtil.isNotEmpty(dto.getMemberCouponId())){
@@ -484,13 +489,12 @@
                orderInfo.setMemberCouponId(memberCouponId);
            }
        }
        BigDecimal deliveryAmount = dto.getDeliveryAmount() == null ? BigDecimal.ZERO : dto.getDeliveryAmount();
        orderInfo.setAmount(total);
        orderInfo.setDiscountAmount(discountAmount);
        BigDecimal deliveryAmount = dto.getDeliveryAmount() == null ? BigDecimal.ZERO : dto.getDeliveryAmount();
        orderInfo.setCarriage(deliveryAmount);
        BigDecimal realAmount = total.subtract(discountAmount).add(deliveryAmount);
        BigDecimal realAmount = total.subtract(discountAmount).add(deliveryAmount).setScale(2, RoundingMode.DOWN);
        orderInfo.setRealAmount(realAmount);
        clothesOrderMapper.updateById(orderInfo);
@@ -550,6 +554,7 @@
        if(
                ObjectUtil.isNotNull(clothesOrder)
                && ClothesEnum.DOWN.getCode() == clothesOrder.getDelFlag()
                && ClothesOrderStatusEnum.CANCEL.getValue() == clothesOrder.getStatus()
        ){
            clothesOrderMapper.update(null,
                    Wrappers.lambdaUpdate(ClothesOrder.class)
@@ -677,4 +682,132 @@
        return new FebsResponse().success().data(apiClothesOrderPayVo).message("支付成功");
    }
    @Override
    public FebsResponse findOrderList(ApiClothesOrderListVoDto dto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        dto.setMemberId(memberId);
        // 创建分页对象,传入当前页和每页大小
        Page<ApiClothesOrderListVo> page = new Page<>(dto.getPageNow(), dto.getPageSize());
        // 调用Mapper方法获取活动分页数据
        Page<ApiClothesOrderListVo> voPage = clothesOrderMapper.selectPageInOrder(page, dto);
        return new FebsResponse().success().data(voPage);
    }
    private List<ApiClothesOrderItemInfoVo> buildOrderItemInfo(Long id) {
        List<ApiClothesOrderItemInfoVo> vos = new ArrayList<>();
        List<ClothesOrderItem> clothesOrderItems = clothesOrderItemMapper.selectList(
                Wrappers.lambdaQuery(ClothesOrderItem.class)
                        .eq(ClothesOrderItem::getOrderId, id)
        );
        if(CollUtil.isNotEmpty(clothesOrderItems)){
            for (ClothesOrderItem item : clothesOrderItems) {
                ApiClothesOrderItemInfoVo vo = new ApiClothesOrderItemInfoVo();
                vo.setName(item.getName());
                vo.setPrice(item.getPrice());
                vo.setType(item.getType());
                vo.setRemark(item.getRemark());
                vos.add( vo);
            }
        }
        return vos;
    }
    @Override
    public FebsResponse orderDetails(Long id) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        ApiClothesOrderListInfoVo apiClothesOrderListInfoVo = new ApiClothesOrderListInfoVo();
        ClothesOrder clothesOrder = clothesOrderMapper.selectById(id);
        if(ObjectUtil.isNull(clothesOrder)){
            throw new FebsException("订单不存在");
        }
        apiClothesOrderListInfoVo.setId(clothesOrder.getId());
        apiClothesOrderListInfoVo.setOrderNo(clothesOrder.getOrderNo());
        apiClothesOrderListInfoVo.setOrderTime(clothesOrder.getOrderTime());
        apiClothesOrderListInfoVo.setAmount(clothesOrder.getAmount());
        apiClothesOrderListInfoVo.setRealAmount(clothesOrder.getRealAmount());
        ClothesType clothesType = clothesTypeMapper.selectById(clothesOrder.getTypeId());
        if(ObjectUtil.isNotNull(clothesType)){
            apiClothesOrderListInfoVo.setTypeName(clothesType.getName());
            apiClothesOrderListInfoVo.setTypeImage(clothesType.getImage());
        }
        apiClothesOrderListInfoVo.setGoodsCnt(clothesOrder.getGoodsCnt());
        apiClothesOrderListInfoVo.setPayMethod(clothesOrder.getPayMethod());
        apiClothesOrderListInfoVo.setStatus(clothesOrder.getStatus());
        apiClothesOrderListInfoVo.setLongitude(clothesOrder.getLongitude());
        apiClothesOrderListInfoVo.setLatitude(clothesOrder.getLatitude());
        apiClothesOrderListInfoVo.setName(clothesOrder.getName());
        apiClothesOrderListInfoVo.setPhone(clothesOrder.getPhone());
        apiClothesOrderListInfoVo.setAddress(clothesOrder.getAddress());
        MallExpressInfo mallExpressInfo = mallExpressInfoMapper.selectOne(
                Wrappers.lambdaQuery(MallExpressInfo.class)
                        .eq(MallExpressInfo::getOrderId, clothesOrder.getId())
                        .eq(MallExpressInfo::getOrderNo, clothesOrder.getOrderNo())
                        .last("limit 1")
        );
        if(ObjectUtil.isNotNull(mallExpressInfo)){
            apiClothesOrderListInfoVo.setExpressNo(mallExpressInfo.getExpressNo());
            apiClothesOrderListInfoVo.setExpressCom(mallExpressInfo.getExpressCom());
        }
        List<ApiClothesOrderItemInfoVo> items = buildOrderItemInfo(clothesOrder.getId());
        apiClothesOrderListInfoVo.setItems(items);
        if (OrderStatusEnum.WAIT_PAY.getValue() == clothesOrder.getStatus()) {
            Date endTime = DateUtil.offsetMinute(clothesOrder.getOrderTime(), 1440);
            long remainTime = DateUtil.between(new Date(), endTime, DateUnit.SECOND, false);
            apiClothesOrderListInfoVo.setRemainTime(remainTime);
        }
        apiClothesOrderListInfoVo.setCarriage(clothesOrder.getCarriage());
        apiClothesOrderListInfoVo.setRemark(clothesOrder.getRemark());
        apiClothesOrderListInfoVo.setCommentState(clothesOrder.getCommentState());
        return new FebsResponse().success().data(apiClothesOrderListInfoVo);
    }
    @Override
    public FebsResponse confirmOrder(Long id) {
        MallMember member = LoginUserUtil.getLoginUser();
        ClothesOrder orderInfo =clothesOrderMapper.selectById(id);
        if(ObjectUtil.isNull(orderInfo)){
            throw new FebsException("订单不存在");
        }
        if (member.getId() != orderInfo.getMemberId()) {
            throw new FebsException("无权限操作");
        }
        if (ClothesEnum.UP.getCode() == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
        }
        if (orderInfo.getStatus() != ClothesOrderStatusEnum.WAIT_FINISH.getValue()) {
            throw new FebsException("订单不是待收货状态");
        }
        clothesOrderMapper.update(null,
                Wrappers.lambdaUpdate(ClothesOrder.class)
                .set(ClothesOrder::getStatus, OrderStatusEnum.FINISH.getValue())
                .set(ClothesOrder::getUpdatedTime, new Date())
                .eq(ClothesOrder::getId, id)
                .eq(ClothesOrder::getMemberId, member.getId())
                );
        return new FebsResponse().success().message("操作成功");
    }
}