Преглед изворни кода

渠道和经销商增删改查接口

guanglong пре 3 година
родитељ
комит
a90d9d30e9

+ 56 - 31
mp-admin/src/main/java/com/qs/mp/web/controller/api/channel/ChannelController.java

@@ -2,9 +2,7 @@ package com.qs.mp.web.controller.api.channel;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qs.mp.channel.domain.Channel;
-import com.qs.mp.channel.domain.ChannelAddr;
 import com.qs.mp.channel.domain.param.ChannelParam;
 import com.qs.mp.channel.domain.param.VerifyParam;
 import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
@@ -12,8 +10,9 @@ import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.common.core.domain.AjaxResult;
 import com.qs.mp.common.core.page.TableDataInfo;
+import com.qs.mp.common.enums.ChannelCertifyStatusEnum;
+import com.qs.mp.common.enums.ChannelVerifyStatusEnum;
 import com.qs.mp.common.enums.ErrorCodeEnum;
-import com.qs.mp.system.service.id.BizIdGenerator;
 import com.qs.mp.utils.SecurityUtils;
 import com.qs.mp.web.controller.common.BaseApiController;
 import io.swagger.annotations.Api;
@@ -21,13 +20,11 @@ import io.swagger.annotations.ApiOperation;
 import ma.glasnost.orika.MapperFacade;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Component;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -49,9 +46,6 @@ public class ChannelController extends BaseApiController {
 	@Autowired
 	private IChannelService channelService;
 
-	@Autowired
-	private BizIdGenerator bizIdGenerator;
-
 	@Autowired
 	private MapperFacade mapperFacade;
 
@@ -67,8 +61,7 @@ public class ChannelController extends BaseApiController {
 		if(null != channelId) {
 			channel.setParentId(channelId);
 			startPage();
-			// List<Channel> list = channelService.list(new LambdaQueryWrapper<Channel>());
-			list = channelService.selectChannelVoList(channel);
+			list = channelService.selectChannelVoList(channel,"channel");
 		}
 		return getDataTable(list);
 	}
@@ -84,9 +77,15 @@ public class ChannelController extends BaseApiController {
 		if (null == channel || null == channel.getChannelId()) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
 		}
-		Long channelId = channel.getChannelId();
+		Long parentlId = SecurityUtils.getLoginUser().getChannelId();
 		ChannelVO channelVO = new ChannelVO();
-		Channel queryChannel = channelService.getById(channelId);
+		Channel queryChannel = channelService.getById(channel.getChannelId());
+		if(null == queryChannel || null == queryChannel.getChannelId()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		if(!parentlId.equals(queryChannel.getParentId())) {
+			return AjaxResult.error("非当前用户的子渠道,查询失败");
+		}
 	    BeanUtils.copyProperties(queryChannel, channelVO);
 	    // 查询今日的销售额、佣金收入、新增用户数
 	    ChannelOperDataVO channelOperDataVO = channelService.getChannelOperData(channelVO.getChannelNo(), 1);
@@ -106,15 +105,14 @@ public class ChannelController extends BaseApiController {
 			return AjaxResult.error("该渠道已存在");
 		}
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
-
 		Channel channel = mapperFacade.map(channelParam, Channel.class);
 		channel.setParentId(channelId);
 		try {
-			channelService.saveChannel(channel);
+			channelService.saveChannel(channel, "channel");
 		} catch (Exception e) {
-			return AjaxResult.error("新增子渠道信息'" + channel.getName() + "'失败");
+			return AjaxResult.error("子渠道信息'" + channel.getName() + "'新增失败");
 		}
-		return AjaxResult.success("新增子渠道信息'" + channel.getName() + "'成功");
+		return AjaxResult.success("子渠道信息'" + channel.getName() + "'新增成功");
 	}
 
 	/**
@@ -131,11 +129,11 @@ public class ChannelController extends BaseApiController {
 		}
 		Channel channel = mapperFacade.map(channelParam, Channel.class);
 		try {
-			channelService.updateChannel(channel);
+			channelService.updateChannel(channel, "channel");
 		} catch (Exception e) {
-			return AjaxResult.error("编辑子渠道信息'" + channel.getName() + "'失败");
+			return AjaxResult.error("子渠道信息'" + channel.getName() + "'编辑失败");
 		}
-		return AjaxResult.success("编辑子渠道信息'" + channel.getName() + "'成功");
+		return AjaxResult.success("子渠道信息'" + channel.getName() + "'编辑成功");
 	}
 	
 	
@@ -153,7 +151,15 @@ public class ChannelController extends BaseApiController {
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
 		int days = jsonObject.getIntValue("days");;
 		if(StringUtils.isNotBlank(jsonObject.getString("channelId"))) {
-			channelId = jsonObject.getLong("channelId");
+			Long _channelId = jsonObject.getLong("channelId");
+			Channel queryChannel = channelService.getById(_channelId);
+			if(null == queryChannel || null == queryChannel.getChannelId()) {
+				return error(ErrorCodeEnum.ERROR_CODE_1001);
+			}
+			if(!channelId.equals(queryChannel.getParentId())) {
+				return AjaxResult.error("非当前用户的子渠道,查询失败");
+			}
+			channelId = _channelId;
 		}
 		days = days > 0?days:1;
 		days = days > 0?days:1;
@@ -210,8 +216,7 @@ public class ChannelController extends BaseApiController {
 		if(null != channelId) {
 			channel.setParentId(channelId);
 			startPage();
-			// List<Channel> list = channelService.list(new LambdaQueryWrapper<Channel>());
-			list = channelService.selectSiteVoList(channel);
+			list = channelService.selectChannelVoList(channel,"channel");
 		}
 		return getDataTable(list);
 	}
@@ -227,9 +232,15 @@ public class ChannelController extends BaseApiController {
 		if (null == channel || null == channel.getChannelId()) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
 		}
-		Long channelId = channel.getChannelId();
+		Long parentlId = SecurityUtils.getLoginUser().getChannelId();
 		ChannelVO channelVO = new ChannelVO();
-		Channel queryChannel = channelService.getById(channelId);
+		Channel queryChannel = channelService.getById(channel.getChannelId());
+		if(null == queryChannel || null == queryChannel.getChannelId()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		if(!parentlId.equals(queryChannel.getParentId())) {
+			return AjaxResult.error("非当前用户的经销商,查询失败");
+		}
 	    BeanUtils.copyProperties(queryChannel, channelVO);
 	    // 查询今日的销售额、佣金收入、新增用户数
 	    ChannelOperDataVO channelOperDataVO = channelService.getChannelOperData(channelVO.getChannelNo(), 1);
@@ -253,7 +264,7 @@ public class ChannelController extends BaseApiController {
 		Channel channel = mapperFacade.map(channelParam, Channel.class);
 		channel.setParentId(channelId);
 		try {
-			channelService.saveSite(channel);
+			channelService.saveChannel(channel,"site");
 		} catch (Exception e) {
 			return AjaxResult.error("新增经销商信息'" + channel.getName() + "'失败");
 		}
@@ -274,11 +285,11 @@ public class ChannelController extends BaseApiController {
 		}
 		Channel channel = mapperFacade.map(channelParam, Channel.class);
 		try {
-			channelService.updateSite(channel);
+			channelService.updateChannel(channel,"site");
 		} catch (Exception e) {
-			return AjaxResult.error("编辑经销商信息'" + channel.getName() + "'失败");
+			return AjaxResult.error("经销商'" + channel.getName() + "'编辑失败");
 		}
-		return AjaxResult.success("编辑经销商信息'" + channel.getName() + "'成功");
+		return AjaxResult.success("经销商'" + channel.getName() + "'编辑成功");
 	}
 	
 	
@@ -294,7 +305,21 @@ public class ChannelController extends BaseApiController {
 		if (null == channel || null == channel.getChannelId() || null == channel.getVerifyStatus()) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
 		}
+		
+		Long parentlId = SecurityUtils.getLoginUser().getChannelId();
+		Channel queryChannel = channelService.getById(channel.getChannelId());
+		if(null == queryChannel || null == queryChannel.getChannelId()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		if(!parentlId.equals(queryChannel.getParentId())) {
+			return AjaxResult.error(queryChannel.getName() + "非当前用户的经销商, 认证审核失败");
+		}
 		try {
+			if(channel.getVerifyStatus() == ChannelVerifyStatusEnum.ACCEPT) {
+				channel.setCertifyStatus(ChannelCertifyStatusEnum.CERTIFIED);
+			}else {
+				channel.setCertifyStatus(ChannelCertifyStatusEnum.NOT_CERTIFIED);
+			}
 			channelService.updateById(channel);
 		} catch (Exception e) {
 			return AjaxResult.error("经销商'" + channel.getName() + "'认证审核失败");
@@ -316,6 +341,7 @@ public class ChannelController extends BaseApiController {
 		}
 		Channel channel = mapperFacade.map(verifyParam, Channel.class);
 		try {
+			channel.setVerifyStatus(ChannelVerifyStatusEnum.WAIT);
 			channelService.updateById(channel);
 		} catch (Exception e) {
 			return AjaxResult.error("经销商'" + channel.getName() + "'提交认证信息失败");
@@ -330,10 +356,9 @@ public class ChannelController extends BaseApiController {
 	 * @param
 	 * @return
 	 */
-	@PostMapping(value = "min/detail")
+	@PostMapping(value = "mine/detail")
 	@ApiOperation(value = "查看我的渠道信息", notes = "渠道端我的里面点击佣金比例")
-	public AjaxResult getMinInfo() {
-		
+	public AjaxResult getMineDetail() {
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
 		if (null == channelId) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);

+ 8 - 3
mp-admin/src/test/java/com/qs/mp/service/ChannelServiceTest.java

@@ -1,11 +1,13 @@
 package com.qs.mp.service;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.qs.mp.MpApplication;
 import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.service.IChannelService;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -25,7 +27,10 @@ public class ChannelServiceTest {
 	@Test
 	public void testListChannel() {
 		Channel channel = new Channel();
-
+		channel.setParentId(1L);
+		List<ChannelVO> list = new ArrayList<ChannelVO>();
+		list = channelService.selectChannelVoList(channel,"channel");
+		System.out.println("result:"+list.toString());
 	}
 	
 	@Test

+ 1 - 1
mp-service/src/main/java/com/qs/mp/channel/mapper/ChannelMapper.java

@@ -32,7 +32,7 @@ public interface ChannelMapper extends BaseMapper<Channel> {
 	 * @param channel
 	 * @return
 	 */
-	public List<ChannelVO> selectSiteVoList(@Param(Constants.WRAPPER) Wrapper<Channel> wrapper);
+	// public List<ChannelVO> selectSiteVoList(@Param(Constants.WRAPPER) Wrapper<Channel> wrapper);
 	
 	
     /**

+ 9 - 35
mp-service/src/main/java/com/qs/mp/channel/service/IChannelService.java

@@ -18,59 +18,33 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IChannelService extends IService<Channel> {
 	
-    
-	/**
-	 * 新增子渠道信息
-	 * 
-	 * @param channel
-	 * @return
-	 */
-    public void saveChannel(Channel channel) throws Exception;
-    
 	/**
-	 * 新增经销商
+	 * 新增子渠道、经销商信息
 	 * 
 	 * @param channel
+	 * @param channelType channel:子渠道  site: 经销商
 	 * @return
 	 */
-    public void saveSite(Channel channel) throws Exception;
-    
-    
+    public void saveChannel(Channel channel, String channelType) throws Exception;
+     
     /**
-	 * 编辑子渠道信息
+	 * 编辑子渠道、经销商信息
 	 * 
 	 * @param channel
+	 * @param channelType channel:子渠道  site: 经销商
 	 * @return
 	 */
-    public void updateChannel(Channel channel) throws Exception;
+    public void updateChannel(Channel channel, String channelType) throws Exception;
     
     
-    /**
-	 * 编辑经销商
-	 * 
-	 * @param channel
-	 * @return
-	 */
-    public void updateSite(Channel channel) throws Exception;
-    
-    
-
 	/**
-	 * 获取我的下级渠道列表信息,支持翻页
+	 * 获取我的下级渠道、经销商列表信息,支持翻页
 	 * 
 	 * @param channel
 	 * @return
 	 */
-	public List<ChannelVO> selectChannelVoList(Channel channel);
+	public List<ChannelVO> selectChannelVoList(Channel channel, String channelType);
 	
-	/**
-	 * 获取我的经销商列表信息,支持翻页
-	 * 
-	 * @param channel
-	 * @return
-	 */
-	public List<ChannelVO> selectSiteVoList(Channel channel);
-
 	/**
 	 * 根据用户ID查询渠道
 	 * 

+ 7 - 0
mp-service/src/main/java/com/qs/mp/channel/service/IChannelUserRelService.java

@@ -13,6 +13,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IChannelUserRelService extends IService<ChannelUserRel> {
 
+	
+	/**
+	 * 根据渠道No查询渠道用户数量
+	 * @param channelNo
+	 * @return
+	 */
+	int getChannelUserCnt(String channelNo);
 	/**
 	 * 根据渠道No查询渠道指定时间内新增的用户数量
 	 * @param channelNo

+ 117 - 87
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelServiceImpl.java

@@ -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.QueryWrapper;
 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.vo.ChannelOperDataVO;
 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.IChannelService;
 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.system.domain.SysUser;
 import com.qs.mp.system.service.ISysUserService;
-import com.qs.mp.system.service.id.BizIdGenerator;
 import com.qs.mp.utils.SecurityUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -50,17 +50,22 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
     @Autowired
     private ISysUserService userService;
 
-	@Autowired
-	private BizIdGenerator bizIdGenerator;
-
 	@Override
 	@Transactional
-	public void saveChannel(Channel channel) throws Exception {
+	public void saveChannel(Channel channel, String channelType) throws Exception {
+		
+		String title = channelType.equals("channel")?"渠道":"经销商";
 		// 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) {
-			 throw new ServiceException("渠道名称" + channel.getName() + "已存在!");
+			 throw new ServiceException(title +"名称" + channel.getName() + "已存在!");
 		}
 		int mobileCount = channelService.count(
 		        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());
 		if(null != parentChannel && null != parentChannel.getCommRate()) {
 			 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.插入数据
 		boolean res = channelService.save(channel);
 		if(res && null != channel.getChannelId()) {
@@ -88,7 +97,7 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
 			sysUser.setCreateBy(SecurityUtils.getUsername());
 			int userNum = userService.insertUser(sysUser);
 		    if (userNum == 0 || null == sysUser.getUserId()) {
-		        throw new ServiceException("新增渠道'" + channel.getName() + "'失败,请联系管理员");
+		        throw new ServiceException("新增'" + title + channel.getName() + "'失败,请联系管理员");
 		    }
 		    channel.setUserId(sysUser.getUserId());
 		    channelService.updateById(channel);
@@ -96,103 +105,124 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
 		}
 	}
 	
-	
+
 	@Override
 	@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(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.更新入库
+		 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
-	public List<ChannelVO> selectChannelVoList(Channel channel) {
+	public List<ChannelVO> selectChannelVoList(Channel channel, String channelType) {
 		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
 		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
 	public Channel getChannelByUserId(Long userId) {
 		return getBaseMapper().selectOne(new LambdaQueryWrapper<Channel>().eq(Channel::getUserId, userId));
 	}
 
-
 	@Override
 	public ChannelOperDataVO getChannelOperData(String channelNo, int days) {
 		ChannelOperDataVO channelOperData = new ChannelOperDataVO();

+ 5 - 0
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelUserRelServiceImpl.java

@@ -17,6 +17,11 @@ import org.springframework.stereotype.Service;
 @Service
 public class ChannelUserRelServiceImpl extends ServiceImpl<ChannelUserRelMapper, ChannelUserRel> implements IChannelUserRelService {
 
+	@Override
+	public int getChannelUserCnt(String channelNo) {
+		return getBaseMapper().getChannelUserCnt(channelNo);
+	}
+
 	@Override
 	public int getChannelUserCnt(String channelNo, int days) {
 		return getBaseMapper().getChannelUserCnt(channelNo, days == 1?0: (~(days - 1)));

+ 0 - 45
mp-service/src/main/resources/mapper/channel/ChannelMapper.xml

@@ -61,41 +61,6 @@
         <result column="created_time" property="createdTime" />
         <result column="updated_time" property="updatedTime" />
         <result column="parentName" property="parentName" />
-        <association property="siteCnt" javaType="java.lang.Integer" select="getChannelSiteCnt" column="{channelNo=channelNo}" />
-        <association property="userCnt" javaType="java.lang.Integer" select="com.qs.mp.channel.mapper.ChannelUserRelMapper.getChannelUserCnt" column="{channelNo=channelNo}" />
-    </resultMap>
-    
-    
-    <!-- 通用查询VO映射结果 -->
-    <resultMap id="SiteVoResultMap" type="com.qs.mp.channel.domain.vo.ChannelVO">
-        <id column="channel_id" property="channelId" />
-        <result column="channel_no" property="channelNo" />
-        <result column="name" property="name" />
-        <result column="parent_id" property="parentId" />
-        <result column="level" property="level" />
-        <result column="site_type" property="siteType" />
-        <result column="comm_rate" property="commRate" />
-        <result column="province" property="province" />
-        <result column="province_id" property="provinceId" />
-        <result column="city" property="city" />
-        <result column="city_id" property="cityId" />
-        <result column="area" property="area" />
-        <result column="area_id" property="areaId" />
-        <result column="address" property="address" />
-        <result column="contact" property="contact" />
-        <result column="mobile" property="mobile" />
-        <result column="user_id" property="userId" />
-        <result column="money" property="money" />
-        <result column="frozen_money" property="frozenMoney" />
-        <result column="certify_status" property="certifyStatus" />
-        <result column="verify_status" property="verifyStatus" />
-        <result column="biz_license_pic" property="bizLicensePic" />
-        <result column="door_pic" property="doorPic" />
-        <result column="memo" property="memo" />
-        <result column="created_time" property="createdTime" />
-        <result column="updated_time" property="updatedTime" />
-        <result column="parentName" property="parentName" />
-        <association property="userCnt" javaType="java.lang.Integer" select="com.qs.mp.channel.mapper.ChannelUserRelMapper.getChannelUserCnt" column="{channelNo=channelNo}" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
@@ -109,18 +74,8 @@
 		from mp_channel t1
 		left join mp_channel t2 on t1.parent_id = t2.channel_id
 		${ew.customSqlSegment}
-		order by t1.channel_id desc
 	</select>
 	
-	 <!-- 查询子经销商信息 -->
-    <select id="selectSiteVoList" resultMap="SiteVoResultMap">
-		select t1.* , t2.name parentName
-		from mp_channel t1
-		left join mp_channel t2 on t1.parent_id = t2.channel_id
-		${ew.customSqlSegment}
-		order by t1.channel_id desc
-	</select>
-
 	<!-- 查询渠道及其子渠道经销商用户数总和 -->
     <select id="getChannelSiteCnt" resultType="integer">
         select count(t1.channel_id) as siteCnt