Commit d00b3add by 吕明尚

修改充值回调

parent bb0d8d54
......@@ -92,7 +92,7 @@ public class RechargeController extends BaseController {
return toAjax(rechargeService.deleteRechargeByIds(ids));
}
//
@Log(title = "充值", businessType = BusinessType.DELETE)
@PostMapping("/recharge")
public R<RechargePayResultResponse> createOrder(@RequestBody @Validated CreateRechargeRequest request) {
if ("1".equals(redisUtil.frontInOutLogSwitch())) {
......
package share.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.ConsumerMember;
import share.system.domain.ConsumerWallet;
import share.system.domain.Recharge;
import share.system.domain.vo.ConsumerWalletVo;
import java.util.List;
......@@ -64,4 +66,6 @@ public interface ConsumerWalletService extends IService<ConsumerWallet> {
ConsumerWalletVo selectByConsumerId();
boolean addConsumerWallet(ConsumerWallet consumerWallet);
boolean editConsumerWallet(ConsumerWallet consumerWallet, Recharge recharge, ConsumerMember one);
}
package share.system.service.impl;
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.MemberTypeEnum;
import share.common.enums.YesNoEnum;
import share.common.utils.DateUtils;
import share.system.domain.*;
......@@ -33,6 +35,12 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
private DurationLogService durationLogService;
@Autowired
private IntegralLogService integralLogService;
@Autowired
private RechargeConfService rechargeConfService;
@Autowired
private MemberConfigService memberConfigService;
@Autowired
private ConsumerMemberService consumerMemberService;
/**
* 查询会员钱包
......@@ -136,4 +144,43 @@ public class ConsumerWalletServiceImpl extends ServiceImpl<ConsumerWalletMapper,
integralLogService.save(integralLog);
return i == 1;
}
@Override
public boolean editConsumerWallet(ConsumerWallet consumerWallet, Recharge recharge, ConsumerMember one) {
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.addDays(new Date(), memberConfig.getValidityPeriod().intValue()));
consumerMemberService.updateConsumerMember(one);
BigDecimal balance = consumerWallet.getBalance().add(recharge.getRechargeAmount()).add(rechargeConf.getGiveAmount());
consumerWallet.setBalance(balance);
BigDecimal duration = consumerWallet.getRemainingDuration().add(rechargeConf.getGiveDuration());
consumerWallet.setRemainingDuration(duration);
BigDecimal Integral = consumerWallet.getRemainingIntegral().add(rechargeConf.getGiveRatio().multiply(recharge.getRechargeAmount()));
consumerWallet.setRemainingIntegral(Integral);
int i = baseMapper.updateConsumerWallet(consumerWallet);
BalanceLog balanceLog = new BalanceLog();
balanceLog.setConsumerId(consumerWallet.getConsumerId());
balanceLog.setCurrentBalance(consumerWallet.getBalance());
balanceLog.setVariableAmount(recharge.getRechargeAmount().add(rechargeConf.getGiveAmount()));
balanceLog.setOperationType(YesNoEnum.yes.getIndex());
balanceLog.setOperationTime(new Date());
balanceLogService.save(balanceLog);
DurationLog durationLog = new DurationLog();
durationLog.setConsumerId(consumerWallet.getConsumerId());
durationLog.setCurrentDuration(consumerWallet.getRemainingDuration());
durationLog.setVariableDuration(rechargeConf.getGiveDuration());
durationLog.setOperationTime(new Date());
durationLog.setOperationType(YesNoEnum.yes.getIndex());
durationLogService.save(durationLog);
IntegralLog integralLog = new IntegralLog();
integralLog.setConsumerId(consumerWallet.getConsumerId());
integralLog.setCurrentIntegral(consumerWallet.getRemainingIntegral());
integralLog.setVariableIntegral(rechargeConf.getGiveRatio().multiply(recharge.getRechargeAmount()));
integralLog.setOperationTime(new Date());
integralLog.setOperationType(YesNoEnum.yes.getIndex());
integralLogService.save(integralLog);
return i == 1;
}
}
......@@ -155,21 +155,35 @@ public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> i
consumerMember.setMembershipProgress(recharge.getRechargeAmount().longValue());
consumerMember.setExpirationDate(DateUtils.addDays(new Date(), memberConfig.getValidityPeriod().intValue()));
consumerMemberService.save(consumerMember);
RechargeConf rechargeConf = rechargeConfService.selectRechargeConfById(recharge.getRechargeConfId());
//新增会员钱包
ConsumerWallet consumerWallet = new ConsumerWallet();
consumerWallet.setConsumerId(recharge.getConsumerId());
BigDecimal balance = recharge.getRechargeAmount().add(rechargeConf.getGiveAmount());
consumerWallet.setBalance(balance);
consumerWallet.setRemainingDuration(rechargeConf.getGiveDuration());
BigDecimal Integral = recharge.getRechargeAmount().multiply(rechargeConf.getGiveRatio());
consumerWallet.setRemainingIntegral(Integral);
consumerWalletService.addConsumerWallet(consumerWallet);
extracted(recharge);
} else {
ConsumerWallet consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>().eq(ConsumerWallet::getConsumerId, recharge.getConsumerId()));
if (one.getMemberType().equals(MemberTypeEnum.RECHARGE.getIndex())) {
consumerWalletService.editConsumerWallet(consumerWallet, recharge, one);
} else if (one.getMemberType().equals(MemberTypeEnum.RIGHTS.getIndex())) {
if (ObjectUtil.isEmpty(consumerWallet)) {
extracted(recharge);
} else {
//修改会员钱包
consumerWalletService.editConsumerWallet(consumerWallet, recharge, one);
}
}
}
}
private void extracted(Recharge recharge) {
//新增会员钱包
RechargeConf rechargeConf = rechargeConfService.selectRechargeConfById(recharge.getRechargeConfId());
ConsumerWallet consumerWallet = new ConsumerWallet();
consumerWallet.setConsumerId(recharge.getConsumerId());
BigDecimal balance = recharge.getRechargeAmount().add(rechargeConf.getGiveAmount());
consumerWallet.setBalance(balance);
consumerWallet.setRemainingDuration(rechargeConf.getGiveDuration());
BigDecimal Integral = recharge.getRechargeAmount().multiply(rechargeConf.getGiveRatio());
consumerWallet.setRemainingIntegral(Integral);
consumerWalletService.addConsumerWallet(consumerWallet);
}
private Recharge generatRecharge(CreateRechargeRequest request, SConsumer user) {
Recharge recharge = new Recharge();
BeanUtils.copyProperties(request, recharge);
......
......@@ -1931,16 +1931,23 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setCouponFee(BigDecimal.ZERO);
priceResponse.setDiscountFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
priceResponse.setDiscountRatio(priceResponse.getDiscountFee().divide(priceResponse.getTotalFee(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
if (ObjectUtil.isNotEmpty(consumerMember)) {
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getId, consumerMember.getMemberConfigId()));
//总金额乘以折扣比例除以100
priceResponse.setPayFee(priceResponse.getPayFee().multiply(memberConfig.getDiscountRatio()).divide(new BigDecimal(100)));
priceResponse.setDiscountFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
priceResponse.setCouponFee(priceResponse.getDiscountFee());
if (ObjectUtil.isNotEmpty(priceResponse.getDiscountFee()) && priceResponse.getTotalFee().compareTo(new BigDecimal(0.00)) > 0) {
priceResponse.setDiscountRatio(priceResponse.getDiscountFee().divide(priceResponse.getTotalFee(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
} else {
priceResponse.setDiscountRatio(new BigDecimal(0));
CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
if (ObjectUtil.isNotEmpty(activity)) {
Cron cron = cronParser.parse(activity.getCronExpression());
ExecutionTime executionTime = ExecutionTime.forCron(cron);
boolean match = executionTime.isMatch(ZonedDateTime.ofInstant(request.getPreStartDate().toInstant(), ZoneId.systemDefault()));
boolean match1 = executionTime.isMatch(ZonedDateTime.ofInstant(request.getPreEndDate().toInstant(), ZoneId.systemDefault()));
if (ObjectUtil.isNotEmpty(consumerMember) && !match && !match1) {
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getId, consumerMember.getMemberConfigId()));
//总金额乘以折扣比例除以100
priceResponse.setPayFee(priceResponse.getPayFee().multiply(memberConfig.getDiscountRatio()).divide(new BigDecimal(100)));
priceResponse.setDiscountFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
priceResponse.setCouponFee(priceResponse.getDiscountFee());
if (ObjectUtil.isNotEmpty(priceResponse.getDiscountFee()) && priceResponse.getTotalFee().compareTo(new BigDecimal(0.00)) > 0) {
priceResponse.setDiscountRatio(priceResponse.getDiscountFee().divide(priceResponse.getTotalFee(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
} else {
priceResponse.setDiscountRatio(new BigDecimal(0));
}
}
}
} else {
......
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