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