From 00efd2e4db8157ece4116c956c314803ed073042 Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Sat, 03 Apr 2021 16:39:15 +0800
Subject: [PATCH] 会员中心手工调整积分

---
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java |  152 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 141 insertions(+), 11 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java
index 9a8f42b..a1f0b08 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java
@@ -12,13 +12,18 @@
 import com.matrix.core.tools.WebUtil;
 import com.matrix.system.app.dto.ServiceOrderListDto;
 import com.matrix.system.app.vo.ServiceOrderListVo;
+import com.matrix.system.common.bean.BusParameterSettings;
 import com.matrix.system.common.bean.SysUsers;
+import com.matrix.system.common.dao.BusParameterSettingsDao;
 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.*;
 import com.matrix.system.hive.plugin.util.MoneyUtil;
 import com.matrix.system.hive.service.*;
+import com.matrix.system.score.constant.ScoreSettingConstant;
+import com.matrix.system.score.entity.ScoreVipDetail;
+import com.matrix.system.score.service.ScoreVipDetailService;
 import com.matrix.system.shopXcx.mqTask.MQTaskRouting;
 import com.matrix.system.wechart.templateMsg.UniformMsgParam;
 import org.apache.commons.collections.CollectionUtils;
@@ -107,6 +112,16 @@
     @Autowired
     private RabiitMqTemplate rabiitMqTemplate;
 
+
+    @Autowired
+    BusParameterSettingsDao busParameterSettingsDao;
+
+    @Autowired
+    ScoreVipDetailService scoreVipDetailService;
+
+    @Autowired
+    SysVipInfoDao sysVipInfoDao;
+
     @Value("${evn}")
     private String evn;
 
@@ -121,7 +136,7 @@
     public SysProjServices addSysProjServices(SysProjServices sysProjServices) throws GlobleException {
 
         //创建服务单
-        if(WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY)!=null){
+        if (WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY) != null) {
             SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
             sysProjServices.setCreateStaffId(user.getSuId());
             sysProjServices.setShopId(user.getShopId());
@@ -482,6 +497,9 @@
             sysOutStoreDao.deleteById(sysOutStore.getId());
             sysOutStoreItemDao.deleteByOrderId(sysOutStore.getId());
         }
+        //删除积分
+        scoreVipDetailService.removeByBusinessId(null,checkProjServices.getVipId(), checkProjServices.getId());
+
         //更新服务单状态
         return sysProjServicesDao.update(checkProjServices);
     }
@@ -494,7 +512,7 @@
     private void backProjCount(SysProjServices projServices) {
         List<SysBeauticianState> beauticianStateList = beauticianStateDao.selectBySerIds(projServices.getId());
 
-        Map<Long ,List<SysProjUse>> taocanMap = new HashMap<>();
+        Map<Long, List<SysProjUse>> taocanMap = new HashMap<>();
         // 回退项目余额
         for (SysBeauticianState beauticianState : beauticianStateList) {
             // 该修改为 有效日期判断更新所有
@@ -599,18 +617,129 @@
 
             projServices.setState(Dictionary.SERVICE_STATU_FFJS);
             projServices.setConsumeTime(new Date());
-            int result=sysProjServicesDao.update(projServices);
+            int result = sysProjServicesDao.update(projServices);
             achieveNewService.addAchieveByServiceOrder(projServices);
 
+            //设置会员积分
+            addVipScore(projServices);
+
             //发送微信公众号提醒
-            UniformMsgParam uniformMsgParam=new UniformMsgParam(projServices.getCompanyId(),UniformMsgParam.GZH_FWWC);
-            uniformMsgParam.put("serviceId",projServices.getId());
-            rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,uniformMsgParam.toJSONString());
+            UniformMsgParam uniformMsgParam = new UniformMsgParam(projServices.getCompanyId(), UniformMsgParam.GZH_FWWC);
+            uniformMsgParam.put("serviceId", projServices.getId());
+            rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn, uniformMsgParam.toJSONString());
+
+
+
 
             return result;
         }
+
+
     }
 
