Merge branch 'test' into dev
This commit is contained in:
@@ -3,6 +3,7 @@ package com.sqx;
|
||||
import com.sqx.modules.pay.wuyou.WuyouPay;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@@ -11,6 +12,7 @@ import java.util.Map;
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@EnableCaching
|
||||
@EnableScheduling
|
||||
@SpringBootApplication
|
||||
public class SqxApplication {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sqx.common.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
@@ -159,4 +160,17 @@ public class DateUtils {
|
||||
DateTime dateTime = new DateTime(date);
|
||||
return dateTime.plusYears(years).toDate();
|
||||
}
|
||||
|
||||
|
||||
//获取当日剩余秒数
|
||||
public static long todayAfterSecond() {
|
||||
Date now = new Date();
|
||||
// 获取当天结束时间(即当天23:59:59对应的Date对象)
|
||||
Date endOfDay = DateUtil.endOfDay(now);
|
||||
// 计算时间差(单位为毫秒)
|
||||
long diffMillis = endOfDay.getTime() - now.getTime();
|
||||
// 将毫秒转换为秒
|
||||
long diffSeconds = diffMillis / 1000;
|
||||
return diffSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
*/
|
||||
public class RedisKeys {
|
||||
|
||||
public static final String PAY_FREE_WATCH_KEY = "pay:free:watch:";
|
||||
public static final String FREE_WATCH_KEY = "free:watch:";
|
||||
|
||||
public static String getSysConfigKey(String key){
|
||||
return "sys:config:" + key;
|
||||
@@ -18,8 +18,11 @@ public class RedisKeys {
|
||||
return "date:" + key;
|
||||
}
|
||||
|
||||
public static String getPayFreeWatchKey(Long userId) {
|
||||
return PAY_FREE_WATCH_KEY + DateUtil.today() + ":" + userId;
|
||||
public static String getFreeWatchKey(Long userId, boolean isPermanently) {
|
||||
if (isPermanently) {
|
||||
return FREE_WATCH_KEY + userId;
|
||||
}
|
||||
return FREE_WATCH_KEY + DateUtil.today() + ":" + userId;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -134,6 +134,10 @@ public class RedisUtils {
|
||||
set(key, value, DEFAULT_EXPIRE);
|
||||
}
|
||||
|
||||
public void expire(String key, long seconds){
|
||||
redisTemplate.expire(key, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public <T> T get(String key, Class<T> clazz, long expire) {
|
||||
String value = valueOperations.get(key);
|
||||
if (expire != NOT_EXPIRE) {
|
||||
@@ -142,6 +146,47 @@ public class RedisUtils {
|
||||
return value == null ? null : fromJson(value, clazz);
|
||||
}
|
||||
|
||||
// 判断键是否设置了过期时间
|
||||
public boolean isExpiredSet(String key) {
|
||||
// 获取过期时间,单位是秒
|
||||
Long expireTime = redisTemplate.getExpire(key);
|
||||
|
||||
if (expireTime == null) {
|
||||
return false; // 如果返回 null,表示键不存在
|
||||
}
|
||||
|
||||
return expireTime != -1; // 如果是 -1,说明没有设置过期时间
|
||||
}
|
||||
|
||||
public Long getExpire(String key) {
|
||||
Long currentExpireTime = redisTemplate.getExpire(key);
|
||||
if (currentExpireTime == null || currentExpireTime == -2 || currentExpireTime == -1) {
|
||||
return null;
|
||||
}
|
||||
return currentExpireTime;
|
||||
}
|
||||
|
||||
// 累加过期时间
|
||||
public boolean extendExpireTime(String key, long additionalTimeInSeconds) {
|
||||
// 获取当前键的剩余过期时间(单位:秒)
|
||||
Long currentExpireTime = redisTemplate.getExpire(key);
|
||||
|
||||
if (currentExpireTime == null || currentExpireTime == -2) {
|
||||
// 键不存在或已经过期,无法进行累加
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentExpireTime == -1) {
|
||||
redisTemplate.expire(key, additionalTimeInSeconds, java.util.concurrent.TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
// 累加剩余过期时间和新增时间
|
||||
long newExpireTime = currentExpireTime + additionalTimeInSeconds;
|
||||
|
||||
// 设置新的过期时间
|
||||
return Boolean.TRUE.equals(redisTemplate.expire(key, newExpireTime, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
public <T> T get(String key, Class<T> clazz) {
|
||||
return get(key, clazz, NOT_EXPIRE);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package com.sqx.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* Redis配置
|
||||
*
|
||||
@@ -16,6 +23,18 @@ public class RedisConfig {
|
||||
@Autowired
|
||||
private RedisConnectionFactory factory;
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(30))
|
||||
// 设置缓存过期时间为30分钟
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()))
|
||||
.disableCachingNullValues();
|
||||
|
||||
return RedisCacheManager.builder(redisConnectionFactory)
|
||||
.cacheDefaults(cacheConfiguration)
|
||||
.build();
|
||||
}
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate() {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
|
||||
@@ -41,6 +41,7 @@ public class ShiroConfig {
|
||||
shiroFilter.setFilters(filters);
|
||||
|
||||
Map<String, String> filterMap = new LinkedHashMap<>();
|
||||
filterMap.put("/uniCallBack/**", "anon");
|
||||
filterMap.put("/course/synCourse", "anon");
|
||||
filterMap.put("/webjars/**", "anon");
|
||||
filterMap.put("/druid/**", "anon");
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.sqx.modules.app.controller.app;
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.service.AdService;
|
||||
import com.sqx.modules.callback.service.UniAdCallbackRecordService;
|
||||
import com.sqx.modules.sys.controller.AbstractController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/app/ad")
|
||||
public class AdController extends AbstractController {
|
||||
|
||||
private final UniAdCallbackRecordService callbackRecordService;
|
||||
private final AdService adService;
|
||||
|
||||
public AdController(UniAdCallbackRecordService callbackRecordService, AdService adService) {
|
||||
this.callbackRecordService = callbackRecordService;
|
||||
this.adService = adService;
|
||||
}
|
||||
|
||||
@Login
|
||||
@GetMapping("/state")
|
||||
public Result getAdState(@RequestParam String extraKey, @RequestAttribute Long userId) {
|
||||
return Result.success(callbackRecordService.getStateByExtraKey(userId, extraKey));
|
||||
}
|
||||
|
||||
@Login
|
||||
@GetMapping("/detail")
|
||||
public Result getAdDetail(@RequestAttribute Long userId) {
|
||||
return Result.success(adService.getDetail(userId));
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户奖品兑换
|
||||
*
|
||||
* @author tankaikai
|
||||
* @since 2024-12-20 17:52
|
||||
*/
|
||||
@@ -33,6 +34,10 @@ public class UserPrizeExchange implements Serializable {
|
||||
* 奖品名称
|
||||
*/
|
||||
private String prizeName;
|
||||
/**
|
||||
* 奖品图片地址
|
||||
*/
|
||||
private String imgUrl;
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
|
||||
7
src/main/java/com/sqx/modules/app/service/AdService.java
Normal file
7
src/main/java/com/sqx/modules/app/service/AdService.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.sqx.modules.app.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface AdService {
|
||||
HashMap<String, Object> getDetail(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sqx.modules.app.service.impl;
|
||||
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.modules.app.service.AdService;
|
||||
import com.sqx.modules.redisService.impl.RedisServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
public class AdServiceImpl implements AdService {
|
||||
|
||||
private final RedisServiceImpl redisServiceImpl;
|
||||
|
||||
public AdServiceImpl(RedisServiceImpl redisServiceImpl) {
|
||||
this.redisServiceImpl = redisServiceImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> getDetail(Long userId) {
|
||||
Long freeWatchRemainTime = redisServiceImpl.getFreeWatchRemainTime(userId, false);
|
||||
Long permanentlyFreeWatchRemainTime = redisServiceImpl.getFreeWatchRemainTime(userId, true);
|
||||
return new HashMap<String, Object>(){{
|
||||
put("adFreeWatchTime", permanentlyFreeWatchRemainTime);
|
||||
put("payFreeWatchTime", freeWatchRemainTime);
|
||||
put("totalFreeWatchTime", freeWatchRemainTime + permanentlyFreeWatchRemainTime);
|
||||
}};
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ public class UserMoneyDetailsServiceImpl extends ServiceImpl<UserMoneyDetailsDao
|
||||
arrayList.add(1);
|
||||
arrayList.add(6);
|
||||
arrayList.add(7);
|
||||
arrayList.add(8);
|
||||
queryWrapper.in("classify", arrayList);
|
||||
}
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.sqx.modules.discSpinning.dao.DiscSpinningRecordDao;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
@@ -75,6 +76,7 @@ public class UserPrizeExchangeServiceImpl extends ServiceImpl<UserPrizeExchangeD
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void exchange(Long currentUserId, UserPrizeExchange dto) {
|
||||
if (dto.getDiscSpinningRecordId() == null) {
|
||||
throw new SqxException("中奖记录ID不能为空");
|
||||
@@ -119,7 +121,11 @@ public class UserPrizeExchangeServiceImpl extends ServiceImpl<UserPrizeExchangeD
|
||||
dto.setUserName(user.getUserName());
|
||||
dto.setStatus(0);
|
||||
dto.setCreateTime(new Date());
|
||||
dto.setImgUrl(record.getImgUrl());
|
||||
baseMapper.insert(dto);
|
||||
record.setTarget("3");
|
||||
record.setTargetId(dto.getId());
|
||||
discSpinningRecordDao.updateById(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.sqx.modules.callback;
|
||||
|
||||
import com.sqx.modules.callback.dao.UniAdCallBackDTO;
|
||||
import com.sqx.modules.callback.service.UniAdCallbackRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/uniCallBack")
|
||||
@Slf4j
|
||||
public class UniCallBackController {
|
||||
private final UniAdCallbackRecordService uniCallBackService;
|
||||
|
||||
public UniCallBackController(UniAdCallbackRecordService uniCallBackService) {
|
||||
this.uniCallBackService = uniCallBackService;
|
||||
}
|
||||
|
||||
@GetMapping("/adCallBack")
|
||||
public ResponseEntity<?> adCallBack(@RequestParam String adpid, @RequestParam String provider,
|
||||
@RequestParam String platform, @RequestParam String sign, @RequestParam String trans_id,
|
||||
@RequestParam String user_id, @RequestParam(required = false) String extra) {
|
||||
UniAdCallBackDTO dto = new UniAdCallBackDTO();
|
||||
dto.setAdpid(adpid);
|
||||
dto.setProvider(provider);
|
||||
dto.setPlatform(platform);
|
||||
dto.setSign(sign);
|
||||
dto.setTrans_id(trans_id);
|
||||
dto.setUser_id(user_id);
|
||||
dto.setExtra(extra);
|
||||
log.info("接收到uni-ad广告完播回调,回调信息: {}", dto);
|
||||
return ResponseEntity.ok(uniCallBackService.adCallBack(dto));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.sqx.modules.callback.dao;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
public class UniAdCallBackDTO {
|
||||
private String adpid;
|
||||
private String provider;
|
||||
private String platform;
|
||||
private String sign;
|
||||
private String trans_id;
|
||||
private String user_id;
|
||||
private String extra;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.sqx.modules.callback.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName uni_ad_callback_record
|
||||
*/
|
||||
@TableName(value ="uni_ad_callback_record")
|
||||
@Data
|
||||
public class UniAdCallbackRecord implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 平台
|
||||
*/
|
||||
private String platform;
|
||||
|
||||
/**
|
||||
* 交易id
|
||||
*/
|
||||
private String transId;
|
||||
|
||||
/**
|
||||
* DCloud广告位id
|
||||
*/
|
||||
private String adpid;
|
||||
|
||||
/**
|
||||
* 广告服务商
|
||||
*/
|
||||
private String provider;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 调用SDK传入并透传,自定义数据
|
||||
*/
|
||||
private String extra;
|
||||
|
||||
/**
|
||||
* 是否播放完毕
|
||||
*/
|
||||
private Integer isEnded;
|
||||
|
||||
/**
|
||||
* 回调时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String errMsg;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != that.getClass()) {
|
||||
return false;
|
||||
}
|
||||
UniAdCallbackRecord other = (UniAdCallbackRecord) that;
|
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
|
||||
&& (this.getPlatform() == null ? other.getPlatform() == null : this.getPlatform().equals(other.getPlatform()))
|
||||
&& (this.getTransId() == null ? other.getTransId() == null : this.getTransId().equals(other.getTransId()))
|
||||
&& (this.getAdpid() == null ? other.getAdpid() == null : this.getAdpid().equals(other.getAdpid()))
|
||||
&& (this.getProvider() == null ? other.getProvider() == null : this.getProvider().equals(other.getProvider()))
|
||||
&& (this.getSign() == null ? other.getSign() == null : this.getSign().equals(other.getSign()))
|
||||
&& (this.getExtra() == null ? other.getExtra() == null : this.getExtra().equals(other.getExtra()))
|
||||
&& (this.getIsEnded() == null ? other.getIsEnded() == null : this.getIsEnded().equals(other.getIsEnded()))
|
||||
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
|
||||
&& (this.getErrMsg() == null ? other.getErrMsg() == null : this.getErrMsg().equals(other.getErrMsg()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
|
||||
result = prime * result + ((getPlatform() == null) ? 0 : getPlatform().hashCode());
|
||||
result = prime * result + ((getTransId() == null) ? 0 : getTransId().hashCode());
|
||||
result = prime * result + ((getAdpid() == null) ? 0 : getAdpid().hashCode());
|
||||
result = prime * result + ((getProvider() == null) ? 0 : getProvider().hashCode());
|
||||
result = prime * result + ((getSign() == null) ? 0 : getSign().hashCode());
|
||||
result = prime * result + ((getExtra() == null) ? 0 : getExtra().hashCode());
|
||||
result = prime * result + ((getIsEnded() == null) ? 0 : getIsEnded().hashCode());
|
||||
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
|
||||
result = prime * result + ((getErrMsg() == null) ? 0 : getErrMsg().hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" [");
|
||||
sb.append("Hash = ").append(hashCode());
|
||||
sb.append(", id=").append(id);
|
||||
sb.append(", userId=").append(userId);
|
||||
sb.append(", platform=").append(platform);
|
||||
sb.append(", transId=").append(transId);
|
||||
sb.append(", adpid=").append(adpid);
|
||||
sb.append(", provider=").append(provider);
|
||||
sb.append(", sign=").append(sign);
|
||||
sb.append(", extra=").append(extra);
|
||||
sb.append(", isEnded=").append(isEnded);
|
||||
sb.append(", createTime=").append(createTime);
|
||||
sb.append(", errMsg=").append(errMsg);
|
||||
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sqx.modules.callback.mapper;
|
||||
|
||||
import com.sqx.modules.callback.entity.UniAdCallbackRecord;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【uni_ad_callback_record】的数据库操作Mapper
|
||||
* @createDate 2024-12-23 10:37:52
|
||||
* @Entity com.sqx.modules.callback.entity.UniAdCallbackRecord
|
||||
*/
|
||||
@Mapper
|
||||
public interface UniAdCallbackRecordMapper extends BaseMapper<UniAdCallbackRecord> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sqx.modules.callback.service;
|
||||
|
||||
import com.sqx.modules.callback.dao.UniAdCallBackDTO;
|
||||
import com.sqx.modules.callback.entity.UniAdCallbackRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【uni_ad_callback_record】的数据库操作Service
|
||||
* @createDate 2024-12-23 10:37:52
|
||||
*/
|
||||
public interface UniAdCallbackRecordService extends IService<UniAdCallbackRecord> {
|
||||
|
||||
Map<String, Object> adCallBack(UniAdCallBackDTO callBackDTO);
|
||||
|
||||
HashMap<String, Object> getStateByExtraKey(Long userId, String extraKey);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.sqx.modules.callback.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.modules.app.dao.UserDao;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.callback.dao.UniAdCallBackDTO;
|
||||
import com.sqx.modules.callback.entity.UniAdCallbackRecord;
|
||||
import com.sqx.modules.callback.service.UniAdCallbackRecordService;
|
||||
import com.sqx.modules.callback.mapper.UniAdCallbackRecordMapper;
|
||||
import com.sqx.modules.common.dao.CommonInfoDao;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.redisService.RedisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【uni_ad_callback_record】的数据库操作Service实现
|
||||
* @createDate 2024-12-23 10:37:52
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UniAdCallbackRecordServiceImpl extends ServiceImpl<UniAdCallbackRecordMapper, UniAdCallbackRecord>
|
||||
implements UniAdCallbackRecordService{
|
||||
@Value("${sqx.uni.adSecret}")
|
||||
private String adSecurity;
|
||||
|
||||
private final UserDao userDao;
|
||||
private final CommonInfoDao commonInfoDao;
|
||||
|
||||
private final RedisService redisService;
|
||||
|
||||
public UniAdCallbackRecordServiceImpl(UserDao userDao, CommonInfoDao commonInfoDao, RedisService redisService) {
|
||||
this.userDao = userDao;
|
||||
this.commonInfoDao = commonInfoDao;
|
||||
this.redisService = redisService;
|
||||
}
|
||||
|
||||
private String getBaseErrInfo(UniAdCallbackRecord callbackRecord) {
|
||||
return StrUtil.format("广告获取免费观看时长回调异常: {}, 用户id: {}, 广告播放回调trans_id: {}",
|
||||
callbackRecord.getErrMsg(), callbackRecord.getUserId(), callbackRecord.getTransId());
|
||||
}
|
||||
|
||||
// 生成签名
|
||||
public static String generateSign(String secret, String transId) {
|
||||
// 生成待加密的字符串
|
||||
String data = secret + ":" + transId;
|
||||
|
||||
// 使用SHA-256生成签名
|
||||
return DigestUtil.sha256Hex(data);
|
||||
}
|
||||
|
||||
// 验证签名
|
||||
public static boolean validateSign(String secret, String transId, String providedSign) {
|
||||
// 生成系统计算出来的签名
|
||||
String generatedSign = generateSign(secret, transId);
|
||||
|
||||
// 比较计算出来的签名和提供的签名
|
||||
return StrUtil.equalsIgnoreCase(generatedSign, providedSign);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> adCallBack(UniAdCallBackDTO callBackDTO) {
|
||||
HashMap<String, Object> respData = new HashMap<>();
|
||||
UniAdCallbackRecord one = getOne(new LambdaQueryWrapper<UniAdCallbackRecord>()
|
||||
.eq(UniAdCallbackRecord::getTransId, callBackDTO.getTrans_id()));
|
||||
if (one != null) {
|
||||
log.warn("回调重复, {}", one.getTransId());
|
||||
respData.put("isValid", false);
|
||||
return respData;
|
||||
}
|
||||
UniAdCallbackRecord callbackRecord = new UniAdCallbackRecord();
|
||||
callbackRecord.setUserId(Long.valueOf(callBackDTO.getUser_id()));
|
||||
callbackRecord.setPlatform(callBackDTO.getPlatform());
|
||||
callbackRecord.setTransId(callBackDTO.getTrans_id());
|
||||
callbackRecord.setAdpid(callBackDTO.getAdpid());
|
||||
callbackRecord.setProvider(callBackDTO.getProvider());
|
||||
callbackRecord.setSign(callBackDTO.getSign());
|
||||
callbackRecord.setExtra(callBackDTO.getExtra());
|
||||
callbackRecord.setCreateTime(DateUtil.date());
|
||||
callbackRecord.setIsEnded(1);
|
||||
|
||||
boolean flag = validateSign(adSecurity, callBackDTO.getTrans_id(), callBackDTO.getSign());
|
||||
if (!flag) {
|
||||
callbackRecord.setErrMsg("签名验证失败");
|
||||
log.warn(getBaseErrInfo(callbackRecord));
|
||||
save(callbackRecord);
|
||||
respData.put("isValid", false);
|
||||
return respData;
|
||||
}
|
||||
|
||||
UserEntity userEntity = userDao.selectById(callBackDTO.getUser_id());
|
||||
if (userEntity == null) {
|
||||
callbackRecord.setErrMsg("用户不存在");
|
||||
log.warn(getBaseErrInfo(callbackRecord));
|
||||
save(callbackRecord);
|
||||
respData.put("isValid", false);
|
||||
return respData;
|
||||
}
|
||||
|
||||
CommonInfo info = commonInfoDao.findOne(921);
|
||||
if (info == null || StrUtil.isBlank(info.getValue())){
|
||||
callbackRecord.setErrMsg("CommonInfo时长时间未配置");
|
||||
log.warn(getBaseErrInfo(callbackRecord));
|
||||
save(callbackRecord);
|
||||
respData.put("isValid", false);
|
||||
return respData;
|
||||
}
|
||||
|
||||
redisService.setFreeWatchTime(callbackRecord.getUserId(), Integer.parseInt(info.getValue()) * 60, true);
|
||||
save(callbackRecord);
|
||||
respData.put("isValid", true);
|
||||
return respData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> getStateByExtraKey(Long userId, String extraKey) {
|
||||
UniAdCallbackRecord one = getOne(new LambdaQueryWrapper<UniAdCallbackRecord>().eq(UniAdCallbackRecord::getUserId, userId)
|
||||
.eq(UniAdCallbackRecord::getExtra, extraKey));
|
||||
return new HashMap<String, Object>(){{
|
||||
put("isEnded", one == null ? 0 : 1);
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,12 +15,12 @@ import java.util.List;
|
||||
* @date 2020/7/8
|
||||
*/
|
||||
@Mapper
|
||||
@CacheConfig(cacheNames = "common")
|
||||
public interface CommonInfoDao extends BaseMapper<CommonInfo> {
|
||||
|
||||
List<CommonInfo> findByCondition(@Param("condition") String condition);
|
||||
|
||||
@Cacheable(key = "#type")
|
||||
CommonInfo findOne(@Param("type") int type);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.course.service.CourseService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -16,6 +20,7 @@ import java.util.Date;
|
||||
* @author fang
|
||||
* @date 2020/7/8
|
||||
*/
|
||||
@CacheConfig(cacheNames = "common")
|
||||
@Service
|
||||
public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo> implements CommonInfoService {
|
||||
|
||||
@@ -25,7 +30,7 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
|
||||
private CourseService courseService;
|
||||
|
||||
|
||||
|
||||
@CacheEvict(key = "#commonInfo.id")
|
||||
@Override
|
||||
public Result update(CommonInfo commonInfo) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
@@ -43,19 +48,19 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CommonInfo findOne(int type) {
|
||||
return commonInfoDao.findOne(type);
|
||||
}
|
||||
|
||||
@CacheEvict(key = "#id")
|
||||
@Override
|
||||
public Result delete(long id) {
|
||||
commonInfoDao.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@CacheEvict(key = "#commonInfo.id")
|
||||
@Override
|
||||
public Result updateBody(CommonInfo commonInfo) {
|
||||
commonInfoDao.updateById(commonInfo);
|
||||
|
||||
@@ -49,6 +49,11 @@ public class Course implements Serializable {
|
||||
*/
|
||||
private BigDecimal price;
|
||||
|
||||
/**
|
||||
* 10集购买价格
|
||||
*/
|
||||
private BigDecimal wholesalePrice;
|
||||
|
||||
/**
|
||||
* 上下架 1上架 2下架
|
||||
*/
|
||||
|
||||
@@ -98,7 +98,7 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
||||
* @return true 可观看
|
||||
*/
|
||||
private boolean checkFreeWatchPayCount(Long userId) {
|
||||
Boolean isExpire = redisServiceImpl.getPayFreeWatchTimeIsExpire(userId);
|
||||
Boolean isExpire = redisServiceImpl.getFreeWatchTimeIsExpire(userId);
|
||||
if (isExpire == null) {
|
||||
Integer count = ordersDao.countPayOrderByDay(userId);
|
||||
CommonInfo needCountCommonInfo = commonInfoDao.selectOne(new LambdaQueryWrapper<CommonInfo>()
|
||||
@@ -113,7 +113,9 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
||||
|
||||
// 购买次数超过,设置redis标识
|
||||
if (count >= Integer.parseInt(needCountCommonInfo.getValue())) {
|
||||
redisServiceImpl.setPayFreeWatchTime(userId, Integer.parseInt(freeTimeCommonInfo.getValue()));
|
||||
redisServiceImpl.setFreeWatchTime(userId, Integer.parseInt(freeTimeCommonInfo.getValue()) * 60, false);
|
||||
// 触发计时
|
||||
redisServiceImpl.getFreeWatchTimeIsExpire(userId);
|
||||
isExpire = false;
|
||||
}else {
|
||||
isExpire = true;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.sqx.modules.discSpinning.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sqx.common.annotation.Debounce;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.RedisKeys;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
@@ -16,6 +19,8 @@ import com.sqx.modules.discSpinning.service.DiscSpinningRecordService;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningService;
|
||||
import com.sqx.modules.orders.entity.Orders;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterRecord;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterRecordService;
|
||||
import com.sqx.modules.taskCenter.service.TaskCenterService;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -41,18 +46,23 @@ public class DiscSpinningController {
|
||||
private final CommonInfoService commonRepository;
|
||||
private final OrdersService ordersService;
|
||||
private final TaskCenterService taskCenterService;
|
||||
private final TaskCenterRecordService taskRecordService;
|
||||
private final UserService userService;
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
@Autowired
|
||||
public DiscSpinningController(CommonInfoService commonRepository, DiscSpinningService discSpinningService,
|
||||
OrdersService ordersService, DiscSpinningRecordService recordService,
|
||||
TaskCenterService taskCenterService, UserService userService) {
|
||||
TaskCenterService taskCenterService, UserService userService, RedisUtils redisUtils,
|
||||
TaskCenterRecordService taskRecordService) {
|
||||
this.commonRepository = commonRepository;
|
||||
this.discSpinningService = discSpinningService;
|
||||
this.ordersService = ordersService;
|
||||
this.recordService = recordService;
|
||||
this.taskCenterService = taskCenterService;
|
||||
this.userService = userService;
|
||||
this.redisUtils = redisUtils;
|
||||
this.taskRecordService = taskRecordService;
|
||||
}
|
||||
|
||||
@PostMapping("/discSpinning/insertDiscSpinning")
|
||||
@@ -143,6 +153,7 @@ public class DiscSpinningController {
|
||||
//任务可抽奖次数
|
||||
map.put("count", taskCenterService.countTaskDisc(userId, source.toString()));
|
||||
} else {
|
||||
//订单可抽奖次数
|
||||
int i = recordService.countDraw(userId);
|
||||
if (drawCount - i > 0) {
|
||||
map.put("count", ordersService.selectOrdersCountStatisticsByDay(userId, drawCount - i));
|
||||
@@ -161,10 +172,11 @@ public class DiscSpinningController {
|
||||
@ApiOperation("抽取大转盘")
|
||||
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @RequestParam(required = false, defaultValue = "1") Integer source) {
|
||||
double amount = 0;
|
||||
Long orderId = null;
|
||||
Long sourceId = null;
|
||||
Integer i = recordService.countDraw(userId);
|
||||
if (source != null && source.equals(1)) {
|
||||
//任务抽奖
|
||||
if (source == null || source.equals(1)) {
|
||||
source = 1;
|
||||
//订单抽奖
|
||||
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
||||
if (i != null && i >= drawCount) {
|
||||
return Result.error("当日可抽奖次数已超限");
|
||||
@@ -174,12 +186,44 @@ public class DiscSpinningController {
|
||||
return Result.error("无可抽奖机会");
|
||||
}
|
||||
amount = orders.getPayMoney().doubleValue();
|
||||
orderId = orders.getOrdersId();
|
||||
} else if (source == null) {
|
||||
source = 1;
|
||||
sourceId = orders.getOrdersId();
|
||||
} else {
|
||||
String redisKey = "";
|
||||
if (source.equals(2)) {
|
||||
redisKey = RedisKeys.getDateKey("spinning:amount:taskW") + userId;
|
||||
} else if (source.equals(3)) {
|
||||
redisKey = RedisKeys.getDateKey("spinning:amount:taskM") + userId;
|
||||
}
|
||||
Map<String, Object> week = redisUtils.get(redisKey, Map.class);
|
||||
for (Map.Entry<String, Object> entry : week.entrySet()) {
|
||||
int value = new BigDecimal(entry.getValue().toString()).intValue();
|
||||
if (value > 1) {
|
||||
value = value - 1;
|
||||
week.put(entry.getKey(), value);
|
||||
sourceId = Long.valueOf(entry.getKey());
|
||||
break;
|
||||
} else {
|
||||
TaskCenterRecord centerRecord = new TaskCenterRecord();
|
||||
centerRecord.setUserId(userId);
|
||||
centerRecord.setTaskId(Long.valueOf(entry.getKey()));
|
||||
if (source.equals(2)) {
|
||||
sourceId = Long.valueOf(entry.getKey());
|
||||
centerRecord.setSourceId(Long.getLong(entry.getKey()));
|
||||
}
|
||||
centerRecord.setName(source.equals(2) ? "周任务奖励" : "月任务奖励");
|
||||
centerRecord.setType(9);
|
||||
centerRecord.setNumber(1);
|
||||
centerRecord.setCreateTime(DateUtil.now());
|
||||
centerRecord.setUpdateTime(DateUtil.now());
|
||||
taskRecordService.save(centerRecord);
|
||||
week.remove(entry.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
redisUtils.set(redisKey, week, DateUtils.todayAfterSecond());
|
||||
}
|
||||
return new Result().put("data",
|
||||
discSpinningService.draws(i == null ? 1 : i + 1, amount, orderId, userId, source));
|
||||
discSpinningService.draws(i == null ? 1 : i + 1, amount, sourceId, userId, source));
|
||||
}
|
||||
|
||||
@ApiOperation("大转盘奖项领取")
|
||||
@@ -191,9 +235,11 @@ public class DiscSpinningController {
|
||||
discSpinningService.receiveAsync(record);
|
||||
});
|
||||
UserEntity userInfo = userService.queryByUserId(record.getUserId());
|
||||
int res = 0;
|
||||
if (StringUtils.isNotBlank(userInfo.getZhiFuBao()) && StringUtils.isNotBlank(userInfo.getZhiFuBaoName())) {
|
||||
res = 1;
|
||||
int res = 1;
|
||||
if (receive.getType().equals(2)) {
|
||||
if (StringUtils.isBlank(userInfo.getZhiFuBao()) && StringUtils.isBlank(userInfo.getZhiFuBaoName())) {
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
return Result.success().put("data", res);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DiscSpinningRecordController {
|
||||
@GetMapping("/selectDiscSpinningRecord")
|
||||
@ApiOperation("查询大转盘抽奖记录")
|
||||
public Result selectDiscSpinningRecord(Integer page, Integer limit,@RequestAttribute("userId") Long userId) {
|
||||
return Result.success().put("data", discSpinningRecordService.page(new Page<>(page, limit), new QueryWrapper<DiscSpinningRecord>().eq("user_id",userId).orderByAsc("create_time")));
|
||||
return Result.success().put("data", discSpinningRecordService.page(new Page<>(page, limit), new QueryWrapper<DiscSpinningRecord>().eq("user_id",userId).orderByDesc("create_time")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
package com.sqx.modules.discSpinning.entity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 大转盘抽奖记录(DiscSpinningRecord)表实体类
|
||||
@@ -23,16 +18,17 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
|
||||
//主键
|
||||
private Long id;
|
||||
|
||||
private Long orderId;
|
||||
private Long sourceId;
|
||||
|
||||
private Long userId;
|
||||
private String imgUrl;
|
||||
//描述
|
||||
private String name;
|
||||
//类型 1谢谢惠顾 2 红包 9 其它
|
||||
private Integer type;
|
||||
//金额
|
||||
private BigDecimal number;
|
||||
//流向 1 提现 2 存入余额
|
||||
//流向 1 提现 2 存入余额 3 兑换
|
||||
private String target;
|
||||
|
||||
private Long targetId;
|
||||
@@ -46,11 +42,12 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
|
||||
public DiscSpinningRecord() {
|
||||
}
|
||||
|
||||
public DiscSpinningRecord(String name, Long orderId, Long userId, Integer type, BigDecimal number,
|
||||
public DiscSpinningRecord(String name, Long sourceId, Long userId,String imgUrl, Integer type, BigDecimal number,
|
||||
String drawDay, String createTime, Integer source) {
|
||||
this.name = name;
|
||||
this.userId = userId;
|
||||
this.orderId = orderId;
|
||||
this.sourceId = sourceId;
|
||||
this.imgUrl = imgUrl;
|
||||
this.type = type;
|
||||
this.number = number;
|
||||
this.drawDay = drawDay;
|
||||
|
||||
@@ -8,5 +8,7 @@ import java.util.Map;
|
||||
public interface DiscSpinningRecordService extends IService<DiscSpinningRecord> {
|
||||
|
||||
Integer countDraw(Long userId);
|
||||
//当月的 月记录 已抽 抽奖次数
|
||||
Integer countSourceRecord(Long sourceId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.sqx.modules.discSpinning.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.modules.discSpinning.dao.DiscSpinningRecordDao;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningRecordService;
|
||||
import com.sqx.modules.userSign.entity.UserSignRecord;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@@ -21,5 +24,14 @@ public class DiscSpinningRecordServiceImpl extends ServiceImpl<DiscSpinningRecor
|
||||
public Integer countDraw(Long userId) {
|
||||
return discSpinningRecordDao.countDraw(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countSourceRecord(Long sourceId) {
|
||||
QueryWrapper<DiscSpinningRecord> recordQuery = new QueryWrapper<>();
|
||||
recordQuery.eq("source_id", sourceId);
|
||||
recordQuery.eq("source", "taskM");
|
||||
recordQuery.gt("create_time", DateUtil.beginOfMonth(new Date()));
|
||||
return discSpinningRecordDao.selectCount(recordQuery);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public DiscSpinningRecord draws(int drawCount, double orderAmount, Long orderId, Long userId, Integer source) {
|
||||
public DiscSpinningRecord draws(int drawCount, double orderAmount, Long sourceId, Long userId, Integer source) {
|
||||
DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, null);
|
||||
List<DiscSpinning> prizes = baseMapper.selectList(new QueryWrapper<DiscSpinning>().eq("disc_type", source).orderByAsc("odds"));
|
||||
|
||||
@@ -216,12 +216,13 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
||||
} else {
|
||||
if (source != 1) {
|
||||
result = prize;
|
||||
result.setNumber(BigDecimal.ONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), orderId, userId, result.getType(),
|
||||
DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), sourceId, userId,result.getUrl(), result.getType(),
|
||||
result.getNumber(), DateUtils.formatYMD(new Date()), DateUtils.format(new Date()), source);
|
||||
recordService.save(record);
|
||||
return record;
|
||||
|
||||
@@ -40,6 +40,20 @@ public class AppOrdersController extends AbstractController {
|
||||
return ordersService.insertCourseOrders(courseId, courseDetailsId,userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成商品订单
|
||||
*
|
||||
* @param courseId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Login
|
||||
@GetMapping("/insertCourseOrders/limit10")
|
||||
@ApiOperation("生成商品订单")
|
||||
public Result insertCourseOrdersLimit10(Long courseId, @RequestAttribute("userId") Long userId) {
|
||||
return ordersService.insertCourseOrdersLimit10(courseId, userId);
|
||||
}
|
||||
|
||||
@Login
|
||||
@GetMapping("/insertVipOrders")
|
||||
@ApiOperation("生成会员订单")
|
||||
|
||||
@@ -49,6 +49,8 @@ public class Orders implements Serializable {
|
||||
|
||||
private Long courseDetailsId;
|
||||
|
||||
private String courseDetailsIds;
|
||||
|
||||
@TableField(exist = false)
|
||||
/**
|
||||
* 短剧对象
|
||||
|
||||
@@ -15,15 +15,17 @@ public interface OrdersService extends IService<Orders> {
|
||||
|
||||
Result payMoney(Long orderId);
|
||||
|
||||
Result insertCourseOrders(Long courseId, Long courseDetailsId,Long userId);
|
||||
Result insertCourseOrders(Long courseId, Long courseDetailsId, Long userId);
|
||||
|
||||
Result insertCourseOrdersLimit10(Long courseId, Long userId);
|
||||
|
||||
Result insertVipOrders(Long vipDetailsId, Long userId);
|
||||
|
||||
Result refundOrder(Long ordersId, String refundContent);
|
||||
|
||||
Result selectOrders(Integer page, Integer limit, String ordersNo,Integer status,Long userId,Long courseId,
|
||||
Integer flag,String time,String userName,Integer ordersType,String startTime,String endTime,
|
||||
Long sysUserId,String qdCode,String sysUserName);
|
||||
Result selectOrders(Integer page, Integer limit, String ordersNo, Integer status, Long userId, Long courseId,
|
||||
Integer flag, String time, String userName, Integer ordersType, String startTime, String endTime,
|
||||
Long sysUserId, String qdCode, String sysUserName);
|
||||
|
||||
Result selectOrderByUserId(Integer page, Integer limit, Long userId);
|
||||
|
||||
@@ -35,31 +37,32 @@ public interface OrdersService extends IService<Orders> {
|
||||
|
||||
Orders selectOrderByTradeNo(String tradeNo);
|
||||
|
||||
Double statisticsIncomeMoney(String time,Integer flag,Integer ordersType);
|
||||
Double statisticsIncomeMoney(String time, Integer flag, Integer ordersType);
|
||||
|
||||
Orders selectOrdersByCourseIdAndUserId(Long userId,Long courseId);
|
||||
Orders selectOrdersByCourseIdAndUserId(Long userId, Long courseId);
|
||||
|
||||
Result selectOrdersMoneyList(Integer page,Integer limit,Integer flag,String time);
|
||||
Result selectOrdersMoneyList(Integer page, Integer limit, Integer flag, String time);
|
||||
|
||||
Integer selectOrdersCount(Integer status,Integer ordersType,Integer flag,String time,Long sysUserId);
|
||||
Integer selectOrdersCount(Integer status, Integer ordersType, Integer flag, String time, Long sysUserId);
|
||||
|
||||
Double selectOrdersMoney(Integer status,Integer ordersType,Integer flag,String time,Long courseId,Long sysUserId);
|
||||
Double selectOrdersMoney(Integer status, Integer ordersType, Integer flag, String time, Long courseId, Long sysUserId);
|
||||
|
||||
Double selectFenXiaoMoney(Integer type,Long sysUserId,Integer flag,String time);
|
||||
Double selectFenXiaoMoney(Integer type, Long sysUserId, Integer flag, String time);
|
||||
|
||||
Integer selectOrdersCountStatisticsByYear(Integer flag,String time,Integer status);
|
||||
Integer selectOrdersCountStatisticsByYear(Integer flag, String time, Integer status);
|
||||
|
||||
Integer selectOrdersCountStatisticsByDay(Long userId,Integer limit);
|
||||
Integer selectOrdersCountStatisticsByDay(Long userId, Integer limit);
|
||||
|
||||
Orders selectOrdersByDay(Long userId);
|
||||
|
||||
/**
|
||||
* 统计 用户成功订单笔数
|
||||
*
|
||||
* @param userId
|
||||
* @param time 时间条件 不传为全部订单 格式 yyyy-MM-dd HH:mm:ss
|
||||
* @return
|
||||
*/
|
||||
Integer countOrderNum(Long userId,String time);
|
||||
Integer countOrderNum(Long userId, String time);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
package com.sqx.modules.orders.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.PageUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.*;
|
||||
import com.sqx.modules.app.entity.UserMoney;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.entity.UserVip;
|
||||
import com.sqx.modules.app.entity.VipDetails;
|
||||
import com.sqx.modules.app.service.*;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.course.dao.CourseDao;
|
||||
import com.sqx.modules.course.dao.CourseDetailsDao;
|
||||
import com.sqx.modules.course.dao.CourseUserDao;
|
||||
import com.sqx.modules.course.entity.Course;
|
||||
import com.sqx.modules.course.entity.CourseDetails;
|
||||
@@ -38,6 +48,7 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -72,6 +83,8 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||
private InviteMoneyService inviteMoneyService;
|
||||
@Autowired
|
||||
private DyService dyService;
|
||||
@Autowired
|
||||
private CourseDetailsDao courseDetailsDao;
|
||||
|
||||
private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock(true);
|
||||
|
||||
@@ -86,6 +99,28 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||
public Result insertOrders(Orders orders) {
|
||||
//如果订单的种类是短剧
|
||||
if (orders.getOrdersType() == 1) {
|
||||
if (StrUtil.isNotEmpty(orders.getCourseDetailsIds())) {
|
||||
List<Long> courseDetailsIdList = JSONUtil.parseArray(orders.getCourseDetailsIds()).toList(Long.class);
|
||||
List<CourseUser> courseUserList = new ArrayList<>();
|
||||
courseDetailsIdList.parallelStream().forEach(courseDetailsId -> {
|
||||
//将短剧加入到我的列表
|
||||
CourseUser courseUser = new CourseUser();
|
||||
//设置短剧id
|
||||
courseUser.setCourseId(orders.getCourseId());
|
||||
courseUser.setCourseDetailsId(courseDetailsId);
|
||||
courseUser.setClassify(2);
|
||||
//设置用户id
|
||||
courseUser.setUserId(orders.getUserId());
|
||||
//设置订单id
|
||||
courseUser.setOrderId(orders.getOrdersId());
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
courseUser.setCreateTime(df.format(new Date()));
|
||||
courseUserList.add(courseUser);
|
||||
});
|
||||
//加入我的列表
|
||||
courseUserService.saveBatch(courseUserList);
|
||||
return Result.success("短剧订单处理完成!");
|
||||
}
|
||||
//将短剧加入到我的列表
|
||||
CourseUser courseUser = new CourseUser();
|
||||
//设置短剧id
|
||||
@@ -209,10 +244,20 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||
log.info("生成商品订单信息接口入参为:{},{}", courseId, userId);
|
||||
reentrantReadWriteLock.writeLock().lock();
|
||||
try {
|
||||
/*CourseUser courseUser1 = courseUserDao.selectCourseUser(courseId, userId);
|
||||
if(courseUser1!=null){
|
||||
return Result.error("您已经购买过了,请不要重复点击!");
|
||||
}*/
|
||||
CourseUser courseUser1 = courseUserDao.selectCourseUser(courseId, userId);
|
||||
if (courseUser1 != null) {
|
||||
return Result.success().put("status", 1);
|
||||
}
|
||||
QueryWrapper<CourseUser> courseUserQueryWrapper = new QueryWrapper<>();
|
||||
courseUserQueryWrapper.eq("user_id", userId);
|
||||
courseUserQueryWrapper.eq("course_id", courseId);
|
||||
courseUserQueryWrapper.eq("course_details_id", courseDetailsId);
|
||||
courseUserQueryWrapper.eq("classify", 2);
|
||||
//加入我的列表
|
||||
int count1 = courseUserService.count(courseUserQueryWrapper);
|
||||
if (count1 > 0) {
|
||||
return Result.success().put("status", 1);
|
||||
}
|
||||
//返回的类型
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
//查询会员信息
|
||||
@@ -249,6 +294,9 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||
orders.setPayMoney(courseDetails.getPrice());
|
||||
orders.setPayDiamond(courseDetails.getPrice().multiply(v));
|
||||
} else {
|
||||
if (course.getPrice() == null || NumberUtil.isLessOrEqual(course.getPrice(), BigDecimal.ZERO)) {
|
||||
return Result.error("该剧暂不支持整剧购买方式!");
|
||||
}
|
||||
orders.setPayMoney(course.getPrice());
|
||||
orders.setPayDiamond(course.getPrice().multiply(v));
|
||||
}
|
||||
@@ -271,6 +319,120 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||
return Result.error("生成订单失败!");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("生成商品订单错误!!!" + e.getMessage());
|
||||
} finally {
|
||||
reentrantReadWriteLock.writeLock().unlock();
|
||||
}
|
||||
return Result.error("系统繁忙,请稍后再试!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成商品订单信息(购买10集)
|
||||
*
|
||||
* @param courseId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result insertCourseOrdersLimit10(Long courseId, Long userId) {
|
||||
log.info("生成商品订单信息接口入参为:{},{}", courseId, userId);
|
||||
reentrantReadWriteLock.writeLock().lock();
|
||||
try {
|
||||
/*CourseUser courseUser1 = courseUserDao.selectCourseUser(courseId, userId);
|
||||
if(courseUser1!=null){
|
||||
return Result.error("您已经购买过了,请不要重复点击!");
|
||||
}*/
|
||||
//返回的类型
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
//查询会员信息
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
if (courseId == null) {
|
||||
return Result.error("短剧的id不能为空");
|
||||
}
|
||||
|
||||
//订单模板对象
|
||||
Orders orders = new Orders();
|
||||
//根据短剧id去查询短剧相关信息 来填充订单模板
|
||||
QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("is_delete", 0);
|
||||
//短剧必须是未删除的
|
||||
queryWrapper.eq("course_id", courseId);
|
||||
Course course = courseDao.selectOne(queryWrapper);
|
||||
if (course == null) {
|
||||
return Result.error("系统繁忙,请刷新后重试!");
|
||||
}
|
||||
if (course.getWholesalePrice() == null) {
|
||||
return Result.error("该剧暂不支持10集购买方式!");
|
||||
}
|
||||
if (NumberUtil.isLessOrEqual(course.getWholesalePrice(), BigDecimal.ZERO)) {
|
||||
return Result.error("该剧暂不支持10集购买方式!");
|
||||
}
|
||||
//是否以购买全集
|
||||
Integer isBuyAllCount = courseUserDao.selectCount(Wrappers.<CourseUser>lambdaQuery().eq(CourseUser::getCourseId, courseId).eq(CourseUser::getCourseUserId, userId).eq(CourseUser::getClassify, 1));
|
||||
if (isBuyAllCount != null && isBuyAllCount > 0) {
|
||||
return Result.error("您已经购买过全集,请不要重复购买!");
|
||||
}
|
||||
List<CourseUser> courseUserList = courseUserDao.selectList(Wrappers.<CourseUser>lambdaQuery()
|
||||
.select(CourseUser::getCourseDetailsId)
|
||||
.eq(CourseUser::getCourseId, courseId)
|
||||
.eq(CourseUser::getUserId, userId)
|
||||
.eq(CourseUser::getClassify, 2)
|
||||
.orderByAsc(CourseUser::getCourseDetailsId)
|
||||
);
|
||||
// 已购买剧集
|
||||
List<Long> courseDetailsIdList = courseUserList.stream().map(CourseUser::getCourseDetailsId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
LambdaQueryWrapper<CourseDetails> wrapper = Wrappers.<CourseDetails>lambdaQuery();
|
||||
wrapper.eq(CourseDetails::getCourseId, courseId);
|
||||
wrapper.eq(CourseDetails::getIsPrice, 1);
|
||||
wrapper.select(CourseDetails::getCourseDetailsId);
|
||||
wrapper.orderByAsc(CourseDetails::getSort);
|
||||
List<CourseDetails> courseDetailsList = courseDetailsDao.selectList(wrapper);
|
||||
if (CollUtil.isEmpty(courseDetailsList)) {
|
||||
return Result.error("该剧的视频资源不存在!");
|
||||
}
|
||||
List<Long> allIds = courseDetailsList.stream().map(CourseDetails::getCourseDetailsId).distinct().collect(Collectors.toList());
|
||||
allIds.removeAll(courseDetailsIdList);
|
||||
// 需要购买的剧集id集合(没有权限的10集)
|
||||
List<Long> buyCourseDetailsIdList = allIds.stream().filter(Objects::nonNull).limit(10).collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(buyCourseDetailsIdList)) {
|
||||
return Result.error("没有需要购买的剧集!");
|
||||
}
|
||||
//设置订单编号
|
||||
orders.setOrdersNo(AliPayOrderUtil.createOrderId());
|
||||
//设置用户id
|
||||
orders.setUserId(userId);
|
||||
//设置短剧id
|
||||
orders.setCourseId(courseId);
|
||||
orders.setCourseDetailsId(null);
|
||||
orders.setCourseDetailsIds(JSONUtil.parseArray(buyCourseDetailsIdList).toString());
|
||||
|
||||
// 金币和金额的比例
|
||||
String value = commonInfoService.findOne(914).getValue();
|
||||
BigDecimal v = new BigDecimal(value);
|
||||
|
||||
orders.setPayMoney(course.getWholesalePrice());
|
||||
orders.setPayDiamond(course.getWholesalePrice().multiply(v));
|
||||
// BigDecimal payDiamond = orders.getPayMoney().multiply(new BigDecimal(commonInfoService.findOne(892).getValue()));
|
||||
// orders.setPayDiamond(payDiamond);
|
||||
//设置支付状态
|
||||
orders.setStatus(0);
|
||||
//设置订单创建时间
|
||||
orders.setCreateTime(df.format(new Date()));
|
||||
//设置订单种类
|
||||
orders.setOrdersType(1);
|
||||
|
||||
//不是会员或会员过期直接生成订单直接生成订单
|
||||
int count = baseMapper.insert(orders);
|
||||
result.put("flag", 2);
|
||||
result.put("orders", orders);
|
||||
if (count > 0) {
|
||||
return Result.success("生成订单成功!").put("data", result);
|
||||
} else {
|
||||
return Result.error("生成订单失败!");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("生成商品订单错误!!!" + e.getMessage());
|
||||
@@ -330,6 +492,12 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||
.eq("classify", 2)
|
||||
.eq("course_id", orders.getCourseId())
|
||||
.eq(orders.getCourseDetailsId() != null, "course_details_id", orders.getCourseDetailsId()));
|
||||
} else if (orders.getCourseDetailsIds() != null) {
|
||||
List<Long> courseDetailsIds = JSONUtil.parseArray(orders.getCourseDetailsIds()).toList(Long.class);
|
||||
count = courseUserDao.selectCount(new QueryWrapper<CourseUser>()
|
||||
.eq("user_id", orders.getUserId())
|
||||
.eq("course_id", orders.getCourseId())
|
||||
.in("course_details_id", courseDetailsIds));
|
||||
} else {
|
||||
count = courseUserDao.selectCount(new QueryWrapper<CourseUser>()
|
||||
.eq("user_id", orders.getUserId())
|
||||
@@ -344,7 +512,7 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
||||
if (userMoney.getMoney().doubleValue() < orders.getPayDiamond().doubleValue()) {
|
||||
return Result.error("账户不足,请充值!");
|
||||
}
|
||||
UserEntity userEntity = userService.selectUserById(orders.getUserId());
|
||||
//UserEntity userEntity = userService.selectUserById(orders.getUserId());
|
||||
userMoneyService.updateMoney(2, orders.getUserId(), orders.getPayDiamond().doubleValue());
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails();
|
||||
userMoneyDetails.setMoney(orders.getPayDiamond());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.sqx.modules.redisService.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
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 +20,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 +41,101 @@ 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 = -1L;
|
||||
}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 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);
|
||||
Long expireTime = -1L;
|
||||
JSONObject jsonObject = null;
|
||||
if (StrUtil.isNotBlank(payFreeWatchInfo)) {
|
||||
jsonObject = JSONObject.parseObject(payFreeWatchInfo);
|
||||
expireTime = jsonObject.getLong("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) {
|
||||
DateTime now = DateUtil.date();
|
||||
jsonObject.put("expireTime", DateUtil.offsetSecond(now, second).getTime());
|
||||
Date tomorrow = DateUtil.beginOfDay(DateUtil.offsetDay(now, 1));
|
||||
long expire = DateUtil.between(now, tomorrow, DateUnit.SECOND);
|
||||
|
||||
redisUtils.set(watchKey, jsonObject.toJSONString(), expire);
|
||||
return false;
|
||||
}else {
|
||||
return DateUtil.current() > expireTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getPayFreeWatchTimeIsExpire(Long userId) {
|
||||
String data = redisUtils.get(RedisKeys.getPayFreeWatchKey(userId));
|
||||
if (data == null) {
|
||||
return null;
|
||||
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;
|
||||
}
|
||||
|
||||
long expireTime = Long.parseLong(data);
|
||||
return DateUtil.current() > expireTime;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,5 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface TaskCenterDao extends BaseMapper<TaskCenter> {
|
||||
|
||||
//大转盘任务
|
||||
List<TaskCenter> queryTaskDiscCenter();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,16 @@ package com.sqx.modules.taskCenter.dao;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterReward;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface TaskCenterRewardDao extends BaseMapper<TaskCenterReward> {
|
||||
|
||||
@Select("SELECT type,number FROM `task_center_reward` where task_id = #{taskId}")
|
||||
List<TaskCenterReward> getRewardMap(Long taskId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,10 @@ public class TaskCenterRecord extends Model<TaskCenterRecord> {
|
||||
private Long id;
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
@ApiModelProperty("任务Id")
|
||||
@ApiModelProperty("任务Id 周任务转盘奖励时 该值为 user_sign_record的id")
|
||||
private Long taskId;
|
||||
@ApiModelProperty("来源Id 目前仅周任务使用")
|
||||
private Long sourceId;
|
||||
@ApiModelProperty("奖励名称")
|
||||
private String name;
|
||||
@ApiModelProperty("奖励类型 1 金币 2 现金 3 4 5 9转盘")
|
||||
|
||||
@@ -7,5 +7,6 @@ import java.util.Map;
|
||||
|
||||
public interface TaskCenterRewardService extends IService<TaskCenterReward> {
|
||||
|
||||
Map<Integer, Integer> getRewardMap(Long taskId);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,13 @@ import java.util.Map;
|
||||
|
||||
public interface TaskCenterService extends IService<TaskCenter> {
|
||||
|
||||
//查询任务中心
|
||||
Result queryTaskCenter(Long userId);
|
||||
|
||||
//任务领取
|
||||
Result taskReceive(Long userId, Long id);
|
||||
|
||||
//获取大转盘抽奖次数
|
||||
int countTaskDisc(Long userId,String type);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,25 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class TaskCenterRewardServiceImpl extends ServiceImpl<TaskCenterRewardDao, TaskCenterReward> implements TaskCenterRewardService {
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Integer, Integer> getRewardMap(Long taskId) {
|
||||
List<TaskCenterReward> rewards = baseMapper.getRewardMap(taskId);
|
||||
|
||||
Map<Integer, Integer> map = rewards.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
TaskCenterReward::getType,
|
||||
Collectors.summingInt(TaskCenterReward::getNumber)
|
||||
));
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
package com.sqx.modules.taskCenter.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.DateUtils;
|
||||
import com.sqx.common.utils.RedisKeys;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
import com.sqx.modules.app.service.UserMoneyDetailsService;
|
||||
import com.sqx.modules.app.service.UserMoneyService;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
import com.sqx.modules.discSpinning.service.DiscSpinningRecordService;
|
||||
import com.sqx.modules.orders.service.OrdersService;
|
||||
import com.sqx.modules.taskCenter.dao.TaskCenterDao;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenter;
|
||||
@@ -25,9 +32,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter> implements TaskCenterService {
|
||||
@@ -44,62 +49,101 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
||||
private UserMoneyService userMoneyService;
|
||||
@Autowired
|
||||
private UserMoneyDetailsService userMoneyDetailsService;
|
||||
@Autowired
|
||||
private DiscSpinningRecordService discSpinningRecordService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
|
||||
@Override
|
||||
public Result queryTaskCenter(Long userId) {
|
||||
//任务
|
||||
List<TaskCenter> taskPage = baseMapper.selectList(new QueryWrapper<TaskCenter>().eq("shows", 1).orderByAsc("sort", "type"));
|
||||
List<TaskCenter> resultTask = new ArrayList<>();
|
||||
boolean todaySign = true;
|
||||
//月 签到记录
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
signWrapper.eq("user_id", userId);
|
||||
signWrapper.gt("sign_day", DateUtil.format(new Date(), "yyyy-MM") + "-00");
|
||||
signWrapper.orderByAsc("create_time");
|
||||
int signCount = signRecordService.count(signWrapper);
|
||||
TaskCenter reTaskCenter = null;
|
||||
Integer signCount = null;
|
||||
for (TaskCenter s : taskPage) {
|
||||
Map<Integer, Integer> rewardMap = taskCenterRewardService.getRewardMap(s.getId());
|
||||
if (CollectionUtil.isEmpty(rewardMap)) {
|
||||
continue;
|
||||
}
|
||||
switch (s.getType()) {
|
||||
//签到任务
|
||||
case 2:
|
||||
//日任务
|
||||
if (s.getNumber().equals(1)) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
if (dayOrderNum < 3) {
|
||||
s.setDiscNumber(dayOrderNum);
|
||||
s.setNumber(3);
|
||||
// s.setDisabled(false);
|
||||
todaySign = false;
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setNumber(null);
|
||||
// s.setDisabled(false);
|
||||
} else {
|
||||
s.setDiscNumber(0);
|
||||
s.setNumber(null);
|
||||
s.setJumpType(0);
|
||||
}
|
||||
} else {
|
||||
if (todaySign) {
|
||||
if ((signCount < (s.getNumber().intValue() - 1))) {
|
||||
s.setDiscNumber(signCount);
|
||||
s.setNumber(null);
|
||||
s.setDisabled(false);
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
//周任务
|
||||
if (s.getNumber() > 1 && s.getNumber() < 8) {
|
||||
if (rewardMap.containsKey(9)) {
|
||||
boolean isBreak = false;
|
||||
//抽奖次数
|
||||
Map<Long, Integer> taskWCount = signRecordService.getTaskWCount(userId, rewardMap.get(9));
|
||||
if (CollectionUtil.isNotEmpty(taskWCount)) {
|
||||
for (Integer value : taskWCount.values()) {
|
||||
if (value > 0) {
|
||||
isBreak = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isBreak) {
|
||||
s.setDiscNumber(null);
|
||||
s.setNumber(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((signCount < s.getNumber().intValue())) {
|
||||
s.setDiscNumber(signCount);
|
||||
Integer wSignCount = signRecordService.getWSignCount(userId);
|
||||
if (wSignCount == null || wSignCount + (todaySign ? 1 : 0) < s.getNumber()) {
|
||||
s.setDiscNumber(wSignCount == null ? 0 : wSignCount);
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), DateUtil.beginOfMonth(new Date()).toString()) > 0) {
|
||||
} else {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
}
|
||||
}
|
||||
|
||||
//月任务
|
||||
else if (s.getNumber() > 7 && s.getNumber() < 32) {
|
||||
if (signCount == null) {
|
||||
signCount = signRecordService.getUserSignCount(userId);
|
||||
}
|
||||
if (signCount + (todaySign ? 1 : 0) < s.getNumber()) {
|
||||
s.setDiscNumber(signCount);
|
||||
s.setDisabled(false);
|
||||
} else {
|
||||
if (rewardMap.containsKey(9)) {
|
||||
Integer spinningCount = discSpinningRecordService.countSourceRecord(s.getId());
|
||||
if (spinningCount == null || rewardMap.get(9) - spinningCount > 0) {
|
||||
s.setDiscNumber(null);
|
||||
s.setNumber(null);
|
||||
break;
|
||||
} else {
|
||||
s.setButtonTitle("已领取");
|
||||
s.setDisabled(false);
|
||||
s.setNumber(null);
|
||||
}
|
||||
}else{
|
||||
s.setDiscNumber(null);
|
||||
s.setNumber(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
//一次性任务
|
||||
@@ -110,32 +154,29 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
||||
s.setDiscNumber(sumOrderNum);
|
||||
s.setNumber(s.getNumber());
|
||||
} else if (recordService.countTaskNum(userId, s.getId(), null) > 0) {
|
||||
reTaskCenter = s;
|
||||
continue;
|
||||
} else {
|
||||
s.setDiscNumber(0);
|
||||
s.setNumber(null);
|
||||
s.setJumpType(0);
|
||||
}
|
||||
} else if (s.getDetail().contains("绑定支付宝")) {
|
||||
UserEntity userInfo = userService.queryByUserId(userId);
|
||||
if (StringUtils.isNotBlank(userInfo.getZhiFuBao()) && StringUtils.isNotBlank(userInfo.getZhiFuBaoName())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
resultTask.add(s);
|
||||
}
|
||||
if (reTaskCenter != null) {
|
||||
taskPage.remove(reTaskCenter);
|
||||
}
|
||||
return Result.success().put("data", taskPage);
|
||||
return Result.success().put("data", resultTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result taskReceive(Long userId, Long id) {
|
||||
TaskCenter taskCenter = baseMapper.selectById(id);
|
||||
//月 签到记录
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
signWrapper.eq("user_id", userId);
|
||||
signWrapper.gt("sign_day", DateUtil.format(new Date(), "yyyy-MM") + "-00");
|
||||
signWrapper.orderByAsc("create_time");
|
||||
int signCount = signRecordService.count(signWrapper);
|
||||
|
||||
if (taskCenter.getType().equals(2)) {
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
@@ -143,7 +184,7 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
||||
UserSignRecord yesterday = signRecordService.getOne(new QueryWrapper<UserSignRecord>().eq("user_id", userId).eq("sign_day",
|
||||
DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd")));
|
||||
UserSignRecord signRecord = new UserSignRecord();
|
||||
if (yesterday != null && yesterday.getDay() != null) {
|
||||
if (yesterday != null && yesterday.getDay() != null && yesterday.getDay() != 7) {
|
||||
signRecord.setDay(yesterday.getDay() + 1);
|
||||
} else {
|
||||
signRecord.setDay(1);
|
||||
@@ -158,22 +199,6 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
signRecordService.save(signRecord);
|
||||
} else {
|
||||
if (dayOrderNum > 2) {
|
||||
if (signCount < (taskCenter.getNumber().intValue() - 1)) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
if (recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
} else {
|
||||
if (signCount < taskCenter.getNumber().intValue()) {
|
||||
return Result.error("领取失败,未达成领取条件");
|
||||
}
|
||||
if (recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") > 0) {
|
||||
return Result.error("不可重复领取");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (taskCenter.getType().equals(3) && taskCenter.getId().equals(1L)) {
|
||||
Integer sumOrderNum = ordersService.countOrderNum(userId, null);
|
||||
@@ -228,49 +253,59 @@ public class TaskCenterServiceImpl extends ServiceImpl<TaskCenterDao, TaskCenter
|
||||
|
||||
@Override
|
||||
public int countTaskDisc(Long userId, String type) {
|
||||
int countTaskDisc = 0;
|
||||
Integer signCount = null;
|
||||
if (StringUtils.isBlank(type) || "1".equals(type)) {
|
||||
return 0;
|
||||
}
|
||||
//月 签到记录
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
signWrapper.eq("user_id", userId);
|
||||
signWrapper.gt("sign_day", DateUtil.format(new Date(), "yyyy-MM") + "-00");
|
||||
signWrapper.orderByAsc("create_time");
|
||||
int signCount = signRecordService.count(signWrapper);
|
||||
|
||||
//TaskCenter的number为大转盘次数
|
||||
List<TaskCenter> taskCenters = baseMapper.queryTaskDiscCenter();
|
||||
int countTaskDisc = 0;
|
||||
Integer dayOrderNum = ordersService.countOrderNum(userId, DateUtil.today() + " 00:00:00");
|
||||
QueryWrapper<TaskCenter> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("type", 2);
|
||||
if ("2".equals(type)) {
|
||||
queryWrapper.gt("number", 1);
|
||||
queryWrapper.lt("number", 8);
|
||||
} else if ("3".equals(type)) {
|
||||
queryWrapper.gt("number", 7);
|
||||
queryWrapper.lt("number", 32);
|
||||
}
|
||||
List<TaskCenter> taskCenters = baseMapper.selectList(queryWrapper);
|
||||
for (TaskCenter taskCenter : taskCenters) {
|
||||
if (taskCenter.getType().equals(2)) {
|
||||
if (taskCenter.getNumber().equals(1)) {
|
||||
if (dayOrderNum > 2 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.today() + " 00:00:00") < 1) {
|
||||
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
|
||||
}
|
||||
} else {
|
||||
if ("2".equals(type) && taskCenter.getNumber().intValue() > 1 && taskCenter.getNumber().intValue() < 8) {
|
||||
if (dayOrderNum > 2) {
|
||||
if (signCount - taskCenter.getNumber().intValue() >= -1 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) {
|
||||
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
|
||||
}
|
||||
} else {
|
||||
if (signCount - taskCenter.getNumber().intValue() >= 0 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) {
|
||||
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
|
||||
}
|
||||
}
|
||||
} else if ("3".equals(type) && taskCenter.getNumber().intValue() > 7 && taskCenter.getNumber().intValue() < 32) {
|
||||
if (dayOrderNum > 2) {
|
||||
if (signCount - taskCenter.getNumber().intValue() >= -1 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) {
|
||||
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
|
||||
}
|
||||
} else {
|
||||
if (signCount - taskCenter.getNumber().intValue() >= 0 && recordService.countTaskNum(userId, taskCenter.getId(), DateUtil.beginOfMonth(new Date()).toString()) < 1) {
|
||||
countTaskDisc = countTaskDisc + taskCenter.getDiscNumber();
|
||||
}
|
||||
Map<Integer, Integer> rewardMap = taskCenterRewardService.getRewardMap(taskCenter.getId());
|
||||
if (CollectionUtil.isEmpty(rewardMap)) {
|
||||
continue;
|
||||
}
|
||||
Map<Integer, Integer> taskWRedisMap = new HashMap<>();
|
||||
if ("2".equals(type)) {
|
||||
//抽奖次数
|
||||
Map<Long, Integer> taskWCount = signRecordService.getTaskWCount(userId, rewardMap.get(9));
|
||||
if (CollectionUtil.isNotEmpty(taskWCount)) {
|
||||
for (Map.Entry<Long, Integer> entry : taskWCount.entrySet()) {
|
||||
Long key = entry.getKey();
|
||||
Integer value = entry.getValue();
|
||||
if (value > 0) {
|
||||
countTaskDisc = countTaskDisc + value;
|
||||
taskWRedisMap.put(key.intValue(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(taskWRedisMap)) {
|
||||
redisUtils.set(RedisKeys.getDateKey("spinning:amount:taskW") + userId, taskWRedisMap, DateUtils.todayAfterSecond());
|
||||
}
|
||||
} else if ("3".equals(type)) {
|
||||
if (signCount == null) {
|
||||
signCount = signRecordService.getUserSignCount(userId);
|
||||
}
|
||||
if (signCount >= taskCenter.getNumber()) {
|
||||
if (rewardMap.containsKey(9)) {
|
||||
Integer spinningCount = discSpinningRecordService.countSourceRecord(taskCenter.getId());
|
||||
countTaskDisc = rewardMap.get(9) + (spinningCount == null ? 0 : spinningCount);
|
||||
if (countTaskDisc > 0) {
|
||||
taskWRedisMap.put(taskCenter.getId().intValue(), countTaskDisc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(taskWRedisMap)) {
|
||||
redisUtils.set(RedisKeys.getDateKey("spinning:amount:taskM") + userId, taskWRedisMap, DateUtils.todayAfterSecond());
|
||||
}
|
||||
}
|
||||
}
|
||||
return countTaskDisc;
|
||||
|
||||
@@ -4,8 +4,17 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.userSign.entity.UserSignRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface UserSignRecordDao extends BaseMapper<UserSignRecord> {
|
||||
//周 抽奖次数
|
||||
List<UserSignRecord> getTaskWCount(long userId, int wCount,String time,List<Long> ids);
|
||||
|
||||
List<Long> getNoRecordTask(long userId, String time);
|
||||
//周 签到 次数 连续签到
|
||||
Integer getWSignCount(long userId,String time);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,19 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.userSign.dto.UserSignDTO;
|
||||
import com.sqx.modules.userSign.entity.UserSignRecord;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface UserSignRecordService extends IService<UserSignRecord> {
|
||||
|
||||
UserSignDTO getUserSignData(long userId);
|
||||
|
||||
//获取当月签到次数
|
||||
int getUserSignCount(long userId);
|
||||
//周 剩余抽奖次数
|
||||
Map<Long,Integer> getTaskWCount(long userId, int wCount);
|
||||
//周 签到 次数
|
||||
Integer getWSignCount(long userId);
|
||||
|
||||
String[] getUserSignAwardConfig();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.exception.SqxException;
|
||||
@@ -11,6 +12,7 @@ import com.sqx.modules.app.dao.UserDao;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.common.dao.CommonInfoDao;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.taskCenter.entity.TaskCenterReward;
|
||||
import com.sqx.modules.userSign.dao.UserSignRecordDao;
|
||||
import com.sqx.modules.userSign.dto.UserSignDTO;
|
||||
import com.sqx.modules.userSign.dto.UserSignRecordDTO;
|
||||
@@ -79,8 +81,7 @@ public class UserSignRecordServiceImpl extends ServiceImpl<UserSignRecordDao, Us
|
||||
dto.setSignDays(signDays);
|
||||
return dto;
|
||||
}
|
||||
String beginSignDay = list.stream().findFirst().get().getSignDay();
|
||||
flowDays = buildFlowDays(LocalDate.parse(beginSignDay, DateTimeFormatter.ofPattern("yyyy-MM-dd")), activeDays);
|
||||
flowDays = buildFlowDays(beginDay.plusDays(-6), activeDays);
|
||||
index = 1;
|
||||
Map<String, Date> signMap = list.stream().collect(Collectors.toMap(UserSignRecord::getSignDay, UserSignRecord::getCreateTime));
|
||||
for (String day : flowDays) {
|
||||
@@ -115,16 +116,40 @@ public class UserSignRecordServiceImpl extends ServiceImpl<UserSignRecordDao, Us
|
||||
dto.setRecordList(recordList);
|
||||
dto.setSignDays(signDays);
|
||||
// 该用户是否可以继续签到
|
||||
UserSignRecordDTO last = recordList.get(recordList.size() - 1);
|
||||
LocalDate lastDay = LocalDate.parse(last.getSignDay());
|
||||
LocalDate currentDay = LocalDate.now();
|
||||
long daysBetween = ChronoUnit.DAYS.between(currentDay, lastDay);
|
||||
if (daysBetween < 0 || "1".equals(last.getStatus())) {
|
||||
if (signDays >= 7) {
|
||||
dto.setEnable(0);
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUserSignCount(long userId) {
|
||||
QueryWrapper<UserSignRecord> signWrapper = new QueryWrapper<>();
|
||||
signWrapper.eq("user_id", userId);
|
||||
signWrapper.gt("sign_day", DateUtil.format(new Date(), "yyyy-MM") + "-00");
|
||||
signWrapper.orderByAsc("create_time");
|
||||
int signCount = baseMapper.selectCount(signWrapper);
|
||||
return signCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long,Integer> getTaskWCount(long userId,int wCount) {
|
||||
Date thirtyDaysAgo = DateUtil.offsetDay(new Date(), -30);
|
||||
List<Long> noRecordTasks = baseMapper.getNoRecordTask(userId, DateUtil.format(thirtyDaysAgo, "yyyy-MM-dd") + " 00:00:00");
|
||||
List<UserSignRecord> taskWCount = baseMapper.getTaskWCount(userId, wCount, DateUtil.format(thirtyDaysAgo, "yyyy-MM-dd") + " 00:00:00", noRecordTasks);
|
||||
Map<Long, Integer> map = taskWCount.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
UserSignRecord::getId,
|
||||
Collectors.summingInt(UserSignRecord::getDay)
|
||||
));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getWSignCount(long userId) {
|
||||
return baseMapper.getWSignCount(userId, DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd") + " 00:00:00");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUserSignAwardConfig() {
|
||||
CommonInfo config = commonInfoDao.findOne(918);
|
||||
|
||||
@@ -81,3 +81,5 @@ sqx:
|
||||
# token有效时长,7天,单位秒
|
||||
expire: 604800
|
||||
header: token
|
||||
uni:
|
||||
adSecret: 122e4ff1edc66dcf8761f7f7ffc81e0f8773cbfafb58aed29c72fbd092c77315
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
</select>
|
||||
|
||||
<select id="queryUserInviteMoney" resultType="Double">
|
||||
select sum(money) from user_money_details where user_id=#{userId} and classify in (1,6,7) and type=1 and state=2 and money_type=1
|
||||
select sum(money) from user_money_details where user_id=#{userId} and classify in (1,6,7,8) and type=1 and state=2 and money_type=1
|
||||
</select>
|
||||
|
||||
<select id="queryUserInviteGoldMoney" resultType="Double">
|
||||
select sum(money) from user_money_details where user_id=#{userId} and classify in (1,6,7) and type=1 and state=2 and money_type=2
|
||||
select sum(money) from user_money_details where user_id=#{userId} and classify in (1,6,7,8) and type=1 and state=2 and money_type=2
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sqx.modules.callback.mapper.UniAdCallbackRecordMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.sqx.modules.callback.entity.UniAdCallbackRecord">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="userId" column="user_id" jdbcType="INTEGER"/>
|
||||
<result property="platform" column="platform" jdbcType="VARCHAR"/>
|
||||
<result property="transId" column="trans_id" jdbcType="VARCHAR"/>
|
||||
<result property="adpid" column="adpid" jdbcType="VARCHAR"/>
|
||||
<result property="provider" column="provider" jdbcType="VARCHAR"/>
|
||||
<result property="sign" column="sign" jdbcType="VARCHAR"/>
|
||||
<result property="extra" column="extra" jdbcType="VARCHAR"/>
|
||||
<result property="isEnded" column="is_ended" jdbcType="TINYINT"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,user_id,platform,
|
||||
trans_id,adpid,provider,
|
||||
sign,extra,is_ended,
|
||||
create_time
|
||||
</sql>
|
||||
</mapper>
|
||||
@@ -21,6 +21,7 @@
|
||||
c.msg_url as msgUrl,
|
||||
c.pay_num as payNum,
|
||||
c.price,
|
||||
c.wholesale_price as wholesalePrice,
|
||||
c.is_over as isOver,
|
||||
c.title,
|
||||
c.is_price as isPrice,
|
||||
@@ -139,6 +140,7 @@
|
||||
c.msg_url as msgUrl,
|
||||
c.pay_num as payNum,
|
||||
c.price,
|
||||
c.wholesale_price as wholesalePrice,
|
||||
c.is_over as isOver,
|
||||
c.title,
|
||||
c.is_price as isPrice,
|
||||
@@ -264,6 +266,7 @@
|
||||
c.msg_url as msgUrl,
|
||||
c.pay_num as payNum,
|
||||
c.price,
|
||||
c.wholesale_price as wholesalePrice,
|
||||
c.status,
|
||||
c.title,
|
||||
c.title_img as titleImg,
|
||||
|
||||
@@ -279,30 +279,26 @@
|
||||
|
||||
|
||||
<select id="selectOrdersCountStatisticsByDay" resultType="Integer">
|
||||
SELECT
|
||||
count(*)
|
||||
FROM
|
||||
orders
|
||||
LEFT JOIN disc_spinning_record record ON orders.orders_id = record.order_id
|
||||
WHERE
|
||||
orders.user_id = #{userId}
|
||||
SELECT count(*)
|
||||
FROM orders
|
||||
LEFT JOIN disc_spinning_record record ON orders.orders_id = record.source_id and record.source = 'order'
|
||||
WHERE orders.user_id = #{userId}
|
||||
AND orders.`status` = 1
|
||||
AND orders.`pay_way` = 9
|
||||
AND orders.create_time > DATE_FORMAT( CURDATE(), '%Y-%m-%d 00:00:00' )
|
||||
AND record.order_id IS NULL
|
||||
ORDER BY
|
||||
orders.create_time
|
||||
AND orders.create_time > DATE_FORMAT(CURDATE(), '%Y-%m-%d 00:00:00')
|
||||
AND record.source_id IS NULL
|
||||
ORDER BY orders.create_time
|
||||
</select>
|
||||
|
||||
<select id="selectOrdersByDay" resultType="com.sqx.modules.orders.entity.Orders">
|
||||
SELECT orders.*
|
||||
FROM orders
|
||||
LEFT JOIN disc_spinning_record record ON orders.orders_id = record.order_id
|
||||
LEFT JOIN disc_spinning_record record ON orders.orders_id = record.source_id
|
||||
WHERE orders.user_id = #{userId}
|
||||
AND orders.`status` = 1
|
||||
AND orders.`pay_way` = 9
|
||||
AND orders.create_time > DATE_FORMAT(CURDATE(), '%Y-%m-%d 00:00:00')
|
||||
AND record.order_id IS NULL
|
||||
AND record.source_id IS NULL
|
||||
ORDER BY orders.create_time LIMIT 1
|
||||
</select>
|
||||
|
||||
|
||||
@@ -2,13 +2,4 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sqx.modules.taskCenter.dao.TaskCenterDao">
|
||||
|
||||
|
||||
<select id="queryTaskDiscCenter" resultType="com.sqx.modules.taskCenter.entity.TaskCenter">
|
||||
SELECT task.*,
|
||||
reward.number as discNumber
|
||||
FROM task_center_reward reward
|
||||
INNER JOIN task_center task ON reward.task_id = task.id and task.shows = 1
|
||||
where reward.type = 9
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
49
src/main/resources/mapper/userSign/TaskCenterDto.xml
Normal file
49
src/main/resources/mapper/userSign/TaskCenterDto.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sqx.modules.userSign.dao.UserSignRecordDao">
|
||||
|
||||
<select id="getNoRecordTask" resultType="Long">
|
||||
SELECT
|
||||
sign.id
|
||||
FROM
|
||||
user_sign_record sign
|
||||
LEFT JOIN task_center_record cenRecord ON sign.id = cenRecord.source_id
|
||||
WHERE
|
||||
sign.`DAY` = 7
|
||||
AND sign.user_id = #{userId}
|
||||
and sign.create_time > #{time}
|
||||
AND cenRecord.id IS NULL
|
||||
order by sign.create_time asc
|
||||
</select>
|
||||
|
||||
<select id="getTaskWCount" resultType="com.sqx.modules.userSign.entity.UserSignRecord">
|
||||
SELECT
|
||||
sign.id as id,
|
||||
#{wCount} - COUNT(CASE WHEN spRecord.source_id IS NOT NULL THEN 1 END) AS `day`
|
||||
FROM
|
||||
user_sign_record sign
|
||||
LEFT JOIN disc_spinning_record spRecord ON sign.id = spRecord.source_id
|
||||
WHERE
|
||||
sign.`DAY` = 7
|
||||
AND sign.user_id = #{userId}
|
||||
AND sign.create_time > #{time}
|
||||
<if test="ids!= null and ids.size() > 0">
|
||||
AND sign.id in
|
||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
GROUP BY sign.id
|
||||
order by sign.create_time asc
|
||||
</select>
|
||||
|
||||
<select id="getWSignCount" resultType="Integer">
|
||||
SELECT `day`
|
||||
FROM user_sign_record
|
||||
WHERE user_id = #{userId}
|
||||
and create_time > #{time}
|
||||
ORDER BY create_time desc
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user