From d08ec8845a4c2663b3502cd83872964b07d7d589 Mon Sep 17 00:00:00 2001
From: jyy <935090232@qq.com>
Date: Mon, 22 Mar 2021 11:14:52 +0800
Subject: [PATCH] 积分商城11

---
 zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java |   53 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java b/zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java
index 3faa9fb..0c44570 100644
--- a/zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java
+++ b/zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java
@@ -1,6 +1,7 @@
 package com.matrix.system.score.service;
 
 import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.matrix.biz.dao.BizUserDao;
 import com.matrix.core.constance.MatrixConstance;
@@ -51,11 +52,6 @@
 
     /**
      * 扣除用户积分
-     *
-     * @param openId
-     * @param score
-     * @param businessId
-     * @param type
      */
     @Transactional(rollbackFor = Exception.class)
     public void deductionScore(String openId, Long vipId,Long shopId, Integer score, Long businessId, int type) {
@@ -120,12 +116,6 @@
 
     /**
      * 新增用户积分
-     * @param openId
-     * @param vipId
-     * @param oprationUserId
-     * @param score
-     * @param businessId
-     * @param type
      */
     @Transactional(rollbackFor = Exception.class)
     public void addScore(String openId, Long vipId, Long oprationUserId,Long shopId, Integer score, Long businessId, int type) {
@@ -193,5 +183,46 @@
 
     }
 
+    /**
+     * 退积分
+     */
+    public void refundScore(String openId, Long vipId, Integer score, Long oldBusinessId, int type){
+        Long companyId=null;
+        if(openId!=null){
+            companyId= bizUserDao.findByOpenId(openId).getCompanyId();
+        }else if(vipId!=null){
+            companyId= vipInfoDao.selectById(vipId).getCompanyId();
+        }else{
+            throw new IllegalArgumentException("vipId,openId必须有一个");
+        }
+        if(score<0){
+            throw new IllegalArgumentException("score必须有为大于零的数");
+        }
+
+        //查询原始使用记录
+        QueryWrapper queryWrapper=new QueryWrapper();
+        queryWrapper.eq("business_id",oldBusinessId);
+        queryWrapper.eq("company_id",companyId);
+        queryWrapper.eq("type",type);
+        List<ScoreUseRecord> scoreUseRecordList = scoreUseRecordDao.selectList(queryWrapper);
+        scoreUseRecordList.forEach(scoreUseRecord -> {
+            ScoreVipDetail scoreVipDetail = scoreVipDetailDao.selectById(scoreUseRecord.getScoreVipDetailId());
+            if(scoreVipDetail!=null){
+                if(DateTime.now().isAfter(scoreVipDetail.getValiditeTime())){
+                    //积分还有效
+                    scoreVipDetail.setRemainScore( scoreVipDetail.getRemainScore()+score);
+                    scoreVipDetail.setUsedScore(scoreVipDetail.getUsedScore()-score);
+                    scoreVipDetail.setState(ScoreVipDetail.SCORE_STATUS_YX);
+                    scoreVipDetailDao.updateById(scoreVipDetail);
+                    scoreUseRecordDao.deleteById(scoreUseRecord.getId());
+                }
+            }
+
+        });
+    }
+
+    public static void main(String[] args) {
+        System.out.println(DateTime.now().isAfter(DateTime.of("2020-11-11 23:22","yyyy-MM-dd HH:mm")));
+    }
 
 }
\ No newline at end of file

--
Gitblit v1.9.1