+    /**
+     * 设置会员消费积分
+     */
+    private void addVipScore(SysProjServices projServices) {
+
+        SysVipInfo vipInfo =sysVipInfoDao.selectById(projServices.getVipId());
+
+        List<SysBeauticianState> sysBeauticianStates = beauticianStateDao.selectBySerIds(projServices.getId());
+
+
+        double principalPrice = 0D;
+        double giftPrice = 0D;
+        for (SysBeauticianState sysBeauticianState : sysBeauticianStates) {
+            SysProjUse projUse = sysBeauticianState.getProjUse();
+            if (projUse.getSource().equals(Dictionary.TAOCAN_SOURCE_ZS)) {
+                giftPrice += projUse.getPrice();
+            } else {
+                principalPrice += projUse.getPrice();
+            }
+        }
+
+        int[] principalConsumScore = {0, 0, 0};
+        BusParameterSettings principalConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.PRINCIPAL_CONSUMPTION, vipInfo.getCompanyId());
+        //本金消耗
+        if (principalPrice > 0
+                && StringUtils.isNotBlank(principalConsumption.getParamValue())) {
+
+            principalConsumScore[0] = (int) (principalPrice / Double.parseDouble(principalConsumption.getParamValue()));
+
+            if (StringUtils.isNotBlank(principalConsumption.getParamValue1())) {
+                principalConsumScore[1] = (int) (principalPrice / Double.parseDouble(principalConsumption.getParamValue1()));
+            }
+
+            if (StringUtils.isNotBlank(principalConsumption.getParamValue2())) {
+                principalConsumScore[2] = (int) (principalPrice / Double.parseDouble(principalConsumption.getParamValue2()));
+            }
+        }
+
+        int[] giveConsumScore = {0, 0, 0};
+        BusParameterSettings giveConsumption = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.GIVE_CONSUMPTION, vipInfo.getCompanyId());
+        //本金消耗
+        if (giftPrice > 0
+                && StringUtils.isNotBlank(giveConsumption.getParamValue())) {
+
+            giveConsumScore[0] = (int) (giftPrice / Double.parseDouble(giveConsumption.getParamValue()));
+
+            if (StringUtils.isNotBlank(giveConsumption.getParamValue1())) {
+                giveConsumScore[1] = (int) (giftPrice / Double.parseDouble(giveConsumption.getParamValue1()));
+            }
+
+            if (StringUtils.isNotBlank(giveConsumption.getParamValue2())) {
+                giveConsumScore[2] = (int) (giftPrice / Double.parseDouble(giveConsumption.getParamValue2()));
+            }
+        }
+
+        int selfScore =principalConsumScore[0]+giveConsumScore[0];
+        int parentScore =principalConsumScore[1]+giveConsumScore[1];
+        int topParentScore =principalConsumScore[2]+giveConsumScore[2];
+
+        //添加自己的积分
+        if (selfScore > 0) {
+            scoreVipDetailService.addScore(null,
+                    vipInfo.getId(),
+                    projServices.getCreateStaffId(),
+                    projServices.getShopId(),
+                    selfScore,
+                    projServices.getId(),
+                    ScoreVipDetail.SCORE_VIP_TYPE_CASH,
+                    "消耗奖励"
+            );
+        }
+
+        if (vipInfo.getRecommendId() != null) {
+            //推荐注册老带新积分奖励
+            SysVipInfo referrerVip = sysVipInfoDao.selectById(vipInfo.getRecommendId());
+            if (parentScore > 0) {
+                scoreVipDetailService.addScore(null,
+                        referrerVip.getId(),
+                        projServices.getCreateStaffId(),
+                        projServices.getShopId(),
+                        parentScore,
+                        projServices.getId(),
+                        ScoreVipDetail.SCORE_VIP_TYPE_CASH,
+                        "推荐消耗奖励"
+                );
+            }
+            //推荐注册二级带新积分奖励
+            if (referrerVip.getRecommendId() != null) {
+                SysVipInfo topVipInfo = sysVipInfoDao.selectById(referrerVip.getRecommendId());
+                if (topParentScore > 0) {
+                    scoreVipDetailService.addScore(null,
+                            topVipInfo.getId(),
+                            projServices.getCreateStaffId(),
+                            projServices.getShopId(),
+                            topParentScore,
+                            projServices.getId(),
+                            ScoreVipDetail.SCORE_VIP_TYPE_CASH,
+                            "推荐消耗奖励"
+                    );
+                }
+            }
+        }
+    }
 
 
     // 派单 jyy
@@ -655,9 +784,9 @@
 
             outStore.setOutStoreNo(codeService.getOutStoreCode());
             outStore.setShopId(projServices.getShopId());
-            if(projServices.getDevisionId()!=null){
+            if (projServices.getDevisionId() != null) {
                 outStore.setStaffId(projServices.getDevisionId());
-            }else{
+            } else {
 
                 outStore.setStaffId(sysUsers.getSuId());
             }
@@ -682,7 +811,7 @@
                     double sum = stores.stream().mapToDouble(item2 -> item2.getStoreTotal()).sum();
                     Double needAmount = MoneyUtil.div(item.getAmount(), Double.valueOf(shoppingGoods.getVolume()));
                     if (sum < needAmount) {
-                        throw new GlobleException("出库失败:【" + shoppingGoods.getName()+"-"+shoppingGoods.getCode()+  "库存不足】");
+                        throw new GlobleException("出库失败:【" + shoppingGoods.getName() + "-" + shoppingGoods.getCode() + "库存不足】");
                     }
                     //循环获取所有批次产品,并扣减库存
                     for (SysStoreInfo storeInfo : stores) {
@@ -716,7 +845,7 @@
         // 设置服务单状态
 //        projServices.setState(Dictionary.SERVICE_STATU_PLWC);
 
-        if(projServices.getDevisionId()==null){
+        if (projServices.getDevisionId() == null) {
             //如果没有设置配料师则默认为操作配料的人为配料师
             projServices.setDevisionId(sysUsers.getSuId());
         }
@@ -745,11 +874,12 @@
 
     /**
      * 服务单收费需要生成出库记录
+     *
      * @param projServicesVo
      * @return
      */
     private boolean isNeedOutStore(SysProjServices projServicesVo) {
-        if(CollectionUtils.isNotEmpty(projServicesVo.getOutStoreItem())){
+        if (CollectionUtils.isNotEmpty(projServicesVo.getOutStoreItem())) {
             for (SysOutStoreItem item : projServicesVo.getOutStoreItem()) {
                 if (item.getAmount() != null && item.getAmount() > 0) {
                     return true;

--
Gitblit v1.9.1