BUGFIX:用户订阅后更新用户身份和积分
This commit is contained in:
@@ -218,4 +218,8 @@ public interface AccountService extends IService<Account> {
|
|||||||
Boolean unbindWeChat();
|
Boolean unbindWeChat();
|
||||||
|
|
||||||
Boolean unbindGoogle();
|
Boolean unbindGoogle();
|
||||||
|
|
||||||
|
void updateAccountValidity(Long accountId, Long currentPeriodEnd);
|
||||||
|
|
||||||
|
void updateUserRoleAndCredits(Long accountId, String type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2591,4 +2591,32 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
accountMapper.updateById(account);
|
accountMapper.updateById(account);
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateAccountValidity(Long accountId, Long currentPeriodEnd){
|
||||||
|
// 不管当前用户的账号是否到期,都根据付款信息重置账号到期时间
|
||||||
|
Account account = accountMapper.selectById(accountId);
|
||||||
|
account.setValidEndTime(currentPeriodEnd * 1000);
|
||||||
|
|
||||||
|
accountMapper.updateById(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateUserRoleAndCredits(Long accountId, String type){
|
||||||
|
Account account = accountMapper.selectById(accountId);
|
||||||
|
switch (type) {
|
||||||
|
case "month":
|
||||||
|
account.setSystemUser(2);
|
||||||
|
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_MONTHLY.getValue())));
|
||||||
|
break;
|
||||||
|
case "year":
|
||||||
|
account.setSystemUser(1);
|
||||||
|
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_YEARLY.getValue())));
|
||||||
|
break;
|
||||||
|
case "day":
|
||||||
|
account.setSystemUser(3);
|
||||||
|
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_WEEKLY.getValue())));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
accountMapper.updateById(account);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ public class StripeServiceImpl implements StripeService {
|
|||||||
private CreditsService creditsService;
|
private CreditsService creditsService;
|
||||||
@Resource
|
@Resource
|
||||||
private RefundInfoService refundInfoService;
|
private RefundInfoService refundInfoService;
|
||||||
|
@Resource
|
||||||
|
private AccountService accountService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AccountMapper accountMapper;
|
private AccountMapper accountMapper;
|
||||||
@@ -368,6 +370,7 @@ public class StripeServiceImpl implements StripeService {
|
|||||||
orderInfoService.updateById(orderInfo);
|
orderInfoService.updateById(orderInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("回调事件 {} 处理完成", event.getType());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,7 +469,10 @@ public class StripeServiceImpl implements StripeService {
|
|||||||
subscriptionInfoMapper.insert(subscriptionInfo);
|
subscriptionInfoMapper.insert(subscriptionInfo);
|
||||||
|
|
||||||
// 更新账号到期时间
|
// 更新账号到期时间
|
||||||
updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||||
|
|
||||||
|
// 更新账号身份和积分
|
||||||
|
accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval);
|
||||||
}
|
}
|
||||||
return subscriptionInfo;
|
return subscriptionInfo;
|
||||||
}
|
}
|
||||||
@@ -519,7 +525,9 @@ public class StripeServiceImpl implements StripeService {
|
|||||||
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));
|
||||||
// 更新账号到期时间
|
// 更新账号到期时间
|
||||||
updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||||
|
// 更新账号身份和积分
|
||||||
|
accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), subscriptionInfo.getType());
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -530,14 +538,6 @@ public class StripeServiceImpl implements StripeService {
|
|||||||
return subscriptionInfo;
|
return subscriptionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAccountValidity(Long accountId, Long currentPeriodEnd){
|
|
||||||
// 不管当前用户的账号是否到期,都根据付款信息重置账号到期时间
|
|
||||||
com.ai.da.mapper.primary.entity.Account account = accountMapper.selectById(accountId);
|
|
||||||
account.setValidEndTime(currentPeriodEnd * 1000);
|
|
||||||
|
|
||||||
accountMapper.updateById(account);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 取消连续订阅 将订阅从pause状态转为cancel状态(使用定时器,定期检索DB中,过期且不续订的订阅)
|
// 取消连续订阅 将订阅从pause状态转为cancel状态(使用定时器,定期检索DB中,过期且不续订的订阅)
|
||||||
public void cancelSubscription(String subscriptionId, String cancelReason) {
|
public void cancelSubscription(String subscriptionId, String cancelReason) {
|
||||||
Stripe.apiKey = privateKey;
|
Stripe.apiKey = privateKey;
|
||||||
|
|||||||
Reference in New Issue
Block a user