From d13ae240c54c59b04c0571bfc0136ed0c8ba32a3 Mon Sep 17 00:00:00 2001
From: jyy <jyy>
Date: Wed, 14 Jul 2021 14:16:06 +0800
Subject: [PATCH] 修复bug

---
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java |   62 ++++++++++++++++++++-----------
 1 files changed, 40 insertions(+), 22 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 1e80f7f..8fa0fcb 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
@@ -401,8 +401,6 @@
 
         //获取折扣-----
         Double zk = zk = 1.0;
-        //验证商品是否只购买了一次
-        checkBuyOnce(car, info.getId());
 
         SysOrder order = new SysOrder();
         SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
@@ -433,8 +431,7 @@
         int count = 0;
         // 设置订单条目
         for (ShoppingCarItem carItem : car.getCarItems()) {
-            // 检测最大销售数量
-            checkIsArrivedMax(carItem);
+
             SysOrderItem orderItem = new SysOrderItem();
             orderItem.setOrderId(order.getId());
             orderItem.setCount(carItem.getCount());
@@ -472,20 +469,6 @@
     }
 
 
-    /**
-     * 验证商品是否购买过一次
-     *
-     * @Title: checkBuyOnce  @author:jyy @param car void 返回类型 @date
-     * 2016年9月22日 上午10:05:33 @throws
-     */
-    private void checkBuyOnce(ShoppingCarItemsVo car, Long vipId) {
-        for (ShoppingCarItem carItem : car.getCarItems()) {
-            if (shoppingGoodsDao.selectBuyCount(carItem.getGoodsId(), vipId) > 0) {
-                ShoppingGoods goods = shoppingGoodsDao.selectById(carItem.getGoodsId());
-                throw new GlobleException(goods.getName() + "只能购买一次!");
-            }
-        }
-    }
 
     /**
      * jyy 收款
@@ -498,8 +481,10 @@
             throw new GlobleException("该订单已经收过款,请刷新页面再试!");
         }
 
-        //交易业绩设置是否合理
+        //检查交易限制调整
+        checkSealLimit(pageOrder);
 
+        //交易业绩设置是否合理
         checkAchieveIsOk(pageOrder);
 
 
@@ -535,6 +520,41 @@
 
         //设置会员积分
         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+"次");
+                 }
+             }
+
+         });
 
     }
 
@@ -780,7 +800,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() + "已超过最大销售数量");
@@ -944,7 +964,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);
@@ -1702,7 +1721,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