From b4a195f07fc3c0c417d9bb2f06acf76f5a62f29e Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期六, 29 五月 2021 16:33:06 +0800
Subject: [PATCH] 会员权益

---
 service-vip/src/main/java/com/ks/vip/service/remote/VipCenterServiceImpl.java |   63 ++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/service-vip/src/main/java/com/ks/vip/service/remote/VipCenterServiceImpl.java b/service-vip/src/main/java/com/ks/vip/service/remote/VipCenterServiceImpl.java
index f3bfce9..2b9474f 100644
--- a/service-vip/src/main/java/com/ks/vip/service/remote/VipCenterServiceImpl.java
+++ b/service-vip/src/main/java/com/ks/vip/service/remote/VipCenterServiceImpl.java
@@ -1,6 +1,7 @@
 package com.ks.vip.service.remote;
 
 
+import com.ks.vip.exception.VipCenterException;
 import com.ks.vip.mapper.VipCenterMapper;
 import com.ks.vip.mapper.VipCenterRecordMapper;
 import com.ks.vip.mapper.VipComboMapper;
@@ -12,6 +13,7 @@
 import org.apache.dubbo.config.annotation.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.DateUtil;
+import org.yeshi.utils.StringUtil;
 
 import javax.annotation.Resource;
 import java.util.Date;
@@ -134,10 +136,26 @@
     public VipGradePotence getVipPotence(String uid) {
         VipGradePotence potence = null;
         VipCenter vipCenter = vipCenterMapper.getByUid(uid);
-        if (vipCenter != null || vipCenter.getGradeId() != null) {
+        if (vipCenter != null && vipCenter.getGradeId() != null) {
             long nowTime = java.lang.System.currentTimeMillis();
             if (vipCenter.getStartTime().getTime() <= nowTime && vipCenter.getEndTime().getTime() >= nowTime) {
-                potence = vipGradePotenceService.getPotenceByGradeId(vipCenter.getGradeId());
+                potence = vipGradePotenceService.getCurrentByGradeId(vipCenter.getGradeId());
+            }
+        }
+        if (potence == null) {
+            potence = vipGradePotenceService.getDefaultGradePotence();
+        }
+        return potence;
+    }
+
+    @Override
+    public VipGradePotence getVipPotenceByTime(String uid, Date time) {
+        VipGradePotence potence = null;
+        VipCenter vipCenter = vipCenterMapper.getByUid(uid);
+        if (vipCenter != null && vipCenter.getGradeId() != null) {
+            long nowTime = java.lang.System.currentTimeMillis();
+            if (vipCenter.getStartTime().getTime() <= nowTime && vipCenter.getEndTime().getTime() >= nowTime) {
+                potence = vipGradePotenceService.getByGradeIdAndTime(vipCenter.getGradeId(), time);
             }
         }
         if (potence == null) {
@@ -186,4 +204,45 @@
         }
         return vipGradeService.selectByPrimaryKey(list.get(0).getGradeId()).getIdentity();
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void  saveManageWeb(VipCenter t) throws VipCenterException {
+        if (t== null || StringUtil.isNullOrEmpty(t.getUid())) {
+            throw new VipCenterException(1, "鐢ㄦ埛ID涓嶅瓨鍦�");
+        }
+
+        if (t.getGradeId() == null) {
+            throw new VipCenterException(1, "璇烽�夋嫨鐢ㄦ埛绛夌骇");
+        }
+
+        if (t.getStartTime() == null) {
+            throw new VipCenterException(1, "璇烽�夋嫨寮�濮嬫椂闂�");
+        }
+
+        if (t.getEndTime() == null) {
+            throw new VipCenterException(1, "璇烽�夋嫨缁撴潫鏃堕棿");
+        }
+
+        VipCenter vipCenter = vipCenterMapper.selectForUpdate(t.getUid());
+        if (vipCenter == null) {
+            t.setCreateTime(new Date());
+            vipCenterMapper.insertSelective(t);
+        } else {
+            t.setUpdateTime(new Date());
+            vipCenterMapper.updateByPrimaryKeySelective(t);
+        }
+
+        // 淇濆瓨璁板綍
+        VipCenterRecord record = new VipCenterRecord();
+        record.setStartTime(t.getStartTime());
+        record.setEndTime(t.getEndTime());
+        record.setUid(t.getUid());
+        record.setGradeId(t.getGradeId());
+        record.setCreateTime(new Date());
+        vipCenterRecordService.insertSelective(record);
+    }
+
+
+
 }
\ No newline at end of file

--
Gitblit v1.8.0