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;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.enums.GiveTypeEnum;
import share.common.enums.MemberTypeEnum;
import share.common.enums.YesNoEnum;
import share.common.utils.DateUtils;
......@@ -122,6 +123,7 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
@Override
public boolean addConsumerWallet(ConsumerWallet consumerWallet) {
int i = consumerWalletMapper.insertConsumerWallet(consumerWallet);
if (consumerWallet.getBalance().compareTo(new BigDecimal(0)) > 0) {
BalanceLog balanceLog = new BalanceLog();
balanceLog.setConsumerId(consumerWallet.getConsumerId());
balanceLog.setCurrentBalance(new BigDecimal(0));
......@@ -129,6 +131,8 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
balanceLog.setOperationType(YesNoEnum.yes.getIndex());
balanceLog.setOperationTime(new Date());
balanceLogService.save(balanceLog);
}
if (consumerWallet.getRemainingDuration().compareTo(new BigDecimal(0)) > 0) {
DurationLog durationLog = new DurationLog();
durationLog.setConsumerId(consumerWallet.getConsumerId());
durationLog.setCurrentDuration(new BigDecimal(0));
......@@ -136,6 +140,8 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
durationLog.setOperationTime(new Date());
durationLog.setOperationType(YesNoEnum.yes.getIndex());
durationLogService.save(durationLog);
}
if (consumerWallet.getRemainingIntegral().compareTo(new BigDecimal(0)) > 0) {
IntegralLog integralLog = new IntegralLog();
integralLog.setConsumerId(consumerWallet.getConsumerId());
integralLog.setCurrentIntegral(new BigDecimal(0));
......@@ -143,26 +149,35 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
integralLog.setOperationTime(new Date());
integralLog.setOperationType(YesNoEnum.yes.getIndex());
integralLogService.save(integralLog);
}
return i == 1;
}
@Override
public boolean editConsumerWallet(ConsumerWallet consumerWallet, Recharge recharge, ConsumerMember one) {
BigDecimal divide = new BigDecimal(0);
RechargeConf rechargeConf = rechargeConfService.selectRechargeConfById(recharge.getRechargeConfId());
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
.eq(MemberConfig::getMembershipLevel, 1L)
.eq(MemberConfig::getMemberType, MemberTypeEnum.RECHARGE.getIndex()));
one.setExpirationDate(DateUtils.addYears(new Date(), memberConfig.getValidityPeriod().intValue()));
consumerMemberService.updateConsumerMember(one);
if (rechargeConf.getGiveType().contains(GiveTypeEnum.AMOUNT.getIndex())) {
BigDecimal balance = consumerWallet.getBalance().add(recharge.getRechargeAmount()).add(rechargeConf.getGiveAmount());
consumerWallet.setBalance(balance);
}
if (rechargeConf.getGiveType().contains(GiveTypeEnum.DURATION.getIndex())) {
BigDecimal duration = consumerWallet.getRemainingDuration().add(rechargeConf.getGiveDuration());
consumerWallet.setRemainingDuration(duration);
BigDecimal divide = recharge.getRechargeAmount().multiply(rechargeConf.getGiveRatio()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
}
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);
if (consumerWallet.getBalance().compareTo(new BigDecimal(0)) > 0) {
BalanceLog balanceLog = new BalanceLog();
balanceLog.setConsumerId(consumerWallet.getConsumerId());
balanceLog.setCurrentBalance(consumerWallet.getBalance());
......@@ -171,6 +186,8 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
balanceLog.setOperationTime(new Date());
balanceLog.setCreateTime(new Date());
balanceLogService.save(balanceLog);
}
if (consumerWallet.getRemainingDuration().compareTo(new BigDecimal(0)) > 0) {
DurationLog durationLog = new DurationLog();
durationLog.setConsumerId(consumerWallet.getConsumerId());
durationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
......@@ -179,6 +196,8 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
durationLog.setOperationType(YesNoEnum.yes.getIndex());
durationLog.setCreateTime(new Date());
durationLogService.save(durationLog);
}
if (consumerWallet.getRemainingIntegral().compareTo(new BigDecimal(0)) > 0) {
IntegralLog integralLog = new IntegralLog();
integralLog.setConsumerId(consumerWallet.getConsumerId());
integralLog.setCurrentIntegral(consumerWallet.getRemainingIntegral());
......@@ -187,6 +206,7 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
integralLog.setOperationType(YesNoEnum.yes.getIndex());
integralLog.setCreateTime(new Date());
integralLogService.save(integralLog);
}
return i == 1;
}
}
......@@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import share.common.enums.GiveTypeEnum;
import share.common.enums.MemberTypeEnum;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException;
......@@ -199,11 +200,23 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i
RechargeConf rechargeConf = rechargeConfService.selectRechargeConfById(recharge.getRechargeConfId());
ConsumerWallet consumerWallet = new ConsumerWallet();
consumerWallet.setConsumerId(recharge.getConsumerId());
if (rechargeConf.getGiveType().contains(GiveTypeEnum.AMOUNT.getIndex())) {
BigDecimal balance = recharge.getRechargeAmount().add(rechargeConf.getGiveAmount());
consumerWallet.setBalance(balance);
} else {
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());
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