Administrator
2025-05-28 f16f74cacb9ef0ae4be89ed15353b6a449479d8c
src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallOrderService.java
@@ -2,10 +2,10 @@
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
import cc.mrbird.febs.common.enumerates.OrderDeliveryStateEnum;
import cc.mrbird.febs.common.enumerates.OrderStatusEnum;
import cc.mrbird.febs.common.enumerates.*;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.common.utils.AppContants;
import cc.mrbird.febs.common.utils.LoginUserUtil;
import cc.mrbird.febs.mall.dto.*;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
@@ -25,6 +25,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Slf4j
@@ -56,6 +57,7 @@
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final IMallMoneyFlowService mallMoneyFlowService;
    private final MallRefundMapper mallRefundMapper;
    private final MallMemberMapper mallMemberMapper;
    @Override
@@ -76,7 +78,16 @@
                if(CollUtil.isNotEmpty(mallOrderItemList)){
                    StringBuffer stringBuffer = new StringBuffer();
                    for(MallOrderItem mallOrderItem : mallOrderItemList){
                        stringBuffer.append(mallOrderItem.getGoodsName()).append("*").append(mallOrderItem.getCnt()).append(";");
                        stringBuffer.append(mallOrderItem.getGoodsName())
                                .append("-")
                                .append(mallOrderItem.getSkuName())
                                .append("*").append(mallOrderItem.getCnt()).append(";");
//                        if(ObjectUtil.isNotEmpty(mallOrderItem.getMemberInviteId())){
//                            MallMember mallMember = mallMemberMapper.selectInfoByInviteId(mallOrderItem.getMemberInviteId());
//                            if(ObjectUtil.isNotEmpty(mallMember)){
//                                adminMallOrderInfoVo.setRefererName(mallMember.getName());
//                            }
//                        }
                    }
                    adminMallOrderInfoVo.setGoodsName(stringBuffer.toString());
                }
@@ -139,7 +150,7 @@
            StringBuffer orderItems = new StringBuffer();
            for (MallOrderItem item : mallOrderItems){
                StringBuffer orderItem = new StringBuffer();
                orderItems.append(item.getGoodsName()+"-"+item.getCnt()+"*"+item.getPrice()+"-合计"+item.getAmount()+"; \n ");
                orderItems.append(item.getGoodsName()+"-"+item.getSkuName()+"-"+item.getCnt()+"*"+item.getPrice()+"-合计"+item.getAmount()+"; \n ");
                orderItems.append(orderItem);
            }
            adminOrderDetailVo.setOrderItems(orderItems.toString());
@@ -184,7 +195,15 @@
            //用户钱包增加对应的余额
            iApiMallMemberWalletService.addBalance(amount, mallOrderInfo.getMemberId());
            mallMoneyFlowService.addMoneyFlow(mallOrderRefund.getMemberId(), amount, MoneyFlowTypeEnum.REFUND.getValue(), mallOrderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue());
            mallMoneyFlowService.addMoneyFlow(
                    mallOrderInfo.getMemberId(),
                    amount,
                    ScoreFlowTypeEnum.REFUND.getValue(),
                    mallOrderInfo.getOrderNo(),
                    FlowTypeEnum.BALANCE.getValue(),
                    StrUtil.format(ScoreFlowTypeEnum.REFUND.getDesc(),amount),
                    2
            );
        }
        MallOrderRefundOperation mallOrderRefundOperation = new MallOrderRefundOperation();
@@ -253,7 +272,17 @@
        iApiMallMemberWalletService.addBalance(refundAmount, mallOrderInfo.getMemberId());
        //新增一条资金流水
        mallMoneyFlowService.addMoneyFlow(mallOrderRefund.getMemberId(), refundAmount, MoneyFlowTypeEnum.REFUND.getValue(), mallOrderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue());
        mallMoneyFlowService.addMoneyFlow(
                mallOrderInfo.getMemberId(),
                refundAmount,
                ScoreFlowTypeEnum.REFUND.getValue(),
                mallOrderInfo.getOrderNo(),
                FlowTypeEnum.BALANCE.getValue(),
                StrUtil.format(ScoreFlowTypeEnum.REFUND.getDesc(),refundAmount),
                2
        );
        return new FebsResponse().success();
    }
@@ -446,6 +475,106 @@
    }
    @Override
    public FebsResponse deliverGoodsUpdate(DeliverGoodsDto deliverGoodsDto) {
        MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectById(deliverGoodsDto.getId());
        if(ObjectUtil.isEmpty(mallOrderInfo)){
            return new FebsResponse().fail().message("订单不存在,刷新后重试");
        }
        Integer status = mallOrderInfo.getStatus();
        if(3 != status){
            return new FebsResponse().fail().message("订单不是待收货状态");
        }
        Integer deliveryType = mallOrderInfo.getDeliveryType();
        if(2 != deliveryType){
            return new FebsResponse().fail().message("订单的配送方式不是快递");
        }
        String expressNo = deliverGoodsDto.getExpressNo();
        if(StrUtil.isEmpty(expressNo)){
            return new FebsResponse().fail().message("请输入物流单号");
        }
        String expressCom = deliverGoodsDto.getExpressCom();
        if(StrUtil.isEmpty(expressCom)){
            return new FebsResponse().fail().message("请输入物流公司");
        }
        MallExpressInfo mallExpressInfo = mallExpressInfoMapper.selectByOrderId(mallOrderInfo.getId());
        if(ObjectUtil.isEmpty(mallExpressInfo)){
            return new FebsResponse().fail().message("请先发货");
        }
        mallExpressInfo.setExpressNo(expressNo);
        mallExpressInfo.setExpressCom(expressCom);
        mallExpressInfoMapper.updateById(mallExpressInfo);
        return new FebsResponse().success();
    }
    @Override
    public FebsResponse confirmOrder(AdminRefundOrderDto dto) {
        Integer type = dto.getType();
        MallOrderInfo orderInfo = this.baseMapper.selectById(dto.getOrderId());
        if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
        }
        if (orderInfo.getStatus() == OrderStatusEnum.REFUNDING.getValue()) {
            throw new FebsException("已提交退款, 请勿重复提交");
        }
        if (orderInfo.getStatus() != OrderStatusEnum.WAIT_SHIPPING.getValue()
                && orderInfo.getStatus() != OrderStatusEnum.WAIT_FINISH.getValue()) {
            throw new FebsException("该订单不能退款");
        }
        Integer beforeStatus = orderInfo.getStatus();
        Long memberId = orderInfo.getMemberId();
        orderInfo.setStatus(OrderStatusEnum.REFUNDING.getValue());
        this.baseMapper.updateById(orderInfo);
        MallOrderRefund orderRefund = mallOrderRefundMapper.selectOrderRefundByOrderId(orderInfo.getId());
        if (orderRefund == null) {
            orderRefund = new MallOrderRefund();
            orderRefund.setOrderId(orderInfo.getId());
            orderRefund.setMemberId(memberId);
            orderRefund.setType(type);
            orderRefund.setRefundTime(new Date());
            orderRefund.setBeforeStatus(beforeStatus);
            orderRefund.setStatus(OrderRefundStatusEnum.REFUND_APPLY.getValue());
            // 未发货则退运费,发货了则不退
            if (beforeStatus == 2) {
                orderRefund.setAmount(orderInfo.getAmount().add(orderInfo.getCarriage()));
            } else {
                orderRefund.setAmount(orderInfo.getAmount());
            }
            orderRefund.setDesp(StrUtil.format("系统发起退款{}", orderRefund.getAmount()));
            orderRefund.setReason(StrUtil.format("系统发起退款{}", orderRefund.getAmount()));
            mallOrderRefundMapper.insert(orderRefund);
        } else {
            orderRefund.setType(type);
            orderRefund.setRefundTime(new Date());
            orderRefund.setBeforeStatus(beforeStatus);
            orderRefund.setStatus(OrderRefundStatusEnum.REFUND_APPLY.getValue());
            // 未发货则退运费,发货了则不退
            if (beforeStatus == 2) {
                orderRefund.setAmount(orderInfo.getAmount().add(orderInfo.getCarriage()));
            } else {
                orderRefund.setAmount(orderInfo.getAmount());
            }
            orderRefund.setDesp(StrUtil.format("系统发起退款{}", orderRefund.getAmount()));
            orderRefund.setReason(StrUtil.format("系统发起退款{}", orderRefund.getAmount()));
            mallOrderRefundMapper.updateById(orderRefund);
        }
        MallOrderRefundOperation operation = new MallOrderRefundOperation();
        operation.setOrderId(orderInfo.getId());
        operation.setRefundId(orderRefund.getId());
        operation.setContent(StrUtil.format("系统发起退款{}", orderRefund.getAmount()));
        mallOrderRefundOperationMapper.insert(operation);
        return new FebsResponse().success().message("操作成功");
    }
    @Override
    public void deliverGoodsByOrderNo(DeliverGoodsDto deliverGoodsDto) {
        MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectByOrderNo(deliverGoodsDto.getOrderNo());
        if (mallOrderInfo == null) {