Commit d00b3add by 吕明尚

修改充值回调

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