|
@@ -11,6 +11,8 @@ import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
|
|
|
import com.qs.mp.channel.domain.vo.ChannelVO;
|
|
|
import com.qs.mp.channel.service.IChannelCommissionService;
|
|
|
import com.qs.mp.channel.service.IChannelService;
|
|
|
+import com.qs.mp.channel.service.IChannelUserRelService;
|
|
|
+import com.qs.mp.common.constant.UserConstants;
|
|
|
import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
import com.qs.mp.common.core.page.TableDataInfo;
|
|
|
import com.qs.mp.common.enums.ChannelCertifyStatusEnum;
|
|
@@ -18,6 +20,7 @@ import com.qs.mp.common.enums.ChannelVerifyStatusEnum;
|
|
|
import com.qs.mp.common.enums.ErrorCodeEnum;
|
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
|
import com.qs.mp.common.utils.DateUtils;
|
|
|
+import com.qs.mp.system.service.ISysUserService;
|
|
|
import com.qs.mp.utils.SecurityUtils;
|
|
|
import com.qs.mp.web.controller.common.BaseApiController;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -57,6 +60,12 @@ public class ChannelController extends BaseApiController {
|
|
|
|
|
|
@Autowired
|
|
|
private IChannelCommissionService channelCommissionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IChannelUserRelService channelUserRelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
private MapperFacade mapperFacade;
|
|
@@ -73,7 +82,21 @@ public class ChannelController extends BaseApiController {
|
|
|
if(null != channelId) {
|
|
|
channel.setParentId(channelId);
|
|
|
startPage();
|
|
|
- list = channelService.selectChannelVoList(channel,"channel");
|
|
|
+ QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("t1.parent_id", channel.getParentId());
|
|
|
+ queryWrapper.gt("t1.level", 0);
|
|
|
+ queryWrapper.orderByAsc("t1.channel_id");
|
|
|
+ list = channelService.selectChannelVoList(queryWrapper);
|
|
|
+ if(null != list && list.size() > 0) {
|
|
|
+ for(ChannelVO channelVO : list) {
|
|
|
+ if(null != channelVO && StringUtils.isNotBlank(channelVO.getChannelNo())) {
|
|
|
+ int siteCnt = channelService.getChannelSiteCnt(channelVO.getChannelNo());
|
|
|
+ int userCnt = channelUserRelService.getChannelUserCnt(channelVO.getChannelNo());
|
|
|
+ channelVO.setSiteCnt(siteCnt);
|
|
|
+ channelVO.setUserCnt(userCnt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return getDataTable(list);
|
|
|
}
|
|
@@ -119,8 +142,36 @@ public class ChannelController extends BaseApiController {
|
|
|
Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
Channel channel = mapperFacade.map(channelParam, Channel.class);
|
|
|
channel.setParentId(channelId);
|
|
|
- channelService.saveChannel(channel, "channel");
|
|
|
- return AjaxResult.success("子渠道'" + channel.getName() + "'新增成功");
|
|
|
+ // 1、校验名称是否重复、手机号是否存在(渠道表)
|
|
|
+ LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Channel::getName, channel.getName());
|
|
|
+ queryWrapper.gt(Channel::getLevel, 1);
|
|
|
+ int nameCount = channelService.count(queryWrapper);
|
|
|
+ if(nameCount > 0) {
|
|
|
+ return AjaxResult.error("渠道名称" + channel.getName() + "已存在!");
|
|
|
+ }
|
|
|
+ int mobileCount = channelService.count(
|
|
|
+ new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, channel.getMobile()));
|
|
|
+ if(mobileCount > 0) {
|
|
|
+ return AjaxResult.error("手机号码" + channel.getMobile() + "已注册!");
|
|
|
+ }
|
|
|
+ // 2.校验佣金比例,不能高于其父渠道的佣金比例
|
|
|
+ Channel parentChannel = channelService.getById(channel.getParentId());
|
|
|
+ if(null != parentChannel && null != parentChannel.getCommRate()) {
|
|
|
+ if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
|
+ return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ channel.setLevel(parentChannel.getLevel()+1);
|
|
|
+ // 3.插入数据
|
|
|
+ channel.setChannelNo(parentChannel.getChannelNo()+".");
|
|
|
+ try {
|
|
|
+ channelService.saveChannel(channel,"channel");
|
|
|
+ } catch (Exception e) {
|
|
|
+ return AjaxResult.error("渠道'" + channel.getName() + "'新增失败" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success("渠道'" + channel.getName() + "'新增成功");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -136,8 +187,61 @@ public class ChannelController extends BaseApiController {
|
|
|
return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
}
|
|
|
Channel channel = mapperFacade.map(channelParam, Channel.class);
|
|
|
- channelService.updateChannel(channel, "channel");
|
|
|
- return AjaxResult.success("子渠道'" + channel.getName() + "'编辑成功");
|
|
|
+ // 1、校验修改子渠道是否为当前用户的子渠道
|
|
|
+ Channel oldChannel = channelService.getById(channel.getChannelId());
|
|
|
+ if(null == oldChannel || null == oldChannel.getChannelId()) {
|
|
|
+ return AjaxResult.error("渠道'" + oldChannel.getName() + "'编辑失败,渠道ID异常");
|
|
|
+ }
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
+ if(!oldChannel.getParentId().equals(channelId)) {
|
|
|
+ return AjaxResult.error("渠道'" + oldChannel.getName() + "'编辑失败,非当前用户子渠道");
|
|
|
+ }
|
|
|
+ // 2.校验名称是否重复、手机号是否存在(渠道表);
|
|
|
+ if(!channel.getName().equals(oldChannel.getName())) {
|
|
|
+ LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Channel::getName, channel.getName());
|
|
|
+ queryWrapper.gt(Channel::getLevel, 1);
|
|
|
+ int nameCount = channelService.count(queryWrapper);
|
|
|
+ if(nameCount > 0) {
|
|
|
+ return AjaxResult.error("渠道名称" + 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) {
|
|
|
+ return AjaxResult.error("手机号码" + channel.getMobile() + "已注册!");
|
|
|
+ }
|
|
|
+ if(UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(channel.getMobile()))) {
|
|
|
+ return AjaxResult.error("手机号码" + channel.getMobile() + "已注册!");
|
|
|
+ }
|
|
|
+ mobileChange = true;
|
|
|
+ }
|
|
|
+ // 3.校验佣金比例,不能高于其父渠道的佣金比例,不能低于其子渠道的最大佣金比例
|
|
|
+ Channel parentChannel = channelService.getById(oldChannel.getParentId());
|
|
|
+ if(null != parentChannel && null != parentChannel.getCommRate()) {
|
|
|
+ if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
|
+ return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询子渠道的最大佣金比例
|
|
|
+ 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) {
|
|
|
+ return AjaxResult.error("不能低于其子渠道的最大佣金比例");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ channelService.updateChannel(channel, mobileChange);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return AjaxResult.success("渠道'" + channel.getName() + "'编辑成功");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -220,7 +324,16 @@ public class ChannelController extends BaseApiController {
|
|
|
if(null != channelId) {
|
|
|
channel.setParentId(channelId);
|
|
|
startPage();
|
|
|
- list = channelService.selectChannelVoList(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(null != channel.getCertifyStatus()) {
|
|
|
+ queryWrapper.eq("t1.certify_status", channel.getCertifyStatus());
|
|
|
+ }
|
|
|
+ list = channelService.selectChannelVoList(queryWrapper);
|
|
|
}
|
|
|
return getDataTable(list);
|
|
|
}
|
|
@@ -267,10 +380,33 @@ public class ChannelController extends BaseApiController {
|
|
|
|
|
|
Channel channel = mapperFacade.map(channelParam, Channel.class);
|
|
|
channel.setParentId(channelId);
|
|
|
+ // 1、校验名称是否重复、手机号是否存在(渠道表)
|
|
|
+ LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Channel::getName, channel.getName());
|
|
|
+ queryWrapper.eq(Channel::getLevel, 0);
|
|
|
+ int nameCount = channelService.count(queryWrapper);
|
|
|
+ if(nameCount > 0) {
|
|
|
+ return AjaxResult.error("经销商名称" + channel.getName() + "已存在!");
|
|
|
+ }
|
|
|
+ int mobileCount = channelService.count(
|
|
|
+ new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, channel.getMobile()));
|
|
|
+ if(mobileCount > 0) {
|
|
|
+ return AjaxResult.error("手机号码" + channel.getMobile() + "已注册!");
|
|
|
+ }
|
|
|
+ // 2.校验佣金比例,不能高于其父渠道的佣金比例
|
|
|
+ Channel parentChannel = channelService.getById(channel.getParentId());
|
|
|
+ if(null != parentChannel && null != parentChannel.getCommRate()) {
|
|
|
+ if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
|
+ return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ channel.setLevel(0);
|
|
|
+ // 3.插入数据
|
|
|
+ channel.setChannelNo(parentChannel.getChannelNo()+".");
|
|
|
try {
|
|
|
channelService.saveChannel(channel,"site");
|
|
|
} catch (Exception e) {
|
|
|
- return AjaxResult.error("经销商'" + channel.getName() + "'新增失败");
|
|
|
+ return AjaxResult.error("经销商'" + channel.getName() + "'新增失败"+e.getMessage());
|
|
|
}
|
|
|
return AjaxResult.success("经销商'" + channel.getName() + "'新增成功");
|
|
|
}
|
|
@@ -288,8 +424,48 @@ public class ChannelController extends BaseApiController {
|
|
|
return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
}
|
|
|
Channel channel = mapperFacade.map(channelParam, Channel.class);
|
|
|
+
|
|
|
+ // 1、校验修改子渠道是否为当前用户的子渠道
|
|
|
+ Channel oldChannel = channelService.getById(channel.getChannelId());
|
|
|
+ if(null == oldChannel || null == oldChannel.getChannelId()) {
|
|
|
+ return AjaxResult.error("经销商'" + oldChannel.getName() + "'编辑失败,渠道ID异常");
|
|
|
+ }
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
+ if(!oldChannel.getParentId().equals(channelId)) {
|
|
|
+ return AjaxResult.error("经销商'" + oldChannel.getName() + "'编辑失败,非当前用户子渠道");
|
|
|
+ }
|
|
|
+ // 2.校验名称是否重复、手机号是否存在(渠道表);
|
|
|
+ if(!channel.getName().equals(oldChannel.getName())) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Channel::getName, channel.getName());
|
|
|
+ queryWrapper.eq(Channel::getLevel, 0);
|
|
|
+ int nameCount = channelService.count(queryWrapper);
|
|
|
+ if(nameCount > 0) {
|
|
|
+ return AjaxResult.error("经销商名称" + 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) {
|
|
|
+ return AjaxResult.error("手机号码" + channel.getMobile() + "已注册!");
|
|
|
+ }
|
|
|
+ if(UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(channel.getMobile()))) {
|
|
|
+ return AjaxResult.error("手机号码" + channel.getMobile() + "已注册!");
|
|
|
+ }
|
|
|
+ mobileChange = true;
|
|
|
+ }
|
|
|
+ // 3.校验佣金比例,不能高于其父渠道的佣金比例,不能低于其子渠道的最大佣金比例
|
|
|
+ Channel parentChannel = channelService.getById(oldChannel.getParentId());
|
|
|
+ if(null != parentChannel && null != parentChannel.getCommRate()) {
|
|
|
+ if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
|
+ return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
|
|
|
+ }
|
|
|
+ }
|
|
|
try {
|
|
|
- channelService.updateChannel(channel,"site");
|
|
|
+ channelService.updateChannel(channel, mobileChange);
|
|
|
} catch (Exception e) {
|
|
|
return AjaxResult.error("经销商'" + channel.getName() + "'编辑失败");
|
|
|
}
|
|
@@ -404,7 +580,6 @@ public class ChannelController extends BaseApiController {
|
|
|
Map<String, Object> map = channelCommissionService.getMap(queryWrapper);
|
|
|
if(null != map && map.containsKey("commAmt")) {
|
|
|
BigDecimal commAmt = new BigDecimal(map.get("commAmt").toString());
|
|
|
-
|
|
|
ChannelOperDataVO channelOperDataVO = new ChannelOperDataVO();
|
|
|
channelOperDataVO.setCommAmt(commAmt.longValue());
|
|
|
channelVO.setOperData(channelOperDataVO);
|