From bd034b20e86824436e9a35ba407a8e626c67f210 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 08 Aug 2022 16:31:10 +0800
Subject: [PATCH] 20220808

---
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java |   89 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 83 insertions(+), 6 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
index a21cfb8..300a206 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -6,6 +6,7 @@
 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.mall.conversion.MallGoodsCommentConversion;
 import cc.mrbird.febs.mall.conversion.MallOrderInfoConversion;
 import cc.mrbird.febs.mall.conversion.MallOrderRefundConversion;
 import cc.mrbird.febs.mall.dto.*;
@@ -31,7 +32,6 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -48,6 +48,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 +60,7 @@
 
     private final AgentProducer agentProducer;
     private final IPayService payService;
+    private final IMallAchieveService mallAchieveService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -90,6 +92,7 @@
 
         this.baseMapper.insert(orderInfo);
         BigDecimal total = BigDecimal.ZERO;
+        BigDecimal carriage = BigDecimal.ZERO;
         for (AddOrderItemDto item : addOrderDto.getItems()) {
             MallOrderItem orderItem = new MallOrderItem();
 
@@ -127,6 +130,15 @@
                 }
 
                 MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
+
+                // 零撸专区购买
+                if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) {
+                    List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId());
+                    if (CollUtil.isNotEmpty(items)) {
+                        throw new FebsException("无法重复领取同一个商品");
+                    }
+                }
+
                 if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                     throw new FebsException(mallGoods.getGoodsName() + "已下架");
                 }
@@ -146,6 +158,7 @@
                 orderItem.setCostPrice(sku.getCostPrice());
 
                 total = total.add(amount);
+                carriage = carriage.add(mallGoods.getCarriage());
 
                 sku.setStock(sku.getStock() - item.getCnt());
                 sku.setSkuVolume(sku.getSkuVolume() + item.getCnt());
@@ -159,6 +172,7 @@
         }
 
         orderInfo.setAmount(total);
+        orderInfo.setCarriage(carriage);
         this.baseMapper.updateById(orderInfo);
 
         agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L);
@@ -231,14 +245,21 @@
                 if (CollUtil.isNotEmpty(orderItems)) {
                     for (MallOrderItem orderItem : orderItems) {
                         MallGoods mallGoods = mallGoodsMapper.selectById(orderItem.getGoodsId());
-
+                        BigDecimal score = BigDecimal.ZERO;
+                        MallGoodsSku sku = mallGoodsSkuMapper.selectById(orderItem.getSkuId());
                         if (mallGoods.getIsNormal() == 2) {
                             hasTc = true;
-                            MallGoodsSku sku = mallGoodsSkuMapper.selectById(orderItem.getSkuId());
-                            BigDecimal score = sku.getOriginalPrice().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) {
                             memberWalletService.add(score, member.getId(), "score");
                             mallMoneyFlowService.addMoneyFlow(member.getId(), score, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue());
+
+                            // 添加业绩
+                            mallAchieveService.add(orderItem.getId());
                         }
                     }
                 }
@@ -253,7 +274,7 @@
                 }
 
                 mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue());
-//                agentProducer.sendAutoLevelUpMsg(member.getId());
+                agentProducer.sendAutoLevelUpMsg(member.getId());
                 agentProducer.sendOrderReturn(orderInfo.getId());
                 break;
             case "4":
@@ -297,7 +318,10 @@
             throw new FebsException("支付密码错误");
         }
 
-        memberWalletService.reduce(orderInfo.getAmount(), mallMember.getId(), field);
+        int reduce = memberWalletService.reduce(orderInfo.getAmount().add(orderInfo.getCarriage()), mallMember.getId(), field);
+        if (reduce == 2) {
+            throw new FebsException("余额不足");
+        }
         return orderInfo.getOrderNo();
     }
 
@@ -404,6 +428,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());
@@ -412,6 +443,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);
         }
 
@@ -458,4 +495,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);
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.1