From ed01e71dc60d274270d33c77ee6c8baa8ba103fc Mon Sep 17 00:00:00 2001 From: khy <2908249413@qq.com> Date: Tue, 5 Nov 2024 16:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=E8=BF=87=E6=9C=9F=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/type/AppMemberCardTypeController.java | 14 +++++++++- .../app/type/vo/AppMemberCardTypeRespVO.java | 9 +++++++ .../user/PaidMemberUserServiceImpl.java | 26 +++++++++---------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/type/AppMemberCardTypeController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/type/AppMemberCardTypeController.java index d009e45..e3b0c9f 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/type/AppMemberCardTypeController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/type/AppMemberCardTypeController.java @@ -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() { @@ -39,7 +45,13 @@ public class AppMemberCardTypeController { MemberUserDO memberUserDO = userService.getUser(getLoginUserId()); /** 根据用户查询是否有试用会员的类型列表 */ List list = cardService.getCardTypeList(memberUserDO.getActivate()); - return success(MemberCardTypeConvert.INSTANCE.convertList(list)); + List cardTypes = MemberCardTypeConvert.INSTANCE.convertList(list); + //设置过期时间 + cardTypes.forEach(card ->{ + LocalDateTime expireTime = paidMemberUserService.getDeadLineDay(card.getName(), getLoginUserId()); + card.setCardExpirationTime(expireTime); + }); + return success(cardTypes); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/type/vo/AppMemberCardTypeRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/type/vo/AppMemberCardTypeRespVO.java index a38279a..c0b6ebb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/type/vo/AppMemberCardTypeRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/type/vo/AppMemberCardTypeRespVO.java @@ -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; } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java index dba7984..effb751 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java @@ -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 list = paidMemberUserMapper.selectList( - new LambdaQueryWrapperX().eq(PaidMemberUserDO::getUid,uid) - .orderByDesc(PaidMemberUserDO::getId)); + List list = paidMemberUserMapper.selectLatestPaidMemberUsers(); if(list.isEmpty()){ return null; } - PaidMemberUserDO paidMemberUserDO = list.get(0); + List 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; }