From ac70afa4e394626dc03d82def3df1db886bb7c2e Mon Sep 17 00:00:00 2001
From: 陶杰 <1378534974@qq.com>
Date: 星期四, 12 九月 2024 14:43:59 +0800
Subject: [PATCH] 1.活动优惠券-管理端-类型是首页领取的活动优惠券,发布的时候将已经发布的设置为下架,只能留有一个已发布的优惠券 3.活动优惠券-小程序-新增首页弹窗优惠券-如果领取数量没有超过当前优惠券还可以再次领取,超过领取优惠券的话则不返回数据

---
 src/main/java/com/mzl/flower/service/point/CustomerPointService.java |   42 +++++++++++++++++++++++++++++++++---------
 1 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/mzl/flower/service/point/CustomerPointService.java b/src/main/java/com/mzl/flower/service/point/CustomerPointService.java
index 6353061..1f9dfa0 100644
--- a/src/main/java/com/mzl/flower/service/point/CustomerPointService.java
+++ b/src/main/java/com/mzl/flower/service/point/CustomerPointService.java
@@ -17,6 +17,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.util.List;
 
@@ -78,21 +79,26 @@
             point.setTotalPoint(0);
             point.setUsedPoint(0);
             point.setExpiredPoint(0);
+            point.setDeductionPoint(0);
             point.create(SecurityUtils.getUserId());
         }
 
         if(POINT_CHANGE_TYPE.add.name().equals(detail.getChangeType())){
             point.setTotalPoint(point.getTotalPoint() + detail.getPoint());
-            point.setUsedPoint(point.getUsedPoint() + detail.getUsePoint());
-            point.setExpiredPoint(point.getExpiredPoint() + detail.getExpiredPoint());
         }else if(POINT_CHANGE_TYPE.reduce.name().equals(detail.getChangeType())){
-//            if(point.getTotalPoint()!= null && point.getTotalPoint()!=0 && point.getTotalPoint()>= detail.getPoint()){
-//                point.setTotalPoint(point.getTotalPoint() - detail.getPoint());
-//            }else{
-//                //积分不足,直接清0
-//                point.setTotalPoint(0);
-//            }
-            point.setTotalPoint(point.getTotalPoint() - detail.getPoint());
+            Integer detailPoint = detail.getPoint();
+            if(POINT_TYPE.deduction.name().equals(detail.getType())){ //积分扣减
+                Integer balancePoint = point.getTotalPoint() - point.getUsedPoint()-point.getExpiredPoint()-point.getDeductionPoint();//可用积分
+                balancePoint = balancePoint.intValue()>0?balancePoint.intValue():0;
+                if(balancePoint.intValue() >= detail.getPoint().intValue()){
+                    point.setDeductionPoint(point.getDeductionPoint() + detail.getPoint());
+                }else{
+                    //积分不足,直接清0
+                    point.setDeductionPoint(point.getDeductionPoint() + balancePoint);
+                    detail.setPoint(balancePoint);
+                    detail.setRemarks(detail.getRemarks()+",当前积分不足"+detailPoint+",实际扣除积分"+balancePoint);
+                }
+            }
         }
         if(isAdd){
             customerPointMapper.insert(point);
@@ -113,6 +119,24 @@
         detail.setChangeType(POINT_CHANGE_TYPE.reduce.name());
         detail.setType(POINT_TYPE.deduction.name());
         detail.create(SecurityUtils.getUserId());
+        //更新汇总表
+        updateCustomerPoint(detail);
+
+        customerPointDetailMapper.insert(detail);
+    }
+
+    public void consumptionPoint(BigDecimal orderAmount, String orderNo,String userId)  {
+        CustomerPointDetail detail = new CustomerPointDetail();
+        Customer customer = getCustomerByUserId(userId);
+        detail.setCustomerId(customer.getId());
+        detail.setUserId(customer.getUserId());
+        BigDecimal point = orderAmount.setScale(0, BigDecimal.ROUND_HALF_UP);
+        detail.setPoint(point.intValue());
+        detail.setRemarks(orderNo);
+        detail.setRecordDate(LocalDate.now());
+        detail.setChangeType(POINT_CHANGE_TYPE.add.name());
+        detail.setType(POINT_TYPE.consume.name());
+        detail.create(SecurityUtils.getUserId());
         customerPointDetailMapper.insert(detail);
 
         //更新汇总表

--
Gitblit v1.9.3