Browse Source

管乐迷商城改造

zouxuan 1 year ago
parent
commit
5276c82dd6

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/SellOrderService.java

@@ -32,7 +32,7 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
      * @param studentPaymentOrder
      * @return
      */
-    List<SellOrder> addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails, StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup,BigDecimal balancePaymentAmount);
+    void addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails, StudentPaymentOrder studentPaymentOrder, String musicGroup);
 
     void batchInsert(List<SellOrder> sellOrders);
 

+ 27 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -274,17 +274,33 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public List<SellOrder> addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails,
-                                                    StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup,BigDecimal balancePaymentAmount) {
+    public void addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails,
+                                                    StudentPaymentOrder studentPaymentOrder, String musicGroupId) {
         //过去非商品详情
         List<StudentPaymentOrderDetail> goodsOrderDetails = orderDetails.stream().filter(e -> StringUtils.isNotEmpty(e.getGoodsIdList())).collect(Collectors.toList());
         if(CollectionUtils.isEmpty(goodsOrderDetails)){
-            throw new BizException("商品详情为空");
+            return;
         }
-        //获取总减免金额
-        BigDecimal detailTotalRemitPrice = goodsOrderDetails.stream().map(StudentPaymentOrderDetail::getRemitFee).reduce(BigDecimal.ZERO, BigDecimal::add);
         //获取总金额
         BigDecimal detailTotalPrice = goodsOrderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+        BigDecimal balancePaymentAmount = studentPaymentOrder.getBalancePaymentAmount();
+        if (balancePaymentAmount.compareTo(BigDecimal.ZERO) > 0) {
+            BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
+            BigDecimal organShareProfit = orderDetails.stream().filter(o -> o.getType() == ORGAN_SHARE_PROFIT).map(StudentPaymentOrderDetail::getPrice)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            if(organShareProfit != null){
+                expectAmount = expectAmount.subtract(organShareProfit);
+            }
+            //获取比例
+            BigDecimal ratioAmount = BigDecimal.ZERO;
+            if(expectAmount.compareTo(BigDecimal.ZERO) > 0){
+                ratioAmount = balancePaymentAmount.divide(expectAmount, 6, BigDecimal.ROUND_HALF_UP);
+            }
+            //获取分配的减免金额
+            balancePaymentAmount = balancePaymentAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
+        }
+        //获取总减免金额
+        BigDecimal detailTotalRemitPrice = goodsOrderDetails.stream().map(StudentPaymentOrderDetail::getRemitFee).reduce(BigDecimal.ZERO, BigDecimal::add);
 
         List<SellOrder> sellOrders = new ArrayList<>();
 
@@ -331,9 +347,12 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
                 subDetailActualAmount = subDetailActualAmount.subtract(detailActualAmount);
             }
             List<Integer> goodsIds = Arrays.asList(orderDetail.getGoodsIdList().split(",")).stream().map(Integer::parseInt).collect(Collectors.toList());
-            sellOrders.addAll(this.initSellOrder(studentPaymentOrder, musicGroup.getId(), goodsIds, orderDetail.getKitGroupPurchaseType(),
+            sellOrders.addAll(this.initSellOrder(studentPaymentOrder, musicGroupId, goodsIds, orderDetail.getKitGroupPurchaseType(),
                     detailBalance, orderDetail.getPrice(), couponRemitFee, detailActualAmount, false));
         }
+        this.batchInsert(sellOrders);
+        //同步销售订单到商城
+        this.syncSellOrder2Mall(sellOrders, studentPaymentOrder);
 
 /*
             BigDecimal goodsTotalPrice = orderDetail.getGoodsList().stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
@@ -460,7 +479,6 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             }
             sellOrderDao.batchInsert(sellOrders);
         }*/
-        return sellOrders;
     }
 
     @Override
@@ -681,7 +699,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             musicGroup = musicGroupDao.get(musicGroupId);
         }
         List<Goods> goodies = goodsDao.getGoodies(goodsIds);
-        BigDecimal goodsTotalPrice = goodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+        BigDecimal goodsTotalPrice = goodies.stream().map(e->order.getGroupType() == MUSIC ?e.getGroupPurchasePrice():e.getDiscountPrice()).
+                reduce(BigDecimal.ZERO, BigDecimal::add);
 
         AccountType accountType = AccountType.INTERNAL;
         if(StringUtils.isNotEmpty(order.getPaymentChannel())){

+ 2 - 24
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -688,30 +688,8 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
 
         //销售订单详情
         if (allDetails.size() > 0 && (detailTypeEnums.contains(MUSICAL) || detailTypeEnums.contains(ACCESSORIES) || detailTypeEnums.contains(TEACHING))) {
-            BigDecimal balancePaymentAmount = studentPaymentOrder.getBalancePaymentAmount();
-            if (balancePaymentAmount.compareTo(BigDecimal.ZERO) > 0) {
-                BigDecimal musicFee = allDetails.stream()
-                        .filter(o -> o.getType() == MUSICAL || o.getType() == ACCESSORIES || o.getType() == TEACHING)
-                        .map(StudentPaymentOrderDetail::getPrice)
-                        .reduce(BigDecimal.ZERO, BigDecimal::add);
-                BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
-
-				BigDecimal organShareProfit = allDetails.stream().filter(o -> o.getType() == ORGAN_SHARE_PROFIT).map(StudentPaymentOrderDetail::getPrice)
-						.reduce(BigDecimal.ZERO, BigDecimal::add);
-
-				if(organShareProfit != null){
-					expectAmount = expectAmount.subtract(organShareProfit);
-				}
-                //获取比例
-                BigDecimal ratioAmount = musicFee.divide(expectAmount, 6, BigDecimal.ROUND_HALF_UP);
-                //获取分配的减免金额
-                balancePaymentAmount = balancePaymentAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
-            }
-            List<SellOrder> sellOrders = sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup, balancePaymentAmount);
-            sellOrderService.batchInsert(sellOrders);
-            sellOrderService.syncSellOrder2Mall(sellOrders, studentPaymentOrder);
-            //同步销售订单到商城
-//            sellOrderService.syncSellOrder2Mall(sellOrders,studentPaymentOrder);
+            sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup.getId());
+
         }
 
         //活动小课包处理

+ 3 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -1132,7 +1132,9 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             //将购买的乐器加入学生乐器列表
             studentGoodsSellService.saveStudentInstrument(studentPaymentOrder);
             //购买的商品加入销售列表
-            saveSellOrder(studentPaymentOrder.getOrderNo());
+//            saveSellOrder(studentPaymentOrder.getOrderNo());
+            List<StudentPaymentOrderDetail> orderDetail = studentPaymentOrderDetailService.getOrderDetail(studentPaymentOrder.getId());
+            sellOrderService.addOrderDetail2SellOrder(orderDetail,studentPaymentOrder,null);
         } else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
 
             //增加商品库存