Просмотр исходного кода

Merge branch 'dev' into 'mp-server-test'

Dev

See merge request quanshu/mp-server!31
zhong chunping 3 лет назад
Родитель
Сommit
843644d666

+ 280 - 0
mp-admin/src/main/java/com/qs/mp/web/controller/api/admin/ChannelTreeController.java

@@ -0,0 +1,280 @@
+package com.qs.mp.web.controller.api.admin;
+
+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.param.ChannelParam;
+import com.qs.mp.channel.domain.vo.ChannelVO;
+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.ErrorCodeEnum;
+import com.qs.mp.system.domain.SysUser;
+import com.qs.mp.system.service.ISysUserService;
+import com.qs.mp.web.controller.common.BaseApiController;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import ma.glasnost.orika.MapperFacade;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+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.Component;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @auther zhongcp
+ * @create 2022-02-28 16:17:48
+ * @describe 渠道管理前端控制器
+ */
+@Api("渠道管理API")
+@RestController
+@RequestMapping("/api/v1/mp/admin/channel/*")
+@Component
+public class ChannelTreeController extends BaseApiController {
+
+	@Autowired
+	private IChannelService channelService;
+	
+	@Autowired
+	private IChannelUserRelService channelUserRelService;
+	
+	@Autowired
+	private ISysUserService userService;
+	
+	@Autowired
+	private MapperFacade mapperFacade;
+
+	/**
+	 * 获取我的下级渠道列表信息,LIMIT 50
+	 *
+	 * @return
+	 */
+	@PostMapping("/tree")
+	public AjaxResult treeChannel(@RequestBody Channel channel) {
+		List<ChannelVO> list = new ArrayList<ChannelVO>();
+		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("t1.parent_id", null!=channel && null != channel.getChannelId()?channel.getChannelId():0);
+		queryWrapper.gt("t1.level", 0);
+		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getMobile()), "t1.mobile", channel.getMobile());
+		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getName()), "t1.name", channel.getName());
+		queryWrapper.orderByAsc("t1.channel_id");
+		queryWrapper.last("limit 50");
+		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);
+					// 查询子渠道数量
+					int childCnt = channelService.count(
+							new LambdaQueryWrapper<Channel>().eq(Channel::getParentId, channelVO.getChannelId())
+							.gt(Channel::getLevel, 0));
+					channelVO.setChildCnt(childCnt);
+				}
+			}
+		}
+		return AjaxResult.success(list);
+	}
+	
+	/**
+	 * 获取我的下级渠道列表信息,支持翻页
+	 *
+	 * @return
+	 */
+	@PostMapping("/list")
+	public TableDataInfo listChannel(@RequestBody Channel channel) {
+		List<ChannelVO> list = new ArrayList<ChannelVO>();
+		startPage();
+		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("t1.parent_id", null!=channel && null != channel.getChannelId()?channel.getChannelId():0);
+		queryWrapper.gt("t1.level", 0);
+		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getMobile()), "t1.mobile", channel.getMobile());
+		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getName()), "t1.name", channel.getName());
+		queryWrapper.orderByAsc("t1.channel_id");
+		queryWrapper.last("limit 50");
+		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);
+					// 查询用户信息
+					SysUser sysUser = userService.selectUserById(channelVO.getUserId());
+					channelVO.setSysUser(sysUser);
+ 				}
+			}
+		}
+		return getDataTable(list);
+	}
+	
+	
+	/**
+	 * 新增子渠道信息
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "新增子渠道信息", notes = "渠道端新增子渠道")
+	@PostMapping("/create")
+	public AjaxResult channelCreate(@Validated @RequestBody ChannelParam channelParam) {
+		if (channelParam.getChannelId() != null && channelParam.getChannelId() != 0) {
+			return AjaxResult.error("该渠道已存在");
+		}
+		Channel channel = mapperFacade.map(channelParam, Channel.class);
+		// 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.校验佣金比例,不能高于其父渠道的佣金比例
+		if(null != channel.getParentId() && channel.getParentId() != 0) {
+			Channel parentChannel = channelService.getById(channel.getParentId());
+			if(null != parentChannel) {
+				 if(null != parentChannel.getCommRate() 
+						 && channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
+					 return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
+				 }
+				 channel.setLevel(parentChannel.getLevel()+1);
+				 channel.setChannelNo(parentChannel.getChannelNo()+".");
+			}else {
+				return AjaxResult.error("父渠道不存在");
+			}
+			
+		}else {
+			channel.setLevel(1);
+			channel.setChannelNo("");
+		}
+		// 3.插入数据
+		try {
+			channelService.saveChannel(channel,"channel");
+		} catch (Exception e) {
+			return AjaxResult.error("渠道'" + channel.getName() + "'新增失败" + e.getMessage());
+		}
+		
+		return AjaxResult.success("渠道'" + channel.getName() + "'新增成功");
+	}
+
+	/**
+	 * 编辑子渠道信息
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "编辑子渠道信息", notes = "渠道端编辑子渠道")
+	@PostMapping("/update")
+	public AjaxResult channelUpdate(@Validated @RequestBody ChannelParam channelParam) {
+		if (null == channelParam || null == channelParam.getChannelId()) {
+			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异常");
+		}
+		// 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) {
+			 if(null != parentChannel.getCommRate() 
+					 && channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
+				 return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
+			 }
+			 channel.setLevel(parentChannel.getLevel()+1);
+			 channel.setChannelNo(parentChannel.getChannelNo()+".");
+		}else {
+			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() + "'编辑成功");
+	}
+	
+	
+	/**
+	 * 停用、启用渠道
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "停用、启用渠道信息", notes = "渠道管理编辑子渠道")
+	@PostMapping("/status")
+	public AjaxResult channelStatus(@RequestBody JSONObject jsonObject) {
+		String channelId = jsonObject.containsKey("channelId")?jsonObject.get("channelId").toString():"";
+		String status = jsonObject.containsKey("status")?jsonObject.get("status").toString():"";
+		if (null == jsonObject || StringUtils.isBlank(channelId)
+				|| StringUtils.isBlank(status)) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		try {
+			// 查询渠道信息
+			Channel channel = channelService.getById(channelId);
+			if(null != channel && null != channel.getUserId()) {
+				SysUser sysUser = new SysUser();
+				sysUser.setUserId(channel.getUserId());
+				sysUser.setStatus(status);
+				userService.updateUserStatus(sysUser);
+			}
+		} catch (Exception e) {
+			return AjaxResult.error("操作失败");
+		}
+		return AjaxResult.success("操作成功");
+	}
+	
+}

+ 239 - 0
mp-admin/src/main/java/com/qs/mp/web/controller/api/admin/SaleSiteController.java

@@ -0,0 +1,239 @@
+package com.qs.mp.web.controller.api.admin;
+
+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.param.ChannelParam;
+import com.qs.mp.channel.domain.vo.ChannelVO;
+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.ErrorCodeEnum;
+import com.qs.mp.system.domain.SysUser;
+import com.qs.mp.system.service.ISysUserService;
+import com.qs.mp.web.controller.common.BaseApiController;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import ma.glasnost.orika.MapperFacade;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+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.Component;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @auther zhongcp
+ * @create 2022-02-28 16:17:48
+ * @describe 渠道管理前端控制器
+ */
+@Api("渠道管理API")
+@RestController
+@RequestMapping("/api/v1/mp/admin/salesite/*")
+@Component
+public class SaleSiteController extends BaseApiController {
+
+	@Autowired
+	private IChannelService channelService;
+	
+	@Autowired
+	private IChannelUserRelService channelUserRelService;
+	
+	@Autowired
+	private ISysUserService userService;
+	
+	@Autowired
+	private MapperFacade mapperFacade;
+
+
+	/**
+	 * 获取经销商列表信息,支持翻页
+	 *
+	 * @return
+	 */
+	@PostMapping("/list")
+	public TableDataInfo listChannel(@RequestBody Channel channel) {
+		List<ChannelVO> list = new ArrayList<ChannelVO>();
+		startPage();
+		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("t1.parent_id", null!=channel && null != channel.getChannelId()?channel.getChannelId():0);
+		queryWrapper.eq("t1.level", 0);
+		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getMobile()), "t1.mobile", channel.getMobile());
+		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getName()), "t1.name", channel.getName());
+		queryWrapper.eq(null != channel && null != channel.getProvinceId(), "t1.province_id", channel.getProvinceId());
+		queryWrapper.eq(null != channel && null != channel.getCityId(), "t1.city_id", channel.getCityId());
+		queryWrapper.eq(null != channel && null != channel.getAreaId(), "t1.area_id", channel.getAreaId());
+		queryWrapper.orderByAsc("t1.channel_id");
+		queryWrapper.last("limit 50");
+		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);
+					// 查询用户信息
+					SysUser sysUser = userService.selectUserById(channelVO.getUserId());
+					channelVO.setSysUser(sysUser);
+ 				}
+			}
+		}
+		return getDataTable(list);
+	}
+	
+	
+	/**
+	 * 新增经销商信息
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "新增经销商信息", notes = "渠道端新增经销商")
+	@PostMapping("/create")
+	public AjaxResult channelCreate(@Validated @RequestBody ChannelParam channelParam) {
+		if (channelParam.getChannelId() != null && channelParam.getChannelId() != 0) {
+			return AjaxResult.error("该经销商已存在");
+		}
+		Channel channel = mapperFacade.map(channelParam, Channel.class);
+		// 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.校验佣金比例,不能高于其父渠道的佣金比例
+		if(null != channel.getParentId() && channel.getParentId() != 0) {
+			Channel parentChannel = channelService.getById(channel.getParentId());
+			if(null != parentChannel) {
+				 if(null != parentChannel.getCommRate() 
+						 && channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
+					 return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
+				 }
+				 channel.setLevel(parentChannel.getLevel()+1);
+				 channel.setChannelNo(parentChannel.getChannelNo()+".");
+			}else {
+				return AjaxResult.error("父渠道不存在");
+			}
+			
+		}else {
+			channel.setLevel(1);
+			channel.setChannelNo("");
+		}
+		// 3.插入数据
+		try {
+			channelService.saveChannel(channel,"channel");
+		} catch (Exception e) {
+			return AjaxResult.error("经销商'" + channel.getName() + "'新增失败" + e.getMessage());
+		}
+		
+		return AjaxResult.success("经销商'" + channel.getName() + "'新增成功");
+	}
+
+	/**
+	 * 编辑经销商信息
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "编辑经销商信息", notes = "经销商端编辑经销商")
+	@PostMapping("/update")
+	public AjaxResult channelUpdate(@Validated @RequestBody ChannelParam channelParam) {
+		if (null == channelParam || null == channelParam.getChannelId()) {
+			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异常");
+		}
+		// 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) {
+			 if(null != parentChannel.getCommRate() 
+					 && channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
+				 return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
+			 }
+			 channel.setLevel(parentChannel.getLevel()+1);
+			 channel.setChannelNo(parentChannel.getChannelNo()+".");
+		}else {
+			return AjaxResult.error("父渠道不存在");
+		}
+		try {
+			channelService.updateChannel(channel, mobileChange);
+		} catch (Exception e) {
+			return AjaxResult.error(e.getMessage());
+		}
+		return AjaxResult.success("经销商'" + channel.getName() + "'编辑成功");
+	}
+	
+	
+	/**
+	 * 停用、启用经销商
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "停用、启用经销商信息", notes = "经销商管理编辑经销商")
+	@PostMapping("/status")
+	public AjaxResult channelStatus(@RequestBody JSONObject jsonObject) {
+		String channelId = jsonObject.containsKey("channelId")?jsonObject.get("channelId").toString():"";
+		String status = jsonObject.containsKey("status")?jsonObject.get("status").toString():"";
+		if (null == jsonObject || StringUtils.isBlank(channelId)
+				|| StringUtils.isBlank(status)) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		try {
+			// 查询渠道信息
+			Channel channel = channelService.getById(channelId);
+			if(null != channel && null != channel.getUserId()) {
+				SysUser sysUser = new SysUser();
+				sysUser.setUserId(channel.getUserId());
+				sysUser.setStatus(status);
+				userService.updateUserStatus(sysUser);
+			}
+		} catch (Exception e) {
+			return AjaxResult.error("操作失败");
+		}
+		return AjaxResult.success("操作成功");
+	}
+	
+}

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

@@ -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);

+ 7 - 5
mp-admin/src/main/java/com/qs/mp/web/controller/api/channel/mall/ChannelOrderController.java

@@ -19,7 +19,6 @@ import com.qs.mp.channel.domain.ChannelAddr;
 import com.qs.mp.channel.domain.ChannelCart;
 import com.qs.mp.channel.domain.ChannelOrder;
 import com.qs.mp.channel.domain.ChannelOrderItem;
-import com.qs.mp.channel.domain.param.ChannelCartParam;
 import com.qs.mp.channel.domain.param.ChannelOrderParam;
 import com.qs.mp.channel.domain.param.ChannelOrderPayParam;
 import com.qs.mp.channel.domain.vo.ChannelCartVO;
@@ -32,18 +31,16 @@ import com.qs.mp.channel.service.IChannelOrderService;
 import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.common.core.domain.AjaxResult;
 import com.qs.mp.common.core.redis.RedisCache;
-import com.qs.mp.common.domain.param.BatchLongIdsParam;
 import com.qs.mp.common.enums.BizTypeEnum;
 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.common.exception.ServiceException;
 import com.qs.mp.common.utils.LogUtil;
 import com.qs.mp.pay.service.IWalletService;
 import com.qs.mp.utils.SecurityUtils;
 import com.qs.mp.web.controller.common.BaseApiController;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import javax.validation.Valid;
@@ -227,7 +224,12 @@ public class ChannelOrderController extends BaseApiController {
   public AjaxResult pay(@Valid @RequestBody ChannelOrderPayParam param) {
     String openId = SecurityUtils.getLoginUser().getUser().getOpenId();
     ChannelOrder channelOrder = channelOrderService.getById(param.getOrderId());
-    JSONObject jsonObject = walletService.channelPay(BizTypeEnum.CHANNEL_ORDER, param.getOrderId(), openId, channelOrder.getPayAmt());
+    JSONObject jsonObject;
+    try {
+      jsonObject = walletService.pay(BizTypeEnum.CHANNEL_ORDER, param.getOrderId(), openId, channelOrder.getPayAmt());
+    }catch (ServiceException e) {
+      return AjaxResult.error(e.getMessage());
+    }
     return AjaxResult.success(jsonObject);
   }
 }

+ 1 - 1
mp-admin/src/main/resources/application-dev.yml

@@ -2,7 +2,7 @@ pay:
     notify:
         url: https://www.quanshu123.com
     call:
-        backUrl: https://api.quanshu123.com/service/notify/payCallback
+        backUrl: https://test-mp.quanshu123.com/service/notify/payCallback
     base:
         url: https://jlpays.kakapaypay.com
     shopNo: 1631243148392

+ 1 - 1
mp-admin/src/main/resources/application-test.yml

@@ -2,7 +2,7 @@ pay:
   notify:
     url: https://www.quanshu123.com
   call:
-    backUrl: https://test-api.quanshu123.com/service/notify/payCallback
+    backUrl: https://test-mp.quanshu123.com/service/notify/payCallback
   base:
     url: https://jlpays.kakapaypay.com
   shopNo: 1631243148392

+ 21 - 1
mp-admin/src/test/java/com/qs/mp/service/ChannelServiceTest.java

@@ -1,13 +1,16 @@
 package com.qs.mp.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 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 com.qs.mp.channel.service.IChannelUserRelService;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang3.StringUtils;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -23,13 +26,30 @@ public class ChannelServiceTest {
 
 	@Autowired
 	private IChannelService channelService;
+	
+	@Autowired
+	private IChannelUserRelService channelUserRelService;
 
 	@Test
 	public void testListChannel() {
 		Channel channel = new Channel();
 		channel.setParentId(1L);
 		List<ChannelVO> list = new ArrayList<ChannelVO>();
-		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);
+				}
+			}
+		}
 		System.out.println("result:"+list.toString());
 	}
 	

+ 7 - 31
mp-common/src/main/java/com/qs/mp/common/jsms/JSMSUtils.java

@@ -36,11 +36,11 @@ public class JSMSUtils {
 
     protected static final Logger logger = LoggerFactory.getLogger(JSMSUtils.class);
 
-    private static final String appkey = "538a7546412c8630bdd6138a";
-    private static final String masterSecret = "5d0471cedfc2edd72641a241";
-
+    private static final String appkey = "2f17e0698d004ca7411a9ef6";
+    private static final String masterSecret = "a6446a6b8bf8a4be72bf86d4";
+/*
     private static final String devKey = "242780bfdd7315dc1989fedb";
-    private static final String devSecret = "2f5ced2bef64167950e63d13";
+    private static final String devSecret = "2f5ced2bef64167950e63d13";*/
     private static String env;
 
     @Value("${server.env}")
