浏览代码

修改维修回调添加销售订单

周箭河 5 年之前
父节点
当前提交
b128b650ae

+ 20 - 13
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -279,7 +279,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
     @Override
     @Transactional
-    public StudentPaymentOrder addOrder(StudentRegistration studentRegistration, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, List<CourseFormDto> courseForms,BigDecimal remitFee,BigDecimal courseRemitFee) throws Exception {
+    public StudentPaymentOrder addOrder(StudentRegistration studentRegistration, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, List<CourseFormDto> courseForms, BigDecimal remitFee, BigDecimal courseRemitFee) throws Exception {
         Date date = new Date();
         StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
         studentPaymentOrder.setUserId(studentRegistration.getUserId());
@@ -411,7 +411,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
     @Override
     @Transactional
-    public StudentPaymentOrder reAddOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, String musicGroupId, StudentPaymentOrder oldOrder, List<CourseFormDto> courseForms,BigDecimal remitFee,BigDecimal courseRemitFee) {
+    public StudentPaymentOrder reAddOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, String musicGroupId, StudentPaymentOrder oldOrder, List<CourseFormDto> courseForms, BigDecimal remitFee, BigDecimal courseRemitFee) {
         //关闭老订单
         oldOrder.setStatus(DealStatusEnum.CLOSE);
         studentPaymentOrderService.update(oldOrder);
@@ -907,13 +907,16 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 //商品总付款
                 BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
                 //商品销售占的余额
-                BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice,2,BigDecimal.ROUND_HALF_UP);
+                BigDecimal detailTotalBalance = detailTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
+                        detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_HALF_UP);
 
                 int i = 1;
                 BigDecimal detailRouteBalance = BigDecimal.ZERO;
                 for (StudentPaymentOrderDetail orderDetail : orderDetails) {
-                    BigDecimal detailBalance = orderDetail.getPrice().multiply(detailTotalBalance).divide(detailTotalPrice,2,BigDecimal.ROUND_HALF_UP);
-                    if(i == orderDetails.size()){
+
+                    BigDecimal detailBalance = orderDetail.getPrice().compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
+                            orderDetail.getPrice().multiply(detailTotalBalance).divide(detailTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
+                    if (i == orderDetails.size()) {
                         detailBalance = detailTotalBalance.subtract(detailRouteBalance);
                     }
                     detailRouteBalance = detailRouteBalance.add(detailBalance);
@@ -928,11 +931,15 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                     BigDecimal routeBalance = BigDecimal.ZERO;
                     int j = 1;
                     for (Goods goods : orderDetail.getGoodsList()) {
-                        BigDecimal expectAmount = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
-                        BigDecimal balance = goods.getGroupPurchasePrice().multiply(detailBalance).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
-                        if(j==orderDetail.getGoodsList().size()){
-                            expectAmount  = orderDetail.getPrice().subtract(routePrice);
-                            balance  = orderDetail.getPrice().subtract(routeBalance);
+                        BigDecimal expectAmount = BigDecimal.ZERO;
+                        BigDecimal balance = BigDecimal.ZERO;
+                        if (goodsTotalPrice.compareTo(BigDecimal.ZERO) > 0) {
+                            expectAmount = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
+                            balance = goods.getGroupPurchasePrice().multiply(detailBalance).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
+                        }
+                        if (j == orderDetail.getGoodsList().size()) {
+                            expectAmount = orderDetail.getPrice().subtract(routePrice);
+                            balance = orderDetail.getPrice().subtract(routeBalance);
                         }
                         routePrice = routePrice.add(expectAmount);
                         routeBalance = routeBalance.add(balance);
@@ -940,9 +947,9 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
                         SellOrder sellOrder = new SellOrder();
                         Map<String, BigDecimal> CostMap = new HashMap<>();
-                        CostMap.put("sellCost",goods.getDiscountPrice());
-                        if(goods.getAgreeCostPrice() != null){
-                            CostMap.put("SellCost2",goods.getAgreeCostPrice());
+                        CostMap.put("sellCost", goods.getDiscountPrice());
+                        if (goods.getAgreeCostPrice() != null) {
+                            CostMap.put("SellCost2", goods.getAgreeCostPrice());
                         }
                         sellOrder.setOrganId(studentPaymentOrder.getOrganId());
                         sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());

+ 11 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -562,12 +562,15 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 //商品总付款
                 BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
                 //商品销售占的余额
-                BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_HALF_UP);
+                BigDecimal detailTotalBalance = detailTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
+                        detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_HALF_UP);
 
                 int i = 1;
                 BigDecimal detailRouteBalance = BigDecimal.ZERO;
                 for (StudentPaymentOrderDetail orderDetail : orderDetails) {
-                    BigDecimal detailBalance = orderDetail.getPrice().multiply(detailTotalBalance).divide(detailTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
+
+                    BigDecimal detailBalance = orderDetail.getPrice().compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
+                            orderDetail.getPrice().multiply(detailTotalBalance).divide(detailTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
                     if (i == orderDetails.size()) {
                         detailBalance = detailTotalBalance.subtract(detailRouteBalance);
                     }
@@ -583,8 +586,12 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                     BigDecimal routeBalance = BigDecimal.ZERO;
                     int j = 1;
                     for (Goods goods : orderDetail.getGoodsList()) {
-                        BigDecimal expectAmount = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
-                        BigDecimal balance = goods.getGroupPurchasePrice().multiply(detailBalance).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
+                        BigDecimal expectAmount = BigDecimal.ZERO;
+                        BigDecimal balance = BigDecimal.ZERO;
+                        if (goodsTotalPrice.compareTo(BigDecimal.ZERO) > 0) {
+                            expectAmount = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
+                            balance = goods.getGroupPurchasePrice().multiply(detailBalance).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
+                        }
                         if (j == orderDetail.getGoodsList().size()) {
                             expectAmount = orderDetail.getPrice().subtract(routePrice);
                             balance = orderDetail.getPrice().subtract(routeBalance);

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderDetailMapper.xml

@@ -173,7 +173,7 @@
     </select>
 
     <select id="getOrderDetail" resultMap="StudentPaymentOrderDetail">
-        SELECT spod.*,g.id_ goods_id_,g.name_ goods_name_,g.group_purchase_price_,g.discount_price_,g.agree_cost_price_,g.type_ good_type_ FROM student_payment_order_detail spod
+        SELECT spod.*,g.id_ goods_id_,g.name_ goods_name_,g.group_purchase_price_,g.discount_price_,g.agree_cost_price_,g.type_ goods_type_ FROM student_payment_order_detail spod
                           LEFT JOIN goods g ON FIND_IN_SET(g.id_,spod.goods_id_list_)
         WHERE spod.payment_order_id_ = #{orderId} AND spod.goods_id_list_ IS NOT NULL
     </select>