From a9f950c0d11a687a7a940443b8c765f6d87ae4f1 Mon Sep 17 00:00:00 2001
From: jyy <935090232@qq.com>
Date: Tue, 20 Apr 2021 00:26:22 +0800
Subject: [PATCH] 合并新的修改
---
zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java | 197 ++++++++++++++++++++++++++++++++++++-------------
1 files changed, 145 insertions(+), 52 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 1b939fc..7c27a80 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,14 +1,16 @@
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;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.tools.DateUtil;
+import com.matrix.core.tools.StringUtils;
import com.matrix.system.common.bean.BusParameterSettings;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.common.dao.SysUsersDao;
+import com.matrix.system.hive.bean.SysVipInfo;
import com.matrix.system.hive.dao.SysVipInfoDao;
import com.matrix.system.score.constant.ScoreSettingConstant;
import com.matrix.system.score.dao.ScoreUseRecordDao;
@@ -38,7 +40,7 @@
ScoreUseRecordDao scoreUseRecordDao;
@Autowired
- BizUserDao bizUserDao;
+ SysVipInfoDao sysVipInfoDao;
@Autowired
SysVipInfoDao vipInfoDao;
@@ -51,24 +53,17 @@
/**
* 扣除用户积分
- *
- * @param openId
- * @param score
- * @param businessId
- * @param type
*/
@Transactional(rollbackFor = Exception.class)
- public void deductionScore(String openId, Long vipId, Integer score, Long businessId, 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必须有一个");
+ public void deductionScore(Long vipId, Long oprationUserId, Long shopId, Integer score, Long businessId, int type, String remark) {
+ Long companyId = vipInfoDao.selectById(vipId).getCompanyId();
+
+ String createBy = MatrixConstance.SYSTEM_USER;
+ if (oprationUserId != null) {
+ createBy = sysUsersDao.selectById(oprationUserId).getSuName();
}
- List<ScoreVipDetail> effectiveScoreList = scoreVipDetailDao.selectEffectiveScore(openId,null);
+ List<ScoreVipDetail> effectiveScoreList = scoreVipDetailDao.selectEffectiveScore(vipId);
for (ScoreVipDetail scoreVipDetail : effectiveScoreList) {
@@ -81,21 +76,23 @@
//余额充足
currentDedution = score;
scoreVipDetail.setRemainScore(surplus);
- if(surplus==0){
+ if (surplus == 0) {
scoreVipDetail.setState(ScoreVipDetail.SCORE_STATUS_WX);
}
scoreVipDetailDao.updateById(scoreVipDetail);
- score=0;
+ score = 0;
} else {
currentDedution = scoreVipDetail.getRemainScore();
scoreVipDetail.setState(ScoreVipDetail.SCORE_STATUS_WX);
scoreVipDetail.setRemainScore(0);
scoreVipDetailDao.updateById(scoreVipDetail);
- score=Math.abs(surplus);
+ score = Math.abs(surplus);
}
+
+
//新增扣除记录
- scoreUseRecord.setCreateBy(MatrixConstance.SYSTEM_USER);
- scoreUseRecord.setUpdateBy(MatrixConstance.SYSTEM_USER);
+ scoreUseRecord.setCreateBy(createBy);
+ scoreUseRecord.setUpdateBy(createBy);
scoreUseRecord.setCreateTime(DateTime.now());
scoreUseRecord.setUpdateTime(DateTime.now());
scoreUseRecord.setNowScore(scoreVipDetail.getRemainScore());
@@ -103,56 +100,46 @@
scoreUseRecord.setScoreVipDetailId(scoreVipDetail.getId());
scoreUseRecord.setBusinessId(businessId);
scoreUseRecord.setRecNum(-currentDedution);
- scoreUseRecord.setRecType(type);
- scoreUseRecord.setOpenId(openId);
+ scoreUseRecord.setType(type);
+ scoreUseRecord.setShopId(shopId);
scoreUseRecord.setVipId(vipId);
+ scoreUseRecord.setRemarks(remark);
+ scoreUseRecord.setOprationUserId(oprationUserId);
scoreUseRecordDao.insert(scoreUseRecord);
- if(surplus > 0 || surplus == 0){
+ if (surplus > 0 || surplus == 0) {
break;
}
}
- if(score>0){
+ if (score > 0) {
throw new GlobleException("积分不足");
}
}
/**
* 新增用户积分
- * @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, Integer score, Long businessId, 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){
+ public void addScore(Long vipId, Long oprationUserId, Long shopId, Integer score, Long businessId, int type, String remark) {
+ Long companyId = vipInfoDao.selectById(vipId).getCompanyId();
+
+ if (score < 0) {
throw new IllegalArgumentException("score必须有为大于零的数");
}
- String createBy=MatrixConstance.SYSTEM_USER;
- if(oprationUserId!=null){
- createBy=sysUsersDao.selectById(oprationUserId).getSuName();
+ String createBy = MatrixConstance.SYSTEM_USER;
+ if (oprationUserId != null) {
+ createBy = sysUsersDao.selectById(oprationUserId).getSuName();
}
//计算过期时间
BusParameterSettings yxqSetting = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.VALID_PERIOD_POINTS, companyId);
- Calendar cal=Calendar.getInstance();
+ Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
- int sxYear=year+(Integer.parseInt(yxqSetting.getParamValue())-1);
- Date sxys=DateUtil.stringToDate(year+"-12-31 23:59",DateUtil.DATE_FORMAT_MM );
+ int sxYear = year + (Integer.parseInt(yxqSetting.getParamValue()) - 1);
+ Date sxys = DateUtil.stringToDate(sxYear + "-12-31 23:59", DateUtil.DATE_FORMAT_MM);
- ScoreVipDetail scoreVipDetail=new ScoreVipDetail();
+ ScoreVipDetail scoreVipDetail = new ScoreVipDetail();
scoreVipDetail.setCreateBy(createBy);
scoreVipDetail.setUpdateBy(createBy);
@@ -161,8 +148,8 @@
scoreVipDetail.setState(ScoreVipDetail.SCORE_STATUS_YX);
scoreVipDetail.setRemainScore(score);
scoreVipDetail.setUsedScore(0);
+ scoreVipDetail.setBusinessId(businessId);
scoreVipDetail.setValiditeTime(sxys);
- scoreVipDetail.setOpenId(openId);
scoreVipDetail.setVipId(vipId);
scoreVipDetail.setGainTime(DateTime.now());
scoreVipDetail.setAllScore(score);
@@ -171,7 +158,7 @@
scoreVipDetailDao.insert(scoreVipDetail);
//新增添加记录
- ScoreUseRecord scoreUseRecord = new ScoreUseRecord();
+ ScoreUseRecord scoreUseRecord = new ScoreUseRecord();
scoreUseRecord.setPreScore(score);
scoreUseRecord.setCreateBy(createBy);
scoreUseRecord.setUpdateBy(createBy);
@@ -182,13 +169,119 @@
scoreUseRecord.setScoreVipDetailId(scoreVipDetail.getId());
scoreUseRecord.setBusinessId(businessId);
scoreUseRecord.setRecNum(score);
- scoreUseRecord.setRecType(type);
- scoreUseRecord.setOpenId(openId);
+ scoreUseRecord.setType(type);
scoreUseRecord.setVipId(vipId);
+ scoreUseRecord.setShopId(shopId);
+ scoreUseRecord.setOprationUserId(oprationUserId);
+ scoreUseRecord.setRemarks(remark);
scoreUseRecordDao.insert(scoreUseRecord);
}
+ /**
+ * 根据固定等级规则新增用户积分
+ */
+ @Transactional(rollbackFor = Exception.class)
+ public void addScoreByParamSetting(Long vipId, Long oprationUserId, Long shopId, Long businessId, int type, String remark, BusParameterSettings parameterSetting) {
+ if (parameterSetting != null) {
+ SysVipInfo vipInfo = sysVipInfoDao.selectById(vipId);
+ //添加自己的积分
+ if (StringUtils.isNotBlank(parameterSetting.getParamValue())) {
+ Integer firstScore = new Integer(parameterSetting.getParamValue());
+ if (firstScore > 0) {
+ addScore(
+ vipInfo.getId(),
+ oprationUserId,
+ shopId,
+ firstScore,
+ businessId,
+ type,
+ remark
+ );
+ }
+ }
+
+ if (StringUtils.isNotBlank(parameterSetting.getParamValue1())
+ && vipInfo.getRecommendId() != null) {
+ //推荐注册老带新积分奖励
+ SysVipInfo referrerVip = sysVipInfoDao.selectById(vipInfo.getRecommendId());
+ Integer secondScore = new Integer(parameterSetting.getParamValue1());
+ if (secondScore > 0) {
+ addScore(
+ referrerVip.getId(),
+ oprationUserId,
+ shopId,
+ secondScore,
+ businessId,
+ type,
+ remark
+ );
+ }
+ //推荐注册二级带新积分奖励
+ if (StringUtils.isNotBlank(parameterSetting.getParamValue2())
+ && referrerVip.getRecommendId() != null) {
+ Integer threeScore = new Integer(parameterSetting.getParamValue2());
+ if (threeScore > 0) {
+ addScore(
+ referrerVip.getRecommendId(),
+ oprationUserId,
+ shopId,
+ threeScore,
+ businessId,
+ type,
+ remark
+ );
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * 退积分
+ */
+ public void refundScore(Long vipId, Integer score, Long oldBusinessId, int type) {
+
+ Long companyId = vipInfoDao.selectById(vipId).getCompanyId();
+
+ 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 void removeByBusinessId(Long vipId, Long oldBusinessId) {
+ Long companyId = vipInfoDao.selectById(vipId).getCompanyId();
+
+ if (oldBusinessId == null) {
+ throw new IllegalArgumentException("oldBusinessId必须有");
+ }
+ QueryWrapper queryWrapper = new QueryWrapper();
+ queryWrapper.eq("business_id", oldBusinessId);
+ queryWrapper.eq("company_id", companyId);
+ scoreVipDetailDao.delete(queryWrapper);
+ scoreUseRecordDao.delete(queryWrapper);
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1