Commit 682ca036 by 吕明尚

修改会员等级逻辑

parent 0c2521ea
...@@ -25,6 +25,7 @@ import share.common.constant.MqttConstants; ...@@ -25,6 +25,7 @@ import share.common.constant.MqttConstants;
import share.common.core.redis.RedisUtil; import share.common.core.redis.RedisUtil;
import share.common.enums.*; import share.common.enums.*;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import share.common.utils.DateUtils;
import share.system.domain.*; import share.system.domain.*;
import share.system.domain.vo.MqttxVo; import share.system.domain.vo.MqttxVo;
import share.system.service.*; import share.system.service.*;
...@@ -508,14 +509,20 @@ public class RedisTask { ...@@ -508,14 +509,20 @@ public class RedisTask {
Date expirationTime = jsonObject.getDate("expirationTime"); Date expirationTime = jsonObject.getDate("expirationTime");
Long consumerId = jsonObject.getLong("consumerId"); Long consumerId = jsonObject.getLong("consumerId");
if (expirationTime.getTime() < new Date().getTime()) { if (expirationTime.getTime() < new Date().getTime()) {
ConsumerWallet consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>().eq(ConsumerWallet::getConsumerId, consumerId));
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, consumerId)); ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, consumerId));
consumerMember.setIsRight(YesNoEnum.no.getIndex());
if (ObjectUtil.isNotEmpty(consumerMember)) { if (ObjectUtil.isNotEmpty(consumerMember)) {
if (ObjectUtil.isNotEmpty(consumerWallet)) { if (consumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex())) {
consumerMember.setMemberType(MemberTypeEnum.RECHARGE.getIndex()); consumerMember.setMemberType(MemberTypeEnum.RECHARGE.getIndex());
} else { } else {
consumerMember.setMemberType(MemberTypeEnum.NORMAL.getIndex()); consumerMember.setMemberType(MemberTypeEnum.NORMAL.getIndex());
} }
MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, consumerMember.getMemberType())
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel())
);
consumerMember.setMemberConfigId(memberConfigServiceOne.getId());
consumerMember.setExpirationDate(DateUtils.addYears(new Date(), memberConfigServiceOne.getValidityPeriod().intValue()));
consumerMemberService.updateConsumerMember(consumerMember); consumerMemberService.updateConsumerMember(consumerMember);
} }
redisUtil.delete(key); redisUtil.delete(key);
...@@ -539,31 +546,45 @@ public class RedisTask { ...@@ -539,31 +546,45 @@ public class RedisTask {
consumerIds.stream().forEach(item -> { consumerIds.stream().forEach(item -> {
List<MemberProgressLog> memberProgressLogs = collect.get(item); List<MemberProgressLog> memberProgressLogs = collect.get(item);
if (memberProgressLogs.size() > 0) { if (memberProgressLogs.size() > 0) {
//查询会员
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, item));
//查询会员配置
MemberConfig memberConfig = memberConfigService.getById(consumerMember.getMemberConfigId());
final BigDecimal[] sum = {BigDecimal.ZERO}; final BigDecimal[] sum = {BigDecimal.ZERO};
//计算扣除进度
memberProgressLogs.stream().forEach(log -> { memberProgressLogs.stream().forEach(log -> {
if (log.getOperationType().equals(YesNoEnum.yes.getIndex())) { if (log.getOperationType().equals(YesNoEnum.yes.getIndex())) {
sum[0] = sum[0].subtract(log.getVariableProgress());
} else if (log.getOperationType().equals(YesNoEnum.no.getIndex())) {
sum[0] = sum[0].add(log.getVariableProgress()); sum[0] = sum[0].add(log.getVariableProgress());
} else if (log.getOperationType().equals(YesNoEnum.no.getIndex())) {
sum[0] = sum[0].subtract(log.getVariableProgress());
} }
}); });
ConsumerMember consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, item));
MemberConfig memberConfig = memberConfigService.getById(consumerMember.getMemberConfigId()); //判断会员进度是否大于扣除进度
if (consumerMember.getMembershipProgress().compareTo(sum[0]) >= 0) { if (consumerMember.getMembershipProgress().compareTo(sum[0]) > 0) {
//会员进度减去扣除进度
BigDecimal subtract = consumerMember.getMembershipProgress().subtract(sum[0]); BigDecimal subtract = consumerMember.getMembershipProgress().subtract(sum[0]);
consumerMember.setMembershipProgress(subtract); consumerMember.setMembershipProgress(subtract);
if (subtract.compareTo(BigDecimal.valueOf(memberConfig.getLimitRequirements())) < 0) { if (subtract.compareTo(BigDecimal.valueOf(memberConfig.getLimitRequirements())) < 0) {
consumerMember.setMembershipLevel(memberConfig.getMembershipLevel() - 1); //等级降一级
MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>() if (consumerMember.getMembershipLevel() > 0L) {
.eq(MemberConfig::getMemberType, consumerMember.getMemberType()) consumerMember.setMembershipLevel(memberConfig.getMembershipLevel() - 1);
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel()) MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
); .eq(MemberConfig::getMemberType, consumerMember.getMemberType())
consumerMember.setMemberConfigId(memberConfigServiceOne.getId()); .eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel())
);
consumerMember.setMemberConfigId(memberConfigServiceOne.getId());
}
} }
} else { } else if (consumerMember.getMembershipProgress().compareTo(sum[0]) == 0) {
consumerMember.setMembershipProgress(BigDecimal.ZERO); consumerMember.setMembershipProgress(BigDecimal.ZERO);
consumerMember.setMembershipLevel(0L); consumerMember.setMembershipLevel(0L);
consumerMember.setMemberType(MemberTypeEnum.NORMAL.getIndex()); MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, consumerMember.getMemberType())
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel())
);
consumerMember.setMemberConfigId(memberConfigServiceOne.getId());
} }
consumerMemberService.updateConsumerMember(consumerMember); consumerMemberService.updateConsumerMember(consumerMember);
} }
......
...@@ -3,8 +3,6 @@ package share.system.domain; ...@@ -3,8 +3,6 @@ package share.system.domain;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel; import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity; import share.common.core.domain.BaseEntity;
...@@ -66,6 +64,16 @@ public class ConsumerMember extends BaseEntity { ...@@ -66,6 +64,16 @@ public class ConsumerMember extends BaseEntity {
private BigDecimal membershipProgress; private BigDecimal membershipProgress;
/** /**
* 是否为充值
*/
private Integer isRecharge;
/**
* 是否为权益
*/
private Integer isRight;
/**
* 是否删除 * 是否删除
*/ */
//逻辑删除注解(0 未删除 1 已删除) //逻辑删除注解(0 未删除 1 已删除)
...@@ -73,23 +81,4 @@ public class ConsumerMember extends BaseEntity { ...@@ -73,23 +81,4 @@ public class ConsumerMember extends BaseEntity {
@TableField(select = false) @TableField(select = false)
private Long isDelete; private Long isDelete;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("consumerId", getConsumerId())
.append("membershipLevel", getMembershipLevel())
.append("memberType", getMemberType())
.append("memberConfigId", getMemberConfigId())
.append("expirationDate", getExpirationDate())
.append("membershipProgress", getMembershipProgress())
.append("isDelete", getIsDelete())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
} }
...@@ -3,8 +3,6 @@ package share.system.domain; ...@@ -3,8 +3,6 @@ package share.system.domain;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import share.common.annotation.Excel; import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity; import share.common.core.domain.BaseEntity;
...@@ -53,6 +51,18 @@ public class Recharge extends BaseEntity { ...@@ -53,6 +51,18 @@ public class Recharge extends BaseEntity {
private BigDecimal giveAmount; private BigDecimal giveAmount;
/** /**
* 充值赠送时长
*/
@Excel(name = "充值赠送时长")
private BigDecimal giveDuration;
/**
* 充值赠送积分
*/
@Excel(name = "充值赠送积分")
private BigDecimal giveIntegral;
/**
* 充值赠送方式;1-不送,2-送金额,3-送优惠券,4-送金额及优惠券 * 充值赠送方式;1-不送,2-送金额,3-送优惠券,4-送金额及优惠券
*/ */
@Excel(name = "充值赠送方式;1-不送,2-送金额,3-送优惠券,4-送金额及优惠券") @Excel(name = "充值赠送方式;1-不送,2-送金额,3-送优惠券,4-送金额及优惠券")
...@@ -122,31 +132,4 @@ public class Recharge extends BaseEntity { ...@@ -122,31 +132,4 @@ public class Recharge extends BaseEntity {
@Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date payTime; private Date payTime;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("rechargeNo", getRechargeNo())
.append("rechargeAmount", getRechargeAmount())
.append("payType", getPayType())
.append("giveAmount", getGiveAmount())
.append("giveType", getGiveType())
.append("status", getStatus())
.append("consumerCouponIds", getConsumerCouponIds())
.append("rechargeConfId", getRechargeConfId())
.append("consumerId", getConsumerId())
.append("phone", getPhone())
.append("rechargeDate", getRechargeDate())
.append("isDelete", getIsDelete())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("outTradeNo", getOutTradeNo())
.append("terminalTrace", getTerminalTrace())
.append("payTime", getPayTime())
.toString();
}
} }
...@@ -161,6 +161,7 @@ public class EquityMembersOrderServiceImpl extends ServiceImpl<EquityMembersOrde ...@@ -161,6 +161,7 @@ public class EquityMembersOrderServiceImpl extends ServiceImpl<EquityMembersOrde
equityMembersOrderConfig.getValidityPeriod().intValue())); equityMembersOrderConfig.getValidityPeriod().intValue()));
newConsumerMember.setMembershipProgress(BigDecimal.ZERO); newConsumerMember.setMembershipProgress(BigDecimal.ZERO);
newConsumerMember.setCreateTime(new Date()); newConsumerMember.setCreateTime(new Date());
newConsumerMember.setIsRight(YesNoEnum.yes.getIndex());
consumerMemberService.save(newConsumerMember); consumerMemberService.save(newConsumerMember);
logger.debug("新增权益会员"); logger.debug("新增权益会员");
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
......
...@@ -164,6 +164,7 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i ...@@ -164,6 +164,7 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i
consumerMember.setMembershipProgress(BigDecimal.ZERO); consumerMember.setMembershipProgress(BigDecimal.ZERO);
consumerMember.setExpirationDate(DateUtils.addYears(new Date(), memberConfig.getValidityPeriod().intValue())); consumerMember.setExpirationDate(DateUtils.addYears(new Date(), memberConfig.getValidityPeriod().intValue()));
consumerMember.setCreateTime(new Date()); consumerMember.setCreateTime(new Date());
consumerMember.setIsRecharge(YesNoEnum.yes.getIndex());
consumerMemberService.save(consumerMember); consumerMemberService.save(consumerMember);
logger.debug("新增充值会员"); logger.debug("新增充值会员");
extracted(recharge); extracted(recharge);
...@@ -245,7 +246,22 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i ...@@ -245,7 +246,22 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i
if (ObjectUtil.isEmpty(byId)) { if (ObjectUtil.isEmpty(byId)) {
throw new BaseException("充值模板异常"); throw new BaseException("充值模板异常");
} }
recharge.setRechargeAmount(byId.getRechargeAmount()); if (byId.getGiveType().contains(GiveTypeEnum.AMOUNT.getIndex())) {
recharge.setRechargeAmount(byId.getRechargeAmount());
} else {
recharge.setRechargeAmount(BigDecimal.ZERO);
}
if (byId.getGiveType().contains(GiveTypeEnum.DURATION.getIndex())) {
recharge.setGiveDuration(byId.getGiveDuration());
} else {
recharge.setGiveDuration(BigDecimal.ZERO);
}
if (byId.getGiveType().contains(GiveTypeEnum.INTEGRAL.getIndex())) {
BigDecimal Integral = recharge.getRechargeAmount().multiply(byId.getGiveRatio()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
recharge.setGiveIntegral(Integral);
} else {
recharge.setGiveIntegral(BigDecimal.ZERO);
}
recharge.setGiveAmount(byId.getGiveAmount()); recharge.setGiveAmount(byId.getGiveAmount());
recharge.setGiveType(byId.getGiveType()); recharge.setGiveType(byId.getGiveType());
recharge.setStatus(YesNoEnum.no.getIndex()); recharge.setStatus(YesNoEnum.no.getIndex());
......
...@@ -1137,13 +1137,23 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1137,13 +1137,23 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
memberProgressLog.setConsumerId(sOrder.getConsumerId()); memberProgressLog.setConsumerId(sOrder.getConsumerId());
memberProgressLog.setCurrentProgress(consumerMember.getMembershipProgress()); memberProgressLog.setCurrentProgress(consumerMember.getMembershipProgress());
if (consumerMember.getMemberType().equals(MemberTypeEnum.NORMAL.getIndex())) { if (consumerMember.getMemberType().equals(MemberTypeEnum.NORMAL.getIndex())) {
MemberConfig memberConfig = memberConfigService.getById(consumerMember.getMemberConfigId()); if (consumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex())) {
if (ObjectUtil.isNotEmpty(memberConfig)) { consumerMember.setMemberType(MemberTypeEnum.RECHARGE.getIndex());
//判断是否升级 MemberConfig one = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
if (membershipProgress.compareTo(BigDecimal.valueOf(memberConfig.getLimitRequirements())) >= 0) { .eq(MemberConfig::getMemberType, consumerMember.getMemberType())
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel() + 1L));
if (membershipProgress.compareTo(BigDecimal.valueOf(one.getLimitRequirements())) >= 0) {
consumerMember.setMembershipLevel(consumerMember.getMembershipLevel() + 1L); consumerMember.setMembershipLevel(consumerMember.getMembershipLevel() + 1L);
consumerMember.setMemberConfigId(memberConfig.getId()); consumerMember.setMemberConfigId(one.getId());
consumerMember.setMemberType(MemberTypeEnum.RECHARGE.getIndex()); }
} else if (consumerMember.getIsRight().equals(YesNoEnum.yes.getIndex())) {
consumerMember.setMemberType(MemberTypeEnum.RIGHTS.getIndex());
MemberConfig one = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, consumerMember.getMemberType())
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel() + 1L));
if (membershipProgress.compareTo(BigDecimal.valueOf(one.getLimitRequirements())) >= 0) {
consumerMember.setMembershipLevel(consumerMember.getMembershipLevel() + 1L);
consumerMember.setMemberConfigId(one.getId());
} }
} }
} else { } else {
...@@ -1159,16 +1169,14 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1159,16 +1169,14 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
} }
} }
} }
memberProgressLog.setVariableProgress(membershipProgress.subtract(consumerMember.getMembershipProgress())); memberProgressLog.setVariableProgress(membershipProgress.subtract(consumerMember.getMembershipProgress()));
consumerMember.setMembershipProgress(membershipProgress); consumerMember.setMembershipProgress(membershipProgress);
memberProgressLog.setOperationType(YesNoEnum.yes.getIndex()); memberProgressLog.setOperationType(YesNoEnum.yes.getIndex());
memberProgressLog.setOperationTime(new Date()); memberProgressLog.setOperationTime(new Date());
memberProgressLog.setCreateTime(new Date()); memberProgressLog.setCreateTime(new Date());
memberProgressLog.setExpirationTime(DateUtils.addYears(new Date(), memberProgressLog.setExpirationTime(DateUtils.addYears(new Date(),
Math.toIntExact(memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>(). Math.toIntExact(memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().
eq(MemberConfig::getId, consumerMember.getMemberConfigId())).getValidityPeriod()))); eq(MemberConfig::getId, consumerMember.getMemberConfigId())).getValidityPeriod())));
memberProgressLogService.save(memberProgressLog); memberProgressLogService.save(memberProgressLog);
consumerMemberService.updateConsumerMember(consumerMember); consumerMemberService.updateConsumerMember(consumerMember);
// } // }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment