Administrator
2025-07-09 44aa87717297bb4fca4bb83ba631646a87749174
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;
@@ -380,15 +381,17 @@
            orderItem.setMemberId(memberId);
            orderItem.setOrderId(orderId);
            orderItem.setType(item.getType());
            orderItem.setItemCnt(dto.getCnt());
            if (ClothesOrderItemEnum.CLOTH.getCode() == item.getType()) {
                ClothesCloth cloth = clothesClothMapper.selectById(item.getSkuId());
                if (ObjectUtil.isNull(cloth)) {
                    throw new FebsException("请选择布料");
                }
                orderItem.setItemId(cloth.getId());
                orderItem.setName(cloth.getName());
                orderItem.setPrice(cloth.getPrice());
                orderItem.setItemCnt(item.getCnt());
                orderItem.setAmount(cloth.getPrice().multiply(new BigDecimal(item.getCnt())).setScale(2, RoundingMode.DOWN));
                orderItem.setAmount(cloth.getPrice().multiply(new BigDecimal(orderItem.getItemCnt())).setScale(2, RoundingMode.DOWN));
                clothesOrderItemMapper.insert(orderItem);
                total = total.add(orderItem.getAmount());
@@ -398,6 +401,7 @@
                if (ObjectUtil.isNull(size)) {
                    throw new FebsException("请选择尺寸");
                }
                orderItem.setItemId(size.getId());
                orderItem.setName(size.getName());
                orderItem.setPrice(size.getPrice());
                orderItem.setItemCnt(item.getCnt());
@@ -411,6 +415,7 @@
                if (ObjectUtil.isNull(location)) {
                    throw new FebsException("请选择图案位置");
                }
                orderItem.setItemId(location.getId());
                orderItem.setName(location.getName());
                orderItem.setPrice(location.getPrice());
                orderItem.setItemCnt(item.getCnt());
@@ -424,6 +429,7 @@
                if (ObjectUtil.isNull(pattern)) {
                    throw new FebsException("请选择图案");
                }
                orderItem.setItemId(pattern.getId());
                orderItem.setRemark(item.getPatternRemark());
                orderItem.setName(pattern.getName());
                orderItem.setPrice(pattern.getPrice());
@@ -438,6 +444,7 @@
                if (ObjectUtil.isNull(art)) {
                    throw new FebsException("请选择工艺");
                }
                orderItem.setItemId(art.getId());
                orderItem.setName(art.getName());
                orderItem.setPrice(art.getPrice());
                orderItem.setItemCnt(item.getCnt());
@@ -448,6 +455,7 @@
                continue;
            } else if (ClothesOrderItemEnum.CUSTOMIZE.getCode() == item.getType()) {
                ClothesMemberStature clothesMemberStature = clothesMemberStatureMapper.selectById(item.getSkuId());
                orderItem.setItemId(clothesMemberStature.getId());
                orderItem.setName(clothesMemberStature.getName());
                orderItem.setPrice(BigDecimal.ZERO);
                orderItem.setItemCnt(item.getCnt());
@@ -460,9 +468,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 +496,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 +561,7 @@
        if(
                ObjectUtil.isNotNull(clothesOrder)
                && ClothesEnum.DOWN.getCode() == clothesOrder.getDelFlag()
                && ClothesOrderStatusEnum.CANCEL.getValue() == clothesOrder.getStatus()
        ){
            clothesOrderMapper.update(null,
                    Wrappers.lambdaUpdate(ClothesOrder.class)
@@ -677,4 +689,133 @@
        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::getDeliveryState, OrderDeliveryStateEnum.DELIVERY_FINISH.getValue())
                    .set(ClothesOrder::getUpdatedTime, new Date())
                    .eq(ClothesOrder::getId, id)
                    .eq(ClothesOrder::getMemberId, member.getId())
                );
        return new FebsResponse().success().message("操作成功");
    }
}