Compare commits

...

2 Commits

Author SHA1 Message Date
eaab153631 Merge pull request '会员过期时间' (#105) from khy-two into master
Reviewed-on: #105
2024-11-06 11:10:21 +08:00
khy
ed01e71dc6 会员过期时间 2024-11-05 16:20:09 +08:00
3 changed files with 35 additions and 14 deletions

View File

@ -6,8 +6,10 @@ import cn.iocoder.yudao.module.member.controller.app.type.vo.AppMemberCardTypeRe
import cn.iocoder.yudao.module.member.convert.type.MemberCardTypeConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.membercardtype.PaidMemberCardTypeDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.PaidMemberUserDO;
import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.service.user.PaidMemberUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
@ -15,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.lang.reflect.Member;
import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -32,6 +35,9 @@ public class AppMemberCardTypeController {
@Resource
private MemberUserService userService;
@Resource
private PaidMemberUserService paidMemberUserService;
@GetMapping("/list")
@Operation(summary = "获得会员卡类型列表")
public CommonResult<List<AppMemberCardTypeRespVO>> list() {
@ -39,7 +45,13 @@ public class AppMemberCardTypeController {
MemberUserDO memberUserDO = userService.getUser(getLoginUserId());
/** 根据用户查询是否有试用会员的类型列表 */
List<PaidMemberCardTypeDO> list = cardService.getCardTypeList(memberUserDO.getActivate());
return success(MemberCardTypeConvert.INSTANCE.convertList(list));
List<AppMemberCardTypeRespVO> cardTypes = MemberCardTypeConvert.INSTANCE.convertList(list);
//设置过期时间
cardTypes.forEach(card ->{
LocalDateTime expireTime = paidMemberUserService.getDeadLineDay(card.getName(), getLoginUserId());
card.setCardExpirationTime(expireTime);
});
return success(cardTypes);
}

View File

@ -6,8 +6,13 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
@Schema(description = "用户 App - 会员卡类型 Response VO")
@Data
public class AppMemberCardTypeRespVO {
@ -22,4 +27,8 @@ public class AppMemberCardTypeRespVO {
@Schema(description = "会员卡优惠价", example = "12301")
private BigDecimal specialPrice;
@Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED)
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDateTime cardExpirationTime;
}

View File

@ -25,6 +25,8 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.user.PaidMemberUserDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -156,17 +158,11 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
public LocalDateTime getDay(String cardName,LocalDateTime dateTime) {
LocalDateTime deadlineDay;
PaidMemberCardTypeDO paidMemberCardTypeDO = memberCardTypeService.selectByName(cardName);
if (cardName.equals("试用")){
deadlineDay = dateTime.plus(Long.parseLong(paidMemberCardTypeDO.getVid()), ChronoUnit.DAYS);
} else if (cardName.equals("月卡")) {
deadlineDay = dateTime.plus(1,ChronoUnit.MONTHS);
} else if (cardName.equals("季卡")) {
deadlineDay = dateTime.plus(3,ChronoUnit.MONTHS);
} else if (cardName.equals("年卡")) {
deadlineDay = dateTime.plus(1,ChronoUnit.YEARS);
} else {
if (cardName.equals("永久")){
//永久设置为一个非常远的的日期
deadlineDay = LocalDateTime.of(9999,12,31,23,59,59);
} else {
deadlineDay = dateTime.plus(Long.parseLong(paidMemberCardTypeDO.getVid()), ChronoUnit.DAYS);
}
return deadlineDay;
}
@ -201,13 +197,17 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
@Override
public PaidMemberUserDO getPaidMemberUserByUid(Long uid) {
List<PaidMemberUserDO> list = paidMemberUserMapper.selectList(
new LambdaQueryWrapperX<PaidMemberUserDO>().eq(PaidMemberUserDO::getUid,uid)
.orderByDesc(PaidMemberUserDO::getId));
List<PaidMemberUserDO> list = paidMemberUserMapper.selectLatestPaidMemberUsers();
if(list.isEmpty()){
return null;
}
PaidMemberUserDO paidMemberUserDO = list.get(0);
List<PaidMemberUserDO> filters = list.stream()
.filter(user -> user.getUid().equals(uid))
.collect(Collectors.toList());
PaidMemberUserDO paidMemberUserDO = filters.get(0);
if (paidMemberUserDO.getCardExpirationTime().isBefore(LocalDateTime.now())){
return null;
}
return paidMemberUserDO;
}