Browse Source

增加计算实际销售金额

周箭河 5 years ago
parent
commit
698553ed32

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

@@ -69,4 +69,12 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
      */
      */
     List<SellOrder> getRefundSellOrder(Long orderId);
     List<SellOrder> getRefundSellOrder(Long orderId);
 
 
+
+    /**
+     * 获取订单的实际销售金额(除去余额部分)
+     * @param orderId
+     * @return
+     */
+    BigDecimal getSellActualAmount(Long orderId);
+
 }
 }

+ 18 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -1,10 +1,7 @@
 package com.ym.mec.biz.service.impl;
 package com.ym.mec.biz.service.impl;
 
 
 
 
-import com.ym.mec.biz.dal.dao.GoodsDao;
-import com.ym.mec.biz.dal.dao.MusicGroupDao;
-import com.ym.mec.biz.dal.dao.SellOrderDao;
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
+import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.biz.service.*;
@@ -35,6 +32,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     private SysUserCashAccountService sysUserCashAccountService;
     private SysUserCashAccountService sysUserCashAccountService;
     @Autowired
     @Autowired
     private GoodsService goodsService;
     private GoodsService goodsService;
+    @Autowired
+    private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
 
 
     @Override
     @Override
     public BaseDAO<Integer, SellOrder> getDAO() {
     public BaseDAO<Integer, SellOrder> getDAO() {
@@ -335,4 +334,19 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         return sellOrderDao.getRefundSellOrder(orderId);
         return sellOrderDao.getRefundSellOrder(orderId);
     }
     }
 
 
+    @Override
+    public BigDecimal getSellActualAmount(Long orderId) {
+        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(orderId);
+        List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetail(orderId);
+        //总余额支付
+        BigDecimal totalBalance = studentPaymentOrder.getBalancePaymentAmount() != null ? studentPaymentOrder.getBalancePaymentAmount() : BigDecimal.ZERO;
+        //总价格
+        BigDecimal totalPrice = studentPaymentOrder.getExpectAmount();
+        //商品总付款
+        BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+        //商品销售占的余额
+        BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_HALF_UP);
+        return detailTotalPrice.subtract(detailTotalBalance);
+    }
+
 }
 }