feat: 1.uni-ad广告回调接入 2.广告奖励免费观看时长
This commit is contained in:
@@ -9,7 +9,9 @@ public interface RedisService {
|
||||
|
||||
void setDiscSpinningAmounts(String key);
|
||||
|
||||
void setPayFreeWatchTime(Long userId, Integer time);
|
||||
void setFreeWatchTime(Long userId, Integer time, boolean isPermanently);
|
||||
|
||||
Boolean getPayFreeWatchTimeIsExpire(Long userId);
|
||||
Boolean getFreeWatchTimeIsExpire(Long userId);
|
||||
|
||||
Long getFreeWatchRemainTime(Long userId, boolean isPermanently);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.sqx.modules.redisService.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.sqx.common.utils.RedisKeys;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
@@ -17,6 +19,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class RedisServiceImpl implements RedisService {
|
||||
@Lazy
|
||||
@@ -36,21 +40,96 @@ public class RedisServiceImpl implements RedisService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPayFreeWatchTime(Long userId, Integer minute) {
|
||||
public void setFreeWatchTime(Long userId, Integer second, boolean isPermanently) {
|
||||
Date now = DateUtil.date();
|
||||
Date tomorrow = DateUtil.beginOfDay(DateUtil.offsetDay(now, 1));
|
||||
long seconds = DateUtil.between(now, tomorrow, DateUnit.SECOND);
|
||||
redisUtils.setIfAbsent(RedisKeys.getPayFreeWatchKey(userId), DateUtil.offsetMinute(now, minute).getTime(), seconds);
|
||||
String freeWatchKey = RedisKeys.getFreeWatchKey(userId, isPermanently);
|
||||
if (isPermanently) {
|
||||
String data = redisUtils.get(freeWatchKey);
|
||||
if (StrUtil.isBlank(data)) {
|
||||
redisUtils.set(freeWatchKey, second, -1);
|
||||
}else {
|
||||
Long expire = redisUtils.getExpire(freeWatchKey);
|
||||
if (expire == null) {
|
||||
expire = Long.valueOf(second);
|
||||
}else {
|
||||
expire += Long.valueOf(second);
|
||||
}
|
||||
redisUtils.set(freeWatchKey, second + Long.parseLong(data), expire);
|
||||
|
||||
}
|
||||
}else {
|
||||
long expire = DateUtil.between(now, tomorrow, DateUnit.SECOND);
|
||||
// redisUtils.setIfAbsent(freeWatchKey, DateUtil.offsetSecond(now, second).getTime(), seconds);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("expireTime", -1);
|
||||
jsonObject.put("second", second);
|
||||
redisUtils.setIfAbsent(freeWatchKey, jsonObject.toJSONString(), expire);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getPayFreeWatchTimeIsExpire(Long userId) {
|
||||
String data = redisUtils.get(RedisKeys.getPayFreeWatchKey(userId));
|
||||
if (data == null) {
|
||||
return null;
|
||||
public Boolean getFreeWatchTimeIsExpire(Long userId) {
|
||||
String freeWatchKey = RedisKeys.getFreeWatchKey(userId, true);
|
||||
String permanentlyFreeWatch = redisUtils.get(freeWatchKey);
|
||||
|
||||
String watchKey = RedisKeys.getFreeWatchKey(userId, false);
|
||||
String payFreeWatchInfo = redisUtils.get(watchKey);
|
||||
Integer expireTime = -1;
|
||||
JSONObject jsonObject = null;
|
||||
if (StrUtil.isNotBlank(payFreeWatchInfo)) {
|
||||
jsonObject = JSONObject.parseObject(payFreeWatchInfo);
|
||||
expireTime = jsonObject.getInteger("expireTime");
|
||||
}
|
||||
|
||||
long expireTime = Long.parseLong(data);
|
||||
return DateUtil.current() > expireTime;
|
||||
if ((StrUtil.isNotBlank(permanentlyFreeWatch) && redisUtils.isExpiredSet(freeWatchKey)) || (StrUtil.isNotBlank(permanentlyFreeWatch) && DateUtil.current() >= expireTime)) {
|
||||
if (StrUtil.isBlank(permanentlyFreeWatch)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!redisUtils.isExpiredSet(freeWatchKey)) {
|
||||
redisUtils.expire(freeWatchKey, Long.parseLong(permanentlyFreeWatch));
|
||||
}
|
||||
return false;
|
||||
}else {
|
||||
if (StrUtil.isBlank(payFreeWatchInfo)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Integer second = jsonObject.getInteger("second");
|
||||
if (expireTime == -1) {
|
||||
jsonObject.put("expireTime", DateUtil.offsetSecond(DateUtil.date(), second).getTime());
|
||||
redisUtils.set(watchKey, jsonObject.toJSONString());
|
||||
return false;
|
||||
}else {
|
||||
return DateUtil.current() > expireTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getFreeWatchRemainTime(Long userId, boolean isPermanently) {
|
||||
String key = RedisKeys.getFreeWatchKey(userId, isPermanently);
|
||||
if (isPermanently) {
|
||||
String permanentlyFreeInfo = redisUtils.get(key);
|
||||
if (StrUtil.isBlank(permanentlyFreeInfo)) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
Long expire = redisUtils.getExpire(key);
|
||||
return expire == null ? Long.valueOf(permanentlyFreeInfo) : expire;
|
||||
}
|
||||
|
||||
|
||||
String payFreeInfo = redisUtils.get(RedisKeys.getFreeWatchKey(userId, false));
|
||||
if (StrUtil.isBlank(payFreeInfo)) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(payFreeInfo);
|
||||
Integer expireTime = jsonObject.getInteger("expireTime");
|
||||
Long second = jsonObject.getLong("second");
|
||||
|
||||
return expireTime == -1 ? second : expireTime > DateUtil.current() ? expireTime - DateUtil.current() : 0L;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user