Browse Source

渠道、经销商CRUD/经营数据接口

guanglong 3 years ago
parent
commit
f4762249a7

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

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.ChannelAddr;
 import com.qs.mp.channel.domain.ChannelAddr;
 import com.qs.mp.channel.domain.param.ChannelParam;
 import com.qs.mp.channel.domain.param.ChannelParam;
+import com.qs.mp.channel.domain.param.VerifyParam;
+import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.common.core.domain.AjaxResult;
 import com.qs.mp.common.core.domain.AjaxResult;
@@ -54,12 +56,12 @@ public class ChannelController extends BaseApiController {
 	private MapperFacade mapperFacade;
 	private MapperFacade mapperFacade;
 
 
 	/**
 	/**
-	 * 子渠道列表查询
+	 * 获取我的下级渠道列表信息,支持翻页
 	 *
 	 *
 	 * @return
 	 * @return
 	 */
 	 */
 	@PostMapping("subchannel/list")
 	@PostMapping("subchannel/list")
-	public TableDataInfo list(@RequestBody Channel channel) {
+	public TableDataInfo listChannel(@RequestBody Channel channel) {
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
 		List<ChannelVO> list = new ArrayList<ChannelVO>();
 		List<ChannelVO> list = new ArrayList<ChannelVO>();
 		if(null != channelId) {
 		if(null != channelId) {
@@ -78,7 +80,7 @@ public class ChannelController extends BaseApiController {
 	 * @return
 	 * @return
 	 */
 	 */
 	@PostMapping(value = "subchannel/detail")
 	@PostMapping(value = "subchannel/detail")
-	public AjaxResult getInfo(@RequestBody Channel channel) {
+	public AjaxResult getChannelDetail(@RequestBody Channel channel) {
 		if (null == channel || null == channel.getChannelId()) {
 		if (null == channel || null == channel.getChannelId()) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
 		}
 		}
@@ -86,6 +88,9 @@ public class ChannelController extends BaseApiController {
 		ChannelVO channelVO = new ChannelVO();
 		ChannelVO channelVO = new ChannelVO();
 		Channel queryChannel = channelService.getById(channelId);
 		Channel queryChannel = channelService.getById(channelId);
 	    BeanUtils.copyProperties(queryChannel, channelVO);
 	    BeanUtils.copyProperties(queryChannel, channelVO);
+	    // 查询今日的销售额、佣金收入、新增用户数
+	    ChannelOperDataVO channelOperDataVO = channelService.getChannelOperData(channelVO.getChannelNo(), 1);
+	    channelVO.setOperData(channelOperDataVO);
 		return AjaxResult.success(channelVO);
 		return AjaxResult.success(channelVO);
 	}
 	}
 
 
@@ -96,7 +101,7 @@ public class ChannelController extends BaseApiController {
 	 */
 	 */
 	@ApiOperation(value = "新增子渠道信息", notes = "渠道端新增子渠道")
 	@ApiOperation(value = "新增子渠道信息", notes = "渠道端新增子渠道")
 	@PostMapping("subchannel/create")
 	@PostMapping("subchannel/create")
-	public AjaxResult addChannel(@Validated @RequestBody ChannelParam channelParam) {
+	public AjaxResult channelCreate(@Validated @RequestBody ChannelParam channelParam) {
 		if (channelParam.getChannelId() != null && channelParam.getChannelId() != 0) {
 		if (channelParam.getChannelId() != null && channelParam.getChannelId() != 0) {
 			return AjaxResult.error("该渠道已存在");
 			return AjaxResult.error("该渠道已存在");
 		}
 		}
@@ -119,7 +124,7 @@ public class ChannelController extends BaseApiController {
 	 */
 	 */
 	@ApiOperation(value = "编辑子渠道信息", notes = "渠道端编辑子渠道")
 	@ApiOperation(value = "编辑子渠道信息", notes = "渠道端编辑子渠道")
 	@PostMapping("subchannel/update")
 	@PostMapping("subchannel/update")
-	public AjaxResult editChannel(@Validated @RequestBody ChannelParam channelParam) {
+	public AjaxResult channelUpdate(@Validated @RequestBody ChannelParam channelParam) {
 
 
 		if (null == channelParam || null == channelParam.getChannelId()) {
 		if (null == channelParam || null == channelParam.getChannelId()) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
@@ -132,5 +137,213 @@ public class ChannelController extends BaseApiController {
 		}
 		}
 		return AjaxResult.success("编辑子渠道信息'" + channel.getName() + "'成功");
 		return AjaxResult.success("编辑子渠道信息'" + channel.getName() + "'成功");
 	}
 	}
+	
+	
+	/**
+	 *获取当前用户渠道或者某个子渠道的经营数据
+	 *
+	 * @param
+	 * @return
+	 */
+	@PostMapping(value = "subchannel/operdata/query")
+	public AjaxResult getOperData(@RequestBody JSONObject jsonObject) {
+		if (null == jsonObject) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		int days = jsonObject.getIntValue("days");;
+		if(StringUtils.isNotBlank(jsonObject.getString("channelId"))) {
+			channelId = jsonObject.getLong("channelId");
+		}
+		days = days > 0?days:1;
+		days = days > 0?days:1;
+		Channel channel = channelService.getById(channelId);
+	    // 查询今日的销售额、佣金收入、新增用户数
+	    ChannelOperDataVO channelOperDataVO = channelService.getChannelOperData(channel.getChannelNo(), 1);
+		return AjaxResult.success(channelOperDataVO);
+	}
+	
+	/**
+	 * 获取子渠道的经营数据列表
+	 *
+	 * @param
+	 * @return
+	 */
+	@PostMapping(value = "subchannel/operdata/list")
+	public TableDataInfo getOperDataList(@RequestBody JSONObject jsonObject) {
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		int days = jsonObject.getIntValue("days");;
+		if(StringUtils.isNotBlank(jsonObject.getString("channelId"))) {
+			channelId = jsonObject.getLong("channelId");
+		}
+		days = days > 0?days:1;
+		List<Channel> list = channelService.list(
+		        new LambdaQueryWrapper<Channel>().eq(Channel::getParentId, channelId)
+		            .orderByDesc(Channel::getChannelId));
+		
+		List<ChannelOperDataVO> dataList = new ArrayList<ChannelOperDataVO>();
+		if(null != list && list.size() > 0) {
+			for(Channel channel : list) {
+				if(null != channel && null != channel.getChannelNo()) {
+				    // 查询今日的销售额、佣金收入、新增用户数
+				    ChannelOperDataVO channelOperDataVO = channelService.getChannelOperData(channel.getChannelNo(), days);
+				    if(null != channelOperDataVO) {
+				    	channelOperDataVO.setName(channel.getName());
+				    	dataList.add(channelOperDataVO);
+				    }
+				}
+			}
+		}
+		return getDataTable(dataList);
+	}
+	
+	
+	/**
+	 * 获取我的经销商列表信息,支持翻页
+	 *
+	 * @return
+	 */
+	@PostMapping("site/list")
+	public TableDataInfo listSite(@RequestBody Channel channel) {
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		List<ChannelVO> list = new ArrayList<ChannelVO>();
+		if(null != channelId) {
+			channel.setParentId(channelId);
+			startPage();
+			// List<Channel> list = channelService.list(new LambdaQueryWrapper<Channel>());
+			list = channelService.selectSiteVoList(channel);
+		}
+		return getDataTable(list);
+	}
+
+	/**
+	 * 获取我的下级渠道详情信息
+	 *
+	 * @param
+	 * @return
+	 */
+	@PostMapping(value = "site/detail")
+	public AjaxResult getSiteDetail(@RequestBody Channel channel) {
+		if (null == channel || null == channel.getChannelId()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		Long channelId = channel.getChannelId();
+		ChannelVO channelVO = new ChannelVO();
+		Channel queryChannel = channelService.getById(channelId);
+	    BeanUtils.copyProperties(queryChannel, channelVO);
+	    // 查询今日的销售额、佣金收入、新增用户数
+	    ChannelOperDataVO channelOperDataVO = channelService.getChannelOperData(channelVO.getChannelNo(), 1);
+	    channelVO.setOperData(channelOperDataVO);
+		return AjaxResult.success(channelVO);
+	}
+
+	/**
+	 * 新增经销商信息
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "渠道端新增经销商", notes = "渠道端新增经销商")
+	@PostMapping("site/create")
+	public AjaxResult siteCreate(@Validated @RequestBody ChannelParam channelParam) {
+		if (channelParam.getChannelId() != null && channelParam.getChannelId() != 0) {
+			return AjaxResult.error("该经销商已存在");
+		}
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
 
 
+		Channel channel = mapperFacade.map(channelParam, Channel.class);
+		channel.setParentId(channelId);
+		try {
+			channelService.saveSite(channel);
+		} catch (Exception e) {
+			return AjaxResult.error("新增经销商信息'" + channel.getName() + "'失败");
+		}
+		return AjaxResult.success("新增经销商信息'" + channel.getName() + "'成功");
+	}
+
+	/**
+	 * 编辑经销商信息
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "编辑经销商信息", notes = "渠道端编辑经销商")
+	@PostMapping("site/update")
+	public AjaxResult siteUpdate(@Validated @RequestBody ChannelParam channelParam) {
+
+		if (null == channelParam || null == channelParam.getChannelId()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		Channel channel = mapperFacade.map(channelParam, Channel.class);
+		try {
+			channelService.updateSite(channel);
+		} catch (Exception e) {
+			return AjaxResult.error("编辑经销商信息'" + channel.getName() + "'失败");
+		}
+		return AjaxResult.success("编辑经销商信息'" + channel.getName() + "'成功");
+	}
+	
+	
+	/**
+	 * 经销商认证审核
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "经销商认证审核", notes = "经销商认证审核")
+	@PostMapping("site/verify")
+	public AjaxResult siteVerify(@RequestBody Channel channel) {
+
+		if (null == channel || null == channel.getChannelId() || null == channel.getVerifyStatus()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		try {
+			channelService.updateById(channel);
+		} catch (Exception e) {
+			return AjaxResult.error("经销商'" + channel.getName() + "'认证审核失败");
+		}
+		return AjaxResult.success("经销商'" + channel.getName() + "'认证审核成功");
+	}
+	
+	/**
+	 * 经销商认证页面点提交
+	 * @param
+	 * @return
+	 */
+	@ApiOperation(value = "经销商认证信息提交", notes = "经销商认证页面点提交")
+	@PostMapping("site/verify/submit")
+	public AjaxResult siteVerifySubmit(@Validated @RequestBody VerifyParam verifyParam) {
+
+		if (null == verifyParam || null == verifyParam.getChannelId()) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		Channel channel = mapperFacade.map(verifyParam, Channel.class);
+		try {
+			channelService.updateById(channel);
+		} catch (Exception e) {
+			return AjaxResult.error("经销商'" + channel.getName() + "'提交认证信息失败");
+		}
+		return AjaxResult.success("经销商'" + channel.getName() + "'提交认证信息成功");
+	}
+	
+	
+	/**
+	 * 查看我的渠道信息
+	 *
+	 * @param
+	 * @return
+	 */
+	@PostMapping(value = "min/detail")
+	@ApiOperation(value = "查看我的渠道信息", notes = "渠道端我的里面点击佣金比例")
+	public AjaxResult getMinInfo() {
+		
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		if (null == channelId) {
+			return error(ErrorCodeEnum.ERROR_CODE_1001);
+		}
+		ChannelVO channelVO = new ChannelVO();
+		Channel queryChannel = channelService.getById(channelId);
+	    BeanUtils.copyProperties(queryChannel, channelVO);
+	    // 查询今日的销售额、佣金收入、新增用户数
+	    Channel parentChannel = channelService.getById(queryChannel.getParentId());
+	    channelVO.setParentName(parentChannel.getName());
+		return AjaxResult.success(channelVO);
+	}
 }
 }

+ 52 - 0
mp-common/src/main/java/com/qs/mp/common/exception/DataOperationException.java

@@ -0,0 +1,52 @@
+package com.qs.mp.common.exception;
+
+import com.qs.mp.common.enums.ErrorCodeEnum;
+
+/**
+ * 
+ * 数据库接口访问异常,所有涉及到service事物调用接口都统一抛异常为失败操作。
+ * 
+ * @author duota
+ *
+ */
+public class DataOperationException extends RuntimeException {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+
+    protected final int code;
+    protected final String message;
+
+    public DataOperationException() {
+        this.code = 1001; // 系统错误
+        this.message = "数据操作失败.";
+    }
+
+    public DataOperationException(ErrorCodeEnum errorCodeEnum){
+        this.code = errorCodeEnum.getCode();
+        this.message = errorCodeEnum.getMsg();
+    }
+
+    public DataOperationException(int code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public DataOperationException(int code, String message, Throwable e) {
+        super(message, e);
+        this.code = code;
+        this.message = message;
+    }
+
+    @Override
+    public String getMessage() {
+        return message;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+}

+ 66 - 0
mp-service/src/main/java/com/qs/mp/channel/domain/param/VerifyParam.java

@@ -0,0 +1,66 @@
+package com.qs.mp.channel.domain.param;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+
+import javax.validation.constraints.NotNull;
+
+import com.qs.mp.common.enums.SiteTypeEnum;
+
+import lombok.Data;
+
+@ApiModel(value= "地址参数")
+@Data
+public class VerifyParam {
+
+	@NotNull(message = "渠道ID不能为空")
+	@ApiModelProperty(value = "渠道ID",required=true)
+	private Long channelId;
+
+	@NotNull(message = "联系人不能为空")
+	@ApiModelProperty(value = "联系人",required=true)
+	private String contact;
+	
+	@NotNull(message = "门店类型不能为空")
+	@ApiModelProperty(value = "门店类型",required=true)
+	private SiteTypeEnum siteType;
+
+	@NotNull(message = "省ID不能为空")
+	@ApiModelProperty(value = "省ID",required=true)
+	private Long provinceId;
+
+	@NotNull(message = "城市ID不能为空")
+	@ApiModelProperty(value = "城市ID",required=true)
+	private Long cityId;
+
+	@NotNull(message = "区ID不能为空")
+	@ApiModelProperty(value = "区ID",required=true)
+	private Long areaId;
+
+	@NotNull(message = "省不能为空")
+	@ApiModelProperty(value = "省",required=true)
+	private String province;
+
+	@NotNull(message = "城市不能为空")
+	@ApiModelProperty(value = "城市",required=true)
+	private String city;
+
+	@NotNull(message = "区不能为空")
+	@ApiModelProperty(value = "区",required=true)
+	private String area;
+	
+	@NotNull(message = "详细地址不能为空")
+	@ApiModelProperty(value = "详细地址",required=true)
+	private String address;
+
+	@NotNull(message = "营业执照不能为空")
+	@ApiModelProperty(value = "营业执照",required=true)
+	private String bizLicensePic;
+	
+	@NotNull(message = "门店照片不能为空")
+	@ApiModelProperty(value = "门店照片",required=true)
+	private String doorPic;
+
+}

+ 10 - 0
mp-service/src/main/java/com/qs/mp/channel/mapper/ChannelCommissionMapper.java

@@ -1,6 +1,9 @@
 package com.qs.mp.channel.mapper;
 package com.qs.mp.channel.mapper;
 
 
 import com.qs.mp.channel.domain.ChannelCommission;
 import com.qs.mp.channel.domain.ChannelCommission;
+
+import org.apache.ibatis.annotations.Param;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 
 /**
 /**
@@ -10,4 +13,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
  */
 public interface ChannelCommissionMapper extends BaseMapper<ChannelCommission> {
 public interface ChannelCommissionMapper extends BaseMapper<ChannelCommission> {
 
 
+	/**
+	 * 根据渠道No查询渠道的经营数据
+	 * @param channelNo
+	 * @param days
+	 * @return
+	 */
+	public ChannelCommission getChannelCommissionCnt(@Param("channelNo") String channelNo,@Param("days") int days);
 }
 }

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

@@ -19,4 +19,11 @@ public interface ChannelUserRelMapper extends BaseMapper<ChannelUserRel> {
      * @return
      * @return
      */
      */
     int getChannelUserCnt(@Param("channelNo") String channelNo);
     int getChannelUserCnt(@Param("channelNo") String channelNo);
+    
+	/**
+	 * 根据渠道No查询渠道指定时间内新增的用户数量
+	 * @param channelNo
+	 * @return
+	 */
+	int getChannelUserCnt(@Param("channelNo") String channelNo, @Param("days") int days);
 }
 }

+ 6 - 0
mp-service/src/main/java/com/qs/mp/channel/service/IChannelCommissionService.java

@@ -13,4 +13,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
  */
 public interface IChannelCommissionService extends IService<ChannelCommission> {
 public interface IChannelCommissionService extends IService<ChannelCommission> {
 
 
+	/**
+	 * 根据渠道No查询渠道的经营数据
+	 * @param channelNo
+	 * @return
+	 */
+	public ChannelCommission getChannelCommissionCnt(String channelNo, int days);
 }
 }

+ 34 - 1
mp-service/src/main/java/com/qs/mp/channel/service/IChannelService.java

@@ -1,6 +1,7 @@
 package com.qs.mp.channel.service;
 package com.qs.mp.channel.service;
 
 
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 
 
 import java.util.List;
 import java.util.List;
@@ -26,6 +27,14 @@ public interface IChannelService extends IService<Channel> {
 	 */
 	 */
     public void saveChannel(Channel channel) throws Exception;
     public void saveChannel(Channel channel) throws Exception;
     
     
+	/**
+	 * 新增经销商
+	 * 
+	 * @param channel
+	 * @return
+	 */
+    public void saveSite(Channel channel) throws Exception;
+    
     
     
     /**
     /**
 	 * 编辑子渠道信息
 	 * 编辑子渠道信息
@@ -35,6 +44,16 @@ public interface IChannelService extends IService<Channel> {
 	 */
 	 */
     public void updateChannel(Channel channel) throws Exception;
     public void updateChannel(Channel channel) throws Exception;
     
     
+    
+    /**
+	 * 编辑经销商
+	 * 
+	 * @param channel
+	 * @return
+	 */
+    public void updateSite(Channel channel) throws Exception;
+    
+    
 
 
 	/**
 	/**
 	 * 获取我的下级渠道列表信息,支持翻页
 	 * 获取我的下级渠道列表信息,支持翻页
@@ -43,6 +62,14 @@ public interface IChannelService extends IService<Channel> {
 	 * @return
 	 * @return
 	 */
 	 */
 	public List<ChannelVO> selectChannelVoList(Channel channel);
 	public List<ChannelVO> selectChannelVoList(Channel channel);
+	
+	/**
+	 * 获取我的经销商列表信息,支持翻页
+	 * 
+	 * @param channel
+	 * @return
+	 */
+	public List<ChannelVO> selectSiteVoList(Channel channel);
 
 
 	/**
 	/**
 	 * 根据用户ID查询渠道
 	 * 根据用户ID查询渠道
@@ -50,5 +77,11 @@ public interface IChannelService extends IService<Channel> {
 	 * @param userId
 	 * @param userId
 	 * @return
 	 * @return
 	 */
 	 */
-	Channel getChannelByUserId(Long userId);
+	public Channel getChannelByUserId(Long userId);
+	
+	
+	/**
+	 * 根据channelNo统计最近几天days的经营数据
+	 */
+	public ChannelOperDataVO getChannelOperData(String channelNo, int days);
 }
 }

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

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

+ 4 - 0
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelCommissionServiceImpl.java

@@ -17,4 +17,8 @@ import org.springframework.stereotype.Service;
 @Service
 @Service
 public class ChannelCommissionServiceImpl extends ServiceImpl<ChannelCommissionMapper, ChannelCommission> implements IChannelCommissionService {
 public class ChannelCommissionServiceImpl extends ServiceImpl<ChannelCommissionMapper, ChannelCommission> implements IChannelCommissionService {
 
 
+	@Override
+	public ChannelCommission getChannelCommissionCnt(String channelNo, int days) {
+		return getBaseMapper().getChannelCommissionCnt(channelNo, days == 1?0: (~(days - 1)));
+	}
 }
 }

+ 130 - 4
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelServiceImpl.java

@@ -3,9 +3,18 @@ package com.qs.mp.channel.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.channel.domain.ChannelAddr;
+import com.qs.mp.channel.domain.ChannelCommission;
+import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.mapper.ChannelMapper;
 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.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.exception.ServiceException;
+import com.qs.mp.system.domain.SysUser;
 import com.qs.mp.system.service.ISysUserService;
 import com.qs.mp.system.service.ISysUserService;
 import com.qs.mp.system.service.id.BizIdGenerator;
 import com.qs.mp.system.service.id.BizIdGenerator;
 import com.qs.mp.utils.SecurityUtils;
 import com.qs.mp.utils.SecurityUtils;
@@ -28,9 +37,16 @@ import org.springframework.transaction.annotation.Transactional;
 @Service
 @Service
 public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> implements IChannelService {
 public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> implements IChannelService {
 
 
+	
 	@Autowired
 	@Autowired
 	private IChannelService channelService;
 	private IChannelService channelService;
 	
 	
+	@Autowired
+	private IChannelUserRelService channelUserRelService;
+	
+	@Autowired
+	private IChannelCommissionService channelCommissionService;
+	
     @Autowired
     @Autowired
     private ISysUserService userService;
     private ISysUserService userService;
 
 
@@ -41,12 +57,87 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
 	@Transactional
 	@Transactional
 	public void saveChannel(Channel channel) throws Exception {
 	public void saveChannel(Channel channel) throws Exception {
 		// 1、校验名称是否重复、手机号是否存在(渠道表)
 		// 1、校验名称是否重复、手机号是否存在(渠道表)
-		
+		int nameCount = channelService.count(
+		        new LambdaQueryWrapper<Channel>().eq(Channel::getName, channel.getName()).gt(Channel::getLevel, 1));
+		if(nameCount > 0) {
+			 throw new ServiceException("渠道名称" + channel.getName() + "已存在!");
+		}
+		int mobileCount = channelService.count(
+		        new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, channel.getMobile()));
+		if(mobileCount > 0) {
+			 throw new ServiceException("手机号码" + channel.getMobile() + "已注册!");
+		}
 		// 2.校验佣金比例,不能高于其父渠道的佣金比例
 		// 2.校验佣金比例,不能高于其父渠道的佣金比例
-		
+		Channel parentChannel = channelService.getById(channel.getParentId());
+		if(null != parentChannel && null != parentChannel.getCommRate()) {
+			 if(channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
+				 throw new ServiceException("渠道佣金比例不能高于父渠道的佣金比例");
+			 }
+		}
+		channel.setLevel(parentChannel.getLevel()+1);
 		// 3.插入数据
 		// 3.插入数据
-		
-		// 4.发送账号创建成功短信
+		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.发送账号创建成功短信
+		}
+	}
+	
+	
+	@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() + "已存在!");
+		}
+		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("经销商佣金比例不能高于父渠道的佣金比例");
+			 }
+		}
+		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.发送账号创建成功短信
+		}
 	}
 	}
 	
 	
 
 
@@ -61,16 +152,51 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
 		
 		
 	    // 4.更新入库
 	    // 4.更新入库
 	}
 	}
+	
+	@Override
+	public void updateSite(Channel channel) throws Exception {
+		// 1、校验修改子渠道是否为当前用户的子渠道
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		
+		// 2.校验名称是否重复、手机号是否存在(渠道表);
+		
+		// 3.校验佣金比例,不能高于其父渠道的佣金比例,不能低于其子渠道的最大佣金比例
+		
+	    // 4.更新入库
+	}
 
 
 	@Override
 	@Override
 	public List<ChannelVO> selectChannelVoList(Channel channel) {
 	public List<ChannelVO> selectChannelVoList(Channel channel) {
 		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
 		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
 		queryWrapper.eq("t1.parent_id", channel.getParentId());
 		queryWrapper.eq("t1.parent_id", channel.getParentId());
+		queryWrapper.gt("t1.level", 0);
 		return getBaseMapper().selectChannelVoList(queryWrapper);
 		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);
+		return getBaseMapper().selectSiteVoList(queryWrapper);
+	}
 
 
 	@Override
 	@Override
 	public Channel getChannelByUserId(Long userId) {
 	public Channel getChannelByUserId(Long userId) {
 		return getBaseMapper().selectOne(new LambdaQueryWrapper<Channel>().eq(Channel::getUserId, userId));
 		return getBaseMapper().selectOne(new LambdaQueryWrapper<Channel>().eq(Channel::getUserId, userId));
 	}
 	}
+
+
+	@Override
+	public ChannelOperDataVO getChannelOperData(String channelNo, int days) {
+		ChannelOperDataVO channelOperData = new ChannelOperDataVO();
+		ChannelCommission channelCommission = channelCommissionService.getChannelCommissionCnt(channelNo, days);
+		if(null != channelCommission) {
+			channelOperData.setSaleAmt(channelCommission.getSaleAmt());
+			channelOperData.setCommAmt(channelCommission.getCommAmt());
+		}
+		int newUserCnt = channelUserRelService.getChannelUserCnt(channelNo, days);
+		channelOperData.setNewUserCnt(newUserCnt);
+		return channelOperData;
+	}
 }
 }

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

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

