|
@@ -3,7 +3,6 @@ package com.qs.mp.channel.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
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.qs.mp.channel.domain.Channel;
|
|
import com.qs.mp.channel.domain.Channel;
|
|
-import com.qs.mp.channel.domain.ChannelAddr;
|
|
|
|
import com.qs.mp.channel.domain.ChannelCommission;
|
|
import com.qs.mp.channel.domain.ChannelCommission;
|
|
import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
|
|
import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
|
|
import com.qs.mp.channel.domain.vo.ChannelVO;
|
|
import com.qs.mp.channel.domain.vo.ChannelVO;
|
|
@@ -11,17 +10,18 @@ import com.qs.mp.channel.mapper.ChannelMapper;
|
|
import com.qs.mp.channel.service.IChannelCommissionService;
|
|
import com.qs.mp.channel.service.IChannelCommissionService;
|
|
import com.qs.mp.channel.service.IChannelService;
|
|
import com.qs.mp.channel.service.IChannelService;
|
|
import com.qs.mp.channel.service.IChannelUserRelService;
|
|
import com.qs.mp.channel.service.IChannelUserRelService;
|
|
-import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
|
-import com.qs.mp.common.enums.ErrorCodeEnum;
|
|
|
|
|
|
+import com.qs.mp.common.constant.UserConstants;
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
import com.qs.mp.system.domain.SysUser;
|
|
import com.qs.mp.system.domain.SysUser;
|
|
import com.qs.mp.system.service.ISysUserService;
|
|
import com.qs.mp.system.service.ISysUserService;
|
|
-import com.qs.mp.system.service.id.BizIdGenerator;
|
|
|
|
import com.qs.mp.utils.SecurityUtils;
|
|
import com.qs.mp.utils.SecurityUtils;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -50,17 +50,22 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
|
|
@Autowired
|
|
@Autowired
|
|
private ISysUserService userService;
|
|
private ISysUserService userService;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private BizIdGenerator bizIdGenerator;
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public void saveChannel(Channel channel) throws Exception {
|
|
|
|
|
|
+ public void saveChannel(Channel channel, String channelType) throws Exception {
|
|
|
|
+
|
|
|
|
+ String title = channelType.equals("channel")?"渠道":"经销商";
|
|
// 1、校验名称是否重复、手机号是否存在(渠道表)
|
|
// 1、校验名称是否重复、手机号是否存在(渠道表)
|
|
- int nameCount = channelService.count(
|
|
|
|
- new LambdaQueryWrapper<Channel>().eq(Channel::getName, channel.getName()).gt(Channel::getLevel, 1));
|
|
|
|
|
|
+ LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(Channel::getName, channel.getName());
|
|
|
|
+ if(channelType.equals("channel")) {
|
|
|
|
+ queryWrapper.gt(Channel::getLevel, 1);
|
|
|
|
+ }else {
|
|
|
|
+ queryWrapper.eq(Channel::getLevel, 0);
|
|
|
|
+ }
|
|
|
|
+ int nameCount = channelService.count(queryWrapper);
|
|
if(nameCount > 0) {
|
|
if(nameCount > 0) {
|
|
- throw new ServiceException("渠道名称" + channel.getName() + "已存在!");
|
|
|
|
|
|
+ throw new ServiceException(title +"名称" + channel.getName() + "已存在!");
|
|
}
|
|
}
|
|
int mobileCount = channelService.count(
|
|
int mobileCount = channelService.count(
|
|
new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, channel.getMobile()));
|
|
new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, channel.getMobile()));
|
|
@@ -71,10 +76,14 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
|
|
Channel parentChannel = channelService.getById(channel.getParentId());
|
|
Channel parentChannel = channelService.getById(channel.getParentId());
|
|
if(null != parentChannel && null != parentChannel.getCommRate()) {
|
|
if(null != parentChannel && null != parentChannel.getCommRate()) {
|
|
if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
- throw new ServiceException("渠道佣金比例不能高于父渠道的佣金比例");
|
|
|
|
|
|
+ throw new ServiceException("佣金比例不能高于父渠道的佣金比例");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- channel.setLevel(parentChannel.getLevel()+1);
|
|
|
|
|
|
+ if(channelType.equals("channel")) {
|
|
|
|
+ channel.setLevel(parentChannel.getLevel()+1);
|
|
|
|
+ }else {
|
|
|
|
+ channel.setLevel(0);
|
|
|
|
+ }
|
|
// 3.插入数据
|
|
// 3.插入数据
|
|
boolean res = channelService.save(channel);
|
|
boolean res = channelService.save(channel);
|
|
if(res && null != channel.getChannelId()) {
|
|
if(res && null != channel.getChannelId()) {
|
|
@@ -88,7 +97,7 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
|
|
sysUser.setCreateBy(SecurityUtils.getUsername());
|
|
sysUser.setCreateBy(SecurityUtils.getUsername());
|
|
int userNum = userService.insertUser(sysUser);
|
|
int userNum = userService.insertUser(sysUser);
|
|
if (userNum == 0 || null == sysUser.getUserId()) {
|
|
if (userNum == 0 || null == sysUser.getUserId()) {
|
|
- throw new ServiceException("新增渠道'" + channel.getName() + "'失败,请联系管理员");
|
|
|
|
|
|
+ throw new ServiceException("新增'" + title + channel.getName() + "'失败,请联系管理员");
|
|
}
|
|
}
|
|
channel.setUserId(sysUser.getUserId());
|
|
channel.setUserId(sysUser.getUserId());
|
|
channelService.updateById(channel);
|
|
channelService.updateById(channel);
|
|
@@ -96,103 +105,124 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public void saveSite(Channel channel) throws Exception {
|
|
|
|
- // 1、校验名称是否重复、手机号是否存在(渠道表)
|
|
|
|
- int nameCount = channelService.count(
|
|
|
|
- new LambdaQueryWrapper<Channel>().eq(Channel::getName, channel.getName()).eq(Channel::getLevel, 0));
|
|
|
|
- if(nameCount > 0) {
|
|
|
|
- throw new ServiceException("经销商名称" + channel.getName() + "已存在!");
|
|
|
|
|
|
+ public void updateChannel(Channel channel, String channelType) throws Exception {
|
|
|
|
+ String title = channelType.equals("channel")?"渠道":"经销商";
|
|
|
|
+ // 1、校验修改子渠道是否为当前用户的子渠道
|
|
|
|
+ Channel oldChannel = channelService.getById(channel.getChannelId());
|
|
|
|
+ if(null == oldChannel || null == oldChannel.getChannelId()) {
|
|
|
|
+ throw new ServiceException(title + "'" + oldChannel.getName() + "'编辑失败,渠道ID异常");
|
|
}
|
|
}
|
|
- int mobileCount = channelService.count(
|
|
|
|
- new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, channel.getMobile()));
|
|
|
|
- if(mobileCount > 0) {
|
|
|
|
- throw new ServiceException("手机号码" + channel.getMobile() + "已注册!");
|
|
|
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
|
+ if(!oldChannel.getParentId().equals(channelId)) {
|
|
|
|
+ throw new ServiceException(title + "'" + oldChannel.getName() + "'编辑失败,非子渠道");
|
|
}
|
|
}
|
|
- // 2.校验佣金比例,不能高于其父渠道的佣金比例
|
|
|
|
- Channel parentChannel = channelService.getById(channel.getParentId());
|
|
|
|
|
|
+ // 2.校验名称是否重复、手机号是否存在(渠道表);
|
|
|
|
+ if(!channel.getName().equals(oldChannel.getName())) {
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(Channel::getName, channel.getName());
|
|
|
|
+ if(channelType.equals("channel")) {
|
|
|
|
+ queryWrapper.gt(Channel::getLevel, 1);
|
|
|
|
+ }else {
|
|
|
|
+ queryWrapper.eq(Channel::getLevel, 0);
|
|
|
|
+ }
|
|
|
|
+ int nameCount = channelService.count(queryWrapper);
|
|
|
|
+ if(nameCount > 0) {
|
|
|
|
+ throw new ServiceException(title + "名称" + channel.getName() + "已存在!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ boolean mobileChange = false; // 手机号码是否有变更
|
|
|
|
+ if(!channel.getMobile().equals(oldChannel.getMobile())) {
|
|
|
|
+ int mobileCount = channelService.count(
|
|
|
|
+ new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, channel.getMobile()));
|
|
|
|
+ if(mobileCount > 0) {
|
|
|
|
+ throw new ServiceException("手机号码" + channel.getMobile() + "已注册!");
|
|
|
|
+ }
|
|
|
|
+ if(UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(channel.getMobile()))) {
|
|
|
|
+ throw new ServiceException("手机号码" + channel.getMobile() + "已注册!");
|
|
|
|
+ }
|
|
|
|
+ mobileChange = true;
|
|
|
|
+ }
|
|
|
|
+ // 3.校验佣金比例,不能高于其父渠道的佣金比例,不能低于其子渠道的最大佣金比例
|
|
|
|
+ Channel parentChannel = channelService.getById(oldChannel.getParentId());
|
|
if(null != parentChannel && null != parentChannel.getCommRate()) {
|
|
if(null != parentChannel && null != parentChannel.getCommRate()) {
|
|
if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
- throw new ServiceException("经销商佣金比例不能高于父渠道的佣金比例");
|
|
|
|
|
|
+ throw new ServiceException("佣金比例不能高于父渠道的佣金比例");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- channel.setLevel(0);
|
|
|
|
- // 3.插入数据
|
|
|
|
- boolean res = channelService.save(channel);
|
|
|
|
- if(res && null != channel.getChannelId()) {
|
|
|
|
- channel.setChannelNo(parentChannel.getChannelNo()+"."+channel.getChannelId());
|
|
|
|
- // 生成用户
|
|
|
|
- SysUser sysUser = new SysUser();
|
|
|
|
- sysUser.setUserName(channel.getMobile());
|
|
|
|
- sysUser.setPhonenumber(channel.getMobile());
|
|
|
|
- sysUser.setNickName(channel.getName());
|
|
|
|
- sysUser.setDeptId(SecurityUtils.getDeptId());
|
|
|
|
- sysUser.setCreateBy(SecurityUtils.getUsername());
|
|
|
|
- int userNum = userService.insertUser(sysUser);
|
|
|
|
- if (userNum == 0 || null == sysUser.getUserId()) {
|
|
|
|
- throw new ServiceException("新增经销商'" + channel.getName() + "'失败,请联系管理员");
|
|
|
|
- }
|
|
|
|
- channel.setUserId(sysUser.getUserId());
|
|
|
|
- channelService.updateById(channel);
|
|
|
|
- // 4.发送账号创建成功短信
|
|
|
|
|
|
+ if(channelType.equals("channel")) {
|
|
|
|
+ // 查询子渠道的最大佣金比例
|
|
|
|
+ QueryWrapper<Channel> queryWrapper = new QueryWrapper<Channel>();
|
|
|
|
+ queryWrapper.select("IFNULL(max(comm_rate),0) as commRate");
|
|
|
|
+ queryWrapper.lambda().eq(Channel::getParentId, channel.getChannelId());
|
|
|
|
+ Map<String, Object> map = channelService.getMap(queryWrapper);
|
|
|
|
+ if(null != map && map.containsKey("commRate")) {
|
|
|
|
+ BigDecimal commRate = new BigDecimal(map.get("commRate").toString());
|
|
|
|
+ if(!commRate.equals(BigDecimal.ZERO) && channel.getCommRate().compareTo(commRate) < 0) {
|
|
|
|
+ throw new ServiceException("不能低于其子渠道的最大佣金比例");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void updateChannel(Channel channel) throws Exception {
|
|
|
|
- // 1、校验修改子渠道是否为当前用户的子渠道
|
|
|
|
- Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
|
-
|
|
|
|
- // 2.校验名称是否重复、手机号是否存在(渠道表);
|
|
|
|
-
|
|
|
|
- // 3.校验佣金比例,不能高于其父渠道的佣金比例,不能低于其子渠道的最大佣金比例
|
|
|
|
-
|
|
|
|
// 4.更新入库
|
|
// 4.更新入库
|
|
|
|
+ boolean editRes = channelService.updateById(channel);
|
|
|
|
+ if(editRes && mobileChange
|
|
|
|
+ && null != oldChannel.getUserId()) {
|
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
|
+ sysUser.setUserId(oldChannel.getUserId());
|
|
|
|
+ sysUser.setUserName(channel.getMobile());
|
|
|
|
+ sysUser.setPhonenumber(channel.getMobile());
|
|
|
|
+ sysUser.setNickName(channel.getName());
|
|
|
|
+ sysUser.setDeptId(SecurityUtils.getDeptId());
|
|
|
|
+ int userNum = userService.updateUser(sysUser);
|
|
|
|
+ if (userNum == 0 || null == sysUser.getUserId()) {
|
|
|
|
+ throw new ServiceException(title + "'" + oldChannel.getName() + "'编辑失败,请联系管理员");
|
|
|
|
+ }
|
|
|
|
+ // 发送账号更新成功短信
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public void updateSite(Channel channel) throws Exception {
|
|
|
|
- // 1、校验修改子渠道是否为当前用户的子渠道
|
|
|
|
- Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
|
-
|
|
|
|
- // 2.校验名称是否重复、手机号是否存在(渠道表);
|
|
|
|
-
|
|
|
|
- // 3.校验佣金比例,不能高于其父渠道的佣金比例,不能低于其子渠道的最大佣金比例
|
|
|
|
-
|
|
|
|
- // 4.更新入库
|
|
|
|
- }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List<ChannelVO> selectChannelVoList(Channel channel) {
|
|
|
|
|
|
+ public List<ChannelVO> selectChannelVoList(Channel channel, String channelType) {
|
|
QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("t1.parent_id", channel.getParentId());
|
|
queryWrapper.eq("t1.parent_id", channel.getParentId());
|
|
- queryWrapper.gt("t1.level", 0);
|
|
|
|
- return getBaseMapper().selectChannelVoList(queryWrapper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<ChannelVO> selectSiteVoList(Channel channel) {
|
|
|
|
- QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.eq("t1.parent_id", channel.getParentId());
|
|
|
|
- queryWrapper.eq("t1.level", 0);
|
|
|
|
- if(null != channel.getVerifyStatus()) {
|
|
|
|
- queryWrapper.eq("t1.verify_status", channel.getVerifyStatus());
|
|
|
|
|
|
+
|
|
|
|
+ if(channelType.equals("channel")) {
|
|
|
|
+ queryWrapper.gt("t1.level", 0);
|
|
|
|
+ queryWrapper.orderByAsc("t1.channel_id");
|
|
|
|
+ }else {
|
|
|
|
+ queryWrapper.eq("t1.level", 0);
|
|
|
|
+ if(null != channel.getVerifyStatus()) {
|
|
|
|
+ queryWrapper.eq("t1.verify_status", channel.getVerifyStatus());
|
|
|
|
+ }
|
|
|
|
+ if(null != channel.getCertifyStatus()) {
|
|
|
|
+ queryWrapper.eq("t1.certify_status", channel.getCertifyStatus());
|
|
|
|
+ }
|
|
|
|
+ queryWrapper.orderByDesc("t1.certify_status").orderByAsc("t1.channel_id");
|
|
}
|
|
}
|
|
- if(null != channel.getCertifyStatus()) {
|
|
|
|
- queryWrapper.eq("t1.certify_status", channel.getCertifyStatus());
|
|
|
|
|
|
+ List<ChannelVO> list = getBaseMapper().selectChannelVoList(queryWrapper);
|
|
|
|
+ if(channelType.equals("channel")
|
|
|
|
+ && null != list && list.size() > 0) {
|
|
|
|
+ for(ChannelVO channelVO : list) {
|
|
|
|
+ if(null != channelVO && StringUtils.isNotBlank(channelVO.getChannelNo())) {
|
|
|
|
+ int siteCnt = getBaseMapper().getChannelSiteCnt(channelVO.getChannelNo());
|
|
|
|
+ int userCnt = channelUserRelService.getChannelUserCnt(channelVO.getChannelNo());
|
|
|
|
+ channelVO.setSiteCnt(siteCnt);
|
|
|
|
+ channelVO.setUserCnt(userCnt);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return getBaseMapper().selectSiteVoList(queryWrapper);
|
|
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Channel getChannelByUserId(Long userId) {
|
|
public Channel getChannelByUserId(Long userId) {
|
|
return getBaseMapper().selectOne(new LambdaQueryWrapper<Channel>().eq(Channel::getUserId, userId));
|
|
return getBaseMapper().selectOne(new LambdaQueryWrapper<Channel>().eq(Channel::getUserId, userId));
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public ChannelOperDataVO getChannelOperData(String channelNo, int days) {
|
|
public ChannelOperDataVO getChannelOperData(String channelNo, int days) {
|
|
ChannelOperDataVO channelOperData = new ChannelOperDataVO();
|
|
ChannelOperDataVO channelOperData = new ChannelOperDataVO();
|