he2802 2 tahun lalu
induk
melakukan
ac1555b6bb

+ 41 - 36
zhongzheng-system/src/main/java/com/zhongzheng/modules/order/service/impl/OrderServiceImpl.java

@@ -3,6 +3,7 @@ package com.zhongzheng.modules.order.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
@@ -1027,7 +1028,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
                 List<TopCostTpItem> tpItems = new ArrayList<>();
                 for (TopCostTpItem x : items) {
                     BigDecimal price = goodsPrice;
-                    if (x.getDockStatus() == 1){
+                    if (ObjectUtil.isNotNull(x.getDockStatus()) && x.getDockStatus() == 1){
                         //启用成本扣除项
                         switch (x.getDockType()){
                             case 1://百分比
@@ -1054,51 +1055,55 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
                     //匹配不到成本项阶梯值
                     continue;
                 }
-                if (tpItems.size() > 1) {
-                    //匹配到多个成本项
-                    throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", businessName, goodsPrice.toString()));
-                }
-                //换算订单成本和盈亏
-                TopCostTpItem topCostTpItem = tpItems.stream().findFirst().get();
-                BigDecimal cost = new BigDecimal("0.00");//成本
+//                if (tpItems.size() > 1) {
+//                    //匹配到多个成本项
+//                    throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", businessName, goodsPrice.toString()));
+//                }
                 BigDecimal divideMoney = new BigDecimal("0.00");//分成
+                BigDecimal cost = new BigDecimal("0.00");//成本
                 BigDecimal bigDecimal = new BigDecimal("100");
-                if (topCostTpItem.getDockStatus() == 1){
-                    //启用成本扣除项
-                    switch (topCostTpItem.getDockType()){
+                for (TopCostTpItem tpItem : tpItems) {
+                    BigDecimal goodsDecimal = goodsPrice;
+                    //换算订单成本和盈亏
+                    TopCostTpItem topCostTpItem = tpItem;
+                    if (ObjectUtil.isNotNull(topCostTpItem.getDockStatus()) && topCostTpItem.getDockStatus() == 1){
+                        //启用成本扣除项
+                        switch (topCostTpItem.getDockType()){
+                            case 1://百分比
+                                //成本扣除金额
+                                BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
+                                BigDecimal multiply = goodsDecimal.multiply(divide1);
+                                goodsDecimal = goodsDecimal.subtract(multiply);
+                                break;
+                            case 2://固定金额
+                                goodsDecimal = goodsDecimal.subtract(topCostTpItem.getDockValue());
+                                break;
+                            default:
+                                break;
+                        }
+                    }
+                    switch (topCostTpItem.getItemType()) {
                         case 1://百分比
-                            //成本扣除金额
-                            BigDecimal divide = topCostTpItem.getDockValue().divide(bigDecimal);
-                            BigDecimal multiply = goodsPrice.multiply(divide);
-                            goodsPrice = goodsPrice.subtract(multiply);
+                            BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
+                            BigDecimal multiply = goodsDecimal.multiply(divide);
+                            cost = cost.add(multiply);
+                            if (topCostTpItem.getItemCategory() == 1 && add.getFinishStatus() == 1){
+                                //订单已完单 并且是分成成本
+                                divideMoney = divideMoney.add(multiply);
+                            }
                             break;
                         case 2://固定金额
-                            goodsPrice = goodsPrice.subtract(topCostTpItem.getDockValue());
+                            cost = cost.add(topCostTpItem.getTypeValue());
+                            if (topCostTpItem.getItemCategory() == 1 && add.getFinishStatus() == 1){
+                                //分成
+                                divideMoney = divideMoney.add(topCostTpItem.getTypeValue());
+                            }
                             break;
                         default:
                             break;
                     }
-
-                }
-                switch (topCostTpItem.getItemType()) {
-                    case 1://百分比
-                        BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
-                        cost = goodsPrice.multiply(divide);
-                        if (topCostTpItem.getItemCategory() == 1 && add.getFinishStatus() == 1){
-                            //订单已完单 并且是分成成本
-                            divideMoney = goodsPrice.multiply(divide);
-                        }
-                        break;
-                    case 2://固定金额
-                        cost = topCostTpItem.getTypeValue();
-                        if (topCostTpItem.getItemCategory() == 1 && add.getFinishStatus() == 1){
-                            //分成
-                            divideMoney = topCostTpItem.getTypeValue();
-                        }
-                        break;
-                    default:
-                        break;
                 }
+
                 if (add.getFinishStatus() == 1 && divideTotal.compareTo(BigDecimal.ZERO) >0 ){
                     orderGoods.setDivideModel(divideModel);
                     orderGoods.setDivideMoney(divideMoney);

+ 121 - 104
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/goods/service/impl/TopOldOrderServiceImpl.java

@@ -413,7 +413,7 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                 List<TopCostTpItem> tpItems = new ArrayList<>();
                 for (TopCostTpItem x : items) {
                     BigDecimal price = goodsPrice;
-                    if (x.getDockStatus() == 1){
+                    if (ObjectUtil.isNotNull(x.getDockStatus()) && x.getDockStatus() == 1){
                         //启用成本扣除项
                         switch (x.getDockType()){
                             case 1://百分比
@@ -440,41 +440,46 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                     //匹配不到成本项阶梯值
                     continue;
                 }
-                if (tpItems.size() > 1) {
-                    //匹配到多个成本项
-                    throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", orderGoods.getBusinessFullName(), goodsPrice.toString()));
-                }
-                //换算订单成本和盈亏
+//                if (tpItems.size() > 1) {
+//                    //匹配到多个成本项
+//                    throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", orderGoods.getBusinessFullName(), goodsPrice.toString()));
+//                }
+
                 BigDecimal cost = new BigDecimal("0.00");//成本
                 BigDecimal bigDecimal = new BigDecimal("100");
-                TopCostTpItem topCostTpItem = tpItems.stream().findFirst().get();
-                if (topCostTpItem.getDockStatus() == 1){
-                    //启用成本扣除项
-                    switch (topCostTpItem.getDockType()){
+                for (TopCostTpItem tpItem : tpItems) {
+                    BigDecimal goodsPriceDecimal = goodsPrice;
+                    //换算订单成本和盈亏
+                    TopCostTpItem topCostTpItem = tpItem;
+                    if (ObjectUtil.isNotNull(topCostTpItem.getDockStatus()) && topCostTpItem.getDockStatus() == 1){
+                        //启用成本扣除项
+                        switch (topCostTpItem.getDockType()){
+                            case 1://百分比
+                                //成本扣除金额
+                                BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
+                                BigDecimal multiply = goodsPriceDecimal.multiply(divide1);
+                                goodsPriceDecimal = goodsPriceDecimal.subtract(multiply);
+                                break;
+                            case 2://固定金额
+                                goodsPriceDecimal = goodsPriceDecimal.subtract(topCostTpItem.getDockValue());
+                                break;
+                            default:
+                                break;
+                        }
+                    }
+                    switch (topCostTpItem.getItemType()) {
                         case 1://百分比
-                            //成本扣除金额
-                            BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
-                            BigDecimal multiply = goodsPrice.multiply(divide1);
-                            goodsPrice = goodsPrice.subtract(multiply);
+                            BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
+                            BigDecimal multiply = goodsPriceDecimal.multiply(divide);
+                            cost = cost.add(multiply);
                             break;
                         case 2://固定金额
-                            goodsPrice = goodsPrice.subtract(topCostTpItem.getDockValue());
+                            cost = cost.add(topCostTpItem.getTypeValue());
                             break;
                         default:
                             break;
                     }
                 }
-                switch (topCostTpItem.getItemType()) {
-                    case 1://百分比
-                        BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
-                        cost = goodsPrice.multiply(divide);
-                        break;
-                    case 2://固定金额
-                        cost = topCostTpItem.getTypeValue();
-                        break;
-                    default:
-                        break;
-                }
                 costTotal = costTotal.add(cost);
             }
 
@@ -684,7 +689,7 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
             List<TopCostTpItemVo> tpItems = new ArrayList<>();
             for (TopCostTpItemVo x : items) {
                 BigDecimal price = goodsPrice;
-                if (x.getDockStatus() == 1){
+                if (ObjectUtil.isNotNull(x.getDockStatus()) && x.getDockStatus() == 1){
                     //启用成本扣除项
                     switch (x.getDockType()){
                         case 1://百分比
@@ -711,41 +716,45 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                 //匹配不到成本项阶梯值
                 continue;
             }
-            if (tpItems.size() > 1) {
-                //匹配到多个成本项
-                throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", orderGoods.getBusinessFullName(), goodsPrice.toString()));
-            }
-            //换算订单成本和盈亏
-            TopCostTpItemVo topCostTpItem = tpItems.stream().findFirst().get();
+//            if (tpItems.size() > 1) {
+//                //匹配到多个成本项
+//                throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", orderGoods.getBusinessFullName(), goodsPrice.toString()));
+//            }
             BigDecimal cost = new BigDecimal("0.00");//成本
             BigDecimal bigDecimal = new BigDecimal("100");
-            if (topCostTpItem.getDockStatus() == 1){
-                //启用成本扣除项
-                switch (topCostTpItem.getDockType()){
+            for (TopCostTpItemVo tpItem : tpItems) {
+                BigDecimal goodsPriceDecimal = goodsPrice;
+                //换算订单成本和盈亏
+                TopCostTpItemVo topCostTpItem = tpItem;
+                if (ObjectUtil.isNotNull(topCostTpItem.getDockStatus()) && topCostTpItem.getDockStatus() == 1){
+                    //启用成本扣除项
+                    switch (topCostTpItem.getDockType()){
+                        case 1://百分比
+                            //成本扣除金额
+                            BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
+                            BigDecimal multiply = goodsPriceDecimal.multiply(divide1);
+                            goodsPriceDecimal = goodsPriceDecimal.subtract(multiply);
+                            break;
+                        case 2://固定金额
+                            goodsPriceDecimal = goodsPriceDecimal.subtract(topCostTpItem.getDockValue());
+                            break;
+                        default:
+                            break;
+                    }
+                }
+                switch (topCostTpItem.getItemType()) {
                     case 1://百分比
-                        //成本扣除金额
-                        BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
-                        BigDecimal multiply = goodsPrice.multiply(divide1);
-                        goodsPrice = goodsPrice.subtract(multiply);
+                        BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
+                        BigDecimal multiply = goodsPriceDecimal.multiply(divide);
+                        cost = cost.add(multiply);
                         break;
                     case 2://固定金额
-                        goodsPrice = goodsPrice.subtract(topCostTpItem.getDockValue());
+                        cost = cost.add(topCostTpItem.getTypeValue());
                         break;
                     default:
                         break;
                 }
             }
-            switch (topCostTpItem.getItemType()) {
-                case 1://百分比
-                    BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
-                    cost = goodsPrice.multiply(divide);
-                    break;
-                case 2://固定金额
-                    cost = topCostTpItem.getTypeValue();
-                    break;
-                default:
-                    break;
-            }
             costTotal = costTotal.add(cost);
         }
         BigDecimal cost = costTotal.add(brokerage);
@@ -2929,7 +2938,7 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                     List<TopCostTpItemVo> tpItems = new ArrayList<>();
                     for (TopCostTpItemVo x : items) {
                         BigDecimal price = goodsPrice;
-                        if (x.getDockStatus() == 1){
+                        if (ObjectUtil.isNotNull(x.getDockStatus()) && x.getDockStatus() == 1){
                             //启用成本扣除项
                             switch (x.getDockType()){
                                 case 1://百分比
@@ -2956,41 +2965,45 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                         //匹配不到成本项阶梯值
                         continue;
                     }
-                    if (tpItems.size() > 1) {
-                        //匹配到多个成本项
-                        throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", businessName, goodsPrice.toString()));
-                    }
-                    //换算订单成本和盈亏
-                    TopCostTpItemVo topCostTpItem = tpItems.stream().findFirst().get();
+//                    if (tpItems.size() > 1) {
+//                        //匹配到多个成本项
+//                        throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", businessName, goodsPrice.toString()));
+//                    }
                     BigDecimal cost = new BigDecimal("0.00");//成本
                     BigDecimal bigDecimal = new BigDecimal("100");
-                    if (topCostTpItem.getDockStatus() == 1){
-                        //启用成本扣除项
-                        switch (topCostTpItem.getDockType()){
+                    for (TopCostTpItemVo tpItem : tpItems) {
+                        BigDecimal goodsPriceDecimal = goodsPrice;
+                        //换算订单成本和盈亏
+                        TopCostTpItemVo topCostTpItem = tpItem;
+                        if (ObjectUtil.isNotNull(topCostTpItem.getDockStatus()) && topCostTpItem.getDockStatus() == 1){
+                            //启用成本扣除项
+                            switch (topCostTpItem.getDockType()){
+                                case 1://百分比
+                                    //成本扣除金额
+                                    BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
+                                    BigDecimal multiply = goodsPriceDecimal.multiply(divide1);
+                                    goodsPriceDecimal = goodsPriceDecimal.subtract(multiply);
+                                    break;
+                                case 2://固定金额
+                                    goodsPriceDecimal = goodsPriceDecimal.subtract(topCostTpItem.getDockValue());
+                                    break;
+                                default:
+                                    break;
+                            }
+                        }
+                        switch (topCostTpItem.getItemType()) {
                             case 1://百分比
-                                //成本扣除金额
-                                BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
-                                BigDecimal multiply = goodsPrice.multiply(divide1);
-                                goodsPrice = goodsPrice.subtract(multiply);
+                                BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
+                                BigDecimal multiply = goodsPriceDecimal.multiply(divide);
+                                cost = cost.add(multiply);
                                 break;
                             case 2://固定金额
-                                goodsPrice = goodsPrice.subtract(topCostTpItem.getDockValue());
+                                cost = cost.add(topCostTpItem.getTypeValue());
                                 break;
                             default:
                                 break;
                         }
                     }
-                    switch (topCostTpItem.getItemType()) {
-                        case 1://百分比
-                            BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
-                            cost = goodsPrice.multiply(divide);
-                            break;
-                        case 2://固定金额
-                            cost = topCostTpItem.getTypeValue();
-                            break;
-                        default:
-                            break;
-                    }
                     costTotal = costTotal.add(cost);
                 }
 
@@ -3068,7 +3081,7 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                     List<TopCostTpItemVo> tpItems = new ArrayList<>();
                     for (TopCostTpItemVo x : items) {
                         BigDecimal price = goodsPrice;
-                        if (x.getDockStatus() == 1){
+                        if (ObjectUtil.isNotNull(x.getDockStatus()) && x.getDockStatus() == 1){
                             //启用成本扣除项
                             switch (x.getDockType()){
                                 case 1://百分比
@@ -3095,41 +3108,45 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                         //匹配不到成本项阶梯值
                         continue;
                     }
-                    if (tpItems.size() > 1) {
-                        //匹配到多个成本项
-                        throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", businessName, goodsPrice.toString()));
-                    }
-                    //换算订单成本和盈亏
-                    TopCostTpItemVo topCostTpItem = tpItems.stream().findFirst().get();
+//                    if (tpItems.size() > 1) {
+//                        //匹配到多个成本项
+//                        throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", businessName, goodsPrice.toString()));
+//                    }
                     BigDecimal cost = new BigDecimal("0.00");//成本
                     BigDecimal bigDecimal = new BigDecimal("100");
-                    if (topCostTpItem.getDockStatus() == 1){
-                        //启用成本扣除项
-                        switch (topCostTpItem.getDockType()){
+                    for (TopCostTpItemVo tpItem : tpItems) {
+                        BigDecimal goodsPriceDecimal = goodsPrice;
+                        //换算订单成本和盈亏
+                        TopCostTpItemVo topCostTpItem = tpItem;
+                        if (ObjectUtil.isNotNull(topCostTpItem.getDockStatus()) && topCostTpItem.getDockStatus() == 1){
+                            //启用成本扣除项
+                            switch (topCostTpItem.getDockType()){
+                                case 1://百分比
+                                    //成本扣除金额
+                                    BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
+                                    BigDecimal multiply = goodsPriceDecimal.multiply(divide1);
+                                    goodsPriceDecimal = goodsPriceDecimal.subtract(multiply);
+                                    break;
+                                case 2://固定金额
+                                    goodsPriceDecimal = goodsPriceDecimal.subtract(topCostTpItem.getDockValue());
+                                    break;
+                                default:
+                                    break;
+                            }
+                        }
+                        switch (topCostTpItem.getItemType()) {
                             case 1://百分比
-                                //成本扣除金额
-                                BigDecimal divide1 = topCostTpItem.getDockValue().divide(bigDecimal);
-                                BigDecimal multiply = goodsPrice.multiply(divide1);
-                                goodsPrice = goodsPrice.subtract(multiply);
+                                BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
+                                BigDecimal multiply = goodsPriceDecimal.multiply(divide);
+                                cost = cost.add(multiply);
                                 break;
                             case 2://固定金额
-                                goodsPrice = goodsPrice.subtract(topCostTpItem.getDockValue());
+                                cost = cost.add(topCostTpItem.getTypeValue());
                                 break;
                             default:
                                 break;
                         }
                     }
-                    switch (topCostTpItem.getItemType()) {
-                        case 1://百分比
-                            BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
-                            cost = goodsPrice.multiply(divide);
-                            break;
-                        case 2://固定金额
-                            cost = topCostTpItem.getTypeValue();
-                            break;
-                        default:
-                            break;
-                    }
                     costTotal = costTotal.add(cost);
                 }
                 BigDecimal cost = costTotal.add(brokerage);