BUGFIX: 新建订阅时更新订阅不更新账号信息
This commit is contained in:
@@ -220,7 +220,7 @@ public interface AccountService extends IService<Account> {
|
||||
|
||||
Boolean unbindGoogle();
|
||||
|
||||
void updateAccountValidity(Long accountId, Long currentPeriodEnd);
|
||||
boolean updateAccountValidity(Long accountId, Long currentPeriodEnd);
|
||||
|
||||
void updateUserRoleAndCredits(Long accountId, String type);
|
||||
|
||||
|
||||
@@ -2744,12 +2744,16 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateAccountValidity(Long accountId, Long currentPeriodEnd){
|
||||
public boolean updateAccountValidity(Long accountId, Long currentPeriodEnd){
|
||||
// 不管当前用户的账号是否到期,都根据付款信息重置账号到期时间
|
||||
Account account = accountMapper.selectById(accountId);
|
||||
account.setValidEndTime(currentPeriodEnd * 1000);
|
||||
|
||||
accountMapper.updateById(account);
|
||||
if (account.getValidEndTime().equals(currentPeriodEnd * 1000)){
|
||||
return false;
|
||||
}else {
|
||||
account.setValidEndTime(currentPeriodEnd * 1000);
|
||||
accountMapper.updateById(account);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateUserRoleAndCredits(Long accountId, String type){
|
||||
|
||||
@@ -40,6 +40,7 @@ import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("LoggingSimilarMessage")
|
||||
@Service
|
||||
@@ -484,11 +485,11 @@ public class StripeServiceImpl implements StripeService {
|
||||
subscriptionInfoMapper.insert(subscriptionInfo);
|
||||
|
||||
if (subscriptionInfo.getStatus().equals("active")){
|
||||
log.info("创建订阅更新账号信息");
|
||||
// 更新账号到期时间
|
||||
accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||
|
||||
boolean b = accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||
// 更新账号身份和积分
|
||||
accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval);
|
||||
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval);
|
||||
}
|
||||
}
|
||||
return subscriptionInfo;
|
||||
@@ -541,6 +542,7 @@ public class StripeServiceImpl implements StripeService {
|
||||
if (!subscriptionInfo.getCurrentPeriodEnd().equals(subscription.getCurrentPeriodEnd())){
|
||||
subscriptionInfo.setCurrentPeriodEnd(subscription.getCurrentPeriodEnd());
|
||||
subscriptionInfo.setNextPayDate(DateUtil.changeTimeStampFormat(subscription.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE));
|
||||
log.info("更新订阅更新账号信息");
|
||||
// 更新账号到期时间
|
||||
accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||
// 更新账号身份和积分
|
||||
@@ -548,6 +550,12 @@ public class StripeServiceImpl implements StripeService {
|
||||
log.info("更新 {} 账号到期时间为:{}", subscriptionInfo.getAccountId(), DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE));
|
||||
flag = true;
|
||||
}
|
||||
if (subscriptionInfo.getStatus().equals("active")){
|
||||
// 更新账号到期时间
|
||||
boolean b = accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||
// 更新账号身份和积分
|
||||
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), subscriptionInfo.getType());
|
||||
}
|
||||
if (flag){
|
||||
subscriptionInfo.setUpdateTime(LocalDateTime.now());
|
||||
subscriptionInfoMapper.updateById(subscriptionInfo);
|
||||
@@ -826,10 +834,20 @@ public class StripeServiceImpl implements StripeService {
|
||||
SubscriptionEmailParamsDTO emailParamsDTO = new SubscriptionEmailParamsDTO();
|
||||
QueryWrapper<SubscriptionInfo> qwSI = new QueryWrapper<>();
|
||||
qwSI.eq("subscription_id", subscriptionId);
|
||||
SubscriptionInfo subscriptionInfo = subscriptionInfoMapper.selectOne(qwSI);
|
||||
if (Objects.isNull(subscriptionInfo)) {
|
||||
List<SubscriptionInfo> subscriptionInfoList = subscriptionInfoMapper.selectList(qwSI);
|
||||
SubscriptionInfo subscriptionInfo;
|
||||
if (subscriptionInfoList.isEmpty()){
|
||||
return false;
|
||||
}else {
|
||||
List<SubscriptionInfo> activeSubscriptions = subscriptionInfoList.stream()
|
||||
.filter(subscription -> "active".equals(subscription.getStatus()))
|
||||
.collect(Collectors.toList());
|
||||
if (activeSubscriptions.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
subscriptionInfo = activeSubscriptions.get(0);
|
||||
}
|
||||
|
||||
QueryWrapper<PaymentInfo> qwPI = new QueryWrapper<>();
|
||||
qwPI.eq("order_no", subscriptionInfo.getOrderNo()).orderByDesc("id");
|
||||
List<PaymentInfo> paymentInfos = paymentInfoMapper.selectList(qwPI);
|
||||
|
||||
Reference in New Issue
Block a user