From 2988a3b34ec2141e7c7262514e5be15b166dd2bd Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 9 Jan 2025 13:50:08 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9code-create=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=20sql=E8=AF=AD=E5=8F=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/AccountServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 09029be7..690e4e13 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -1227,7 +1227,7 @@ public class AccountServiceImpl extends ServiceImpl impl private static final String QUERY_CUSTOMER_EMAIL = "SELECT username, email, country FROM pmr_wc_customer_lookup " + "WHERE customer_id = ? "; private static final String UPDATE_ORDER_STATUS = "UPDATE pmr_wc_order_stats " + - "SET status = 'wc-complete' , date_completed = ? " + + "SET status = 'wc-completed' , date_completed = ? " + "WHERE order_id = ?"; private static final DataSource dataSource; From 9f4ab20b9d3e2253a13b1921bb653eabda2505f6 Mon Sep 17 00:00:00 2001 From: xupei Date: Wed, 5 Feb 2025 10:49:10 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E6=B5=8B=E8=AF=95=20code-create=20DB?= =?UTF-8?q?=E6=9C=80=E5=A4=A7=E8=BF=9E=E6=8E=A5=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/AccountServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 690e4e13..93299562 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -1243,7 +1243,7 @@ public class AccountServiceImpl extends ServiceImpl impl config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); - config.addDataSourceProperty("maxLifetime", 300000); + config.addDataSourceProperty("maxLifetime", 60000); dataSource = new HikariDataSource(config); } From d840185ec78cf73b6931343065bdd5c5d25fc098 Mon Sep 17 00:00:00 2001 From: xupei Date: Wed, 5 Feb 2025 10:56:17 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E6=B5=8B=E8=AF=95=20code-create=20DB?= =?UTF-8?q?=E6=9C=80=E5=A4=A7=E8=BF=9E=E6=8E=A5=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/AccountServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index 93299562..27279068 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -1243,7 +1243,7 @@ public class AccountServiceImpl extends ServiceImpl impl config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); - config.addDataSourceProperty("maxLifetime", 60000); + config.addDataSourceProperty("maxLifetime", 50000); dataSource = new HikariDataSource(config); } From e587ad3ca145476957a3105d24aab3c358044ddf Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 09:53:03 +0800 Subject: [PATCH 04/13] =?UTF-8?q?1=E3=80=81=E6=94=AF=E4=BB=98=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=88=87=E6=8D=A2=E4=B8=BAprod=202=E3=80=81=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E9=80=9A=E7=9F=A5=E5=AF=B9=E8=B1=A1=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?Kim=203=E3=80=81=E6=89=93=E5=BC=80=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/common/task/AccountTask.java | 8 +++--- .../com/ai/da/common/task/PaymentTask.java | 2 +- .../com/ai/da/common/utils/SendEmailUtil.java | 10 ++++--- .../da/service/impl/AffiliateServiceImpl.java | 8 +++--- src/main/resources/payment.properties | 28 +++++++++---------- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/ai/da/common/task/AccountTask.java b/src/main/java/com/ai/da/common/task/AccountTask.java index b4aacac8..1deeb4c2 100644 --- a/src/main/java/com/ai/da/common/task/AccountTask.java +++ b/src/main/java/com/ai/da/common/task/AccountTask.java @@ -31,14 +31,14 @@ public class AccountTask { accountService.refreshCreditsWeekly(); } -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void getPaidUser() { // 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单 accountService.extendValidityForCC(); } // 每天凌晨0点执行一次 -// @Scheduled(cron = "0 0 0 * * ?") + @Scheduled(cron = "0 0 0 * * ?") public void cancelActivityBenefits() { // 1、查询当前所有参与了活动且过期的用户 List accountList = accountService.getExpiredUserBySystemUser(4); @@ -51,7 +51,7 @@ public class AccountTask { } // 每天检测正式用户到期情况,每天凌晨0点执行 -// @Scheduled(cron = "0 0 0 * * ?") + @Scheduled(cron = "0 0 0 * * ?") public void paidUserToVisitor() { // 1、查询当前已过期正式用户或试用用户 List accountList = accountService.getExpiredUserBySystemUser(1); @@ -68,7 +68,7 @@ public class AccountTask { /** * 将Code-Create上注册的用户添加为AiDA的游客 */ -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void registerUserToVisitor() { accountService.registerUserToVisitor(); } diff --git a/src/main/java/com/ai/da/common/task/PaymentTask.java b/src/main/java/com/ai/da/common/task/PaymentTask.java index f926e6f3..01c29d2f 100644 --- a/src/main/java/com/ai/da/common/task/PaymentTask.java +++ b/src/main/java/com/ai/da/common/task/PaymentTask.java @@ -45,7 +45,7 @@ public class PaymentTask { @Resource private PayPalCheckoutService payPalCheckoutService; - // @Scheduled(cron = "0/30 * * * * ?") + @Scheduled(cron = "0/30 * * * * ?") public void orderConfirmForPaypal() throws SerializeException { // log.info("PayPal orderConfirm 被执行......"); diff --git a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java index 7770019e..e5162afa 100644 --- a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java +++ b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java @@ -635,8 +635,10 @@ public class SendEmailUtil { SendEmailResponse resp = client.SendEmail(req); log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp)); } catch (TencentCloudSDKException e) { - log.info("邮件发送失败###{}", e.toString()); - throw new BusinessException("failed.to.send.mail"); + log.info("邮件发送至{} 发送失败###{}", receiverAddress, e.toString()); + log.error(e.getMessage()); + // 这里不再抛出异常 失败就不发,保证后续正常运行 +// throw new BusinessException("failed.to.send.mail"); } } @@ -835,9 +837,9 @@ public class SendEmailUtil { public static void subscriptionEmailReminder(String type, SubscriptionEmailParamsDTO subscriptionEmailParamsDTO, String language, String receiverAddress) { try { -// String merchantEmail = "kimwong@code-create.com.hk"; + String merchantEmail = "kimwong@code-create.com.hk"; String developer = "xupei3360@163.com"; - String[] receiverEmail = {/*merchantEmail, */developer}; + String[] receiverEmail = {merchantEmail, developer}; Credential cred = new Credential(SECRET_ID, SECRET_KEy); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); diff --git a/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java b/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java index 27a8ac6a..509325a0 100644 --- a/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java @@ -76,9 +76,9 @@ public class AffiliateServiceImpl extends ServiceImpl Date: Thu, 6 Feb 2025 10:04:30 +0800 Subject: [PATCH 05/13] =?UTF-8?q?TASK:=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=BC=80=E5=90=AF;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/common/config/MyTaskScheduler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index 3e73536e..7eb5d0d2 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -51,7 +51,7 @@ public class MyTaskScheduler { // 定时任务,每十五天执行一次 // @Scheduled(cron = "0 0 0 ? * MON") -// @Scheduled(cron = "0 0 0 */15 * ?") + @Scheduled(cron = "0 0 0 */15 * ?") public void checkExpiry() { // 检测正式用户是否快要过期 QueryWrapper qw = new QueryWrapper<>(); @@ -85,7 +85,7 @@ public class MyTaskScheduler { } } } -// @Scheduled(cron = "0 0 9 * * ?") + @Scheduled(cron = "0 0 9 * * ?") public void sendTrialOrderExcelToManagements() { // 获取前一天日期 LocalDate yesterday = LocalDate.now().minusDays(1); From a9b01566e1e6d8dda51b617fc1deb9a2586f56ea Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 14:09:15 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/service/CreditsService.java | 2 + .../da/service/impl/CreditsServiceImpl.java | 6 +++ .../ai/da/service/impl/StripeServiceImpl.java | 46 +++++++++++-------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ai/da/service/CreditsService.java b/src/main/java/com/ai/da/service/CreditsService.java index 62d9e5e4..a3030057 100644 --- a/src/main/java/com/ai/da/service/CreditsService.java +++ b/src/main/java/com/ai/da/service/CreditsService.java @@ -36,4 +36,6 @@ public interface CreditsService extends IService { void preInsert(Long accountId, String changeEventName, String taskId, Boolean isPreInsert, String changedCredits); void updateChangedCredits(String accountId, String taskId); + + CreditsDetail queryDetailByTaskId(String taskId); } diff --git a/src/main/java/com/ai/da/service/impl/CreditsServiceImpl.java b/src/main/java/com/ai/da/service/impl/CreditsServiceImpl.java index 5c24211c..959461c6 100644 --- a/src/main/java/com/ai/da/service/impl/CreditsServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CreditsServiceImpl.java @@ -318,4 +318,10 @@ public class CreditsServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("task_id", taskId); + return baseMapper.selectOne(queryWrapper); + } + } diff --git a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java index f4699890..e81277a3 100644 --- a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java @@ -9,10 +9,7 @@ import com.ai.da.common.utils.SendEmailUtil; import com.ai.da.mapper.primary.AccountMapper; import com.ai.da.mapper.primary.PaymentInfoMapper; import com.ai.da.mapper.primary.SubscriptionInfoMapper; -import com.ai.da.mapper.primary.entity.OrderInfo; -import com.ai.da.mapper.primary.entity.PaymentInfo; -import com.ai.da.mapper.primary.entity.RefundInfo; -import com.ai.da.mapper.primary.entity.SubscriptionInfo; +import com.ai.da.mapper.primary.entity.*; import com.ai.da.model.dto.ProductPurchaseDTO; import com.ai.da.model.dto.SubscriptionEmailParamsDTO; import com.ai.da.service.*; @@ -24,6 +21,7 @@ import com.stripe.Stripe; import com.stripe.exception.SignatureVerificationException; import com.stripe.exception.StripeException; import com.stripe.model.*; +import com.stripe.model.Product; import com.stripe.model.checkout.Session; import com.stripe.net.Webhook; import com.stripe.param.*; @@ -140,6 +138,9 @@ public class StripeServiceImpl implements StripeService { // one-time 手动创建发票;订阅会自动创建invoice sessionBuilder.setInvoiceCreation(SessionCreateParams.InvoiceCreation.builder().setEnabled(Boolean.TRUE).build()); } +// sessionBuilder.setPaymentMethodConfiguration("pmc_1QIKyq02n1TEydyNKVEYvhW7"); +// sessionBuilder.addPaymentMethodType(SessionCreateParams.PaymentMethodType.ALIPAY); +// sessionBuilder.addPaymentMethodType(SessionCreateParams.PaymentMethodType.CARD); sessionBuilder.setCustomer(customerId); sessionBuilder.setSuccessUrl(productPurchaseDTO.getReturnUrl());//可自定义成功页面 sessionBuilder.setLocale(account.getLanguage().equals("CHINESE_SIMPLIFIED") ? SessionCreateParams.Locale.ZH : SessionCreateParams.Locale.EN); @@ -151,7 +152,12 @@ public class StripeServiceImpl implements StripeService { sessionBuilder.putMetadata("orderId", orderId); //通过订单号关联用于检索支付信息(可选) Session session = Session.create(sessionBuilder.build()); - log.info("sessionId:" + session.getId()); //退款方式1:拿到sessionId入库,退款的时候根据这个id找到PaymentIntent的id然后发起退款 + List paymentMethodTypes = session.getPaymentMethodTypes(); + log.info("paymentMethodTypes: {}", paymentMethodTypes); + + Session.PaymentMethodConfigurationDetails paymentMethodConfigurationDetails = session.getPaymentMethodConfigurationDetails(); + log.info("paymentMethodConfigurationDetails ID: {}", paymentMethodConfigurationDetails.getId()); + log.info("sessionId:{}", session.getId()); //退款方式1:拿到sessionId入库,退款的时候根据这个id找到PaymentIntent的id然后发起退款 // 更新order信息 orderInfoService.updateOrderNoById(orderInfo.getId(), orderId); @@ -387,22 +393,26 @@ public class StripeServiceImpl implements StripeService { // 当订单状态处于未支付或超时已关闭时,更新订单状态,其他状态均不更新订单状态 if (!OrderStatusEnum.NOT_PAY.getType().equals(orderStatus) && !OrderStatusEnum.TIMEOUT_CLOSED.getType().equals(orderStatus)) { log.info("订单状态 : {}", orderStatus); - return; + }else { + //更新订单状态 + orderInfoService.updateStatusByOrderNo(orderId, OrderStatusEnum.SUCCESS); + log.info("Stripe 订单:{} 状态更新成功", orderId); } - //更新订单状态 - orderInfoService.updateStatusByOrderNo(orderId, OrderStatusEnum.SUCCESS); - log.info("Stripe 订单:{} 状态更新成功", orderId); if (orderByOrderNo.getTitle().startsWith("积分购买")){ - float quantity = totalAmount / ProductEnum.CreditsProduct.getPrice(); - // 更新积分 - creditsService.buyCredits(orderByOrderNo.getAccountId(), quantity); - // 添加积分变更记录 - creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(), - CreditsEventsEnum.BUY_CREDITS.getName() + "--Stripe", - String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)), - "positive", orderId); - log.info("用户:{} 积分信息更新成功", orderByOrderNo.getAccountId()); + // 查询当前订单的积分是否已添加 + CreditsDetail creditsDetail = creditsService.queryDetailByTaskId(orderId); + if (Objects.isNull(creditsDetail)){ + float quantity = totalAmount / ProductEnum.CreditsProduct.getPrice(); + // 更新积分 + creditsService.buyCredits(orderByOrderNo.getAccountId(), quantity); + // 添加积分变更记录 + creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(), + CreditsEventsEnum.BUY_CREDITS.getName() + "--Stripe", + String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)), + "positive", orderId); + log.info("用户:{} 积分信息更新成功", orderByOrderNo.getAccountId()); + } } } catch (Exception e) { log.info(e.getMessage()); From 433d8a460e6c2c5142bc857b51a7a2c8ff3ae577 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 14:22:27 +0800 Subject: [PATCH 07/13] to dev --- .../java/com/ai/da/common/config/MyTaskScheduler.java | 4 ++-- src/main/java/com/ai/da/common/task/AccountTask.java | 10 +++++----- src/main/java/com/ai/da/common/task/PaymentTask.java | 8 ++++---- src/main/resources/application.properties | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index 7eb5d0d2..3e73536e 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -51,7 +51,7 @@ public class MyTaskScheduler { // 定时任务,每十五天执行一次 // @Scheduled(cron = "0 0 0 ? * MON") - @Scheduled(cron = "0 0 0 */15 * ?") +// @Scheduled(cron = "0 0 0 */15 * ?") public void checkExpiry() { // 检测正式用户是否快要过期 QueryWrapper qw = new QueryWrapper<>(); @@ -85,7 +85,7 @@ public class MyTaskScheduler { } } } - @Scheduled(cron = "0 0 9 * * ?") +// @Scheduled(cron = "0 0 9 * * ?") public void sendTrialOrderExcelToManagements() { // 获取前一天日期 LocalDate yesterday = LocalDate.now().minusDays(1); diff --git a/src/main/java/com/ai/da/common/task/AccountTask.java b/src/main/java/com/ai/da/common/task/AccountTask.java index 1deeb4c2..e74612a0 100644 --- a/src/main/java/com/ai/da/common/task/AccountTask.java +++ b/src/main/java/com/ai/da/common/task/AccountTask.java @@ -31,14 +31,14 @@ public class AccountTask { accountService.refreshCreditsWeekly(); } - @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes +// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void getPaidUser() { // 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单 accountService.extendValidityForCC(); } // 每天凌晨0点执行一次 - @Scheduled(cron = "0 0 0 * * ?") +// @Scheduled(cron = "0 0 0 * * ?") public void cancelActivityBenefits() { // 1、查询当前所有参与了活动且过期的用户 List accountList = accountService.getExpiredUserBySystemUser(4); @@ -51,7 +51,7 @@ public class AccountTask { } // 每天检测正式用户到期情况,每天凌晨0点执行 - @Scheduled(cron = "0 0 0 * * ?") +// @Scheduled(cron = "0 0 0 * * ?") public void paidUserToVisitor() { // 1、查询当前已过期正式用户或试用用户 List accountList = accountService.getExpiredUserBySystemUser(1); @@ -68,12 +68,12 @@ public class AccountTask { /** * 将Code-Create上注册的用户添加为AiDA的游客 */ - @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes +// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void registerUserToVisitor() { accountService.registerUserToVisitor(); } - @Scheduled(cron = "0 0 0 1 * ?") +// @Scheduled(cron = "0 0 0 1 * ?") // 每月初刷新所有用户用户名剩余修改次数 public void resetUsernameModifyTimes(){ log.info("重置所有用户的用户名修改次数"); diff --git a/src/main/java/com/ai/da/common/task/PaymentTask.java b/src/main/java/com/ai/da/common/task/PaymentTask.java index 01c29d2f..e08be0e8 100644 --- a/src/main/java/com/ai/da/common/task/PaymentTask.java +++ b/src/main/java/com/ai/da/common/task/PaymentTask.java @@ -45,7 +45,7 @@ public class PaymentTask { @Resource private PayPalCheckoutService payPalCheckoutService; - @Scheduled(cron = "0/30 * * * * ?") +// @Scheduled(cron = "0/30 * * * * ?") public void orderConfirmForPaypal() throws SerializeException { // log.info("PayPal orderConfirm 被执行......"); @@ -85,7 +85,7 @@ public class PaymentTask { } // 提前7天向用户发送提醒邮件,每天早上8点执行 - @Scheduled(cron = "0 0 8 * * ?") +// @Scheduled(cron = "0 0 8 * * ?") public void subscriptionReminder(){ stripeService.subscriptionReminder(); } @@ -102,13 +102,13 @@ public class PaymentTask { } - @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes +// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void updateAffiliateInfoWithPayment(){ // log.info("佣金计算定时器"); affiliateService.updateAffiliateInfoWithPayment(); } - @Scheduled(cron = "0 0 8 28-31 * ?") +// @Scheduled(cron = "0 0 8 28-31 * ?") public void commissionSummaryReminder(){ // 每个月末的最后一天的早上八点执行 LocalDate today = LocalDate.now(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 605b072c..974fee23 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,4 +5,4 @@ #spring.profiles.active=prod #����application-dev�ļ�(��������) -spring.profiles.active=prod +spring.profiles.active=dev From 91189968e9003f5c61db4f4982474a0365ac1a50 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 14:37:06 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E5=9C=A8dev=E6=B5=8B=E8=AF=95=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E7=8E=AF=E5=A2=83=E7=9A=84Stripe=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/payment.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/payment.properties b/src/main/resources/payment.properties index 0a544f3c..e1565bc4 100644 --- a/src/main/resources/payment.properties +++ b/src/main/resources/payment.properties @@ -37,4 +37,5 @@ paypal.webhook_id=1D107312EX592781K # kim - live stripe.private-key=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 -stripe.webhook-sign-secret=whsec_hhGDgdelQRHSg4LmChtQe41crj41eb11 \ No newline at end of file +#stripe.webhook-sign-secret=whsec_hhGDgdelQRHSg4LmChtQe41crj41eb11 +stripe.webhook-sign-secret=whsec_cFUtjUOo8wnrIKZmt4GNvt7ZY1bOfrYr From dba5625446f11758e7656c7ab02e60b906a01e90 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 14:42:45 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=E5=8C=BA=E5=88=86=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E5=88=86=E6=94=AF=E4=B8=8E=E6=B5=8B=E8=AF=95=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/payment.properties | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/resources/payment.properties b/src/main/resources/payment.properties index e1565bc4..6bdc0f6b 100644 --- a/src/main/resources/payment.properties +++ b/src/main/resources/payment.properties @@ -37,5 +37,7 @@ paypal.webhook_id=1D107312EX592781K # kim - live stripe.private-key=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 -#stripe.webhook-sign-secret=whsec_hhGDgdelQRHSg4LmChtQe41crj41eb11 -stripe.webhook-sign-secret=whsec_cFUtjUOo8wnrIKZmt4GNvt7ZY1bOfrYr +# 正式支付环境下生产分支端点 +stripe.webhook-sign-secret=whsec_hhGDgdelQRHSg4LmChtQe41crj41eb11 +# 正式支付环境下测试分支端点 +#stripe.webhook-sign-secret=whsec_cFUtjUOo8wnrIKZmt4GNvt7ZY1bOfrYr From c3259274183e4c8cfb65f7050720fd69a2a4910b Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 14:46:50 +0800 Subject: [PATCH 10/13] to prod --- .../java/com/ai/da/common/config/MyTaskScheduler.java | 4 ++-- src/main/java/com/ai/da/common/task/AccountTask.java | 10 +++++----- src/main/java/com/ai/da/common/task/PaymentTask.java | 8 ++++---- src/main/resources/application.properties | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index 3e73536e..7eb5d0d2 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -51,7 +51,7 @@ public class MyTaskScheduler { // 定时任务,每十五天执行一次 // @Scheduled(cron = "0 0 0 ? * MON") -// @Scheduled(cron = "0 0 0 */15 * ?") + @Scheduled(cron = "0 0 0 */15 * ?") public void checkExpiry() { // 检测正式用户是否快要过期 QueryWrapper qw = new QueryWrapper<>(); @@ -85,7 +85,7 @@ public class MyTaskScheduler { } } } -// @Scheduled(cron = "0 0 9 * * ?") + @Scheduled(cron = "0 0 9 * * ?") public void sendTrialOrderExcelToManagements() { // 获取前一天日期 LocalDate yesterday = LocalDate.now().minusDays(1); diff --git a/src/main/java/com/ai/da/common/task/AccountTask.java b/src/main/java/com/ai/da/common/task/AccountTask.java index e74612a0..1deeb4c2 100644 --- a/src/main/java/com/ai/da/common/task/AccountTask.java +++ b/src/main/java/com/ai/da/common/task/AccountTask.java @@ -31,14 +31,14 @@ public class AccountTask { accountService.refreshCreditsWeekly(); } -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void getPaidUser() { // 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单 accountService.extendValidityForCC(); } // 每天凌晨0点执行一次 -// @Scheduled(cron = "0 0 0 * * ?") + @Scheduled(cron = "0 0 0 * * ?") public void cancelActivityBenefits() { // 1、查询当前所有参与了活动且过期的用户 List accountList = accountService.getExpiredUserBySystemUser(4); @@ -51,7 +51,7 @@ public class AccountTask { } // 每天检测正式用户到期情况,每天凌晨0点执行 -// @Scheduled(cron = "0 0 0 * * ?") + @Scheduled(cron = "0 0 0 * * ?") public void paidUserToVisitor() { // 1、查询当前已过期正式用户或试用用户 List accountList = accountService.getExpiredUserBySystemUser(1); @@ -68,12 +68,12 @@ public class AccountTask { /** * 将Code-Create上注册的用户添加为AiDA的游客 */ -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void registerUserToVisitor() { accountService.registerUserToVisitor(); } -// @Scheduled(cron = "0 0 0 1 * ?") + @Scheduled(cron = "0 0 0 1 * ?") // 每月初刷新所有用户用户名剩余修改次数 public void resetUsernameModifyTimes(){ log.info("重置所有用户的用户名修改次数"); diff --git a/src/main/java/com/ai/da/common/task/PaymentTask.java b/src/main/java/com/ai/da/common/task/PaymentTask.java index e08be0e8..223757f7 100644 --- a/src/main/java/com/ai/da/common/task/PaymentTask.java +++ b/src/main/java/com/ai/da/common/task/PaymentTask.java @@ -45,7 +45,7 @@ public class PaymentTask { @Resource private PayPalCheckoutService payPalCheckoutService; -// @Scheduled(cron = "0/30 * * * * ?") + @Scheduled(cron = "0/30 * * * * ?") public void orderConfirmForPaypal() throws SerializeException { // log.info("PayPal orderConfirm 被执行......"); @@ -85,7 +85,7 @@ public class PaymentTask { } // 提前7天向用户发送提醒邮件,每天早上8点执行 -// @Scheduled(cron = "0 0 8 * * ?") + @Scheduled(cron = "0 0 8 * * ?") public void subscriptionReminder(){ stripeService.subscriptionReminder(); } @@ -102,13 +102,13 @@ public class PaymentTask { } -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void updateAffiliateInfoWithPayment(){ // log.info("佣金计算定时器"); affiliateService.updateAffiliateInfoWithPayment(); } -// @Scheduled(cron = "0 0 8 28-31 * ?") + @Scheduled(cron = "0 0 8 28-31 * ?") public void commissionSummaryReminder(){ // 每个月末的最后一天的早上八点执行 LocalDate today = LocalDate.now(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 974fee23..8550475d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ #spring.profiles.active=test #����application-prod�ļ�(��������) -#spring.profiles.active=prod +spring.profiles.active=prod #����application-dev�ļ�(��������) -spring.profiles.active=dev +#spring.profiles.active=dev From d648a79ec47f19d8163a0cb913f1584505188515 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 16:36:07 +0800 Subject: [PATCH 11/13] =?UTF-8?q?BUGFIX:=20=E8=AE=A2=E9=98=85=E4=BB=98?= =?UTF-8?q?=E6=AC=BE=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=BB=8D=E6=9C=89=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/service/impl/StripeServiceImpl.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java index e81277a3..75d2d182 100644 --- a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java @@ -356,6 +356,11 @@ public class StripeServiceImpl implements StripeService { // 发送续订失败邮件 response = sendRenewalFailEmail(invoice.getId(), null, paymentInfo.getOrderNo()); + }else { + // 新增支付信息 + PaymentInfo paymentInfoFail = paymentInfoService.createOrUpdatePaymentInfoForStripe(invoice); + // 发送新订阅失败邮件 + response = sendEmail(paymentInfoFail.getOrderNo()); } } }else if (stripeObject instanceof Charge) { @@ -478,11 +483,13 @@ public class StripeServiceImpl implements StripeService { subscriptionInfo.setCreateTime(LocalDateTime.now()); subscriptionInfoMapper.insert(subscriptionInfo); - // 更新账号到期时间 - accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd()); + if (subscriptionInfo.getStatus().equals("active")){ + // 更新账号到期时间 + accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd()); - // 更新账号身份和积分 - accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval); + // 更新账号身份和积分 + accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval); + } } return subscriptionInfo; } @@ -534,11 +541,13 @@ 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)); - // 更新账号到期时间 - 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)); + if (subscription.getStatus().equals("active")){ + // 更新账号到期时间 + 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)); + } flag = true; } if (flag){ From 4c738cc61d05cc177911211e57b950c4bc1546dd Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 17:35:35 +0800 Subject: [PATCH 12/13] =?UTF-8?q?BUGFIX:=20=E8=BF=94=E5=9B=9E=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E8=AE=A2=E9=98=85=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/common/utils/SendEmailUtil.java | 2 +- .../ai/da/service/impl/StripeServiceImpl.java | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java index e5162afa..3fa750e2 100644 --- a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java +++ b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java @@ -1012,7 +1012,7 @@ public class SendEmailUtil { template.setTemplateID(CREDITS_PURCHASE_MERCHANT); JSONObject jsonObject = new JSONObject(); // 设置试用订单相关数据 - jsonObject.put("userName", username); + jsonObject.put("username", username); jsonObject.put("quantity", quantity); jsonObject.put("totalFee", amount); diff --git a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java index 75d2d182..bf3d23c0 100644 --- a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java @@ -515,7 +515,7 @@ public class StripeServiceImpl implements StripeService { public SubscriptionInfo getLatestSubscriptionInfoByAccountId(Long accountId){ QueryWrapper qw = new QueryWrapper<>(); - qw.eq("account_id", accountId); + qw.eq("account_id", accountId).orderByDesc("id"); List subscriptionInfos = subscriptionInfoMapper.selectList(qw); if (subscriptionInfos.isEmpty()){ return null; @@ -541,13 +541,11 @@ 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)); - if (subscription.getStatus().equals("active")){ - // 更新账号到期时间 - 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)); - } + // 更新账号到期时间 + 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)); flag = true; } if (flag){ @@ -560,8 +558,8 @@ public class StripeServiceImpl implements StripeService { // 取消连续订阅 将订阅从pause状态转为cancel状态(使用定时器,定期检索DB中,过期且不续订的订阅) public void cancelSubscription(String subscriptionId, String cancelReason) { Stripe.apiKey = privateKey; + log.info("cancel subscription"); Long accountId = UserContext.getUserHolder().getId(); - log.info("用户 {} 申请取消连续订阅 {}", accountId, subscriptionId); com.ai.da.mapper.primary.entity.Account account = accountMapper.selectById(accountId); List subscriptions = getSubscription(account.getUserName(), account.getUserEmail()); // 获取status = active的订阅 @@ -570,7 +568,7 @@ public class StripeServiceImpl implements StripeService { try { Subscription cancel = subscription.cancel(); cancel.getStatus(); - + log.info("用户 {} 申请取消连续订阅 {}", accountId, subscriptionId); // 更新数据库 updateCancelReason(subscriptionId, cancelReason); } catch (StripeException e) { From ba3c98771fe27201eb7150cf0672f4bc0062ba2d Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 6 Feb 2025 18:39:06 +0800 Subject: [PATCH 13/13] =?UTF-8?q?BUGFIX:=20=E6=96=B0=E5=BB=BA=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E6=97=B6=E6=9B=B4=E6=96=B0=E8=AE=A2=E9=98=85=E4=B8=8D?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B4=A6=E5=8F=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/service/AccountService.java | 2 +- .../da/service/impl/AccountServiceImpl.java | 12 +++++--- .../ai/da/service/impl/StripeServiceImpl.java | 28 +++++++++++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/ai/da/service/AccountService.java b/src/main/java/com/ai/da/service/AccountService.java index 531c3fc7..59fdf023 100644 --- a/src/main/java/com/ai/da/service/AccountService.java +++ b/src/main/java/com/ai/da/service/AccountService.java @@ -220,7 +220,7 @@ public interface AccountService extends IService { Boolean unbindGoogle(); - void updateAccountValidity(Long accountId, Long currentPeriodEnd); + boolean updateAccountValidity(Long accountId, Long currentPeriodEnd); void updateUserRoleAndCredits(Long accountId, String type); diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index f6bc567c..0ad0b784 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -2744,12 +2744,16 @@ public class AccountServiceImpl extends ServiceImpl 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){ diff --git a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java index bf3d23c0..80d4dd63 100644 --- a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java @@ -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 qwSI = new QueryWrapper<>(); qwSI.eq("subscription_id", subscriptionId); - SubscriptionInfo subscriptionInfo = subscriptionInfoMapper.selectOne(qwSI); - if (Objects.isNull(subscriptionInfo)) { + List subscriptionInfoList = subscriptionInfoMapper.selectList(qwSI); + SubscriptionInfo subscriptionInfo; + if (subscriptionInfoList.isEmpty()){ return false; + }else { + List activeSubscriptions = subscriptionInfoList.stream() + .filter(subscription -> "active".equals(subscription.getStatus())) + .collect(Collectors.toList()); + if (activeSubscriptions.isEmpty()){ + return false; + } + subscriptionInfo = activeSubscriptions.get(0); } + QueryWrapper qwPI = new QueryWrapper<>(); qwPI.eq("order_no", subscriptionInfo.getOrderNo()).orderByDesc("id"); List paymentInfos = paymentInfoMapper.selectList(qwPI);