+ 12 - 0
mp-service/src/main/resources/mapper/channel/ChannelCommissionMapper.xml

@@ -21,5 +21,17 @@
     <sql id="Base_Column_List">
     <sql id="Base_Column_List">
         id, channel_id, order_id, ticket_id, sale_amt, sale_comm_rate, sale_comm_amt, comm_rate, comm_amt, created_time, updated_time
         id, channel_id, order_id, ticket_id, sale_amt, sale_comm_rate, sale_comm_amt, comm_rate, comm_amt, created_time, updated_time
     </sql>
     </sql>
+    
+    
+      <!-- 查询子渠道信息 -->
+    <select id="getChannelCommissionCnt" resultMap="BaseResultMap">
+		select IFNULL(SUM(t1.sale_amt),0) sale_amt, IFNULL(SUM(t1.comm_amt),0) comm_amt
+		from mp_channel_commission t1
+		left join mp_channel t2 on t1.channel_id = t2.channel_id
+		where t2.channel_no like concat(#{channelNo},'.%')
+		and date_format(t1.created_time,'%Y-%m-%d') between date_format(DATE_ADD(CURDATE(),INTERVAL #{days} DAY),'%Y-%m-%d') 
+		and date_format(CURDATE(),'%Y-%m-%d')
+	</select>
+    
 
 
 </mapper>
 </mapper>

+ 44 - 2
mp-service/src/main/resources/mapper/channel/ChannelMapper.xml

@@ -33,7 +33,7 @@
     </resultMap>
     </resultMap>
 
 
     <!-- 通用查询VO映射结果 -->
     <!-- 通用查询VO映射结果 -->
-    <resultMap id="VoResultMap" type="com.qs.mp.channel.domain.vo.ChannelVO">
+    <resultMap id="ChannelVoResultMap" type="com.qs.mp.channel.domain.vo.ChannelVO">
         <id column="channel_id" property="channelId" />
         <id column="channel_id" property="channelId" />
         <result column="channel_no" property="channelNo" />
         <result column="channel_no" property="channelNo" />
         <result column="name" property="name" />
         <result column="name" property="name" />
@@ -64,6 +64,39 @@
         <association property="siteCnt" javaType="java.lang.Integer" select="getChannelSiteCnt" column="{channelNo=channelNo}" />
         <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}" />
         <association property="userCnt" javaType="java.lang.Integer" select="com.qs.mp.channel.mapper.ChannelUserRelMapper.getChannelUserCnt" column="{channelNo=channelNo}" />
     </resultMap>
     </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>
 
 
     <!-- 通用查询结果列 -->
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
     <sql id="Base_Column_List">
@@ -71,7 +104,16 @@
     </sql>
     </sql>
 
 
     <!-- 查询子渠道信息 -->
     <!-- 查询子渠道信息 -->
-    <select id="selectChannelVoList" resultMap="VoResultMap">
+    <select id="selectChannelVoList" resultMap="ChannelVoResultMap">
+		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 a.channel_id desc
+	</select>
+	
+	 <!-- 查询子经销商信息 -->
+    <select id="selectSiteVoList" resultMap="SiteVoResultMap">
 		select t1.* , t2.name parentName
 		select t1.* , t2.name parentName
 		from mp_channel t1
 		from mp_channel t1
 		left join mp_channel t2 on t1.parent_id = t2.channel_id
 		left join mp_channel t2 on t1.parent_id = t2.channel_id

+ 3 - 2
mp-service/src/main/resources/mapper/channel/ChannelUserRelMapper.xml

@@ -22,8 +22,9 @@
 		from mp_channel_user_rel t1
 		from mp_channel_user_rel t1
 		left join mp_channel t2 on t1.channel_id = t2.channel_id
 		left join mp_channel t2 on t1.channel_id = t2.channel_id
 		where t2.channel_no like concat(#{channelNo}, '.%')
 		where t2.channel_no like concat(#{channelNo}, '.%')
+		<if test="days != null and days != ''">
+			AND date_format(t1.created_time,'%Y-%m-%d') between date_format(DATE_ADD(CURDATE(),INTERVAL #{days} DAY),'%Y-%m-%d') and date_format(CURDATE(),'%Y-%m-%d')
+		 </if>
     </select>
     </select>
-    
-    
 
 
 </mapper>
 </mapper>