Merge remote-tracking branch 'origin/dev/dev' into dev/dev

This commit is contained in:
shahaibo
2025-01-06 10:49:39 +08:00
6 changed files with 90 additions and 10 deletions

View File

@@ -985,4 +985,44 @@ public class SendEmailUtil {
}
}
private final static Long CREDITS_PURCHASE_MERCHANT = 133275L;
public static void creditsPurchaseReminder(String username, String quantity, String amount) {
try {
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
// 实例化一个http选项可选的没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("ses.tencentcloudapi.com");
// 实例化一个client选项可选的没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// 实例化要请求产品的client对象,clientProfile是可选的
SesClient client = new SesClient(cred, "ap-hongkong", clientProfile);
// 实例化一个请求对象,每个接口都会对应一个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});
Template template = new Template();
req.setSubject("New Credit Purchase Order");
template.setTemplateID(CREDITS_PURCHASE_MERCHANT);
JSONObject jsonObject = new JSONObject();
// 设置试用订单相关数据
jsonObject.put("userName", username);
jsonObject.put("quantity", quantity);
jsonObject.put("totalFee", amount);
template.setTemplateData(JSON.toJSONString(jsonObject));
req.setTemplate(template);
// 返回的resp是一个SendEmailResponse的实例与请求对象对应
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");
}
}
}

View File

@@ -218,4 +218,8 @@ public interface AccountService extends IService<Account> {
Boolean unbindWeChat();
Boolean unbindGoogle();
void updateAccountValidity(Long accountId, Long currentPeriodEnd);
void updateUserRoleAndCredits(Long accountId, String type);
}

View File

@@ -2591,4 +2591,32 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountMapper.updateById(account);
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);
}
}

View File

@@ -6,6 +6,8 @@ import com.ai.da.common.enums.OrderStatusEnum;
import com.ai.da.common.enums.PayTypeEnum;
import com.ai.da.common.utils.AlipayHKEncryptionUtil;
import com.ai.da.common.utils.AlipayHKRequestUtil;
import com.ai.da.common.utils.SendEmailUtil;
import com.ai.da.mapper.primary.AccountMapper;
import com.ai.da.mapper.primary.entity.OrderInfo;
import com.ai.da.model.dto.AlipayHKCallbackDTO;
import com.ai.da.model.dto.AlipayHKRequestDTO;
@@ -54,6 +56,8 @@ public class AlipayHKServiceImpl implements AlipayHKService {
private AlipayHKEncryptionUtil alipayHKEncryptionUtil;
@Resource
private AlipayHKRequestUtil alipayHKRequestUtil;
@Resource
private AccountMapper accountMapper;
/**
@@ -251,6 +255,9 @@ public class AlipayHKServiceImpl implements AlipayHKService {
"positive",
orderByOrderNo.getOrderNo());
log.info("用户:{} 积分信息更新成功",orderByOrderNo.getAccountId());
// 邮件通知Kim
String username = accountMapper.selectById(orderByOrderNo.getAccountId()).getUserName();
SendEmailUtil.creditsPurchaseReminder(username, String.valueOf(quantity), totalAmount);
} finally {
//要主动释放锁
lock.unlock();

View File

@@ -58,6 +58,8 @@ public class StripeServiceImpl implements StripeService {
private CreditsService creditsService;
@Resource
private RefundInfoService refundInfoService;
@Resource
private AccountService accountService;
@Resource
private AccountMapper accountMapper;
@@ -368,6 +370,7 @@ public class StripeServiceImpl implements StripeService {
orderInfoService.updateById(orderInfo);
}
}
log.info("回调事件 {} 处理完成", event.getType());
return response;
}
@@ -466,7 +469,10 @@ public class StripeServiceImpl implements StripeService {
subscriptionInfoMapper.insert(subscriptionInfo);
// 更新账号到期时间
updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
accountService.updateAccountValidity(subscriptionInfo.getAccountId(), subscriptionInfo.getCurrentPeriodEnd());
// 更新账号身份和积分
accountService.updateUserRoleAndCredits(subscriptionInfo.getAccountId(), interval);
}
return subscriptionInfo;
}
@@ -519,7 +525,9 @@ public class StripeServiceImpl implements StripeService {
subscriptionInfo.setCurrentPeriodEnd(subscription.getCurrentPeriodEnd());
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));
flag = true;
}
@@ -530,14 +538,6 @@ public class StripeServiceImpl implements StripeService {
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中过期且不续订的订阅
public void cancelSubscription(String subscriptionId, String cancelReason) {
Stripe.apiKey = privateKey;