Commit 682ca036 by 吕明尚

修改会员等级逻辑

parent 0c2521ea
......@@ -25,6 +25,7 @@ import share.common.constant.MqttConstants;
import share.common.core.redis.RedisUtil;
import share.common.enums.*;
import share.common.exception.base.BaseException;
import share.common.utils.DateUtils;
import share.system.domain.*;
import share.system.domain.vo.MqttxVo;
import share.system.service.*;
......@@ -508,14 +509,20 @@ public class RedisTask {
Date expirationTime = jsonObject.getDate("expirationTime");
Long consumerId = jsonObject.getLong("consumerId");
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.setIsRight(YesNoEnum.no.getIndex());
if (ObjectUtil.isNotEmpty(consumerMember)) {
if (ObjectUtil.isNotEmpty(consumerWallet)) {
if (consumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex())) {
consumerMember.setMemberType(MemberTypeEnum.RECHARGE.getIndex());
} else {
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);
}
redisUtil.delete(key);
......@@ -539,31 +546,45 @@ public class RedisTask {
consumerIds.stream().forEach(item -> {
List<MemberProgressLog> memberProgressLogs = collect.get(item);
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};
//计算扣除进度
memberProgressLogs.stream().forEach(log -> {
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());
} 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]);
consumerMember.setMembershipProgress(subtract);
if (subtract.compareTo(BigDecimal.valueOf(memberConfig.getLimitRequirements())) < 0) {
consumerMember.setMembershipLevel(memberConfig.getMembershipLevel() - 1);
MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, consumerMember.getMemberType())
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel())
);
consumerMember.setMemberConfigId(memberConfigServiceOne.getId());
//等级降一级
if (consumerMember.getMembershipLevel() > 0L) {
consumerMember.setMembershipLevel(memberConfig.getMembershipLevel() - 1);
MemberConfig memberConfigServiceOne = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMemberType, consumerMember.getMemberType())
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel())
);
consumerMember.setMemberConfigId(memberConfigServiceOne.getId());
}
}
} else {
} else if (consumerMember.getMembershipProgress().compareTo(sum[0]) == 0) {
consumerMember.setMembershipProgress(BigDecimal.ZERO);
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);
}
......
......@@ -3,8 +3,6 @@ package share.system.domain;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
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.core.domain.BaseEntity;
......@@ -66,6 +64,16 @@ public class ConsumerMember extends BaseEntity {
private BigDecimal membershipProgress;
/**
* 是否为充值
*/
private Integer isRecharge;
/**
* 是否为权益
*/
private Integer isRight;
/**
* 是否删除
*/
//逻辑删除注解(0 未删除 1 已删除)
......@@ -73,23 +81,4 @@ public class ConsumerMember extends BaseEntity {
@TableField(select = false)
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;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
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.core.domain.BaseEntity;
......@@ -53,6 +51,18 @@ public class Recharge extends BaseEntity {
private BigDecimal giveAmount;
/**
* 充值赠送时长
*/
@Excel(name = "充值赠送时长")
private BigDecimal giveDuration;
/**
* 充值赠送积分
*/
@Excel(name = "充值赠送积分")
private BigDecimal giveIntegral;
/**
* 充值赠送方式;1-不送,2-送金额,3-送优惠券,4-送金额及优惠券
*/
@Excel(name = "充值赠送方式;1-不送,2-送金额,3-送优惠券,4-送金额及优惠券")
......@@ -122,31 +132,4 @@ public class Recharge extends BaseEntity {
@Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
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
equityMembersOrderConfig.getValidityPeriod().intValue()));
newConsumerMember.setMembershipProgress(BigDecimal.ZERO);
newConsumerMember.setCreateTime(new Date());
newConsumerMember.setIsRight(YesNoEnum.yes.getIndex());
consumerMemberService.save(newConsumerMember);
logger.debug("新增权益会员");
Map<String, String> map = new HashMap<>();
......
......@@ -164,6 +164,7 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i
consumerMember.setMembershipProgress(BigDecimal.ZERO);
consumerMember.setExpirationDate(DateUtils.addYears(new Date(), memberConfig.getValidityPeriod().intValue()));
consumerMember.setCreateTime(new Date());
consumerMember.setIsRecharge(YesNoEnum.yes.getIndex());
consumerMemberService.save(consumerMember);
logger.debug("新增充值会员");
extracted(recharge);
......@@ -245,7 +246,22 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i
if (ObjectUtil.isEmpty(byId)) {
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.setGiveType(byId.getGiveType());
recharge.setStatus(YesNoEnum.no.getIndex());
......
......@@ -1137,13 +1137,23 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
memberProgressLog.setConsumerId(sOrder.getConsumerId());
memberProgressLog.setCurrentProgress(consumerMember.getMembershipProgress());
if (consumerMember.getMemberType().equals(MemberTypeEnum.NORMAL.getIndex())) {
MemberConfig memberConfig = memberConfigService.getById(consumerMember.getMemberConfigId());
if (ObjectUtil.isNotEmpty(memberConfig)) {
//判断是否升级
if (membershipProgress.compareTo(BigDecimal.valueOf(memberConfig.getLimitRequirements())) >= 0) {
if (consumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex())) {
consumerMember.setMemberType(MemberTypeEnum.RECHARGE.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(memberConfig.getId());
consumerMember.setMemberType(MemberTypeEnum.RECHARGE.getIndex());
consumerMember.setMemberConfigId(one.getId());
}
} 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 {
......@@ -1159,16 +1169,14 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
}
}
memberProgressLog.setVariableProgress(membershipProgress.subtract(consumerMember.getMembershipProgress()));
consumerMember.setMembershipProgress(membershipProgress);
memberProgressLog.setOperationType(YesNoEnum.yes.getIndex());
memberProgressLog.setOperationTime(new Date());
memberProgressLog.setOperationType(YesNoEnum.yes.getIndex());
memberProgressLog.setOperationTime(new Date());
memberProgressLog.setCreateTime(new Date());
memberProgressLog.setExpirationTime(DateUtils.addYears(new Date(),
Math.toIntExact(memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().
eq(MemberConfig::getId, consumerMember.getMemberConfigId())).getValidityPeriod())));
memberProgressLogService.save(memberProgressLog);
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