xiaoyong931011
2022-07-27 3280d1bd977e8fb5c9c60e615612fabb7b99c3e3
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -2,10 +2,8 @@
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.common.utils.MallUtils;
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.common.utils.*;
import cc.mrbird.febs.mall.conversion.MallGoodsCommentConversion;
import cc.mrbird.febs.mall.conversion.MallOrderInfoConversion;
import cc.mrbird.febs.mall.conversion.MallOrderRefundConversion;
import cc.mrbird.febs.mall.dto.*;
@@ -15,7 +13,9 @@
import cc.mrbird.febs.mall.vo.OrderDetailVo;
import cc.mrbird.febs.mall.vo.OrderListVo;
import cc.mrbird.febs.mall.vo.OrderRefundVo;
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;
@@ -31,7 +31,6 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -48,6 +47,7 @@
    private final MallAddressInfoMapper mallAddressInfoMapper;
    private final MallOrderItemMapper mallOrderItemMapper;
    private final MallMemberMapper memberMapper;
    private final MallGoodsCommentMapper mallGoodsCommentMapper;
    private final IApiMallMemberWalletService memberWalletService;
    private final MallExpressInfoMapper expressInfoMapper;
    private final MallOrderRefundMapper mallOrderRefundMapper;
@@ -59,6 +59,7 @@
    private final AgentProducer agentProducer;
    private final IPayService payService;
    private final IXcxPayService iXcxPayService;
    private final IMallAchieveService mallAchieveService;
    @Override
@@ -84,6 +85,9 @@
        orderInfo.setLongitude(address.getLongitude());
        orderInfo.setRemark(addOrderDto.getRemark());
        orderInfo.setOrderType(addOrderDto.getOrderType());
        orderInfo.setTakeUniqueCode(addOrderDto.getTakeUniqueCode());
        orderInfo.setDeliveryType(1);
        if (CollUtil.isEmpty(addOrderDto.getItems())) {
            throw new FebsException("参数错误");
@@ -215,6 +219,13 @@
            case "1":
//                orderInfo.setPayOrderNo(payOrderDto.getPayOrderNo());
//                orderInfo.setPayImage(payOrderDto.getPayImage());
                BrandWCPayRequestData brandWCPayRequestData = null;
                try {
                    brandWCPayRequestData = iXcxPayService.startPayment(orderInfo);
                } catch (Exception e) {
                    throw new FebsException("支付失败");
                }
                payResultStr = brandWCPayRequestData.getPrepay_id();
                orderInfo.setPayMethod("微信支付");
                agentProducer.sendOrderReturn(orderInfo.getId());
                break;
@@ -248,7 +259,9 @@
                        MallGoodsSku sku = mallGoodsSkuMapper.selectById(orderItem.getSkuId());
                        if (mallGoods.getIsNormal() == 2) {
                            hasTc = true;
                            score = sku.getPresentPrice().multiply(mallGoods.getStaticMulti());
                            score = sku.getPresentPrice().multiply(mallGoods.getStaticMulti()).multiply(new BigDecimal(orderItem.getCnt()));
//                            BigDecimal staticMulti = mallGoods.getStaticMulti() == null ? BigDecimal.ZERO : mallGoods.getStaticMulti();
//                            score = sku.getPresentPrice().multiply(staticMulti);
                        }
                        if (score.compareTo(BigDecimal.ZERO) > 0) {
@@ -291,6 +304,9 @@
            default:
        }
        //订单支付成功产生一个提货码
        String takeCode = ShareCodeUtil.toSerialCode(orderInfo.getId());
        orderInfo.setTakeCode(takeCode);
        this.baseMapper.updateById(orderInfo);
        Map<String, Object> map = new HashMap<>();
@@ -315,7 +331,10 @@
            throw new FebsException("支付密码错误");
        }
        memberWalletService.reduce(orderInfo.getAmount().add(orderInfo.getCarriage()), mallMember.getId(), field);
        int reduce = memberWalletService.reduce(orderInfo.getAmount().add(orderInfo.getCarriage()), mallMember.getId(), field);
        if (reduce == 2) {
            throw new FebsException("余额不足");
        }
        return orderInfo.getOrderNo();
    }
@@ -422,6 +441,13 @@
            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());
            }
            mallOrderRefundMapper.insert(orderRefund);
        } else {
            orderRefund.setDesp(addRefundDto.getDesp());
@@ -430,6 +456,12 @@
            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());
            }
            mallOrderRefundMapper.updateById(orderRefund);
        }
@@ -476,4 +508,44 @@
            this.baseMapper.updateById(orderInfo);
        }
    }
    @Override
    @Transactional
    public void goodsComment(ApiAddCommentDtos addCommentDtos) {
        Long orderId = addCommentDtos.getOrderId();
        MallMember member = LoginUserUtil.getLoginUser();
        MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(orderId);
        if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
        }
        if (OrderStatusEnum.FINISH.getValue() != orderInfo.getStatus()) {
            throw new FebsException("该状态不能评价");
        }
        if (MallOrderInfo.COMMENT_STATE_YES == orderInfo.getCommentState()) {
            throw new FebsException("该状态不能评价");
        }
        orderInfo.setCommentState(MallOrderInfo.COMMENT_STATE_YES);
        this.baseMapper.updateById(orderInfo);
        List<ApiAddCommentDto> apiAddCommentDtos = addCommentDtos.getApiAddCommentDtos();
        if(CollUtil.isNotEmpty(apiAddCommentDtos)){
            for(ApiAddCommentDto apiAddCommentDto : apiAddCommentDtos){
                Long skuId = apiAddCommentDto.getSkuId();
                MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(skuId);
                Long goodsId = apiAddCommentDto.getGoodsId();
                MallGoods mallGoods = mallGoodsMapper.selectById(goodsId);
                MallGoodsComment mallGoodsComment = MallGoodsCommentConversion.INSTANCE.dtoToEntity(apiAddCommentDto);
                mallGoodsComment.setMemberId(member.getId());
                mallGoodsComment.setOrderId(orderId);
                mallGoodsComment.setGoodsName(mallGoods.getGoodsName());
                mallGoodsComment.setSkuName(mallGoodsSku.getSkuName());
                mallGoodsComment.setStyleId(mallGoodsSku.getStyleId());
                mallGoodsComment.setStyleName(mallGoodsSku.getStyleName());
                mallGoodsComment.setShowState(MallGoodsComment.SHOW_STATE_ENABLE);
                mallGoodsCommentMapper.insert(mallGoodsComment);
            }
        }
    }
}