Commit ff703c2f by 吕明尚

Merge branch 'refs/heads/dev' into test

parents 600b2d7f 89fa8e3b
package share.common.enums;
public enum GiveTypeEnum {
//金额
AMOUNT("1", "金额"),
//时长
DURATION("2", "时长"),
//积分
INTEGRAL("3", "积分"),
;
private String index;
private String name;
GiveTypeEnum(String index, String name) {
this.index = index;
this.name = name;
}
GiveTypeEnum() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
}
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import share.common.enums.GiveTypeEnum;
import share.common.enums.MemberTypeEnum; import share.common.enums.MemberTypeEnum;
import share.common.enums.YesNoEnum; import share.common.enums.YesNoEnum;
import share.common.utils.DateUtils; import share.common.utils.DateUtils;
...@@ -122,71 +123,90 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper, ...@@ -122,71 +123,90 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
@Override @Override
public boolean addConsumerWallet(ConsumerWallet consumerWallet) { public boolean addConsumerWallet(ConsumerWallet consumerWallet) {
int i = consumerWalletMapper.insertConsumerWallet(consumerWallet); int i = consumerWalletMapper.insertConsumerWallet(consumerWallet);
BalanceLog balanceLog = new BalanceLog(); if (consumerWallet.getBalance().compareTo(new BigDecimal(0)) > 0) {
balanceLog.setConsumerId(consumerWallet.getConsumerId()); BalanceLog balanceLog = new BalanceLog();
balanceLog.setCurrentBalance(new BigDecimal(0)); balanceLog.setConsumerId(consumerWallet.getConsumerId());
balanceLog.setVariableAmount(consumerWallet.getBalance()); balanceLog.setCurrentBalance(new BigDecimal(0));
balanceLog.setOperationType(YesNoEnum.yes.getIndex()); balanceLog.setVariableAmount(consumerWallet.getBalance());
balanceLog.setOperationTime(new Date()); balanceLog.setOperationType(YesNoEnum.yes.getIndex());
balanceLogService.save(balanceLog); balanceLog.setOperationTime(new Date());
DurationLog durationLog = new DurationLog(); balanceLogService.save(balanceLog);
durationLog.setConsumerId(consumerWallet.getConsumerId()); }
durationLog.setCurrentDuration(new BigDecimal(0)); if (consumerWallet.getRemainingDuration().compareTo(new BigDecimal(0)) > 0) {
durationLog.setVariableDuration(consumerWallet.getRemainingDuration()); DurationLog durationLog = new DurationLog();
durationLog.setOperationTime(new Date()); durationLog.setConsumerId(consumerWallet.getConsumerId());
durationLog.setOperationType(YesNoEnum.yes.getIndex()); durationLog.setCurrentDuration(new BigDecimal(0));
durationLogService.save(durationLog); durationLog.setVariableDuration(consumerWallet.getRemainingDuration());
IntegralLog integralLog = new IntegralLog(); durationLog.setOperationTime(new Date());
integralLog.setConsumerId(consumerWallet.getConsumerId()); durationLog.setOperationType(YesNoEnum.yes.getIndex());
integralLog.setCurrentIntegral(new BigDecimal(0)); durationLogService.save(durationLog);
integralLog.setVariableIntegral(consumerWallet.getRemainingIntegral()); }
integralLog.setOperationTime(new Date()); if (consumerWallet.getRemainingIntegral().compareTo(new BigDecimal(0)) > 0) {
integralLog.setOperationType(YesNoEnum.yes.getIndex()); IntegralLog integralLog = new IntegralLog();
integralLogService.save(integralLog); integralLog.setConsumerId(consumerWallet.getConsumerId());
integralLog.setCurrentIntegral(new BigDecimal(0));
integralLog.setVariableIntegral(consumerWallet.getRemainingIntegral());
integralLog.setOperationTime(new Date());
integralLog.setOperationType(YesNoEnum.yes.getIndex());
integralLogService.save(integralLog);
}
return i == 1; return i == 1;
} }
@Override @Override
public boolean editConsumerWallet(ConsumerWallet consumerWallet, Recharge recharge, ConsumerMember one) { public boolean editConsumerWallet(ConsumerWallet consumerWallet, Recharge recharge, ConsumerMember one) {
BigDecimal divide = new BigDecimal(0);
RechargeConf rechargeConf = rechargeConfService.selectRechargeConfById(recharge.getRechargeConfId()); RechargeConf rechargeConf = rechargeConfService.selectRechargeConfById(recharge.getRechargeConfId());
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>() MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMembershipLevel, 1L) .eq(MemberConfig::getMembershipLevel, 1L)
.eq(MemberConfig::getMemberType, MemberTypeEnum.RECHARGE.getIndex())); .eq(MemberConfig::getMemberType, MemberTypeEnum.RECHARGE.getIndex()));
one.setExpirationDate(DateUtils.addYears(new Date(), memberConfig.getValidityPeriod().intValue())); one.setExpirationDate(DateUtils.addYears(new Date(), memberConfig.getValidityPeriod().intValue()));
consumerMemberService.updateConsumerMember(one); consumerMemberService.updateConsumerMember(one);
BigDecimal balance = consumerWallet.getBalance().add(recharge.getRechargeAmount()).add(rechargeConf.getGiveAmount()); if (rechargeConf.getGiveType().contains(GiveTypeEnum.AMOUNT.getIndex())) {
consumerWallet.setBalance(balance); BigDecimal balance = consumerWallet.getBalance().add(recharge.getRechargeAmount()).add(rechargeConf.getGiveAmount());
BigDecimal duration = consumerWallet.getRemainingDuration().add(rechargeConf.getGiveDuration()); consumerWallet.setBalance(balance);
consumerWallet.setRemainingDuration(duration); }
BigDecimal divide = recharge.getRechargeAmount().multiply(rechargeConf.getGiveRatio()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); if (rechargeConf.getGiveType().contains(GiveTypeEnum.DURATION.getIndex())) {
BigDecimal Integral = consumerWallet.getRemainingIntegral().add(divide); BigDecimal duration = consumerWallet.getRemainingDuration().add(rechargeConf.getGiveDuration());
consumerWallet.setRemainingDuration(duration);
consumerWallet.setRemainingIntegral(Integral); }
if (rechargeConf.getGiveType().contains(GiveTypeEnum.INTEGRAL.getIndex())) {
divide = recharge.getRechargeAmount().multiply(rechargeConf.getGiveRatio()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
BigDecimal Integral = consumerWallet.getRemainingIntegral().add(divide);
consumerWallet.setRemainingIntegral(Integral);
}
int i = updateConsumerWallet(consumerWallet); int i = updateConsumerWallet(consumerWallet);
BalanceLog balanceLog = new BalanceLog();
balanceLog.setConsumerId(consumerWallet.getConsumerId()); if (consumerWallet.getBalance().compareTo(new BigDecimal(0)) > 0) {
balanceLog.setCurrentBalance(consumerWallet.getBalance()); BalanceLog balanceLog = new BalanceLog();
balanceLog.setVariableAmount(recharge.getRechargeAmount().add(rechargeConf.getGiveAmount())); balanceLog.setConsumerId(consumerWallet.getConsumerId());
balanceLog.setOperationType(YesNoEnum.yes.getIndex()); balanceLog.setCurrentBalance(consumerWallet.getBalance());
balanceLog.setOperationTime(new Date()); balanceLog.setVariableAmount(recharge.getRechargeAmount().add(rechargeConf.getGiveAmount()));
balanceLog.setCreateTime(new Date()); balanceLog.setOperationType(YesNoEnum.yes.getIndex());
balanceLogService.save(balanceLog); balanceLog.setOperationTime(new Date());
DurationLog durationLog = new DurationLog(); balanceLog.setCreateTime(new Date());
durationLog.setConsumerId(consumerWallet.getConsumerId()); balanceLogService.save(balanceLog);
durationLog.setCurrentDuration(consumerWallet.getRemainingDuration()); }
durationLog.setVariableDuration(rechargeConf.getGiveDuration()); if (consumerWallet.getRemainingDuration().compareTo(new BigDecimal(0)) > 0) {
durationLog.setOperationTime(new Date()); DurationLog durationLog = new DurationLog();
durationLog.setOperationType(YesNoEnum.yes.getIndex()); durationLog.setConsumerId(consumerWallet.getConsumerId());
durationLog.setCreateTime(new Date()); durationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
durationLogService.save(durationLog); durationLog.setVariableDuration(rechargeConf.getGiveDuration());
IntegralLog integralLog = new IntegralLog(); durationLog.setOperationTime(new Date());
integralLog.setConsumerId(consumerWallet.getConsumerId()); durationLog.setOperationType(YesNoEnum.yes.getIndex());
integralLog.setCurrentIntegral(consumerWallet.getRemainingIntegral()); durationLog.setCreateTime(new Date());
integralLog.setVariableIntegral(divide); durationLogService.save(durationLog);
integralLog.setOperationTime(new Date()); }
integralLog.setOperationType(YesNoEnum.yes.getIndex()); if (consumerWallet.getRemainingIntegral().compareTo(new BigDecimal(0)) > 0) {
integralLog.setCreateTime(new Date()); IntegralLog integralLog = new IntegralLog();
integralLogService.save(integralLog); integralLog.setConsumerId(consumerWallet.getConsumerId());
integralLog.setCurrentIntegral(consumerWallet.getRemainingIntegral());
integralLog.setVariableIntegral(divide);
integralLog.setOperationTime(new Date());
integralLog.setOperationType(YesNoEnum.yes.getIndex());
integralLog.setCreateTime(new Date());
integralLogService.save(integralLog);
}
return i == 1; return i == 1;
} }
} }
...@@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import share.common.enums.GiveTypeEnum;
import share.common.enums.MemberTypeEnum; import share.common.enums.MemberTypeEnum;
import share.common.enums.YesNoEnum; import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
...@@ -199,11 +200,23 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i ...@@ -199,11 +200,23 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i
RechargeConf rechargeConf = rechargeConfService.selectRechargeConfById(recharge.getRechargeConfId()); RechargeConf rechargeConf = rechargeConfService.selectRechargeConfById(recharge.getRechargeConfId());
ConsumerWallet consumerWallet = new ConsumerWallet(); ConsumerWallet consumerWallet = new ConsumerWallet();
consumerWallet.setConsumerId(recharge.getConsumerId()); consumerWallet.setConsumerId(recharge.getConsumerId());
BigDecimal balance = recharge.getRechargeAmount().add(rechargeConf.getGiveAmount()); if (rechargeConf.getGiveType().contains(GiveTypeEnum.AMOUNT.getIndex())) {
consumerWallet.setBalance(balance); BigDecimal balance = recharge.getRechargeAmount().add(rechargeConf.getGiveAmount());
consumerWallet.setRemainingDuration(rechargeConf.getGiveDuration()); consumerWallet.setBalance(balance);
BigDecimal Integral = recharge.getRechargeAmount().multiply(rechargeConf.getGiveRatio()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); } else {
consumerWallet.setRemainingIntegral(Integral); consumerWallet.setBalance(new BigDecimal(0));
}
if (rechargeConf.getGiveType().contains(GiveTypeEnum.DURATION.getIndex())) {
consumerWallet.setRemainingDuration(rechargeConf.getGiveDuration());
} else {
consumerWallet.setRemainingDuration(new BigDecimal(0));
}
if (rechargeConf.getGiveType().contains(GiveTypeEnum.INTEGRAL.getIndex())) {
BigDecimal Integral = recharge.getRechargeAmount().multiply(rechargeConf.getGiveRatio()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
consumerWallet.setRemainingIntegral(Integral);
} else {
consumerWallet.setRemainingIntegral(new BigDecimal(0));
}
consumerWallet.setCreateTime(new Date()); consumerWallet.setCreateTime(new Date());
consumerWalletService.addConsumerWallet(consumerWallet); consumerWalletService.addConsumerWallet(consumerWallet);
} }
......
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