From 1d917e41e6a31a535932fbfde6324fe4bdf6ed8b Mon Sep 17 00:00:00 2001
From: jyy <jyy>
Date: Fri, 04 Jun 2021 14:55:15 +0800
Subject: [PATCH] 业绩规则3

---
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/AchieveNewServiceImpl.java |   43 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/AchieveNewServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/AchieveNewServiceImpl.java
index f0c6d88..6b84084 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/AchieveNewServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/AchieveNewServiceImpl.java
@@ -1,6 +1,7 @@
 package com.matrix.system.hive.service.imp;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.json.JSONUtil;
 import com.matrix.core.constance.MatrixConstance;
 import com.matrix.core.exception.GlobleException;
 import com.matrix.core.pojo.PaginationVO;
@@ -16,13 +17,11 @@
 import com.matrix.system.common.dao.SysUsersDao;
 import com.matrix.system.constance.Dictionary;
 import com.matrix.system.hive.bean.*;
-import com.matrix.system.hive.dao.AchieveNewDao;
-import com.matrix.system.hive.dao.ShoppingGoodsDao;
-import com.matrix.system.hive.dao.SysBeauticianStateDao;
-import com.matrix.system.hive.dao.SysProjUseDao;
+import com.matrix.system.hive.dao.*;
 import com.matrix.system.hive.plugin.util.CollectionUtils;
 import com.matrix.system.hive.service.AchieveNewService;
 import com.matrix.system.hive.service.SysProjServicesService;
+import com.matrix.system.hiveErp.pojo.AchieveRuleItem;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -185,8 +184,14 @@
             // 是否为赠送业绩
             if (Dictionary.TAOCAN_SOURCE_ZS.equals(projUse.getSource())) {
                 achieveNew.setFreeConsume(projUse.getPrice()*beauticianState.getCount());
+                //计算提成
+                achieveNew.setProjPercentage(
+                        calculationProjPercentage(AchieveRuleItem.ACHIEVE_TYPE_ZS,achieveNew.getFreeConsume(),beauticianState.getProjId()));
             } else {
                 achieveNew.setHisConsume(projUse.getPrice()*beauticianState.getCount());
+                //计算提成
+                achieveNew.setProjPercentage(
+                        calculationProjPercentage(AchieveRuleItem.ACHIEVE_TYPE_BJ,achieveNew.getHisConsume(),beauticianState.getProjId()));
             }
             achieveNew.setT2(projUse.getSource());
             achieveNew.setDatatime(new Date());
@@ -239,6 +244,36 @@
 
     }
 
+    @Autowired
+    AchieveRuleDao achieveRuleDao;
+
+    private Double calculationProjPercentage(int type, Double consume, Long goodsId) {
+         ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(goodsId);
+         if(shoppingGoods.getAchieveRuleId()!=null){
+
+             AchieveRule achieveRule = achieveRuleDao.selectById(shoppingGoods.getAchieveRuleId());
+             if(achieveRule!=null){
+                 List<AchieveRuleItem> achieveRuleItems = JSONUtil.toList(JSONUtil.parseArray(achieveRule.getRules()), AchieveRuleItem.class);
+                 double percentage=0D;
+                 for(AchieveRuleItem item:achieveRuleItems){
+                     if(item.getAchieveType()==type
+                        && (item.getLower() == consume
+                             || (item.getLower()< consume && consume < item.getUpper() ))){
+
+                         if(AchieveRuleItem.ACHIEVE_TYPE_FIXED==item.getCalculationType()){
+                             percentage=item.getAchieve();
+                         }else{
+                             percentage= consume * (item.getAchieve()/100);
+                         }
+                         break;
+                     }
+                 }
+                 return percentage;
+             }
+         }
+        return 0D;
+    }
+
     /**
      * 顾问人头业绩
      * @param achieveNew

--
Gitblit v1.9.1