From 22a592a5ef3343e7a6ceac5991e2956b52dccd79 Mon Sep 17 00:00:00 2001
From: jyy <jyy>
Date: Sat, 10 Jul 2021 09:36:35 +0800
Subject: [PATCH] 新增美度正式环境配置

---
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java |  101 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 91 insertions(+), 10 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
index 93553f8..e3e1fa1 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
@@ -497,6 +497,14 @@
         if (!Dictionary.ORDER_STATU_DFK.equals(pageOrder.getStatu())) {
             throw new GlobleException("该订单已经收过款,请刷新页面再试!");
         }
+
+        //检查交易限制调整
+        checkSealLimit(pageOrder);
+
+        //交易业绩设置是否合理
+        checkAchieveIsOk(pageOrder);
+
+
         // 更新收款时间
         pageOrder.setPayTime(new Date());
         pageOrder.setStatu(Dictionary.ORDER_STATU_YFK);
@@ -530,6 +538,63 @@
         //设置会员积分
         addVipScore(pageOrder);
 
+    }
+
+    /**
+     * 检查产品销售次数
+     */
+    private void checkSealLimit(SysOrder pageOrder) {
+         pageOrder.getItems().forEach(item->{
+             ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId());
+
+             //最大销售次数检测
+             Integer maxNum = shopGoods.getCarMaxSaleCount();
+             if (maxNum != null && maxNum != 0) {
+                 Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(),null);
+                 if ((buyNum + item.getCount()) > maxNum) {
+                     throw new GlobleException(shopGoods.getName() + "已超过最大销售数量");
+                 }
+                 if ((buyNum + item.getCount()) == maxNum) {
+                     if (!shopGoods.getStaus().equals(Dictionary.BUSINESS_STATE_DOWN)) {
+                         shopGoods.setStaus(Dictionary.BUSINESS_STATE_DOWN);
+                         shoppingGoodsDao.update(shopGoods);
+                     }
+                 }
+             }
+             //每人限购次数检测
+             Integer onceCount = shopGoods.getIsOnce();
+             if(onceCount!=null && onceCount!=0){
+                 Integer buyOnceCount = orderItemDao.selectByGoodsId(shopGoods.getId(),pageOrder.getVipId());
+
+                 if ((buyOnceCount + item.getCount()) > onceCount) {
+                     throw new GlobleException(shopGoods.getName() + "每人限购"+onceCount+"次");
+                 }
+             }
+
+         });
+
+    }
+
+    /**
+     * 交易业绩设置是否合理
+     * @param pageOrder
+     */
+    private void checkAchieveIsOk(SysOrder pageOrder) {
+        double huakouSum = pageOrder.getItems().stream()
+                .mapToDouble(
+                        item ->
+                                item.getAchieveList().stream()
+                                        .filter(achieveNew -> "划扣".equals(achieveNew.getPayMethod()))
+                                        .mapToDouble(achieve -> achieve.getGoodsCash()).sum()
+                ).sum();
+
+        double czkPay= pageOrder.getFlows().stream()
+                .filter(sysOrderFlow -> "储值卡".equals(sysOrderFlow.getPayMethod()))
+                .mapToDouble(sysOrderFlow ->sysOrderFlow.getAmount().doubleValue()).sum();
+
+        if(czkPay!=huakouSum){
+            throw new GlobleException("划扣业绩不等于储值卡扣款金额,请修改业绩设置!");
+        }
     }
 
     /**
@@ -752,7 +817,7 @@
         // 最大发卡数量为0代表不做限制
         if (maxNum != null && maxNum != 0) {
             // 查询该商品已经被购买的次数
-            Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId());
+            Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(),null);
             buyNum = (buyNum == null ? 0 : buyNum);
             if ((buyNum + carItem.getCount()) > maxNum) {
                 throw new GlobleException(shopGoods.getName() + "已超过最大销售数量");
@@ -916,7 +981,6 @@
                     moneyCardUse.setGiftMoney(moneyCar.getReferencePice());
                     moneyCardUse.setRealMoney(moneyCar.getSealPice());
                     moneyCardUse.setGoodsId(moneyCar.getId());
-                    moneyCardUse.setIsOver(Dictionary.FLAG_NO_N);
                     moneyCardUse.setOrderItemId(sysOrderItem.getId());
                     moneyCardUse.setSource(Dictionary.TAOCAN_SOURCE_GM);
                     moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_YX);
@@ -1210,13 +1274,21 @@
         if (sysOrderItem.getIsFree().equals(Dictionary.FLAG_NO) && sysOrderItem.getZkPrice() > 0) {
             puse.setSource(Dictionary.TAOCAN_SOURCE_GM);
         } else {
-            //赠送产品按原价计算消耗
+
             puse.setSource(Dictionary.TAOCAN_SOURCE_ZS);
-            if (taocanId == null) {
-                puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() );
-            } else {
-                puse.setPrice(goodsAssemble.getPrice());
+            //赠送项目是否计算消耗业绩否则 赠送产品按原价计算消耗
+            boolean zsConsumeAchieve = projServicesService.skipServiceOrderStep(Dictionary.ZS_CONSUME_ACHIEVE);
+            if(zsConsumeAchieve){
+                if (taocanId == null) {
+                    puse.setPrice(goodsAssemble.getShoppingGoods().getPrice() );
+                } else {
+                    puse.setPrice(goodsAssemble.getPrice());
+                }
+            }else{
+                puse.setPrice(0D);
             }
+
+
         }
         puse.setBalance(MoneyUtil.mul(puse.getPrice(), Double.valueOf(puse.getSurplusCount())));
         puse.setFailTime(failTime);
@@ -1283,6 +1355,9 @@
         sysProjUseDao.update(taocanProjUse);
     }
 
+    @Autowired
+    private SysProjServicesService projServicesService;
+
     /**
      * 根据订单创建用户项目使用情况
      *
@@ -1307,8 +1382,15 @@
             puse.setPrice(sysOrderItem.getZkPrice());
         } else {
             puse.setSource(Dictionary.TAOCAN_SOURCE_ZS);
-            //赠送产品按原价计算消耗
-            puse.setPrice(sysOrderItem.getShoppingGoods().getSealPice());
+            //赠送项目是否计算消耗业绩否则 赠送产品按原价计算消耗
+            boolean zsConsumeAchieve = projServicesService.skipServiceOrderStep(Dictionary.ZS_CONSUME_ACHIEVE);
+            if(zsConsumeAchieve){
+                puse.setPrice(sysOrderItem.getShoppingGoods().getSealPice());
+            }else{
+                puse.setPrice(0D);
+            }
+
+
         }
         // 设置失效时间
         Date invalidTime = shoppingGoodsService.calInvalidTime(sysOrderItem.getShoppingGoods(), 1, null);
@@ -1656,7 +1738,6 @@
 
             if (Dictionary.SHOPPING_GOODS_TYPE_CZK.equals(item.getType())) {
                 MoneyCardUse queryCardUse = new MoneyCardUse();
-                queryCardUse.setIsOver(Dictionary.FLAG_NO_N);
                 queryCardUse.setStatus(Dictionary.TAOCAN_STATUS_YX);
                 queryCardUse.setOrderItemId(item.getOldItemId());
 

--
Gitblit v1.9.1