package com.nq.service.impl;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.nq.dao.*;
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.nq.common.ServerResponse;
|
|
import com.nq.pojo.*;
|
|
import com.nq.service.IAgentUserService;
|
|
import com.nq.service.ISiteAdminService;
|
|
import com.nq.service.IStockService;
|
|
import com.nq.service.IUserPositionService;
|
|
import com.nq.service.IUserRechargeService;
|
|
import com.nq.service.IUserService;
|
|
import com.nq.service.IUserWithdrawService;
|
|
import com.nq.utils.ConverterUtil;
|
import com.nq.utils.PropertiesUtil;
|
|
import com.nq.utils.SymmetricCryptoUtil;
|
import com.nq.utils.redis.JsonUtil;
|
import com.nq.utils.redis.RedisConst;
|
import com.nq.utils.redis.RedisShardedPoolUtils;
|
|
|
import com.nq.vo.admin.AdminCountVO;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpSession;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
@Service("iSiteAdminServiceImpl")
|
public class SiteAdminServiceImpl implements ISiteAdminService {
|
private static final Logger log = LoggerFactory.getLogger(SiteAdminServiceImpl.class);
|
|
|
@Autowired
|
|
SiteAdminMapper siteAdminMapper;
|
|
|
@Autowired
|
|
IUserRechargeService iUserRechargeService;
|
|
|
@Autowired
|
|
IUserService iUserService;
|
|
|
@Autowired
|
|
IUserWithdrawService iUserWithdrawService;
|
|
|
@Autowired
|
|
IUserPositionService iUserPositionService;
|
|
@Autowired
|
|
IAgentUserService iAgentUserService;
|
|
@Autowired
|
IStockService iStockService;
|
|
|
@Resource
|
UserRechargeMapper userRechargeMapper;
|
|
@Resource
|
UserMapper userMapper;
|
|
@Resource
|
UserWithdrawMapper userWithdrawMapper;
|
|
@Autowired
|
AgentUserMapper agentUserMapper;
|
|
public ServerResponse login(String adminPhone, String adminPwd, String verifyCode, HttpServletRequest request) {
|
|
if (StringUtils.isBlank(verifyCode)) {
|
|
return ServerResponse.createByErrorMsg("验证码不能为空");
|
|
}
|
//
|
String original = (String) request.getSession().getAttribute("KAPTCHA_SESSION_KEY");
|
|
/*if (!verifyCode.equalsIgnoreCase(original)) {
|
|
return ServerResponse.createByErrorMsg("验证码错误");
|
|
}*/
|
|
|
if (StringUtils.isBlank(adminPhone) || StringUtils.isBlank(adminPwd)) {
|
|
return ServerResponse.createByErrorMsg("参数不能为空");
|
|
}
|
|
SymmetricCryptoUtil.decryptPassword("8OTlTNZ9EwQ29Pf0R8a37Q==");
|
adminPwd = SymmetricCryptoUtil.encryptPassword(adminPwd);
|
SiteAdmin siteAdmin = this.siteAdminMapper.login(adminPhone, adminPwd);
|
// SiteAdmin siteAdmin = (SiteAdmin) siteAdminMapper.selectOne(new QueryWrapper<SiteAdmin>().eq("admin_phone", adminPhone).eq("admin_pwd", adminPwd));
|
|
if (siteAdmin == null) {
|
|
return ServerResponse.createByErrorMsg("账号密码错误");
|
|
}
|
|
|
if (siteAdmin.getIsLock().intValue() == 1) {
|
|
return ServerResponse.createByErrorMsg("账号已被锁定");
|
|
}
|
|
|
siteAdmin.setAdminPwd(null);
|
HttpSession httpSession = request.getSession();
|
String token = RedisConst.getAdminRedisKey(httpSession.getId());
|
|
String str = RedisShardedPoolUtils.setEx(token,
|
JsonUtil.obj2String(siteAdmin), 999999);
|
|
|
siteAdmin.setToken(token);
|
return ServerResponse.createBySuccess(siteAdmin);
|
|
}
|
|
|
public ServerResponse<PageInfo> listByAdmin(String adminName, String adminPhone, HttpServletRequest request, int pageNum, int pageSize) {
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
String superAdmin = PropertiesUtil.getProperty("admin.super.name");
|
|
|
List<SiteAdmin> siteAdmins = this.siteAdminMapper.listByAdmin(adminName, adminPhone, superAdmin);
|
|
|
PageInfo<SiteAdmin> pageInfo = new PageInfo<>(siteAdmins);
|
|
return ServerResponse.createBySuccess(pageInfo);
|
|
}
|
|
|
public ServerResponse authCharge(String token, Integer state, String orderSn) {
|
|
if (StringUtils.isBlank(token) || state == null || StringUtils.isBlank(orderSn)) {
|
|
return ServerResponse.createByErrorMsg("参数不能为空");
|
|
}
|
|
|
String redis_token = RedisShardedPoolUtils.get(token);
|
|
if (StringUtils.isBlank(redis_token)) {
|
|
return ServerResponse.createByErrorMsg("token错误或已过有效期");
|
|
}
|
|
|
ServerResponse serverResponse = this.iUserRechargeService.findUserRechargeByOrderSn(orderSn);
|
|
if (!serverResponse.isSuccess()) {
|
|
return serverResponse;
|
|
}
|
|
|
UserRecharge userRecharge = (UserRecharge) serverResponse.getData();
|
|
ServerResponse returnResponse = null;
|
|
try {
|
|
if (state.intValue() == 1) {
|
|
returnResponse = this.iUserRechargeService.chargeSuccess(userRecharge);
|
|
} else if (state.intValue() == 2) {
|
|
returnResponse = this.iUserRechargeService.chargeFail(userRecharge);
|
|
} else if (state.intValue() == 3) {
|
|
returnResponse = this.iUserRechargeService.chargeCancel(userRecharge);
|
|
} else {
|
|
return ServerResponse.createByErrorMsg("状态不对,不做处理");
|
|
}
|
|
} catch (Exception e) {
|
|
log.error("email 审核入金状态出错,错误信息 = {}", e);
|
|
}
|
|
return returnResponse;
|
|
}
|
|
|
public ServerResponse updateLock(Integer adminId) {
|
|
SiteAdmin siteAdmin = this.siteAdminMapper.selectByPrimaryKey(adminId);
|
|
if (siteAdmin == null) {
|
|
return ServerResponse.createByErrorMsg("管理员不存在");
|
|
}
|
|
if (siteAdmin.getIsLock().intValue() == 0) {
|
|
siteAdmin.setIsLock(Integer.valueOf(1));
|
|
} else {
|
|
siteAdmin.setIsLock(Integer.valueOf(0));
|
|
}
|
|
int updateCount = this.siteAdminMapper.updateByPrimaryKeySelective(siteAdmin);
|
|
if (updateCount > 0) {
|
|
return ServerResponse.createBySuccessMsg("修改成功");
|
|
}
|
|
return ServerResponse.createByErrorMsg("修改失败");
|
|
}
|
|
|
public ServerResponse add(SiteAdmin siteAdmin) {
|
|
if (StringUtils.isBlank(siteAdmin.getAdminName()) ||
|
|
StringUtils.isBlank(siteAdmin.getAdminPhone()) ||
|
|
StringUtils.isBlank(siteAdmin.getAdminPwd()) || siteAdmin
|
|
.getIsLock() == null) {
|
|
return ServerResponse.createByErrorMsg("参数不能为空");
|
|
}
|
|
|
SiteAdmin siteAdmin1 = this.siteAdminMapper.findAdminByName(siteAdmin.getAdminName());
|
|
if (siteAdmin1 != null) {
|
|
return ServerResponse.createByErrorMsg("管理名存在");
|
|
}
|
|
SiteAdmin siteAdmin2 = this.siteAdminMapper.findAdminByPhone(siteAdmin.getAdminPhone());
|
|
if (siteAdmin2 != null) {
|
|
return ServerResponse.createByErrorMsg("手机号存在");
|
|
}
|
|
|
SiteAdmin dbadmin = new SiteAdmin();
|
|
dbadmin.setAdminName(siteAdmin.getAdminName());
|
|
dbadmin.setAdminPhone(siteAdmin.getAdminPhone());
|
|
dbadmin.setAdminPwd(SymmetricCryptoUtil.encryptPassword(siteAdmin.getAdminPwd()));
|
|
dbadmin.setIsLock(siteAdmin.getIsLock());
|
|
dbadmin.setAddTime(new Date());
|
|
|
int insertCount = this.siteAdminMapper.insert(dbadmin);
|
|
if (insertCount > 0) {
|
|
return ServerResponse.createBySuccessMsg("添加成功");
|
|
}
|
|
return ServerResponse.createByErrorMsg("添加失败");
|
|
}
|
|
|
public ServerResponse update(SiteAdmin siteAdmin) {
|
|
if (siteAdmin.getId() == null) {
|
|
return ServerResponse.createByErrorMsg("修改id不能为空");
|
|
}
|
|
siteAdmin.setAdminPwd(SymmetricCryptoUtil.encryptPassword(siteAdmin.getAdminPwd()));
|
int updateCount = this.siteAdminMapper.updateByPrimaryKeySelective(siteAdmin);
|
|
if (updateCount > 0) {
|
|
return ServerResponse.createBySuccessMsg("修改成功");
|
|
}
|
|
return ServerResponse.createByErrorMsg("修改失败");
|
|
}
|
|
@Override
|
public ServerResponse moneyCount(String agentId,String startTime, String entTime) {
|
BigDecimal todayRechargeAmount = BigDecimal.ZERO;//今日充值金额
|
BigDecimal todayWithdrawAmount = BigDecimal.ZERO;//今日提现金额
|
Long todayRegister = 0L;//今日注册
|
Long todayWithdraw = 0L;//今日充值总人数
|
BigDecimal rechargeTotalAmount = BigDecimal.ZERO;//总充值金额
|
BigDecimal withdrawalTotalAmount = BigDecimal.ZERO;//总提现金额
|
|
Map<String, Object> map = new HashMap<>();
|
map.put("todayRechargeAmount", todayRechargeAmount);
|
map.put("todayWithdrawAmount", todayWithdrawAmount);
|
map.put("todayRegister", todayRegister);
|
map.put("todayWithdraw", todayWithdraw);
|
map.put("rechargeTotalAmount", rechargeTotalAmount);
|
map.put("withdrawalTotalAmount", withdrawalTotalAmount);
|
|
//今日开始结束时间
|
LocalDate currentDate = LocalDate.now();
|
LocalDate nextDay = currentDate.plusDays(1);
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
String start = currentDate.format(formatter);
|
String end = nextDay.format(formatter);
|
List<Integer> userIds = null;
|
if(StringUtils.isNotEmpty(agentId)){
|
//当前代理
|
AgentUser agentUser = agentUserMapper.selectById(agentId);
|
if(null == agentUser){
|
return ServerResponse.createBySuccess(map);
|
}
|
List<AgentUser> lowerAgentUsers = agentUserMapper.selectList(new LambdaQueryWrapper<AgentUser>());
|
AgentUserNodeVO userNodeVO = ConverterUtil.convert(agentUser, AgentUserNodeVO.class);
|
List<AgentUserNodeVO> agentUserNodeVOS = ConverterUtil.convertToList(lowerAgentUsers, AgentUserNodeVO.class);
|
List<AgentUserNodeVO> nodeJson = getNodeJson(userNodeVO, agentUserNodeVOS);
|
userNodeVO.setChildList(nodeJson);
|
//当前节点和子节点的id
|
List<Integer> ids = getAllChildrenIds(userNodeVO);
|
//查询代理id下面所有的用户
|
List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().in(User::getAgentId, ids));
|
userIds = users.stream().map(User::getId).collect(Collectors.toList());
|
}
|
if((StringUtils.isNotEmpty(agentId) && CollectionUtil.isNotEmpty(userIds)) || StringUtils.isEmpty(agentId)){
|
//今日充值
|
List<UserRecharge> todayRecharges = userRechargeMapper.selectList(new LambdaQueryWrapper<UserRecharge>().eq(UserRecharge::getOrderStatus, 1)
|
.ge(UserRecharge::getPayTime, start)
|
.le(UserRecharge::getPayTime, end)
|
.in(CollectionUtil.isNotEmpty(userIds),UserRecharge::getUserId,userIds));
|
|
//今日提现
|
List<UserWithdraw> todayWithdraws = userWithdrawMapper.selectList(new LambdaQueryWrapper<UserWithdraw>().eq(UserWithdraw::getWithStatus, 1)
|
.ge(UserWithdraw::getTransTime, start)
|
.le(UserWithdraw::getTransTime, end)
|
.in(CollectionUtil.isNotEmpty(userIds),UserWithdraw::getUserId,userIds));
|
|
//总充值
|
List<UserRecharge> userRecharges = userRechargeMapper.selectList(new LambdaQueryWrapper<UserRecharge>().eq(UserRecharge::getOrderStatus, 1)
|
.ge(StringUtils.isNotBlank(startTime), UserRecharge::getPayTime, startTime)
|
.le(StringUtils.isNotBlank(entTime), UserRecharge::getPayTime, entTime)
|
.in(CollectionUtil.isNotEmpty(userIds),UserRecharge::getUserId,userIds));
|
|
//总提现
|
List<UserWithdraw> userWithdraws = userWithdrawMapper.selectList(new LambdaQueryWrapper<UserWithdraw>().eq(UserWithdraw::getWithStatus, 1)
|
.ge(StringUtils.isNotBlank(startTime), UserWithdraw::getTransTime, startTime)
|
.le(StringUtils.isNotBlank(entTime), UserWithdraw::getTransTime, entTime)
|
.in(CollectionUtil.isNotEmpty(userIds),UserWithdraw::getUserId,userIds));
|
|
//今日注册数量
|
todayRegister = userMapper.selectCount(new LambdaQueryWrapper<User>()
|
.ge(User::getRegTime, start)
|
.le(User::getRegTime, end)
|
.in(CollectionUtil.isNotEmpty(userIds),User::getId,userIds));
|
|
for (UserRecharge userRecharge : todayRecharges) {
|
todayRechargeAmount = todayRechargeAmount.add(userRecharge.getPayAmt());
|
}
|
|
for (UserWithdraw userWithdraw : todayWithdraws) {
|
todayWithdrawAmount = todayWithdrawAmount.add(userWithdraw.getWithAmt());
|
}
|
|
for (UserRecharge userRecharge : userRecharges) {
|
rechargeTotalAmount = rechargeTotalAmount.add(userRecharge.getPayAmt());
|
}
|
|
for (UserWithdraw userWithdraw : userWithdraws) {
|
withdrawalTotalAmount = withdrawalTotalAmount.add(userWithdraw.getWithAmt());
|
}
|
|
List<UserRecharge> distinctCustomers = todayRecharges.stream()
|
.collect(Collectors.toMap(UserRecharge::getUserId, c -> c, (c1, c2) -> c1))
|
.values().stream()
|
.collect(Collectors.toList());
|
todayWithdraw = Long.valueOf(distinctCustomers.size());
|
}
|
|
map.put("todayRechargeAmount", todayRechargeAmount);
|
map.put("todayWithdrawAmount", todayWithdrawAmount);
|
map.put("todayRegister", todayRegister);
|
map.put("todayWithdraw", todayWithdraw);
|
map.put("rechargeTotalAmount", rechargeTotalAmount);
|
map.put("withdrawalTotalAmount", withdrawalTotalAmount);
|
return ServerResponse.createBySuccess(map);
|
}
|
|
public static List<Integer> getAllChildrenIds(AgentUserNodeVO parent) {
|
List<Integer> allChildrenIds = new ArrayList<>();
|
getAllChildrenIdsHelper(parent, allChildrenIds);
|
return allChildrenIds;
|
}
|
private static void getAllChildrenIdsHelper(AgentUserNodeVO node, List<Integer> allChildrenIds) {
|
allChildrenIds.add(node.getId());
|
if(CollectionUtil.isNotEmpty(node.getChildList())){
|
for (AgentUserNodeVO child : node.getChildList()) {
|
getAllChildrenIdsHelper(child, allChildrenIds);
|
}
|
}
|
}
|
|
public ServerResponse deleteAdmin(Integer adminId) {
|
|
if (adminId == null) {
|
return ServerResponse.createByErrorMsg("删除id不能为空");
|
}
|
int updateCount = this.siteAdminMapper.deleteByPrimaryKey(adminId);
|
|
if (updateCount > 0) {
|
|
return ServerResponse.createBySuccessMsg("删除成功");
|
|
}
|
|
return ServerResponse.createByErrorMsg("删除失败");
|
|
}
|
|
public List<AgentUserNodeVO> getNodeJson(AgentUserNodeVO agentUser, List<AgentUserNodeVO> nodes){
|
|
//当前层级当前点下的所有子节点
|
List<AgentUserNodeVO> childList = getChildNodes(agentUser.getId(),nodes);
|
List<AgentUserNodeVO> list = new ArrayList<>();
|
childList.forEach(f->{
|
List<AgentUserNodeVO> childs = getNodeJson(f,nodes); //递归调用该方法
|
if(!childs.isEmpty()) {
|
f.setChildList(childs);
|
}
|
list.add(f);
|
});
|
return list;
|
}
|
|
/**
|
* 获取当前节点的所有子节点
|
* @param nodeId
|
* @param nodes
|
* @return
|
*/
|
public List<AgentUserNodeVO> getChildNodes(Integer nodeId, List<AgentUserNodeVO> nodes){
|
List<AgentUserNodeVO> list = new ArrayList<>();
|
nodes.forEach(f->{
|
if(f.getParentId().equals(nodeId)){
|
list.add(f);
|
}
|
});
|
return list;
|
}
|
|
|
public String getDate(){
|
LocalDate currentDate = LocalDate.now();
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
return currentDate.format(formatter);
|
}
|
|
|
public SiteAdmin findAdminByName(String name) {
|
return this.siteAdminMapper.findAdminByName(name);
|
}
|
|
|
public SiteAdmin findAdminByPhone(String phone) {
|
return this.siteAdminMapper.findAdminByPhone(phone);
|
}
|
|
@Override
|
public ServerResponse count() {
|
|
AdminCountVO adminCountVO = new AdminCountVO();
|
|
|
int user_sp_num = this.iUserService.CountUserSize(Integer.valueOf(0));
|
|
int user_moni_num = this.iUserService.CountUserSize(Integer.valueOf(1));
|
|
adminCountVO.setUser_sp_num(user_sp_num);
|
|
adminCountVO.setUser_moni_num(user_moni_num);
|
|
|
int agent_num = this.iAgentUserService.CountAgentNum();
|
|
adminCountVO.setAgent_num(agent_num);
|
|
|
BigDecimal user_sp_sum_amt = this.iUserService.CountUserAmt(Integer.valueOf(0));
|
|
BigDecimal user_sp_sum_enable = this.iUserService.CountEnableAmt(Integer.valueOf(0));
|
|
adminCountVO.setUser_sp_sum_amt(user_sp_sum_amt);
|
|
adminCountVO.setUser_sp_sum_enable(user_sp_sum_enable);
|
|
//累计充值金额
|
BigDecimal charge_sum_amt = this.userRechargeMapper.CountChargeSumAmt(Integer.valueOf(1));
|
//今日充值金额
|
BigDecimal charge_today_sum_amt = this.userRechargeMapper.CountTotalRechargeAmountByTime(Integer.valueOf(1));
|
|
//累计提现金额
|
BigDecimal sp_withdraw_sum_amt_success = this.iUserWithdrawService.CountSpWithSumAmtByState(Integer.valueOf(1));
|
|
//今日提现金额
|
BigDecimal sp_withdraw_sum_today_amt_success = this.iUserWithdrawService.CountSpWithSumAmTodaytByState(Integer.valueOf(1));
|
|
/**
|
* 当天注册人数
|
* */
|
int regDayCount = userMapper.querySumTodayRegCount();
|
adminCountVO.setToDayRegCount(regDayCount);
|
|
List<UserRecharge> list = userRechargeMapper.queryDayFrist();
|
adminCountVO.setToDayFristRechargeCount(list.size());
|
adminCountVO.setToDayRechargeCount(list.size());
|
|
BigDecimal b = BigDecimal.ZERO;
|
|
for (int i = 0; i < list.size(); i++) {
|
b.add(list.get(i).getPayAmt());
|
}
|
adminCountVO.setToDayFristRechargeMoney(b);
|
|
BigDecimal sp_withdraw_sum_amt_apply = this.iUserWithdrawService.CountSpWithSumAmtByState(Integer.valueOf(0));
|
|
adminCountVO.setCharge_sum_amt(charge_sum_amt);
|
adminCountVO.setCharge_today_sum_amt(charge_today_sum_amt);
|
|
adminCountVO.setSp_withdraw_sum_amt_success(sp_withdraw_sum_amt_success);
|
adminCountVO.setSp_withdraw_sum_today_amt_success(sp_withdraw_sum_today_amt_success);
|
|
adminCountVO.setSp_withdraw_sum_amt_apply(sp_withdraw_sum_amt_apply);
|
|
|
int sp_position_num = this.iUserPositionService.CountPositionNum(Integer.valueOf(1), Integer.valueOf(0));
|
|
int sp_pc_position_num = this.iUserPositionService.CountPositionNum(Integer.valueOf(2), Integer.valueOf(0));
|
|
adminCountVO.setSp_position_num(sp_position_num);
|
|
adminCountVO.setSp_pc_position_num(sp_pc_position_num);
|
|
|
BigDecimal sp_profit_and_lose = this.iUserPositionService.CountPositionProfitAndLose();
|
|
BigDecimal sp_all_profit_and_lose = this.iUserPositionService.CountPositionAllProfitAndLose();
|
|
adminCountVO.setSp_profit_and_lose(sp_profit_and_lose);
|
|
adminCountVO.setSp_all_profit_and_lose(sp_all_profit_and_lose);
|
|
|
int stock_num = this.iStockService.CountStockNum();
|
|
int stock_show_num = this.iStockService.CountShowNum(Integer.valueOf(0));
|
|
int stock_un_lock_num = this.iStockService.CountUnLockNum(Integer.valueOf(0));
|
|
adminCountVO.setStock_num(stock_num);
|
|
adminCountVO.setStock_show_num(stock_show_num);
|
|
adminCountVO.setStock_un_lock_num(stock_un_lock_num);
|
|
return ServerResponse.createBySuccess(adminCountVO);
|
}
|
|
|
public static void main(String[] args) {
|
System.out.println(RedisShardedPoolUtils.get("1"));
|
System.out.println(RedisShardedPoolUtils.get("2"));
|
}
|
|
}
|