@@ -78,34 +78,10 @@ public class JSMSUtils {
         return null;
     }
 
-    public static SendSMSResult sendMerchAct(String mobile) {
-        SMSClient client = new SMSClient(masterSecret, appkey);
-        SMSPayload payload = SMSPayload.newBuilder().setMobileNumber(mobile).setTempId(203647).build();
-        try {
-            if (ServerEnvEnum.PROD.getCode().equals(env)) {
-                SendSMSResult res = client.sendTemplateSMS(payload);
-                LogUtil.info(logger, "商户账户创建短信发送结果,mobile:{0}, res:{1}", new Object[]{mobile, JSON.toJSONString(res)});
-                return res;
-            } else {
-                logger.info("非生产环境,不发送商户账号通知短信!" + mobile);
-                return (new GsonBuilder()).excludeFieldsWithoutExposeAnnotation().create().fromJson("{\"msg_id\":\"123456789\"}", SendSMSResult.class);
-
-            }
-        } catch (APIConnectionException e) {
-            LogUtil.error(logger, e, "商户账户创建短信发送失败,mobile:{0}", mobile);
-        } catch (APIRequestException e) {
-            LogUtil.error(logger, e, "商户账户创建短信发送失败,mobile:{0}", mobile);
-        }
-        return null;
-    }
-
-    public static SendSMSResult sendBillPayFail(String mobile) {
-        return sendSMSResult(mobile, 201476);
+    public static SendSMSResult sendChannelActNotify(String mobile) {
+        return sendSMSResult(mobile, 206374);
     }
 
-    public static SendSMSResult sendBillPayFailLastDay(String mobile) {
-        return sendSMSResult(mobile, 202305);
-    }
 
 
     private static SendSMSResult sendSMSResult(String mobile, int tempId) {
@@ -318,7 +294,7 @@ public class JSMSUtils {
     }
 
     public static void testGetAccountSMSBalance() {
-        SMSClient client = new SMSClient(devSecret, devKey);
+        SMSClient client = new SMSClient(masterSecret, appkey);
         try {
             AccountBalanceResult result = client.getSMSBalance();
             logger.info(result.toString());

+ 3 - 0
mp-service/src/main/java/com/qs/mp/channel/domain/param/ChannelParam.java

@@ -51,5 +51,8 @@ public class ChannelParam {
 	@NotNull(message = "分佣百分比不能为空")
 	@ApiModelProperty(value = "分佣百分比",required=true)
     private BigDecimal commRate;
+	
+	@ApiModelProperty(value = "父渠道ID",required=true)
+	private Long parentId;
 
 }

+ 7 - 4
mp-service/src/main/java/com/qs/mp/channel/domain/vo/ChannelVO.java

@@ -1,6 +1,8 @@
 package com.qs.mp.channel.domain.vo;
 
 import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.system.domain.SysUser;
+
 import lombok.Data;
 
 /**
@@ -9,10 +11,11 @@ import lombok.Data;
  */
 @Data
 public class ChannelVO extends Channel {
-  long siteCnt; // 经销网点数
-  long userCnt; // 经销用户数
-
+  long siteCnt;   // 经销网点数
+  long userCnt;   // 经销用户数
   String parentName; // 上级渠道名称
   
-  ChannelOperDataVO operData;
+  int childCnt;  // 子渠道数量
+  ChannelOperDataVO operData;  // 经营数据
+  SysUser sysUser;  // 关联的用户账号信息
 }

+ 13 - 3
mp-service/src/main/java/com/qs/mp/channel/service/IChannelService.java

@@ -1,11 +1,15 @@
 package com.qs.mp.channel.service;
 
 import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.channel.domain.ChannelCart;
 import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 
 import java.util.List;
 
+import org.apache.ibatis.annotations.Param;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 /**
@@ -31,10 +35,10 @@ public interface IChannelService extends IService<Channel> {
 	 * 编辑子渠道、经销商信息
 	 * 
 	 * @param channel
-	 * @param channelType channel:子渠道  site: 经销商
+	 * @param mobileChange 手机号码是否发生变更
 	 * @return
 	 */
-    public void updateChannel(Channel channel, String channelType);
+    public void updateChannel(Channel channel, boolean mobileChange);
     
     
 	/**
@@ -43,7 +47,7 @@ public interface IChannelService extends IService<Channel> {
 	 * @param channel
 	 * @return
 	 */
-	public List<ChannelVO> selectChannelVoList(Channel channel, String channelType);
+	public List<ChannelVO> selectChannelVoList(Wrapper<Channel> queryWrapper);
 	
 	/**
 	 * 根据用户ID查询渠道
@@ -53,6 +57,12 @@ public interface IChannelService extends IService<Channel> {
 	 */
 	public Channel getChannelByUserId(Long userId);
 	
+    /**
+     * 查询渠道及其子渠道经销商总数
+     * @param channelNo
+     * @return
+     */
+	public int getChannelSiteCnt(String channelNo);
 	
 	/**
 	 * 根据channelNo统计最近几天days的经营数据

+ 26 - 145
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelServiceImpl.java

@@ -1,7 +1,7 @@
 package com.qs.mp.channel.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 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.ChannelCommission;
 import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
@@ -10,10 +10,9 @@ 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.constant.UserConstants;
-import com.qs.mp.common.core.domain.AjaxResult;
 import com.qs.mp.common.enums.RoleTypeEnum;
 import com.qs.mp.common.exception.ServiceException;
+import com.qs.mp.common.jsms.JSMSUtils;
 import com.qs.mp.system.domain.SysRole;
 import com.qs.mp.system.domain.SysUser;
 import com.qs.mp.system.service.ISysRoleService;
@@ -21,11 +20,7 @@ import com.qs.mp.system.service.ISysUserService;
 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;
@@ -41,66 +36,32 @@ import org.springframework.transaction.annotation.Transactional;
 @Service
 public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> implements IChannelService {
 
-	
 	@Autowired
 	private IChannelService channelService;
-	
+
 	@Autowired
 	private IChannelUserRelService channelUserRelService;
-	
+
 	@Autowired
 	private IChannelCommissionService channelCommissionService;
-	
+
     @Autowired
     private ISysUserService userService;
-    
+
     @Autowired
     private ISysRoleService roleService;
 
 	@Override
 	@Transactional
 	public void saveChannel(Channel channel, String channelType){
-		
-		String title = channelType.equals("channel")?"渠道":"经销商";
-		// 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(title +"名称" + channel.getName() + "已存在!");
-		}
-		int mobileCount = channelService.count(
-		        new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, channel.getMobile()));
-		if(mobileCount > 0) {
-			 throw new ServiceException("手机号码" + channel.getMobile() + "已注册!");
-		}
-		// 2.校验佣金比例,不能高于其父渠道的佣金比例
-		Channel parentChannel = channelService.getById(channel.getParentId());
-		if(null != parentChannel && null != parentChannel.getCommRate()) {
-			 if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
-				 throw new ServiceException("佣金比例不能高于父渠道的佣金比例");
-			 }
-		}
-		if(channelType.equals("channel")) {
-			channel.setLevel(parentChannel.getLevel()+1);
-		}else {
-			channel.setLevel(0);
-		}
-		// 3.插入数据
-		channel.setChannelNo(parentChannel.getChannelNo()+".");
 		boolean res = channelService.save(channel);
 		if(res && null != channel.getChannelId()) {
-			channel.setChannelNo(parentChannel.getChannelNo()+"."+channel.getChannelId());
+			channel.setChannelNo(channel.getChannelNo()+channel.getChannelId());
 		    // 获取默认的角色
 		    SysRole sysRole = roleService.selectDefaultRoleByType(channelType.equals("channel")?RoleTypeEnum.CHANNEL_ROLE.getValue():RoleTypeEnum.SALESITE_ROLE.getValue());
 		    if (null == sysRole || null == sysRole.getRoleId()) {
 		      throw new ServiceException(
-		          "新增'" + title + channel.getName() + "'失败,未设置"+title+"默认角色,请联系管理员");
+		          "未设置默认角色,请联系管理员");
 		    }
 			// 生成用户
 			SysUser sysUser = new SysUser();
@@ -114,137 +75,57 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
 		    sysUser.setRoleIds(roleIds);
 			int userNum = userService.insertUser(sysUser);
 		    if (userNum == 0 || null == sysUser.getUserId()) {
-		        throw new ServiceException("新增'" + title + channel.getName() + "'失败,请联系管理员");
+		        throw new ServiceException("账号未创建失败,请联系管理员");
 		    }
 		    channel.setUserId(sysUser.getUserId());
 		    boolean ures = channelService.updateById(channel);
 		    if(!ures) {
-		    	throw new ServiceException("新增'" + title + channel.getName() + "'失败,请联系管理员");
+		    	throw new ServiceException("请联系管理员");
 		    }
 		    // 4.发送账号创建成功短信
+			JSMSUtils.sendChannelActNotify(channel.getMobile());
 		}else {
-			throw new ServiceException("新增'" + title + channel.getName() + "'失败,请联系管理员");
+			throw new ServiceException("请联系管理员");
 		}
 	}
-	
+
 
 	@Override
 	@Transactional
-	public void updateChannel(Channel channel, String channelType) {
-		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异常");
-		}
-		Long channelId = SecurityUtils.getLoginUser().getChannelId();
-		if(!oldChannel.getParentId().equals(channelId)) {
-			throw new ServiceException(title + "'" + oldChannel.getName() + "'编辑失败,非当前用户子渠道");
-		}
-		// 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("佣金比例不能高于父渠道的佣金比例");
-			 }
-		}
-		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("不能低于其子渠道的最大佣金比例");
-				 }
-			 }
-		}
+	public void updateChannel(Channel channel, boolean mobileChange) {
 	    // 4.更新入库
 		 boolean editRes = channelService.updateById(channel);
-		 if(editRes && mobileChange 
-				 && null != oldChannel.getUserId()) {
+		 if(editRes && mobileChange
+				 && null != channel.getUserId()) {
 			 SysUser sysUser = new SysUser();
-			 sysUser.setUserId(oldChannel.getUserId());
+			 sysUser.setUserId(channel.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() + "'编辑失败,请联系管理员");
+		        throw new ServiceException("更新失败,请联系管理员");
 		      }
 			 // 发送账号更新成功短信
 		 }
 	}
-	
 
 	@Override
-	public List<ChannelVO> selectChannelVoList(Channel channel, String channelType) {
-		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
-		queryWrapper.eq("t1.parent_id", channel.getParentId());
-		
-		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");
-		}
-		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 list;
+	public List<ChannelVO> selectChannelVoList(Wrapper<Channel> queryWrapper) {
+		return getBaseMapper().selectChannelVoList(queryWrapper);
 	}
-	
+
 	@Override
 	public Channel getChannelByUserId(Long userId) {
 		return getBaseMapper().selectOne(new LambdaQueryWrapper<Channel>().eq(Channel::getUserId, userId));
 	}
 
+	@Override
+	public int getChannelSiteCnt(String channelNo) {
+		return getBaseMapper().getChannelSiteCnt(channelNo);
+	}
+
 	@Override
 	public ChannelOperDataVO getChannelOperData(String channelNo, int days) {
 		ChannelOperDataVO channelOperData = new ChannelOperDataVO();

+ 1 - 1
mp-service/src/main/java/com/qs/mp/pay/service/IWalletService.java

@@ -19,7 +19,7 @@ public interface IWalletService {
    * @param money
    * @return
    */
-  JSONObject channelPay(BizTypeEnum bizType, String bizId, String openId, int money);
+  JSONObject pay(BizTypeEnum bizType, String bizId, String openId, int money);
 
   /**
    *

+ 22 - 20
mp-service/src/main/java/com/qs/mp/pay/service/impl/WalletServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.qs.mp.channel.service.IChannelOrderService;
 import com.qs.mp.common.enums.BizTypeEnum;
+import com.qs.mp.common.exception.ServiceException;
 import com.qs.mp.common.utils.DateUtils;
 import com.qs.mp.common.utils.LogUtil;
 import com.qs.mp.common.utils.StringUtils;
@@ -59,38 +60,39 @@ public class WalletServiceImpl implements IWalletService {
   private static final String PAY_RESOURCE_TYPE = "1017"; //2:微信小程序
 
   @Override
-  public JSONObject channelPay(BizTypeEnum bizType, String bizId, String openId, int money) {
+  public JSONObject pay(BizTypeEnum bizType, String bizId, String openId, int money) {
     String reqUrl = baseUrl + "/pay/payMoneyCTB";
-    JSONObject params = new JSONObject();
-    params = buildPayOrderReqData(payShopNo, paySign, money, openId);
+    JSONObject params = buildPayOrderReqData(payShopNo, paySign, money, openId);
     String result = OkHttpUtil.postJsonParams(reqUrl, params.toJSONString());
     logger.info("request params:" + params.toJSONString() + "  result:" + result);
     if (StringUtils.isBlank(result)) {
       LogUtil.error(logger, "创建充值订单接口失败");
-      return null;
+      throw new ServiceException("创建三方支付订单失败");
     }
     JSONObject resultJson = JSONObject.parseObject(result);
     String code = resultJson.getString("code");
     String orderNo = resultJson.getString("order_no");
     JSONObject data = resultJson.getJSONObject("pay_info");
     String orderstatus = resultJson.getString("orderstatus");
-    if (REQ_STATUS_SUCCESS.equalsIgnoreCase(code)) {
-      //保存订单记录
-      PayOrder payOrder = buildPayOrder(params);
-      payOrder.setOrderId(resultJson.getString("shop_order_no"));
-      payOrder.setOrderNo(orderNo);
-      payOrder.setCode(code);
-      payOrder.setBizType(bizType);
-      payOrder.setBizId(bizId);
-      payOrder.setOrderStatus(orderstatus);
-      boolean ret = payOrderService.save(payOrder);
-      if (ret) {
-        return data;
-      } else {
-        LogUtil.error(logger, "渠道支付订单数据库保存失败.");
-      }
+    String resultMsg = resultJson.getString("result");
+    if (!REQ_STATUS_SUCCESS.equalsIgnoreCase(code)) {
+      throw new ServiceException(resultMsg);
     }
-    return null;
+    //保存订单记录
+    PayOrder payOrder = buildPayOrder(params);
+    payOrder.setOrderId(resultJson.getString("shop_order_no"));
+    payOrder.setOrderNo(orderNo);
+    payOrder.setCode(code);
+    payOrder.setBizType(bizType);
+    payOrder.setBizId(bizId);
+    payOrder.setOrderStatus(orderstatus);
+    boolean ret = payOrderService.save(payOrder);
+    if (!ret) {
+      LogUtil.error(logger, "渠道支付订单数据库保存失败.");
+      throw new ServiceException("支付订单保存失败");
+    }
+    return data;
+
   }
 
   @Override