TASK:Stripe订阅,添加月付(经济版)及相应费用、积分的更新
This commit is contained in:
@@ -152,7 +152,7 @@ public interface AccountService extends IService<Account> {
|
||||
|
||||
Boolean collectQuestionnaires(String questionnaireInfo);
|
||||
|
||||
void refreshCreditsWeekly();
|
||||
void refreshCreditsMonthly();
|
||||
|
||||
List<Account> getExpiredUserBySystemUser(Integer systemUserNum);
|
||||
|
||||
@@ -227,7 +227,7 @@ public interface AccountService extends IService<Account> {
|
||||
|
||||
boolean updateAccountValidity(Long accountId, Long currentPeriodEnd);
|
||||
|
||||
void updateUserRoleAndCredits(Long accountId, String type);
|
||||
void updateUserRoleAndCredits(Long accountId, String orderNo);
|
||||
|
||||
Boolean updateUserInfo(UpdateUserInfoDTO updateUserInfoDTO);
|
||||
|
||||
|
||||
@@ -3045,9 +3045,48 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateUserRoleAndCredits(Long accountId, String type){
|
||||
@Override
|
||||
public void updateUserRoleAndCredits(Long accountId, String orderNo){
|
||||
Account account = accountMapper.selectById(accountId);
|
||||
switch (type) {
|
||||
OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(orderNo);
|
||||
if (Objects.nonNull(orderInfo) && !StringUtil.isNullOrEmpty(orderInfo.getTitle())){
|
||||
String description = orderInfo.getTitle();
|
||||
Long productCredits;
|
||||
if (description.equals(ProductEnum.DailySubscription.getName())){
|
||||
productCredits = ProductEnum.DailySubscription.getCredits();
|
||||
account.setSystemUser(3);
|
||||
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_WEEKLY.getValue())));
|
||||
}else if (description.equals(ProductEnum.MonthlySubscription.getName())){
|
||||
productCredits = ProductEnum.MonthlySubscription.getCredits();
|
||||
account.setSystemUser(2);
|
||||
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_MONTHLY.getValue())));
|
||||
} else if (description.equals(ProductEnum.Eco_MonthlySubscription.getName())){
|
||||
productCredits = ProductEnum.Eco_MonthlySubscription.getCredits();
|
||||
account.setSystemUser(2);
|
||||
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_MONTHLY_ECO.getValue())));
|
||||
} else if (description.equals(ProductEnum.AnnualSubscription.getName())){
|
||||
productCredits = ProductEnum.AnnualSubscription.getCredits();
|
||||
account.setSystemUser(1);
|
||||
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_YEARLY.getValue())));
|
||||
}else {
|
||||
log.error("未知订阅类型: {}", description);
|
||||
return;
|
||||
}
|
||||
accountMapper.updateById(account);
|
||||
|
||||
// 先判断是否已添加添加积分变更记录
|
||||
CreditsDetail creditsDetail = creditsService.queryDetailByTaskId(orderNo);
|
||||
if (Objects.isNull(creditsDetail)){
|
||||
creditsService.insertToCreditsDetail(accountId,
|
||||
description + "--Stripe",
|
||||
String.valueOf(productCredits),
|
||||
"positive", orderNo);
|
||||
}
|
||||
} else {
|
||||
log.error("orderNo: {} 无法找到对应的记录", orderNo);
|
||||
}
|
||||
|
||||
/*switch (type) {
|
||||
case "month":
|
||||
account.setSystemUser(2);
|
||||
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_MONTHLY.getValue())));
|
||||
@@ -3060,9 +3099,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
account.setSystemUser(3);
|
||||
account.setCredits(BigDecimal.valueOf(Long.parseLong(CreditsEventsEnum.INIT_WEEKLY.getValue())));
|
||||
break;
|
||||
}
|
||||
|
||||
accountMapper.updateById(account);
|
||||
}*/
|
||||
}
|
||||
|
||||
public Boolean updateUserInfo(UpdateUserInfoDTO updateUserInfoDTO){
|
||||
|
||||
@@ -108,6 +108,10 @@ public class StripeServiceImpl implements StripeService {
|
||||
case "Month":
|
||||
productEnum = ProductEnum.MonthlySubscription;
|
||||
break;
|
||||
case "EcoMonth":
|
||||
productEnum = ProductEnum.Eco_MonthlySubscription;
|
||||
productPurchaseDTO.setSubscribeType("Month");
|
||||
break;
|
||||
case "Year":
|
||||
productEnum = ProductEnum.AnnualSubscription;
|
||||
break;
|
||||
@@ -586,7 +590,7 @@ public class StripeServiceImpl implements StripeService {
|
||||
// 更新账号到期时间
|
||||
boolean b = accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||
// 更新账号身份和积分
|
||||
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval);
|
||||
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), orderNo);
|
||||
}
|
||||
}
|
||||
return subscriptionInfo;
|
||||
@@ -618,7 +622,13 @@ public class StripeServiceImpl implements StripeService {
|
||||
// 获取一天后的时间戳(秒级)
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
currentPeriodEnd = now.plusMonths(1).toEpochSecond();
|
||||
}else if (description.equals(ProductEnum.AnnualSubscription.getName())
|
||||
} else if (description.equals(ProductEnum.Eco_MonthlySubscription.getName())
|
||||
&& amount.equals(ProductEnum.Eco_MonthlySubscription.getPrice() * 100)){
|
||||
interval = "month";
|
||||
// 获取一天后的时间戳(秒级)
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
currentPeriodEnd = now.plusMonths(1).toEpochSecond();
|
||||
} else if (description.equals(ProductEnum.AnnualSubscription.getName())
|
||||
&& amount.equals(ProductEnum.AnnualSubscription.getPrice() * 100)){
|
||||
interval = "year";
|
||||
// 获取一天后的时间戳(秒级)
|
||||
@@ -643,7 +653,7 @@ public class StripeServiceImpl implements StripeService {
|
||||
// 更新账号到期时间
|
||||
boolean b = accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||
// 更新账号身份和积分
|
||||
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval);
|
||||
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), orderNo);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
@@ -700,7 +710,7 @@ public class StripeServiceImpl implements StripeService {
|
||||
// 更新账号到期时间
|
||||
accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||
// 更新账号身份和积分
|
||||
accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), subscriptionInfo.getType());
|
||||
accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), subscriptionInfo.getOrderNo());
|
||||
log.info("更新 {} 账号到期时间为:{}", subscriptionInfo.getAccountId(), DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy_EEEE));
|
||||
flag = true;
|
||||
}
|
||||
@@ -708,7 +718,7 @@ public class StripeServiceImpl implements StripeService {
|
||||
// 更新账号到期时间
|
||||
boolean b = accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
|
||||
// 更新账号身份和积分
|
||||
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), subscriptionInfo.getType());
|
||||
if (b) accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), subscriptionInfo.getOrderNo());
|
||||
}
|
||||
if (flag){
|
||||
subscriptionInfo.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
Reference in New Issue
Block a user