Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
package com.sqx.common.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
|
||||
/**
|
||||
* Redis所有Keys
|
||||
*
|
||||
*/
|
||||
public class RedisKeys {
|
||||
|
||||
public static final String PAY_FREE_WATCH_KEY = "pay:free:watch:";
|
||||
|
||||
public static String getSysConfigKey(String key){
|
||||
return "sys:config:" + key;
|
||||
}
|
||||
@@ -13,4 +17,12 @@ public class RedisKeys {
|
||||
public static String getDateKey(String 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;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.sqx.modules.redisService.RedisService;
|
||||
@@ -10,12 +11,14 @@ import org.springframework.stereotype.Component;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Redis工具类
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class RedisUtils {
|
||||
@@ -33,19 +36,31 @@ public class RedisUtils {
|
||||
private SetOperations<String, Object> setOperations;
|
||||
@Autowired
|
||||
private ZSetOperations<String, Object> zSetOperations;
|
||||
/** 默认过期时长,单位:秒 */
|
||||
/**
|
||||
* 默认过期时长,单位:秒
|
||||
*/
|
||||
public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
|
||||
/** 不设置过期时长 */
|
||||
/**
|
||||
* 不设置过期时长
|
||||
*/
|
||||
public final static long NOT_EXPIRE = -1;
|
||||
private final static Gson Gson = new Gson();
|
||||
|
||||
/**
|
||||
* 获取缓存里的数据 如果不存在 则插入 并返回
|
||||
* @param key redis Key
|
||||
* @param clazz 返回类型
|
||||
* @param method RedisService调用的方法名 如果数据不存在会执行该调用方法
|
||||
*/
|
||||
public <T> List<T> getListData(String key, Class<T> clazz,String method) {
|
||||
|
||||
public <T> Map<String, List<T>> getMapData(String key, String method, Class<T> clazz) {
|
||||
String jsonStr = getDate(key, method);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
JsonNode jsonNode = objectMapper.readTree(jsonStr);
|
||||
|
||||
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);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
@@ -59,26 +74,27 @@ public class RedisUtils {
|
||||
|
||||
/**
|
||||
* 获取缓存里的数据 如果不存在 则插入 并返回
|
||||
* @param key redis Key
|
||||
* @param clazz 返回类型
|
||||
*
|
||||
* @param key redis Key
|
||||
* @param clazz 返回类型
|
||||
* @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);
|
||||
return this.fromJson(jsonStr, clazz);
|
||||
}
|
||||
|
||||
public String getDate(String key, String method) {
|
||||
public String getDate(String key, String method) {
|
||||
if (!this.hasKey(key)) {
|
||||
try {
|
||||
// 获取Lookup对象
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
// 构建方法类型(这里假设方法无参数,返回类型为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.invoke(redisService,key);
|
||||
methodHandle.invoke(redisService, key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
@@ -93,20 +109,34 @@ public class RedisUtils {
|
||||
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));
|
||||
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){
|
||||
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);
|
||||
}
|
||||
|
||||
public <T> T get(String key, Class<T> clazz, long expire) {
|
||||
String value = valueOperations.get(key);
|
||||
if(expire != NOT_EXPIRE){
|
||||
if (expire != NOT_EXPIRE) {
|
||||
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||
}
|
||||
return value == null ? null : fromJson(value, clazz);
|
||||
@@ -118,7 +148,7 @@ public class RedisUtils {
|
||||
|
||||
public String get(String key, long expire) {
|
||||
String value = valueOperations.get(key);
|
||||
if(expire != NOT_EXPIRE){
|
||||
if (expire != NOT_EXPIRE) {
|
||||
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||
}
|
||||
return value;
|
||||
@@ -150,9 +180,9 @@ public class RedisUtils {
|
||||
/**
|
||||
* Object转成JSON数据
|
||||
*/
|
||||
private String toJson(Object object){
|
||||
if(object instanceof Integer || object instanceof Long || object instanceof Float ||
|
||||
object instanceof Double || object instanceof Boolean || object instanceof String){
|
||||
private String toJson(Object object) {
|
||||
if (object instanceof Integer || object instanceof Long || object instanceof Float ||
|
||||
object instanceof Double || object instanceof Boolean || object instanceof String) {
|
||||
return String.valueOf(object);
|
||||
}
|
||||
return Gson.toJson(object);
|
||||
@@ -161,7 +191,25 @@ public class RedisUtils {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
|
||||
if (count > 0) {
|
||||
return Result.error("一个支付宝账号仅可绑定一个支付宝用户");
|
||||
return Result.error("一个支付宝账号仅可绑定一个用户");
|
||||
}
|
||||
if (!ApiAccessLimitUtil.isAccessAllowed(userId.toString(), "updateZFB", 3, "month")) {
|
||||
return Result.error("每月仅支持修改三次,请联系管理员");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.sqx.modules.course.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.CollectionUtils;
|
||||
@@ -12,6 +14,8 @@ import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.entity.UserEntity;
|
||||
import com.sqx.modules.app.service.UserService;
|
||||
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.CourseDao;
|
||||
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.service.CourseDetailsService;
|
||||
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.redisService.impl.RedisServiceImpl;
|
||||
import com.sqx.modules.utils.EasyPoi.ExcelUtils;
|
||||
import com.sqx.modules.utils.HttpClientUtil;
|
||||
import com.sqx.modules.utils.SenInfoCheckUtil;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -39,6 +47,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, CourseDetails> implements CourseDetailsService {
|
||||
|
||||
@Autowired
|
||||
@@ -53,6 +62,12 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private OrdersDao ordersDao;
|
||||
@Autowired
|
||||
private CommonInfoDao commonInfoDao;
|
||||
@Autowired
|
||||
private RedisServiceImpl redisServiceImpl;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -77,6 +92,37 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
||||
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
|
||||
public Result selectCourseDetailsById(Long id, String token, String courseDetailsId) {
|
||||
Course bean = courseDao.selectById(id);
|
||||
@@ -99,7 +145,9 @@ public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsDao, Cour
|
||||
UserEntity userEntity = userService.selectUserById(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));
|
||||
} else {
|
||||
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) {
|
||||
double amount = 0;
|
||||
Long orderId = null;
|
||||
Integer i = recordService.countDraw(userId);
|
||||
if (maps == null || !maps.containsKey("source") || !"task".equals(maps.get("source"))) {
|
||||
//任务抽奖
|
||||
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
||||
Integer i = recordService.countDraw(userId);
|
||||
if (i != null && i >= drawCount) {
|
||||
return Result.error("当日可抽奖次数已超限");
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class DiscSpinningController {
|
||||
}
|
||||
}
|
||||
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("大转盘奖项领取")
|
||||
|
||||
@@ -18,6 +18,8 @@ import lombok.Data;
|
||||
public class DiscSpinningAmount extends Model<DiscSpinningAmount> {
|
||||
@ApiModelProperty("主键id")
|
||||
private Long id;
|
||||
@ApiModelProperty("从第几次开始变化")
|
||||
private Integer num;
|
||||
@ApiModelProperty("描述")
|
||||
private String name;
|
||||
@ApiModelProperty("0-1 小于 多少为该奖励")
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.sqx.modules.discSpinning.entity.DiscSpinningRecord;
|
||||
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);
|
||||
|
||||
@@ -33,10 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSpinning> implements DiscSpinningService {
|
||||
@@ -125,11 +122,11 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
||||
cashOut.setState(2);
|
||||
if (baseResp.getErrorMsg().contains("收款人账户号出款属性不匹配")) {
|
||||
cashOut.setRefund("提现失败,请检查支付宝账号与收款人姓名后,重试。");
|
||||
}else {
|
||||
} else {
|
||||
cashOut.setRefund(baseResp.getErrorMsg());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
UserMoneyDetails userMoneyDetails = new UserMoneyDetails(
|
||||
userInfo.getUserId(), null, null, "[现金大转盘]", 4, 2, 1,
|
||||
new BigDecimal(money), "现金红包自动提现" + money + "元", 1);
|
||||
@@ -142,7 +139,7 @@ public class DiscSpinningServiceImpl extends ServiceImpl<DiscSpinningDao, DiscSp
|
||||
|
||||
@Override
|
||||
@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);
|
||||
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);
|
||||
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) {
|
||||
if (randomNum.compareTo(prize.getNumber()) < 0) {
|
||||
if (prize.getType() == 2) {
|
||||
|
||||
@@ -39,6 +39,8 @@ public interface OrdersDao extends BaseMapper<Orders> {
|
||||
Integer selectOrdersCountStatisticsByDay(Long userId);
|
||||
|
||||
Orders selectOrdersByDay(Long userId);
|
||||
Integer countPayOrderByDay(Long userId);
|
||||
|
||||
|
||||
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.ExportExcelUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.val;
|
||||
@@ -484,8 +486,16 @@ public class CashController {
|
||||
@Login
|
||||
@GetMapping(value = "/withdraw")
|
||||
@ApiOperation("发起提现 余额 金钱")
|
||||
public Result withdraw(Long userId, Double money) {
|
||||
return cashOutService.withdraw(userId, money, true);
|
||||
@ApiImplicitParams({
|
||||
@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")
|
||||
@ApiOperation("发起提现 余额 金钱")
|
||||
public Result withdraw(@RequestAttribute("userId") Long userId, Double amount) {
|
||||
return cashOutService.withdraw(userId, amount, false);
|
||||
return cashOutService.withdraw(userId, amount, null, false);
|
||||
}
|
||||
|
||||
@Login
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
|
||||
public interface CashOutService {
|
||||
|
||||
PageUtils selectCashOutList(Integer page,Integer limit,CashOut cashOut);
|
||||
PageUtils selectCashOutList(Integer page, Integer limit, CashOut cashOut);
|
||||
|
||||
ExcelData excelPayDetails(CashOut cashOut);
|
||||
|
||||
@@ -43,11 +43,10 @@ public interface CashOutService {
|
||||
Result sysCashMoney(Long userId, Double money);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId 用户Id tb_user的id
|
||||
* @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.sqx.common.utils.PageUtils;
|
||||
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.UserMoney;
|
||||
import com.sqx.modules.app.entity.UserMoneyDetails;
|
||||
@@ -76,6 +78,8 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
||||
private InviteMoneyService inviteMoneyService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private MsgDao msgDao;
|
||||
|
||||
@Override
|
||||
public PageUtils selectCashOutList(Integer page, Integer limit, CashOut cashOut) {
|
||||
@@ -402,7 +406,7 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
||||
|
||||
@Override
|
||||
@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) {
|
||||
return Result.error("请不要输入小于0的数字,请输入正确的提现金额!");
|
||||
}
|
||||
@@ -412,6 +416,10 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
|
||||
|
||||
if (isSys) {
|
||||
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())) {
|
||||
return Result.error(9999, "请先绑定支付宝账号!");
|
||||
}
|
||||
|
||||
@@ -8,4 +8,8 @@ public interface RedisService {
|
||||
|
||||
|
||||
void setDiscSpinningAmounts(String key);
|
||||
|
||||
void setPayFreeWatchTime(Long userId, Integer time);
|
||||
|
||||
Boolean getPayFreeWatchTimeIsExpire(Long userId);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
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.sqx.common.utils.RedisKeys;
|
||||
import com.sqx.common.utils.RedisUtils;
|
||||
import com.sqx.modules.discSpinning.entity.DiscSpinningAmount;
|
||||
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.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class RedisServiceImpl implements RedisService {
|
||||
@Lazy
|
||||
@@ -21,6 +28,29 @@ public class RedisServiceImpl implements RedisService {
|
||||
@Override
|
||||
public void setDiscSpinningAmounts(String key) {
|
||||
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;
|
||||
|
||||
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.form.SysLoginForm;
|
||||
import com.sqx.modules.sys.service.SysCaptchaService;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
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.lang.StringUtils;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -19,80 +28,113 @@ import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 登录相关
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Api(value = "登录相关", tags = {"登录相关"})
|
||||
public class SysLoginController extends AbstractController {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysUserTokenService sysUserTokenService;
|
||||
@Autowired
|
||||
private SysCaptchaService sysCaptchaService;
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysUserTokenService sysUserTokenService;
|
||||
@Autowired
|
||||
private SysCaptchaService sysCaptchaService;
|
||||
@Autowired
|
||||
private MsgDao msgDao;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
@GetMapping("captcha.jpg")
|
||||
public void captcha(HttpServletResponse response, String uuid)throws IOException {
|
||||
response.setHeader("Cache-Control", "no-store, no-cache");
|
||||
response.setContentType("image/jpeg");
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
@GetMapping("captcha.jpg")
|
||||
public void captcha(HttpServletResponse response, String uuid) throws IOException {
|
||||
response.setHeader("Cache-Control", "no-store, no-cache");
|
||||
response.setContentType("image/jpeg");
|
||||
|
||||
//获取图片验证码
|
||||
BufferedImage image = sysCaptchaService.getCaptcha(uuid);
|
||||
//获取图片验证码
|
||||
BufferedImage image = sysCaptchaService.getCaptcha(uuid);
|
||||
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
ImageIO.write(image, "jpg", 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;
|
||||
}
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
ImageIO.write(image, "jpg", out);
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出
|
||||
*/
|
||||
@PostMapping("/sys/logout")
|
||||
public Result logout() {
|
||||
sysUserTokenService.logout(getUserId());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/registered")
|
||||
@ApiOperation("代理注册")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "msg", value = "验证码", dataTypeClass = String.class, paramType = "param"),
|
||||
})
|
||||
public Result registered(@RequestBody SysUserEntity user, String msg) {
|
||||
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.SysUserRoleService;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
import com.sqx.modules.utils.InvitationCodeUtil;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
@@ -25,103 +26,105 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
@Service("sysUserService")
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements SysUserService {
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String username = (String)params.get("username");
|
||||
Long createUserId = (Long)params.get("createUserId");
|
||||
Object isChannel = params.get("isChannel");
|
||||
Object sysUserId = params.get("sysUserId");
|
||||
IPage<SysUserEntity> page = this.page(
|
||||
new Query<SysUserEntity>().getPage(params),
|
||||
new QueryWrapper<SysUserEntity>()
|
||||
.like(StringUtils.isNotBlank(username),"username", username)
|
||||
.eq(createUserId != null,"create_user_id", createUserId)
|
||||
.eq(isChannel!=null,"is_channel",isChannel)
|
||||
.eq(sysUserId!=null,"sys_user_id",sysUserId)
|
||||
.isNull(sysUserId==null,"sys_user_id")
|
||||
.isNull(isChannel==null,"is_channel")
|
||||
);
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String username = (String) params.get("username");
|
||||
Long createUserId = (Long) params.get("createUserId");
|
||||
Object isChannel = params.get("isChannel");
|
||||
Object sysUserId = params.get("sysUserId");
|
||||
IPage<SysUserEntity> page = this.page(
|
||||
new Query<SysUserEntity>().getPage(params),
|
||||
new QueryWrapper<SysUserEntity>()
|
||||
.like(StringUtils.isNotBlank(username), "username", username)
|
||||
.eq(createUserId != null, "create_user_id", createUserId)
|
||||
.eq(isChannel != null, "is_channel", isChannel)
|
||||
.eq(sysUserId != null, "sys_user_id", sysUserId)
|
||||
.isNull(sysUserId == null, "sys_user_id")
|
||||
.isNull(isChannel == null, "is_channel")
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryAllPerms(Long userId) {
|
||||
return baseMapper.queryAllPerms(userId);
|
||||
}
|
||||
@Override
|
||||
public List<String> queryAllPerms(Long userId) {
|
||||
return baseMapper.queryAllPerms(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> queryAllMenuId(Long userId) {
|
||||
return baseMapper.queryAllMenuId(userId);
|
||||
}
|
||||
@Override
|
||||
public List<Long> queryAllMenuId(Long userId) {
|
||||
return baseMapper.queryAllMenuId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserEntity queryByUserName(String username) {
|
||||
return baseMapper.queryByUserName(username);
|
||||
}
|
||||
@Override
|
||||
public SysUserEntity queryByUserName(String username) {
|
||||
return baseMapper.queryByUserName(username);
|
||||
}
|
||||
|
||||
@SuppressWarnings("AlibabaTransactionMustHaveRollback")
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveUser(SysUserEntity user) {
|
||||
user.setCreateTime(new Date());
|
||||
//sha256加密
|
||||
String salt = RandomStringUtils.randomAlphanumeric(20);
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
|
||||
user.setSalt(salt);
|
||||
this.save(user);
|
||||
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
@SuppressWarnings("AlibabaTransactionMustHaveRollback")
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveUser(SysUserEntity user) {
|
||||
user.setCreateTime(new Date());
|
||||
//sha256加密
|
||||
String salt = RandomStringUtils.randomAlphanumeric(20);
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
|
||||
user.setSalt(salt);
|
||||
this.save(user);
|
||||
if (user.getIsChannel() != null && user.getIsChannel().equals(1) && StringUtils.isBlank(user.getQdCode())) {
|
||||
user.setQdCode(InvitationCodeUtil.toRegisteredCode(user.getUserId()));
|
||||
this.save(user);
|
||||
}
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
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());
|
||||
}
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBatch(Long[] userId) {
|
||||
this.removeByIds(Arrays.asList(userId));
|
||||
}
|
||||
@Override
|
||||
@Transactional
|
||||
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) {
|
||||
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){
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
|
||||
//保存用户与角色关系
|
||||
sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBatch(Long[] userId) {
|
||||
this.removeByIds(Arrays.asList(userId));
|
||||
}
|
||||
|
||||
@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){
|
||||
return;
|
||||
}
|
||||
@@ -137,11 +140,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
|
||||
if(!roleIdList.containsAll(user.getRoleIdList())){
|
||||
throw new SqxException("新增用户所选角色,不是本人创建");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserEntity selectSysUserByQdCode(String qdCode){
|
||||
return baseMapper.selectOne(new QueryWrapper<SysUserEntity>().isNull("sys_user_id").eq("qd_code", qdCode));
|
||||
}
|
||||
@Override
|
||||
public SysUserEntity selectSysUserByQdCode(String 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
|
||||
* @date 2020/7/8
|
||||
*/
|
||||
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生成六位随机码
|
||||
*
|
||||
* @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
|
||||
* @return 随机码
|
||||
*/
|
||||
public static String toSerialCode(long id) {
|
||||
char[] buf=new char[32];
|
||||
int charPos=32;
|
||||
char[] buf = new char[32];
|
||||
int charPos = 32;
|
||||
|
||||
while((id / binLen) > 0) {
|
||||
int ind=(int)(id % binLen);
|
||||
buf[--charPos]=r[ind];
|
||||
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));
|
||||
buf[--charPos] = r[(int) (id % binLen)];
|
||||
String str = new String(buf, charPos, (32 - charPos));
|
||||
// 不够长度的自动补全
|
||||
if(str.length() < s) {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append(e.subSequence(0, s-str.length()));
|
||||
str+=sb.toString();
|
||||
if (str.length() < s) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(e.subSequence(0, s - str.length()));
|
||||
str += sb.toString();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据随机码生成ID
|
||||
*
|
||||
* @param code 随机码
|
||||
* @return ID
|
||||
*/
|
||||
public static long codeToId(String code) {
|
||||
char[] chs;
|
||||
chs = code.toCharArray();
|
||||
long res=0L;
|
||||
for(int i=0; i < chs.length; i++) {
|
||||
int ind=0;
|
||||
for(int j=0; j < binLen; j++) {
|
||||
if(chs[i] == r[j]) {
|
||||
ind=j;
|
||||
long res = 0L;
|
||||
for (int i = 0; i < chs.length; i++) {
|
||||
int ind = 0;
|
||||
for (int j = 0; j < binLen; j++) {
|
||||
if (chs[i] == r[j]) {
|
||||
ind = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(chs[i] == b) {
|
||||
if (chs[i] == b) {
|
||||
break;
|
||||
}
|
||||
if(i > 0) {
|
||||
res=res * binLen + ind;
|
||||
if (i > 0) {
|
||||
res = res * binLen + ind;
|
||||
} else {
|
||||
res=ind;
|
||||
res = ind;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -319,4 +319,12 @@
|
||||
and create_time > #{time}
|
||||
</if>
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user