完善c端接口
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.ShopUser;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class MusicUtil {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前时间 n 天后的日期
|
||||
*
|
||||
* @param n 天数(正数表示未来,负数表示过去)
|
||||
* @return n 天后的 Date 对象
|
||||
*/
|
||||
@@ -19,7 +21,39 @@ public class MusicUtil {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getDateAfterNDays(1));;
|
||||
System.out.println(getDateAfterNDays(1));
|
||||
;
|
||||
}
|
||||
|
||||
// 判断用户是否是vip
|
||||
public static boolean getShopIsVip(ShopUser shopUser) {
|
||||
if (shopUser.getVip() != null && shopUser.getVip() == 1) {
|
||||
Date startTime = shopUser.getVipStartTime();
|
||||
Date endTime = shopUser.getVipEndTime();
|
||||
return isCurrentTimeInRange(startTime, endTime);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查当前时间是否在指定的时间范围内
|
||||
*
|
||||
* @param startDate 开始时间
|
||||
* @param endDate 结束时间
|
||||
* @return true 如果当前时间在范围内,否则 false
|
||||
*/
|
||||
public static boolean isCurrentTimeInRange(Date startDate, Date endDate) {
|
||||
Date now = new Date(); // 获取当前时间
|
||||
|
||||
// 处理跨越日期的情况(结束时间早于开始时间)
|
||||
if (endDate.before(startDate)) {
|
||||
// 当前时间 >= 开始时间 或 当前时间 <= 结束时间
|
||||
return now.after(startDate) || now.before(endDate) || now.equals(startDate) || now.equals(endDate);
|
||||
} else {
|
||||
// 开始时间 <= 当前时间 <= 结束时间
|
||||
return (now.after(startDate) || now.equals(startDate)) && (now.before(endDate) || now.equals(endDate));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user