|
@@ -20,10 +20,9 @@ import cn.kdan.cloud.pdf.office.common.exception.BackendRuntimeException;
|
|
|
import cn.kdan.cloud.pdf.office.common.pojo.ResultMap;
|
|
|
import cn.kdan.cloud.pdf.office.common.utils.CommonUtils;
|
|
|
import cn.kdan.cloud.pdf.office.common.vo.UserInfoVO;
|
|
|
+import cn.kdan.cloud.pdf.office.common.vo.UserSubscriptionInfoVO;
|
|
|
import cn.kdan.cloud.pdf.office.common.vo.UserVO;
|
|
|
import cn.kdan.cloud.pdf.office.website.service.OrderGiftService;
|
|
|
-import cn.kdan.cloud.pdf.office.website.utils.SecurityUtils;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -32,8 +31,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -47,7 +47,7 @@ public class OrderGiftServiceImpl implements OrderGiftService {
|
|
|
private final ProductApi productApi;
|
|
|
@Resource
|
|
|
private UserSubscriptionInfoApi userSubscriptionInfoApi;
|
|
|
- @Value("${orderGiftUrl:www.baidu.com}")
|
|
|
+ @Value("${orderGiftUrl:}")
|
|
|
private String orderGiftUrl;
|
|
|
|
|
|
@Override
|
|
@@ -61,6 +61,7 @@ public class OrderGiftServiceImpl implements OrderGiftService {
|
|
|
//判断接受人是否已经有账号
|
|
|
UserVO userVO = userApi.getByEmail(email).getResult();
|
|
|
String giftEmail = userApi.getById(userId).getResult().getEmail();
|
|
|
+ AtomicBoolean gifted = new AtomicBoolean(false);
|
|
|
//如果没有账号直接发送赠送邮件,并且记录赠送日志
|
|
|
if (ObjectUtils.isEmpty(userVO)) {
|
|
|
OrderGiftLogVO orderGiftLogVO = orderApi.giveAway(userId, email, name).getResult();
|
|
@@ -81,7 +82,7 @@ public class OrderGiftServiceImpl implements OrderGiftService {
|
|
|
throw new BackendRuntimeException(ExceptionEnum.USER_ALREADY_SUBSCRIBED_PACKAGE);
|
|
|
}
|
|
|
//是订阅中的订阅会员, //3.如果是订阅会员,如果有isGift且为ture,则直接赠送,如果没有则提醒你已经是订阅会员了
|
|
|
- if (userSubscriptionInfoVO.getPaymentModel().equals("1")) {
|
|
|
+ if (userSubscriptionInfoVO.getPaymentModel().equals("1")&&userSubscriptionInfoVO.getPlatform().equals(2)) {
|
|
|
if (isGift) {
|
|
|
OrderGiftLogVO orderGiftLogVO = orderApi.giveAway(userId, email, name).getResult();
|
|
|
String orderGiftId = orderGiftLogVO.getId();
|
|
@@ -89,23 +90,24 @@ public class OrderGiftServiceImpl implements OrderGiftService {
|
|
|
EmailSendBO bo = new EmailSendBO();
|
|
|
bo.setToEmail(email);
|
|
|
handleEmailSendBO(EmailCodeTypeEnum.GIVE_AWAY, bo, giftEmail,email,orderGiftId);
|
|
|
+ gifted.set(true);
|
|
|
} else {
|
|
|
throw new BackendRuntimeException(ExceptionEnum.USER_ALREADY_SUBSCRIBED_PLAN);
|
|
|
}
|
|
|
}
|
|
|
- if (userSubscriptionInfoVO.getPaymentModel().equals("2")
|
|
|
- && userSubscriptionInfoVO.getStatus().equals(PDFOfficeUserSubscriptionStatusEnum.REGISTER.value())) {
|
|
|
- //发送赠送邮件
|
|
|
- //1.如果是免费用户,接收人是免费用户,则直接发送邮件 (赠送邮件24小时有效,超过24小时未确认,邮件失效,【接收会员】按钮点击提示已失效,需要用户重新发起赠送邀请)
|
|
|
- //修改orderGift中的一条记录为赠送中,且记录赠送日志为未接收
|
|
|
- OrderGiftLogVO orderGiftLogVO = orderApi.giveAway(userId, email, name).getResult();
|
|
|
- String orderGiftId = orderGiftLogVO.getId();
|
|
|
- //存到redis里
|
|
|
- EmailSendBO bo = new EmailSendBO();
|
|
|
- bo.setToEmail(email);
|
|
|
- handleEmailSendBO(EmailCodeTypeEnum.GIVE_AWAY, bo, giftEmail,email,orderGiftId);
|
|
|
- }
|
|
|
});
|
|
|
+ if(!gifted.get()){
|
|
|
+ //发送赠送邮件
|
|
|
+ //1.如果是免费用户,接收人是免费用户,则直接发送邮件 (赠送邮件24小时有效,超过24小时未确认,邮件失效,【接收会员】按钮点击提示已失效,需要用户重新发起赠送邀请)
|
|
|
+ //修改orderGift中的一条记录为赠送中,且记录赠送日志为未接收
|
|
|
+ OrderGiftLogVO orderGiftLogVO = orderApi.giveAway(userId, email, name).getResult();
|
|
|
+ String orderGiftId = orderGiftLogVO.getId();
|
|
|
+ //存到redis里
|
|
|
+ EmailSendBO bo = new EmailSendBO();
|
|
|
+ bo.setToEmail(email);
|
|
|
+ handleEmailSendBO(EmailCodeTypeEnum.GIVE_AWAY, bo, giftEmail,email,orderGiftId);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -118,12 +120,48 @@ public class OrderGiftServiceImpl implements OrderGiftService {
|
|
|
Map<String, String> contentMap = new HashMap<>();
|
|
|
contentMap.put("@userEmail@", userEmail);
|
|
|
contentMap.put("@receviceEmail@", receiveEmail);
|
|
|
- contentMap.put("@url@", orderGiftUrl+"?orderGiftLogId="+orderGiftLogId);
|
|
|
+ contentMap.put("@url@", orderGiftUrl+orderGiftLogId);
|
|
|
bo.setSendTitleContent(titleMap);
|
|
|
//设置内容
|
|
|
bo.setSendContent(contentMap);
|
|
|
+ emailApi.sendEmail(bo);
|
|
|
}
|
|
|
|
|
|
+ public UserSubscriptionInfoVO findActiveSubscription(List<UserSubscriptionInfoVO> subscriptionInfoList) {
|
|
|
+ // 过滤掉isAi为true的记录
|
|
|
+ List<UserSubscriptionInfoVO> filteredList = subscriptionInfoList.stream()
|
|
|
+ .filter(info -> ObjectUtils.isEmpty(info.getIsAi())||ValidStatusEnum.INVALID.value().equals(info.getIsAi())) // 排除AI记录
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 找到一条生效的记录,按优先级排序
|
|
|
+ Optional<UserSubscriptionInfoVO> activeSubscription = filteredList.stream()
|
|
|
+ .sorted(Comparator.comparingInt(this::getLevelPriority)
|
|
|
+ .reversed() // 按优先级降序排列
|
|
|
+ .thenComparing(Comparator.comparingInt(UserSubscriptionInfoVO::getMaxDeviceNum).reversed()) // 如果优先级相同按max_device_num降序
|
|
|
+ )
|
|
|
+ .findFirst(); // 找到优先级最高的记录
|
|
|
+
|
|
|
+ return activeSubscription.orElse(null); // 返回结果,如果没有找到则返回null
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getLevelPriority(UserSubscriptionInfoVO info) {
|
|
|
+ // 假设 levels 是以逗号分隔的字符串
|
|
|
+ String[] levels = info.getLevels().split(",");
|
|
|
+ int maxPriority = Integer.MIN_VALUE;
|
|
|
+
|
|
|
+ for (String level : levels) {
|
|
|
+ int lvl = Integer.parseInt(level.trim());
|
|
|
+ maxPriority = Math.max(maxPriority, lvl);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 定义优先级
|
|
|
+ switch (maxPriority) {
|
|
|
+ case 3: return 3; // 高级版
|
|
|
+ case 2: return 2; // 标准版
|
|
|
+ case 1: return 1; // 免费版
|
|
|
+ default: return 0; // 未知或无效等级
|
|
|
+ }
|
|
|
+ }
|
|
|
@Override
|
|
|
//链接过期的逻辑(已完成)
|
|
|
//接受会员接口
|