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 2d7a9e74..8e9ecb4f 100644 --- a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java +++ b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java @@ -17,17 +17,38 @@ import com.tencentcloudapi.ses.v20201002.models.SendEmailRequest; import com.tencentcloudapi.ses.v20201002.models.SendEmailResponse; import com.tencentcloudapi.ses.v20201002.models.Template; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; +import jakarta.annotation.PostConstruct; + +import java.util.ArrayList; import java.util.Base64; import java.util.Date; +import java.util.List; import java.util.Objects; /** * 邮件发送类 */ @Slf4j +@Component public class SendEmailUtil { + @Value("${merchant.email:}") + private String merchantEmailInstance; + @Value("${developer.email: xupei@code-create.com.hk}") + private String developerEmailInstance; + + private static String merchantEmail; + private static String developerEmail; + + @PostConstruct + public void init() { + merchantEmail = merchantEmailInstance; + developerEmail = developerEmailInstance; + } + /** * 秘钥id */ @@ -765,9 +786,7 @@ public class SendEmailUtil { public static boolean subscriptionEmailReminder(String type, SubscriptionEmailParamsDTO subscriptionEmailParamsDTO, String language, String receiverAddress) { try { - String merchantEmail = "kimwong@code-create.com.hk"; - String developer = "xupei3360@163.com"; - String[] receiverEmail = {/*merchantEmail,*/ developer}; + String[] receiverEmail = buildMerchantReceiverEmail(); Credential cred = new Credential(SECRET_ID, SECRET_KEy); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); @@ -966,9 +985,7 @@ public class SendEmailUtil { // 实例化一个请求对象,每个接口都会对应一个request对象 SendEmailRequest req = new SendEmailRequest(); req.setFromEmailAddress(SEND_ADDRESS); - String merchantEmail = "kimwong@code-create.com.hk"; - String developerEmail = "xupei@code-create.com.hk"; - req.setDestination(new String[]{/*merchantEmail,*/ developerEmail}); + req.setDestination(buildMerchantReceiverEmail()); Template template = new Template(); req.setSubject("New Credit Purchase Order"); template.setTemplateID(CREDITS_PURCHASE_MERCHANT); @@ -1076,4 +1093,25 @@ public class SendEmailUtil { } + public static String[] buildMerchantReceiverEmail() { + List emails = new ArrayList<>(); + if (!StringUtils.isEmpty(merchantEmail)) { + for (String e : merchantEmail.split(",")) { + String trimmed = e.trim(); + if (!trimmed.isEmpty()) { + emails.add(trimmed); + } + } + } + if (!StringUtils.isEmpty(developerEmail)) { + for (String e : developerEmail.split(",")) { + String trimmed = e.trim(); + if (!trimmed.isEmpty()) { + emails.add(trimmed); + } + } + } + return emails.toArray(new String[0]); + } + } 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 853f7824..9ea7c7c2 100644 --- a/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AffiliateServiceImpl.java @@ -34,7 +34,6 @@ import jakarta.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; -import java.util.*; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.Function; @@ -80,9 +79,7 @@ public class AffiliateServiceImpl extends ServiceImpl merchantReceiver = Arrays.asList(/*merchantEmail,*/ developer); + List merchantReceiver = buildMerchantReceiverList(); String merchantSubject = null; String merchantTemplate = null; @@ -723,15 +722,13 @@ public class EmailServiceImpl implements EmailService { private final static String CREDITS_PURCHASE_MERCHANT = "133275_AiDA 积分购买通知-merchant.html"; public void creditsPurchaseReminder(String username, String quantity, String amount) { - String merchantEmail = "kimwong@code-create.com.hk"; - String developerEmail = "xupei@code-create.com.hk"; JSONObject jsonObject = new JSONObject(); // 设置试用订单相关数据 jsonObject.put("username", username); jsonObject.put("quantity", quantity); jsonObject.put("totalFee", amount); - sendEmail(Arrays.asList(/*merchantEmail,*/ developerEmail), jsonObject, CREDITS_PURCHASE_MERCHANT, "New Credit Purchase Order", null, null); + sendEmail(buildMerchantReceiverList(), jsonObject, CREDITS_PURCHASE_MERCHANT, "New Credit Purchase Order", null, null); } private final static String COMMON_EXCEPTION_REMINDER = "135279_common-exception-reminder.html"; @@ -742,6 +739,10 @@ public class EmailServiceImpl implements EmailService { sendEmail(destination, param, COMMON_EXCEPTION_REMINDER, "AiDA发生异常,请及时处理", null, null); } + + private List buildMerchantReceiverList() { + return Arrays.asList(SendEmailUtil.buildMerchantReceiverEmail()); + } } diff --git a/src/main/java/com/ai/da/service/impl/StripeSubscriptionServiceImpl.java b/src/main/java/com/ai/da/service/impl/StripeSubscriptionServiceImpl.java index b772b759..3b88a1c1 100644 --- a/src/main/java/com/ai/da/service/impl/StripeSubscriptionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/StripeSubscriptionServiceImpl.java @@ -180,7 +180,7 @@ public class StripeSubscriptionServiceImpl implements StripeSubscriptionService .orderByDesc("id") .last("LIMIT 1"); if (!type.contains("fail")) { - last.in("trade_state", "paid", "COMPLETED"); + last.in("trade_state", "paid", "COMPLETED", "Refunded"); } List infos = paymentInfoMapper.selectList(last); return infos.isEmpty() ? null : infos.getFirst(); diff --git a/src/main/java/com/ai/da/service/stripe/handler/SubscriptionDeletedHandler.java b/src/main/java/com/ai/da/service/stripe/handler/SubscriptionDeletedHandler.java index 3cd685d0..7d41e585 100644 --- a/src/main/java/com/ai/da/service/stripe/handler/SubscriptionDeletedHandler.java +++ b/src/main/java/com/ai/da/service/stripe/handler/SubscriptionDeletedHandler.java @@ -67,7 +67,7 @@ public class SubscriptionDeletedHandler implements StripeEventHandler { // 发送取消订阅通知邮件 if (subscriptionInfo.getCancelNotified() == 0) { - boolean sent = stripeSubscriptionService.sendSubscriptionEmail(null, "cancel", subscriptionInfo.getOrderNo(), null); + boolean sent = stripeSubscriptionService.sendSubscriptionEmail(null, "cancel", subscriptionInfo.getOrderNo(), subscriptionInfo); if (sent) { subscriptionInfo.setCancelNotified((byte) 1); diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 9a084f29..ccc80692 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -181,4 +181,10 @@ file.upload.max.size.video=104857600 # 上传任务过期时间(小时) file.upload.task.expiry.hours=24 -global.award.link=https://aida-global-design-awards.com.hk/contestants?id= \ No newline at end of file +global.award.link=https://aida-global-design-awards.com.hk/contestants?id= + +# merchant email receivers (comma-separated, multiple supported) +# dev/local: developer.email 不配置,使用默认值 xupei3360@163.com +# prod: 两个都配置 +merchant.email= +developer.email=xupei@code-create.com.hk,yizhang@aidlab.hk \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index c1108874..ed3797bc 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -179,4 +179,9 @@ file.upload.max.size.video=104857600 # 上传任务过期时间(小时) file.upload.task.expiry.hours=24 -global.award.link=https://aida-global-design-awards.com.hk/contestants?id= \ No newline at end of file +global.award.link=https://aida-global-design-awards.com.hk/contestants?id= + +# merchant email receivers (comma-separated, multiple supported) +# prod: includes merchant email +merchant.email=kimwong@code-create.com.hk +developer.email=xupei3360@163.com \ No newline at end of file diff --git a/src/main/resources/mapper/primary/PaymentInfoMapper.xml b/src/main/resources/mapper/primary/PaymentInfoMapper.xml index 99d1c8e7..fedcc4ad 100644 --- a/src/main/resources/mapper/primary/PaymentInfoMapper.xml +++ b/src/main/resources/mapper/primary/PaymentInfoMapper.xml @@ -51,47 +51,41 @@ a.user_email email, p.payment_type platform, p.payer_total, - p.type, + CASE + WHEN o.title LIKE '%Subscription' THEN 'Subscription' + ELSE 'Credits' + END AS type, p.payment_method, p.last4, p.country, p.city, p.create_time, CASE - - WHEN p.trade_state IN ( 'paid', 'COMPLETED', 'complete', 'liquidated' ) THEN - 'Success' - WHEN p.trade_state IN ( 'failed', 'expired', 'VOIDED', 'void', 'uncollectible' ) THEN - 'Fail' - WHEN p.trade_state IN ( 'Refunded' ) THEN - 'Refunded' + WHEN p.trade_state IN ('paid', 'COMPLETED', 'complete', 'liquidated') THEN 'Success' + WHEN p.trade_state IN ('failed', 'expired', 'VOIDED', 'void', 'uncollectible') THEN 'Fail' + WHEN p.trade_state IN ('Refunded') THEN 'Refunded' ELSE 'Pending' END AS status - FROM - t_payment_info p - LEFT JOIN - t_order_info o ON p.order_no = o.order_no - LEFT JOIN - t_account a ON a.id = o.account_id - WHERE - 1 = 1 + FROM t_payment_info p + LEFT JOIN t_order_info o ON p.order_no = o.order_no + LEFT JOIN t_account a ON a.id = o.account_id + WHERE 1 = 1 AND p.payment_type = #{paymentType} AND p.payer_total = #{payerTotal} - - AND p.type = #{type} - + - AND - CASE - WHEN p.trade_state IN ('paid', 'COMPLETED', 'complete', 'liquidated') THEN 'Success' - WHEN p.trade_state IN ('failed', 'expired', 'VOIDED', 'void', 'uncollectible') THEN 'Fail' - WHEN p.trade_state IN ('Refunded') THEN 'Refunded' - ELSE 'Pending' - END = #{status} + AND ( + (p.trade_state IN ('paid', 'COMPLETED', 'complete', 'liquidated') AND #{status} = 'Success') + OR (p.trade_state IN ('failed', 'expired', 'VOIDED', 'void', 'uncollectible') AND #{status} = 'Fail') + OR (p.trade_state IN ('Refunded') AND #{status} = 'Refunded') + OR (p.trade_state NOT IN ('paid', 'COMPLETED', 'complete', 'liquidated', + 'failed', 'expired', 'VOIDED', 'void', 'uncollectible', 'Refunded') + AND #{status} = 'Pending') + ) AND p.country = #{country} @@ -106,9 +100,8 @@ AND a.user_name = #{payer} AND p.transaction_id NOT LIKE 'cs_test%' - ORDER BY - p.id ${order} - LIMIT ${limit} OFFSET ${offset} + ORDER BY p.id ${order} + LIMIT #{limit} OFFSET #{offset}