Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
package com.sqx.common.utils;
|
package com.sqx.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis所有Keys
|
* Redis所有Keys
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RedisKeys {
|
public class RedisKeys {
|
||||||
|
|
||||||
|
public static final String PAY_FREE_WATCH_KEY = "pay:free:watch:";
|
||||||
|
|
||||||
public static String getSysConfigKey(String key){
|
public static String getSysConfigKey(String key){
|
||||||
return "sys:config:" + key;
|
return "sys:config:" + key;
|
||||||
}
|
}
|
||||||
@@ -13,4 +17,12 @@ public class RedisKeys {
|
|||||||
public static String getDateKey(String key){
|
public static String getDateKey(String key){
|
||||||
return "date:" + key;
|
return "date:" + key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getPayFreeWatchKey(Long userId) {
|
||||||
|
return PAY_FREE_WATCH_KEY + DateUtil.today() + ":" + userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(DateUtil.today());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.sqx.common.utils;
|
package com.sqx.common.utils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.sqx.modules.redisService.RedisService;
|
import com.sqx.modules.redisService.RedisService;
|
||||||
@@ -10,12 +11,14 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis工具类
|
* Redis工具类
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class RedisUtils {
|
public class RedisUtils {
|
||||||
@@ -33,19 +36,31 @@ public class RedisUtils {
|
|||||||
private SetOperations<String, Object> setOperations;
|
private SetOperations<String, Object> setOperations;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ZSetOperations<String, Object> zSetOperations;
|
private ZSetOperations<String, Object> zSetOperations;
|
||||||
/** 默认过期时长,单位:秒 */
|
/**
|
||||||
|
* 默认过期时长,单位:秒
|
||||||
|
*/
|
||||||
public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
|
public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
|
||||||
/** 不设置过期时长 */
|
/**
|
||||||
|
* 不设置过期时长
|
||||||
|
*/
|
||||||
public final static long NOT_EXPIRE = -1;
|
public final static long NOT_EXPIRE = -1;
|
||||||
private final static Gson Gson = new Gson();
|
private final static Gson Gson = new Gson();
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取缓存里的数据 如果不存在 则插入 并返回
|
public <T> Map<String, List<T>> getMapData(String key, String method, Class<T> clazz) {
|
||||||
* @param key redis Key
|
String jsonStr = getDate(key, method);
|
||||||
* @param clazz 返回类型
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
* @param method RedisService调用的方法名 如果数据不存在会执行该调用方法
|
try {
|
||||||
*/
|
JsonNode jsonNode = objectMapper.readTree(jsonStr);
|
||||||
public <T> List<T> getListData(String key, Class<T> clazz,String method) {
|
|
||||||
|
return jsonNodeToMap(jsonNode, clazz);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getListData(String key, Class<T> clazz, String method) {
|
||||||
String jsonStr = getDate(key, method);
|
String jsonStr = getDate(key, method);
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
try {
|
try {
|
||||||
@@ -59,26 +74,27 @@ public class RedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取缓存里的数据 如果不存在 则插入 并返回
|
* 获取缓存里的数据 如果不存在 则插入 并返回
|
||||||
* @param key redis Key
|
*
|
||||||
* @param clazz 返回类型
|
* @param key redis Key
|
||||||
|
* @param clazz 返回类型
|
||||||
* @param method RedisService调用的方法名 如果数据不存在会执行该调用方法
|
* @param method RedisService调用的方法名 如果数据不存在会执行该调用方法
|
||||||
*/
|
*/
|
||||||
public <T> T getObjectDate(String key, Class<T> clazz,String method) {
|
public <T> T getObjectDate(String key, Class<T> clazz, String method) {
|
||||||
String jsonStr = getDate(key, method);
|
String jsonStr = getDate(key, method);
|
||||||
return this.fromJson(jsonStr, clazz);
|
return this.fromJson(jsonStr, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDate(String key, String method) {
|
public String getDate(String key, String method) {
|
||||||
if (!this.hasKey(key)) {
|
if (!this.hasKey(key)) {
|
||||||
try {
|
try {
|
||||||
// 获取Lookup对象
|
// 获取Lookup对象
|
||||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||||
// 构建方法类型(这里假设方法无参数,返回类型为void)
|
// 构建方法类型(这里假设方法无参数,返回类型为void)
|
||||||
MethodType methodType = MethodType.methodType(void.class , String.class);
|
MethodType methodType = MethodType.methodType(void.class, String.class);
|
||||||
// 获取方法句柄
|
// 获取方法句柄
|
||||||
MethodHandle methodHandle = lookup.findVirtual(redisService.getClass(), method, methodType);
|
MethodHandle methodHandle = lookup.findVirtual(redisService.getClass(), method, methodType);
|
||||||
// 调用方法句柄
|
// 调用方法句柄
|
||||||
methodHandle.invoke(redisService,key);
|
methodHandle.invoke(redisService, key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
@@ -93,20 +109,34 @@ public class RedisUtils {
|
|||||||
return redisTemplate.hasKey(key);
|
return redisTemplate.hasKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String key, Object value, long expire){
|
public void set(String key, Object value, long expire) {
|
||||||
valueOperations.set(key, toJson(value));
|
valueOperations.set(key, toJson(value));
|
||||||
|
if (expire != NOT_EXPIRE) {
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setIfAbsent(String key, Object value, long expire){
|
||||||
|
Boolean absent = valueOperations.setIfAbsent(key, toJson(value));
|
||||||
|
if (Boolean.FALSE.equals(absent)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if(expire != NOT_EXPIRE){
|
if(expire != NOT_EXPIRE){
|
||||||
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String key, Object value){
|
public void set(String key, Object value) {
|
||||||
set(key, value, DEFAULT_EXPIRE);
|
set(key, value, DEFAULT_EXPIRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T get(String key, Class<T> clazz, long expire) {
|
public <T> T get(String key, Class<T> clazz, long expire) {
|
||||||
String value = valueOperations.get(key);
|
String value = valueOperations.get(key);
|
||||||
if(expire != NOT_EXPIRE){
|
if (expire != NOT_EXPIRE) {
|
||||||
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
return value == null ? null : fromJson(value, clazz);
|
return value == null ? null : fromJson(value, clazz);
|
||||||
@@ -118,7 +148,7 @@ public class RedisUtils {
|
|||||||
|
|
||||||
public String get(String key, long expire) {
|
public String get(String key, long expire) {
|
||||||
String value = valueOperations.get(key);
|
String value = valueOperations.get(key);
|
||||||
if(expire != NOT_EXPIRE){
|
if (expire != NOT_EXPIRE) {
|
||||||
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@@ -150,9 +180,9 @@ public class RedisUtils {
|
|||||||
/**
|
/**
|
||||||
* Object转成JSON数据
|
* Object转成JSON数据
|
||||||
*/
|
*/
|
||||||
private String toJson(Object object){
|
private String toJson(Object object) {
|
||||||
if(object instanceof Integer || object instanceof Long || object instanceof Float ||
|
if (object instanceof Integer || object instanceof Long || object instanceof Float ||
|
||||||
object instanceof Double || object instanceof Boolean || object instanceof String){
|
object instanceof Double || object instanceof Boolean || object instanceof String) {
|
||||||
return String.valueOf(object);
|
return String.valueOf(object);
|
||||||
}
|
}
|
||||||
return Gson.toJson(object);
|
return Gson.toJson(object);
|
||||||
@@ -161,7 +191,25 @@ public class RedisUtils {
|
|||||||
/**
|
/**
|
||||||
* JSON数据,转成Object
|
* JSON数据,转成Object
|
||||||
*/
|
*/
|
||||||
private <T> T fromJson(String json, Class<T> clazz){
|
private <T> T fromJson(String json, Class<T> clazz) {
|
||||||
return Gson.fromJson(json, clazz);
|
return Gson.fromJson(json, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public <T> Map<String, List<T>> jsonNodeToMap(JsonNode jsonNode, Class<T> clazz) {
|
||||||
|
Map<String, List<T>> resultMap = new HashMap<>();
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
if (jsonNode.isObject()) {
|
||||||
|
// 获取字段名(也就是键)的迭代器
|
||||||
|
Iterator<String> fieldNames = jsonNode.fieldNames();
|
||||||
|
while (fieldNames.hasNext()) {
|
||||||
|
String key = fieldNames.next();
|
||||||
|
JsonNode elementNode = jsonNode.get(key);
|
||||||
|
resultMap.put(key, objectMapper.convertValue(elementNode,
|
||||||
|
objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class AppController {
|
|||||||
.eq("zhi_fu_bao", zhiFuBao));
|
.eq("zhi_fu_bao", zhiFuBao));
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
return Result.error("一个支付宝账号仅可绑定一个支付宝用户");
|
return Result.error("一个支付宝账号仅可绑定一个用户");
|
||||||
}
|
}
|
||||||
if (!ApiAccessLimitUtil.isAccessAllowed(userId.toString(), "updateZFB", 3, "month")) {
|
if (!ApiAccessLimitUtil.isAccessAllowed(userId.toString(), "updateZFB", 3, "month")) {
|
||||||
return Result.error("每月仅支持修改三次,请联系管理员");
|
return Result.error("每月仅支持修改三次,请联系管理员");
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.sqx.modules.course.service.impl;
|
package com.sqx.modules.course.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
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.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
@@ -12,6 +14,8 @@ import com.sqx.common.utils.Result;
|
|||||||
import com.sqx.modules.app.entity.UserEntity;
|
import com.sqx.modules.app.entity.UserEntity;
|
||||||
import com.sqx.modules.app.service.UserService;
|
import com.sqx.modules.app.service.UserService;
|
||||||
import com.sqx.modules.app.utils.JwtUtils;
|
import com.sqx.modules.app.utils.JwtUtils;
|
||||||
|
import com.sqx.modules.common.dao.CommonInfoDao;
|
||||||
|
import com.sqx.modules.common.entity.CommonInfo;
|
||||||
import com.sqx.modules.course.dao.CourseCollectDao;
|
import com.sqx.modules.course.dao.CourseCollectDao;
|
||||||
import com.sqx.modules.course.dao.CourseDao;
|
import com.sqx.modules.course.dao.CourseDao;
|
||||||
import com.sqx.modules.course.dao.CourseDetailsDao;
|
import com.sqx.modules.course.dao.CourseDetailsDao;
|
||||||
@@ -22,11 +26,15 @@ import com.sqx.modules.course.entity.CourseDetails;
|
|||||||
import com.sqx.modules.course.entity.CourseUser;
|
import com.sqx.modules.course.entity.CourseUser;
|
||||||
import com.sqx.modules.course.service.CourseDetailsService;
|
import com.sqx.modules.course.service.CourseDetailsService;
|
||||||
import com.sqx.modules.course.vo.CourseDetailsIn;
|
import com.sqx.modules.course.vo.CourseDetailsIn;
|
||||||
|
import com.sqx.modules.orders.dao.OrdersDao;
|
||||||
|
import com.sqx.modules.orders.entity.Orders;
|
||||||
import com.sqx.modules.orders.service.OrdersService;
|
import com.sqx.modules.orders.service.OrdersService;
|
||||||
|
import com.sqx.modules.redisService.impl.RedisServiceImpl;
|
||||||
import com.sqx.modules.utils.EasyPoi.ExcelUtils;
|
import com.sqx.modules.utils.EasyPoi.ExcelUtils;
|
||||||
import com.sqx.modules.utils.HttpClientUtil;
|
import com.sqx.modules.utils.HttpClientUtil;
|
||||||
import com.sqx.modules.utils.SenInfoCheckUtil;
|
import com.sqx.modules.utils.SenInfoCheckUtil;
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -39,6 +47,7 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, CourseDetails> implements CourseDetailsService {
|
public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, CourseDetails> implements CourseDetailsService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -53,6 +62,12 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
|||||||
private OrdersService ordersService;
|
private OrdersService ordersService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
@Autowired
|
||||||
|
private OrdersDao ordersDao;
|
||||||
|
@Autowired
|
||||||
|
private CommonInfoDao commonInfoDao;
|
||||||
|
@Autowired
|
||||||
|
private RedisServiceImpl redisServiceImpl;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,6 +92,37 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
|||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验用户是否达到免费播放购买次数
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return true 可观看
|
||||||
|
*/
|
||||||
|
private boolean checkFreeWatchPayCount(Long userId) {
|
||||||
|
Boolean isExpire = redisServiceImpl.getPayFreeWatchTimeIsExpire(userId);
|
||||||
|
if (isExpire == null) {
|
||||||
|
Integer count = ordersDao.countPayOrderByDay(userId);
|
||||||
|
CommonInfo needCountCommonInfo = commonInfoDao.selectOne(new LambdaQueryWrapper<CommonInfo>()
|
||||||
|
.eq(CommonInfo::getType, 916));
|
||||||
|
CommonInfo freeTimeCommonInfo = commonInfoDao.selectOne(new LambdaQueryWrapper<CommonInfo>()
|
||||||
|
.eq(CommonInfo::getType, 917));
|
||||||
|
if (needCountCommonInfo == null || freeTimeCommonInfo == null
|
||||||
|
|| StrUtil.isBlank(needCountCommonInfo.getValue()) || StrUtil.isBlank(freeTimeCommonInfo.getValue())) {
|
||||||
|
log.warn("系统未配置全免次数或时间");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 购买次数超过,设置redis标识
|
||||||
|
if (count >= Integer.parseInt(needCountCommonInfo.getValue())) {
|
||||||
|
redisServiceImpl.setPayFreeWatchTime(userId, Integer.parseInt(freeTimeCommonInfo.getValue()));
|
||||||
|
isExpire = false;
|
||||||
|
}else {
|
||||||
|
isExpire = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !isExpire;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result selectCourseDetailsById(Long id, String token, String courseDetailsId) {
|
public Result selectCourseDetailsById(Long id, String token, String courseDetailsId) {
|
||||||
Course bean = courseDao.selectById(id);
|
Course bean = courseDao.selectById(id);
|
||||||
@@ -99,7 +145,9 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
|||||||
UserEntity userEntity = userService.selectUserById(userId);
|
UserEntity userEntity = userService.selectUserById(userId);
|
||||||
//查询用户是否购买了整集
|
//查询用户是否购买了整集
|
||||||
CourseUser courseUser = courseUserDao.selectCourseUser(id, userId);
|
CourseUser courseUser = courseUserDao.selectCourseUser(id, userId);
|
||||||
if (courseUser != null || (userEntity != null && userEntity.getMember() != null && userEntity.getMember() == 2)) {
|
// 每天购买超过上限,获得免费时间段资格
|
||||||
|
boolean freeWatch = checkFreeWatchPayCount(userId);
|
||||||
|
if (freeWatch || courseUser != null || (userEntity != null && userEntity.getMember() != null && userEntity.getMember() == 2)) {
|
||||||
bean.setListsDetail(baseMapper.findByCourseId(id, userId));
|
bean.setListsDetail(baseMapper.findByCourseId(id, userId));
|
||||||
} else {
|
} else {
|
||||||
bean.setListsDetail(baseMapper.findByCourseIdNotUrl(id, userId));
|
bean.setListsDetail(baseMapper.findByCourseIdNotUrl(id, userId));
|
||||||
|
|||||||
@@ -151,10 +151,10 @@ public class DiscSpinningController {
|
|||||||
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @Nullable @ApiIgnore @RequestBody Map maps) {
|
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId, @Nullable @ApiIgnore @RequestBody Map maps) {
|
||||||
double amount = 0;
|
double amount = 0;
|
||||||
Long orderId = null;
|
Long orderId = null;
|
||||||
|
Integer i = recordService.countDraw(userId);
|
||||||
if (maps == null || !maps.containsKey("source") || !"task".equals(maps.get("source"))) {
|
if (maps == null || !maps.containsKey("source") || !"task".equals(maps.get("source"))) {
|
||||||
//任务抽奖
|
//任务抽奖
|
||||||
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
||||||
Integer i = recordService.countDraw(userId);
|
|
||||||
if (i != null && i >= drawCount) {
|
if (i != null && i >= drawCount) {
|
||||||
return Result.error("当日可抽奖次数已超限");
|
return Result.error("当日可抽奖次数已超限");
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ public class DiscSpinningController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Result().put("data",
|
return new Result().put("data",
|
||||||
discSpinningService.draws(amount, orderId, userId, maps == null || maps.get("source") == null ? "order" : maps.get("source").toString()));
|
discSpinningService.draws(i == null ? 1 : i + 1, amount, orderId, userId, maps == null || maps.get("source") == null ? "order" : maps.get("source").toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("大转盘奖项领取")
|
@ApiOperation("大转盘奖项领取")
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import lombok.Data;
|
|||||||
public class DiscSpinningAmount extends Model<DiscSpinningAmount> {
|
public class DiscSpinningAmount extends Model<DiscSpinningAmount> {
|
||||||
@ApiModelProperty("主键id")
|
@ApiModelProperty("主键id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
@ApiModelProperty("从第几次开始变化")
|
||||||
|
private Integer num;
|
||||||
@ApiModelProperty("描述")
|
@ApiModelProperty("描述")
|
||||||
private String name;
|
private String name;
|
||||||
@ApiModelProperty("0-1 小于 多少为该奖励")
|
@ApiModelProperty("0-1 小于 多少为该奖励")
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
|||||||
public interface DiscSpinningService extends IService<DiscSpinning> {
|
public interface DiscSpinningService extends IService<DiscSpinning> {
|
||||||
|
|
||||||
//抽奖
|
//抽奖
|
||||||
DiscSpinningRecord draws(double orderAmount, Long orderId, Long userId, String source);
|
DiscSpinningRecord draws(int drawCount, double orderAmount, Long orderId, Long userId, String source);
|
||||||
|
|
||||||
//领奖
|
//领奖
|
||||||
void receiveAsync(DiscSpinningRecord receive);
|
void receiveAsync(DiscSpinningRecord receive);
|
||||||
|
|||||||
@@ -33,10 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSpinning> implements DiscSpinningService {
|
public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSpinning> implements DiscSpinningService {
|
||||||
@@ -125,11 +122,11 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||||||
cashOut.setState(2);
|
cashOut.setState(2);
|
||||||
if (baseResp.getErrorMsg().contains("收款人账户号出款属性不匹配")) {
|
if (baseResp.getErrorMsg().contains("收款人账户号出款属性不匹配")) {
|
||||||
cashOut.setRefund("提现失败,请检查支付宝账号与收款人姓名后,重试。");
|
cashOut.setRefund("提现失败,请检查支付宝账号与收款人姓名后,重试。");
|
||||||
}else {
|
} else {
|
||||||
cashOut.setRefund(baseResp.getErrorMsg());
|
cashOut.setRefund(baseResp.getErrorMsg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||||
userInfo.getUserId(), null, null, "[现金大转盘]", 4, 2, 1,
|
userInfo.getUserId(), null, null, "[现金大转盘]", 4, 2, 1,
|
||||||
new BigDecimal(money), "现金红包自动提现" + money + "元", 1);
|
new BigDecimal(money), "现金红包自动提现" + money + "元", 1);
|
||||||
@@ -142,7 +139,7 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public DiscSpinningRecord draws(double orderAmount, Long orderId, Long userId, String source) {
|
public DiscSpinningRecord draws(int drawCount, double orderAmount, Long orderId, Long userId, String source) {
|
||||||
DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, null);
|
DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, null);
|
||||||
List<DiscSpinning> prizes = baseMapper.selectList(new QueryWrapper<DiscSpinning>().eq("disc_type", "order".equals(source) ? 1 : 2).orderByAsc("odds"));
|
List<DiscSpinning> prizes = baseMapper.selectList(new QueryWrapper<DiscSpinning>().eq("disc_type", "order".equals(source) ? 1 : 2).orderByAsc("odds"));
|
||||||
|
|
||||||
@@ -153,7 +150,14 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
|||||||
} while (randomDouble == 0);
|
} while (randomDouble == 0);
|
||||||
BigDecimal randomNum = new BigDecimal(randomDouble).multiply(new BigDecimal(10000)).divide(new BigDecimal(100));
|
BigDecimal randomNum = new BigDecimal(randomDouble).multiply(new BigDecimal(10000)).divide(new BigDecimal(100));
|
||||||
|
|
||||||
List<DiscSpinningAmount> amounts = redisUtils.getListData(RedisKeys.getDateKey("spinning:amount"), DiscSpinningAmount.class, "setDiscSpinningAmounts");
|
List<DiscSpinningAmount> amounts = new ArrayList<>();
|
||||||
|
Map<String, List<DiscSpinningAmount>> amountMaps = redisUtils.getMapData(RedisKeys.getDateKey("spinning:amount"), "setDiscSpinningAmounts", DiscSpinningAmount.class);
|
||||||
|
for (int i = drawCount; i >= 0; i--) {
|
||||||
|
if (amountMaps.containsKey(i + "")) {
|
||||||
|
amounts = amountMaps.get(i + "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (DiscSpinning prize : prizes) {
|
for (DiscSpinning prize : prizes) {
|
||||||
if (randomNum.compareTo(prize.getNumber()) < 0) {
|
if (randomNum.compareTo(prize.getNumber()) < 0) {
|
||||||
if (prize.getType() == 2) {
|
if (prize.getType() == 2) {
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public interface OrdersDao extends BaseMapper<Orders> {
|
|||||||
Integer selectOrdersCountStatisticsByDay(Long userId);
|
Integer selectOrdersCountStatisticsByDay(Long userId);
|
||||||
|
|
||||||
Orders selectOrdersByDay(Long userId);
|
Orders selectOrdersByDay(Long userId);
|
||||||
|
Integer countPayOrderByDay(Long userId);
|
||||||
|
|
||||||
|
|
||||||
Integer countOrderNum(Long userId, String time);
|
Integer countOrderNum(Long userId, String time);
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import com.sqx.modules.utils.AmountCalUtils;
|
|||||||
import com.sqx.modules.utils.excel.ExcelData;
|
import com.sqx.modules.utils.excel.ExcelData;
|
||||||
import com.sqx.modules.utils.excel.ExportExcelUtils;
|
import com.sqx.modules.utils.excel.ExportExcelUtils;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
@@ -484,8 +486,16 @@ public class CashController {
|
|||||||
@Login
|
@Login
|
||||||
@GetMapping(value = "/withdraw")
|
@GetMapping(value = "/withdraw")
|
||||||
@ApiOperation("发起提现 余额 金钱")
|
@ApiOperation("发起提现 余额 金钱")
|
||||||
public Result withdraw(Long userId, Double money) {
|
@ApiImplicitParams({
|
||||||
return cashOutService.withdraw(userId, money, true);
|
@ApiImplicitParam(name = "userId", value = "提现人员Id", dataTypeClass = String.class, paramType = "param"),
|
||||||
|
@ApiImplicitParam(name = "money", value = "提现金额", dataTypeClass = Double.class, paramType = "param"),
|
||||||
|
@ApiImplicitParam(name = "msg", value = "验证码", dataTypeClass = String.class, paramType = "param"),
|
||||||
|
})
|
||||||
|
public Result withdraw(Long userId, Double money, String msg) {
|
||||||
|
if (StringUtils.isBlank(msg)) {
|
||||||
|
return Result.error("请输入验证码");
|
||||||
|
}
|
||||||
|
return cashOutService.withdraw(userId, money, msg, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class AppCashController {
|
|||||||
@Debounce(interval = 3000, value = "#userId")
|
@Debounce(interval = 3000, value = "#userId")
|
||||||
@ApiOperation("发起提现 余额 金钱")
|
@ApiOperation("发起提现 余额 金钱")
|
||||||
public Result withdraw(@RequestAttribute("userId") Long userId, Double amount) {
|
public Result withdraw(@RequestAttribute("userId") Long userId, Double amount) {
|
||||||
return cashOutService.withdraw(userId, amount, false);
|
return cashOutService.withdraw(userId, amount, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Login
|
@Login
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface CashOutService {
|
public interface CashOutService {
|
||||||
|
|
||||||
PageUtils selectCashOutList(Integer page,Integer limit,CashOut cashOut);
|
PageUtils selectCashOutList(Integer page, Integer limit, CashOut cashOut);
|
||||||
|
|
||||||
ExcelData excelPayDetails(CashOut cashOut);
|
ExcelData excelPayDetails(CashOut cashOut);
|
||||||
|
|
||||||
@@ -43,11 +43,10 @@ public interface CashOutService {
|
|||||||
Result sysCashMoney(Long userId, Double money);
|
Result sysCashMoney(Long userId, Double money);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param userId 用户Id tb_user的id
|
* @param userId 用户Id tb_user的id
|
||||||
* @param money 提现金额
|
* @param money 提现金额
|
||||||
* @param isSys 是否是系统用户提现
|
* @param isSys 是否是系统用户提现
|
||||||
*/
|
*/
|
||||||
Result withdraw(Long userId, Double money, boolean isSys);
|
Result withdraw(Long userId, Double money, String msg, boolean isSys);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.sqx.common.utils.PageUtils;
|
import com.sqx.common.utils.PageUtils;
|
||||||
import com.sqx.common.utils.Result;
|
import com.sqx.common.utils.Result;
|
||||||
|
import com.sqx.modules.app.dao.MsgDao;
|
||||||
|
import com.sqx.modules.app.entity.Msg;
|
||||||
import com.sqx.modules.app.entity.UserEntity;
|
import com.sqx.modules.app.entity.UserEntity;
|
||||||
import com.sqx.modules.app.entity.UserMoney;
|
import com.sqx.modules.app.entity.UserMoney;
|
||||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||||
@@ -76,6 +78,8 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
|||||||
private InviteMoneyService inviteMoneyService;
|
private InviteMoneyService inviteMoneyService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysUserService sysUserService;
|
private SysUserService sysUserService;
|
||||||
|
@Autowired
|
||||||
|
private MsgDao msgDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageUtils selectCashOutList(Integer page, Integer limit, CashOut cashOut) {
|
public PageUtils selectCashOutList(Integer page, Integer limit, CashOut cashOut) {
|
||||||
@@ -402,7 +406,7 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Result withdraw(Long userId, Double money, boolean isSys) {
|
public Result withdraw(Long userId, Double money, String msg, boolean isSys) {
|
||||||
if (money == null || money <= 0.00) {
|
if (money == null || money <= 0.00) {
|
||||||
return Result.error("请不要输入小于0的数字,请输入正确的提现金额!");
|
return Result.error("请不要输入小于0的数字,请输入正确的提现金额!");
|
||||||
}
|
}
|
||||||
@@ -412,6 +416,10 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
|||||||
|
|
||||||
if (isSys) {
|
if (isSys) {
|
||||||
SysUserEntity sysUserEntity = sysUserService.getById(userId);
|
SysUserEntity sysUserEntity = sysUserService.getById(userId);
|
||||||
|
Msg msg1 = msgDao.findByPhoneAndCode(sysUserEntity.getMobile(), msg);
|
||||||
|
if (msg1 == null) {
|
||||||
|
return Result.error("验证码不正确!");
|
||||||
|
}
|
||||||
if (StringUtils.isBlank(sysUserEntity.getZhiFuBao()) || StringUtils.isBlank(sysUserEntity.getZhiFuBaoName())) {
|
if (StringUtils.isBlank(sysUserEntity.getZhiFuBao()) || StringUtils.isBlank(sysUserEntity.getZhiFuBaoName())) {
|
||||||
return Result.error(9999, "请先绑定支付宝账号!");
|
return Result.error(9999, "请先绑定支付宝账号!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,8 @@ public interface RedisService {
|
|||||||
|
|
||||||
|
|
||||||
void setDiscSpinningAmounts(String key);
|
void setDiscSpinningAmounts(String key);
|
||||||
|
|
||||||
|
void setPayFreeWatchTime(Long userId, Integer time);
|
||||||
|
|
||||||
|
Boolean getPayFreeWatchTimeIsExpire(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.sqx.modules.redisService.impl;
|
package com.sqx.modules.redisService.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUnit;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.sqx.common.utils.RedisKeys;
|
||||||
import com.sqx.common.utils.RedisUtils;
|
import com.sqx.common.utils.RedisUtils;
|
||||||
import com.sqx.modules.discSpinning.entity.DiscSpinningAmount;
|
import com.sqx.modules.discSpinning.entity.DiscSpinningAmount;
|
||||||
import com.sqx.modules.discSpinning.service.DiscSpinningAmountService;
|
import com.sqx.modules.discSpinning.service.DiscSpinningAmountService;
|
||||||
@@ -9,7 +12,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class RedisServiceImpl implements RedisService {
|
public class RedisServiceImpl implements RedisService {
|
||||||
@Lazy
|
@Lazy
|
||||||
@@ -21,6 +28,29 @@ public class RedisServiceImpl implements RedisService {
|
|||||||
@Override
|
@Override
|
||||||
public void setDiscSpinningAmounts(String key) {
|
public void setDiscSpinningAmounts(String key) {
|
||||||
List<DiscSpinningAmount> amounts = amountService.list(new QueryWrapper<DiscSpinningAmount>().eq("status", 1).orderByAsc("max_amount"));
|
List<DiscSpinningAmount> amounts = amountService.list(new QueryWrapper<DiscSpinningAmount>().eq("status", 1).orderByAsc("max_amount"));
|
||||||
redisUtils.set(key, amounts);
|
Map<Integer, List<DiscSpinningAmount>> map =
|
||||||
|
amounts.stream().collect(Collectors.groupingBy(
|
||||||
|
disc -> disc.getNum() == null ? 0 : disc.getNum()
|
||||||
|
));
|
||||||
|
redisUtils.set(key, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPayFreeWatchTime(Long userId, Integer minute) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean getPayFreeWatchTimeIsExpire(Long userId) {
|
||||||
|
String data = redisUtils.get(RedisKeys.getPayFreeWatchKey(userId));
|
||||||
|
if (data == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
long expireTime = Long.parseLong(data);
|
||||||
|
return DateUtil.current() > expireTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
package com.sqx.modules.sys.controller;
|
package com.sqx.modules.sys.controller;
|
||||||
|
|
||||||
import com.sqx.common.utils.Result;
|
import com.sqx.common.utils.Result;
|
||||||
|
import com.sqx.common.validator.ValidatorUtils;
|
||||||
|
import com.sqx.common.validator.group.AddGroup;
|
||||||
|
import com.sqx.modules.app.dao.MsgDao;
|
||||||
|
import com.sqx.modules.app.entity.Msg;
|
||||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||||
import com.sqx.modules.sys.form.SysLoginForm;
|
import com.sqx.modules.sys.form.SysLoginForm;
|
||||||
import com.sqx.modules.sys.service.SysCaptchaService;
|
import com.sqx.modules.sys.service.SysCaptchaService;
|
||||||
import com.sqx.modules.sys.service.SysUserService;
|
import com.sqx.modules.sys.service.SysUserService;
|
||||||
import com.sqx.modules.sys.service.SysUserTokenService;
|
import com.sqx.modules.sys.service.SysUserTokenService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -19,80 +28,113 @@ import javax.servlet.ServletOutputStream;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录相关
|
* 登录相关
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
@Api(value = "登录相关", tags = {"登录相关"})
|
||||||
public class SysLoginController extends AbstractController {
|
public class SysLoginController extends AbstractController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysUserService sysUserService;
|
private SysUserService sysUserService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysUserTokenService sysUserTokenService;
|
private SysUserTokenService sysUserTokenService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysCaptchaService sysCaptchaService;
|
private SysCaptchaService sysCaptchaService;
|
||||||
|
@Autowired
|
||||||
|
private MsgDao msgDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码
|
* 验证码
|
||||||
*/
|
*/
|
||||||
@GetMapping("captcha.jpg")
|
@GetMapping("captcha.jpg")
|
||||||
public void captcha(HttpServletResponse response, String uuid)throws IOException {
|
public void captcha(HttpServletResponse response, String uuid) throws IOException {
|
||||||
response.setHeader("Cache-Control", "no-store, no-cache");
|
response.setHeader("Cache-Control", "no-store, no-cache");
|
||||||
response.setContentType("image/jpeg");
|
response.setContentType("image/jpeg");
|
||||||
|
|
||||||
//获取图片验证码
|
//获取图片验证码
|
||||||
BufferedImage image = sysCaptchaService.getCaptcha(uuid);
|
BufferedImage image = sysCaptchaService.getCaptcha(uuid);
|
||||||
|
|
||||||
ServletOutputStream out = response.getOutputStream();
|
ServletOutputStream out = response.getOutputStream();
|
||||||
ImageIO.write(image, "jpg", out);
|
ImageIO.write(image, "jpg", out);
|
||||||
IOUtils.closeQuietly(out);
|
IOUtils.closeQuietly(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录
|
|
||||||
*/
|
|
||||||
@PostMapping("/sys/login")
|
|
||||||
public Map<String, Object> login(@RequestBody SysLoginForm form)throws IOException {
|
|
||||||
boolean captcha = sysCaptchaService.validate(form.getUuid(), form.getCaptcha());
|
|
||||||
if(!captcha){
|
|
||||||
return Result.error("验证码不正确");
|
|
||||||
}
|
|
||||||
|
|
||||||
//用户信息
|
|
||||||
SysUserEntity user = sysUserService.queryByUserName(form.getUsername());
|
|
||||||
|
|
||||||
//账号不存在、密码错误
|
|
||||||
if(user == null || !user.getPassword().equals(new Sha256Hash(form.getPassword(), user.getSalt()).toHex())) {
|
|
||||||
return Result.error("账号或密码不正确");
|
|
||||||
}
|
|
||||||
|
|
||||||
//账号锁定
|
|
||||||
if(user.getStatus() == 0){
|
|
||||||
return Result.error("账号已被锁定,请联系管理员");
|
|
||||||
}
|
|
||||||
|
|
||||||
//判断角色类型
|
|
||||||
if(form.getAdminType()==1 && user.getIsChannel()!=null && user.getIsChannel()==1){
|
|
||||||
return Result.error("代理账号请登录代理端!");
|
|
||||||
}else if(form.getAdminType()==2 && user.getIsChannel()==null){
|
|
||||||
return Result.error("管理员请登录管理端!");
|
|
||||||
}
|
|
||||||
|
|
||||||
//生成token,并保存到数据库
|
|
||||||
Result r = sysUserTokenService.createToken(user.getUserId());
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
@PostMapping("/registered")
|
||||||
* 退出
|
@ApiOperation("代理注册")
|
||||||
*/
|
@ApiImplicitParams({
|
||||||
@PostMapping("/sys/logout")
|
@ApiImplicitParam(name = "msg", value = "验证码", dataTypeClass = String.class, paramType = "param"),
|
||||||
public Result logout() {
|
})
|
||||||
sysUserTokenService.logout(getUserId());
|
public Result registered(@RequestBody SysUserEntity user, String msg) {
|
||||||
return Result.success();
|
if(StringUtils.isBlank(user.getMobile())){
|
||||||
}
|
return Result.error("注册失败,请输入手机号");
|
||||||
|
}
|
||||||
|
if(StringUtils.isBlank(msg)){
|
||||||
|
return Result.error("注册失败,请输入验证码");
|
||||||
|
}
|
||||||
|
Msg msg1 = msgDao.findByPhoneAndCode(user.getMobile(), msg);
|
||||||
|
if (msg1 == null) {
|
||||||
|
return Result.error("验证码不正确!");
|
||||||
|
}
|
||||||
|
user.setIsChannel(1);
|
||||||
|
user.setQdRate(new BigDecimal("0.01"));
|
||||||
|
user.setStatus(1);
|
||||||
|
user.setRoleIdList(Collections.singletonList(4L));
|
||||||
|
ValidatorUtils.validateEntity(user, AddGroup.class);
|
||||||
|
sysUserService.saveUser(user);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录
|
||||||
|
*/
|
||||||
|
@PostMapping("/sys/login")
|
||||||
|
public Map<String, Object> login(@RequestBody SysLoginForm form) throws IOException {
|
||||||
|
boolean captcha = sysCaptchaService.validate(form.getUuid(), form.getCaptcha());
|
||||||
|
if (!captcha) {
|
||||||
|
return Result.error("验证码不正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
//用户信息
|
||||||
|
SysUserEntity user = sysUserService.queryByUserName(form.getUsername());
|
||||||
|
|
||||||
|
//账号不存在、密码错误
|
||||||
|
if (user == null || !user.getPassword().equals(new Sha256Hash(form.getPassword(), user.getSalt()).toHex())) {
|
||||||
|
return Result.error("账号或密码不正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
//账号锁定
|
||||||
|
if (user.getStatus() == 0) {
|
||||||
|
return Result.error("账号已被锁定,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断角色类型
|
||||||
|
if (form.getAdminType() == 1 && user.getIsChannel() != null && user.getIsChannel() == 1) {
|
||||||
|
return Result.error("代理账号请登录代理端!");
|
||||||
|
} else if (form.getAdminType() == 2 && user.getIsChannel() == null) {
|
||||||
|
return Result.error("管理员请登录管理端!");
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成token,并保存到数据库
|
||||||
|
Result r = sysUserTokenService.createToken(user.getUserId());
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出
|
||||||
|
*/
|
||||||
|
@PostMapping("/sys/logout")
|
||||||
|
public Result logout() {
|
||||||
|
sysUserTokenService.logout(getUserId());
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.sqx.modules.sys.entity.SysUserEntity;
|
|||||||
import com.sqx.modules.sys.service.SysRoleService;
|
import com.sqx.modules.sys.service.SysRoleService;
|
||||||
import com.sqx.modules.sys.service.SysUserRoleService;
|
import com.sqx.modules.sys.service.SysUserRoleService;
|
||||||
import com.sqx.modules.sys.service.SysUserService;
|
import com.sqx.modules.sys.service.SysUserService;
|
||||||
|
import com.sqx.modules.utils.InvitationCodeUtil;
|
||||||
import org.apache.commons.lang.RandomStringUtils;
|
import org.apache.commons.lang.RandomStringUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||||
@@ -25,103 +26,105 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统用户
|
* 系统用户
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
@Service("sysUserService")
|
@Service("sysUserService")
|
||||||
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysUserRoleService sysUserRoleService;
|
private SysUserRoleService sysUserRoleService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleService sysRoleService;
|
private SysRoleService sysRoleService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageUtils queryPage(Map<String, Object> params) {
|
public PageUtils queryPage(Map<String, Object> params) {
|
||||||
String username = (String)params.get("username");
|
String username = (String) params.get("username");
|
||||||
Long createUserId = (Long)params.get("createUserId");
|
Long createUserId = (Long) params.get("createUserId");
|
||||||
Object isChannel = params.get("isChannel");
|
Object isChannel = params.get("isChannel");
|
||||||
Object sysUserId = params.get("sysUserId");
|
Object sysUserId = params.get("sysUserId");
|
||||||
IPage<SysUserEntity> page = this.page(
|
IPage<SysUserEntity> page = this.page(
|
||||||
new Query<SysUserEntity>().getPage(params),
|
new Query<SysUserEntity>().getPage(params),
|
||||||
new QueryWrapper<SysUserEntity>()
|
new QueryWrapper<SysUserEntity>()
|
||||||
.like(StringUtils.isNotBlank(username),"username", username)
|
.like(StringUtils.isNotBlank(username), "username", username)
|
||||||
.eq(createUserId != null,"create_user_id", createUserId)
|
.eq(createUserId != null, "create_user_id", createUserId)
|
||||||
.eq(isChannel!=null,"is_channel",isChannel)
|
.eq(isChannel != null, "is_channel", isChannel)
|
||||||
.eq(sysUserId!=null,"sys_user_id",sysUserId)
|
.eq(sysUserId != null, "sys_user_id", sysUserId)
|
||||||
.isNull(sysUserId==null,"sys_user_id")
|
.isNull(sysUserId == null, "sys_user_id")
|
||||||
.isNull(isChannel==null,"is_channel")
|
.isNull(isChannel == null, "is_channel")
|
||||||
);
|
);
|
||||||
|
|
||||||
return new PageUtils(page);
|
return new PageUtils(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> queryAllPerms(Long userId) {
|
public List<String> queryAllPerms(Long userId) {
|
||||||
return baseMapper.queryAllPerms(userId);
|
return baseMapper.queryAllPerms(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Long> queryAllMenuId(Long userId) {
|
public List<Long> queryAllMenuId(Long userId) {
|
||||||
return baseMapper.queryAllMenuId(userId);
|
return baseMapper.queryAllMenuId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysUserEntity queryByUserName(String username) {
|
public SysUserEntity queryByUserName(String username) {
|
||||||
return baseMapper.queryByUserName(username);
|
return baseMapper.queryByUserName(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("AlibabaTransactionMustHaveRollback")
|
@SuppressWarnings("AlibabaTransactionMustHaveRollback")
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveUser(SysUserEntity user) {
|
public void saveUser(SysUserEntity user) {
|
||||||
user.setCreateTime(new Date());
|
user.setCreateTime(new Date());
|
||||||
//sha256加密
|
//sha256加密
|
||||||
String salt = RandomStringUtils.randomAlphanumeric(20);
|
String salt = RandomStringUtils.randomAlphanumeric(20);
|
||||||
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
|
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
|
||||||
user.setSalt(salt);
|
user.setSalt(salt);
|
||||||
this.save(user);
|
this.save(user);
|
||||||
|
if (user.getIsChannel() != null && user.getIsChannel().equals(1) && StringUtils.isBlank(user.getQdCode())) {
|
||||||
//检查角色是否越权
|
user.setQdCode(InvitationCodeUtil.toRegisteredCode(user.getUserId()));
|
||||||
checkRole(user);
|
this.save(user);
|
||||||
|
}
|
||||||
//保存用户与角色关系
|
//检查角色是否越权
|
||||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
checkRole(user);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
//保存用户与角色关系
|
||||||
@Transactional
|
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||||
public void update(SysUserEntity user) {
|
}
|
||||||
if(StringUtils.isBlank(user.getPassword())){
|
|
||||||
user.setPassword(null);
|
|
||||||
}else{
|
|
||||||
user.setPassword(new Sha256Hash(user.getPassword(), user.getSalt()).toHex());
|
|
||||||
}
|
|
||||||
this.updateById(user);
|
|
||||||
|
|
||||||
//检查角色是否越权
|
|
||||||
checkRole(user);
|
|
||||||
|
|
||||||
//保存用户与角色关系
|
|
||||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteBatch(Long[] userId) {
|
@Transactional
|
||||||
this.removeByIds(Arrays.asList(userId));
|
public void update(SysUserEntity user) {
|
||||||
}
|
if (StringUtils.isBlank(user.getPassword())) {
|
||||||
|
user.setPassword(null);
|
||||||
|
} else {
|
||||||
|
user.setPassword(new Sha256Hash(user.getPassword(), user.getSalt()).toHex());
|
||||||
|
}
|
||||||
|
this.updateById(user);
|
||||||
|
|
||||||
@Override
|
//检查角色是否越权
|
||||||
public boolean updatePassword(Long userId, String password, String newPassword) {
|
checkRole(user);
|
||||||
SysUserEntity userEntity = new SysUserEntity();
|
|
||||||
userEntity.setPassword(newPassword);
|
//保存用户与角色关系
|
||||||
return this.update(userEntity,
|
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||||
new QueryWrapper<SysUserEntity>().eq("user_id", userId).eq("password", password));
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
/**
|
public void deleteBatch(Long[] userId) {
|
||||||
* 检查角色是否越权
|
this.removeByIds(Arrays.asList(userId));
|
||||||
*/
|
}
|
||||||
private void checkRole(SysUserEntity user){
|
|
||||||
|
@Override
|
||||||
|
public boolean updatePassword(Long userId, String password, String newPassword) {
|
||||||
|
SysUserEntity userEntity = new SysUserEntity();
|
||||||
|
userEntity.setPassword(newPassword);
|
||||||
|
return this.update(userEntity,
|
||||||
|
new QueryWrapper<SysUserEntity>().eq("user_id", userId).eq("password", password));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查角色是否越权
|
||||||
|
*/
|
||||||
|
private void checkRole(SysUserEntity user) {
|
||||||
/*if(user.getRoleIdList() == null || user.getRoleIdList().size() == 0){
|
/*if(user.getRoleIdList() == null || user.getRoleIdList().size() == 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -137,11 +140,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
|
|||||||
if(!roleIdList.containsAll(user.getRoleIdList())){
|
if(!roleIdList.containsAll(user.getRoleIdList())){
|
||||||
throw new SqxException("新增用户所选角色,不是本人创建");
|
throw new SqxException("新增用户所选角色,不是本人创建");
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysUserEntity selectSysUserByQdCode(String qdCode){
|
public SysUserEntity selectSysUserByQdCode(String qdCode) {
|
||||||
return baseMapper.selectOne(new QueryWrapper<SysUserEntity>().isNull("sys_user_id").eq("qd_code", qdCode));
|
return baseMapper.selectOne(new QueryWrapper<SysUserEntity>().isNull("sys_user_id").eq("qd_code", qdCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,85 +2,125 @@ package com.sqx.modules.utils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 邀请码生成解密工具类
|
* 邀请码生成解密工具类
|
||||||
|
*
|
||||||
* @author fang
|
* @author fang
|
||||||
* @date 2020/7/8
|
* @date 2020/7/8
|
||||||
*/
|
*/
|
||||||
public class InvitationCodeUtil {
|
public class InvitationCodeUtil {
|
||||||
|
|
||||||
|
|
||||||
/** 自定义进制(选择你想要的进制数,不能重复且最好不要0、1这些容易混淆的字符) */
|
/**
|
||||||
private static final char[] r=new char[]{ 'M', 'J', 'U', 'D', 'Z', 'X', '9', 'C', '7', 'P','E', '8', '6', 'B', 'G', 'H', 'S', '2', '5', 'F', 'R', '4','Q', 'W', 'K', '3', 'V', 'Y', 'T', 'N'};
|
* 自定义进制(选择你想要的进制数,不能重复且最好不要0、1这些容易混淆的字符)
|
||||||
|
*/
|
||||||
|
private static final char[] r = new char[]{'M', 'J', 'U', 'D', 'Z', 'X', '9', 'C', '7', 'P', 'E', '8', '6', 'B', 'G', 'H', 'S', '2', '5', 'F', 'R', '4', 'Q', 'W', 'K', '3', 'V', 'Y', 'T', 'N'};
|
||||||
|
|
||||||
/** 定义一个字符用来补全邀请码长度(该字符前面是计算出来的邀请码,后面是用来补全用的) */
|
/**
|
||||||
private static final char b='A';
|
* 定义一个字符用来补全邀请码长度(该字符前面是计算出来的邀请码,后面是用来补全用的)
|
||||||
|
*/
|
||||||
|
private static final char b = 'A';
|
||||||
|
|
||||||
/** 进制长度 */
|
/**
|
||||||
private static final int binLen=r.length;
|
* 进制长度
|
||||||
|
*/
|
||||||
|
private static final int binLen = r.length;
|
||||||
|
|
||||||
/** 邀请码长度 */
|
/**
|
||||||
private static final int s=6;
|
* 邀请码长度
|
||||||
|
*/
|
||||||
|
private static final int s = 6;
|
||||||
|
|
||||||
|
|
||||||
/** 补位字符串 */
|
/**
|
||||||
private static final String e="KSLFXFR";
|
* 补位字符串
|
||||||
|
*/
|
||||||
|
private static final String e = "KSLFXFR";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理注册 补位字符串
|
||||||
|
*/
|
||||||
|
private static final String re = "REGISTER";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID生成六位随机码
|
* 根据ID生成六位随机码
|
||||||
|
*
|
||||||
|
* @param id ID
|
||||||
|
* @return 随机码
|
||||||
|
*/
|
||||||
|
public static String toRegisteredCode(long id) {
|
||||||
|
char[] buf = new char[32];
|
||||||
|
int charPos = 32;
|
||||||
|
|
||||||
|
while ((id / binLen) > 0) {
|
||||||
|
int ind = (int) (id % binLen);
|
||||||
|
buf[--charPos] = r[ind];
|
||||||
|
id /= binLen;
|
||||||
|
}
|
||||||
|
buf[--charPos] = r[(int) (id % binLen)];
|
||||||
|
String str = new String(buf, charPos, (32 - charPos));
|
||||||
|
// 不够长度的自动补全
|
||||||
|
if (str.length() < s) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(re.subSequence(0, s - str.length()));
|
||||||
|
str += sb.toString();
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID生成六位随机码
|
||||||
|
*
|
||||||
* @param id ID
|
* @param id ID
|
||||||
* @return 随机码
|
* @return 随机码
|
||||||
*/
|
*/
|
||||||
public static String toSerialCode(long id) {
|
public static String toSerialCode(long id) {
|
||||||
char[] buf=new char[32];
|
char[] buf = new char[32];
|
||||||
int charPos=32;
|
int charPos = 32;
|
||||||
|
|
||||||
while((id / binLen) > 0) {
|
while ((id / binLen) > 0) {
|
||||||
int ind=(int)(id % binLen);
|
int ind = (int) (id % binLen);
|
||||||
buf[--charPos]=r[ind];
|
buf[--charPos] = r[ind];
|
||||||
id /= binLen;
|
id /= binLen;
|
||||||
}
|
}
|
||||||
buf[--charPos]=r[(int)(id % binLen)];
|
buf[--charPos] = r[(int) (id % binLen)];
|
||||||
String str=new String(buf, charPos, (32 - charPos));
|
String str = new String(buf, charPos, (32 - charPos));
|
||||||
// 不够长度的自动补全
|
// 不够长度的自动补全
|
||||||
if(str.length() < s) {
|
if (str.length() < s) {
|
||||||
StringBuilder sb=new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(e.subSequence(0, s-str.length()));
|
sb.append(e.subSequence(0, s - str.length()));
|
||||||
str+=sb.toString();
|
str += sb.toString();
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据随机码生成ID
|
* 根据随机码生成ID
|
||||||
|
*
|
||||||
* @param code 随机码
|
* @param code 随机码
|
||||||
* @return ID
|
* @return ID
|
||||||
*/
|
*/
|
||||||
public static long codeToId(String code) {
|
public static long codeToId(String code) {
|
||||||
char[] chs;
|
char[] chs;
|
||||||
chs = code.toCharArray();
|
chs = code.toCharArray();
|
||||||
long res=0L;
|
long res = 0L;
|
||||||
for(int i=0; i < chs.length; i++) {
|
for (int i = 0; i < chs.length; i++) {
|
||||||
int ind=0;
|
int ind = 0;
|
||||||
for(int j=0; j < binLen; j++) {
|
for (int j = 0; j < binLen; j++) {
|
||||||
if(chs[i] == r[j]) {
|
if (chs[i] == r[j]) {
|
||||||
ind=j;
|
ind = j;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(chs[i] == b) {
|
if (chs[i] == b) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(i > 0) {
|
if (i > 0) {
|
||||||
res=res * binLen + ind;
|
res = res * binLen + ind;
|
||||||
} else {
|
} else {
|
||||||
res=ind;
|
res = ind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -319,4 +319,12 @@
|
|||||||
and create_time > #{time}
|
and create_time > #{time}
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="countPayOrderByDay" resultType="java.lang.Integer">
|
||||||
|
SELECT count(*)
|
||||||
|
FROM orders
|
||||||
|
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')
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user