|
@@ -4,8 +4,13 @@ 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.ChannelOrder;
|
|
|
+import com.qs.mp.channel.domain.ChannelUserRel;
|
|
|
import com.qs.mp.channel.domain.param.ChannelParam;
|
|
|
+import com.qs.mp.channel.domain.param.SaleSiteParam;
|
|
|
+import com.qs.mp.channel.domain.vo.ChannelOperDataVO;
|
|
|
import com.qs.mp.channel.domain.vo.ChannelVO;
|
|
|
+import com.qs.mp.channel.service.IChannelOrderService;
|
|
|
import com.qs.mp.channel.service.IChannelService;
|
|
|
import com.qs.mp.channel.service.IChannelUserRelService;
|
|
|
import com.qs.mp.common.constant.UserConstants;
|
|
@@ -37,9 +42,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
/**
|
|
|
* @auther zhongcp
|
|
|
* @create 2022-02-28 16:17:48
|
|
|
- * @describe 渠道管理前端控制器
|
|
|
+ * @describe 经销商管理前端控制器
|
|
|
*/
|
|
|
-@Api("渠道管理API")
|
|
|
+@Api("经销商管理API")
|
|
|
@RestController
|
|
|
@RequestMapping("/api/v1/mp/admin/salesite/*")
|
|
|
@Component
|
|
@@ -51,6 +56,9 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
@Autowired
|
|
|
private IChannelUserRelService channelUserRelService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IChannelOrderService channelOrderService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ISysUserService userService;
|
|
|
|
|
@@ -82,9 +90,10 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
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.getChannelTotalUserCnt(channelVO.getChannelNo());
|
|
|
- channelVO.setSiteCnt(siteCnt);
|
|
|
+ // int siteCnt = channelService.getChannelSiteCnt(channelVO.getChannelNo());
|
|
|
+ LambdaQueryWrapper<ChannelUserRel> userCntQueryWrapper = new LambdaQueryWrapper<ChannelUserRel>();
|
|
|
+ userCntQueryWrapper.eq(ChannelUserRel::getChannelId, channelVO.getChannelId());
|
|
|
+ int userCnt = channelUserRelService.count(userCntQueryWrapper);
|
|
|
channelVO.setUserCnt(userCnt);
|
|
|
// 查询用户信息
|
|
|
//SysUser sysUser = userService.selectUserById(channelVO.getUserId());
|
|
@@ -101,38 +110,38 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation(value = "新增经销商信息", notes = "渠道端新增经销商")
|
|
|
+ @ApiOperation(value = "新增经销商信息", notes = "经销商端新增经销商")
|
|
|
@PostMapping("/create")
|
|
|
- public AjaxResult channelCreate(@Validated @RequestBody ChannelParam channelParam) {
|
|
|
+ public AjaxResult channelCreate(@Validated @RequestBody SaleSiteParam channelParam) {
|
|
|
if (channelParam.getChannelId() != null && channelParam.getChannelId() != 0) {
|
|
|
return AjaxResult.error("该经销商已存在");
|
|
|
}
|
|
|
Channel channel = mapperFacade.map(channelParam, Channel.class);
|
|
|
- // 1、校验名称是否重复、手机号是否存在(渠道表)
|
|
|
+ // 1、校验名称是否重复、手机号是否存在(经销商表)
|
|
|
LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(Channel::getName, channel.getName());
|
|
|
- queryWrapper.gt(Channel::getLevel, 1);
|
|
|
+ queryWrapper.eq(Channel::getLevel, 0);
|
|
|
int nameCount = channelService.count(queryWrapper);
|
|
|
if(nameCount > 0) {
|
|
|
- return AjaxResult.error("渠道名称" + channel.getName() + "已存在!");
|
|
|
+ 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.校验佣金比例,不能高于其父渠道的佣金比例
|
|
|
+ // 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("佣金比例不能高于父渠道的佣金比例");
|
|
|
+ return AjaxResult.error("佣金比例不能高于父经销商的佣金比例");
|
|
|
}
|
|
|
channel.setLevel(parentChannel.getLevel()+1);
|
|
|
channel.setChannelNo(parentChannel.getChannelNo()+".");
|
|
|
}else {
|
|
|
- return AjaxResult.error("父渠道不存在");
|
|
|
+ return AjaxResult.error("父经销商不存在");
|
|
|
}
|
|
|
|
|
|
}else {
|
|
@@ -161,16 +170,16 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
}
|
|
|
Channel channel = mapperFacade.map(channelParam, Channel.class);
|
|
|
- // 1、校验修改子渠道是否为当前用户的子渠道
|
|
|
+ // 1、校验修改子经销商是否为当前用户的子经销商
|
|
|
Channel oldChannel = channelService.getById(channel.getChannelId());
|
|
|
if(null == oldChannel || null == oldChannel.getChannelId()) {
|
|
|
return AjaxResult.error("经销商'" + oldChannel.getName() + "'编辑失败,ID异常");
|
|
|
}
|
|
|
- // 2.校验名称是否重复、手机号是否存在(渠道表);
|
|
|
+ // 2.校验名称是否重复、手机号是否存在(经销商表);
|
|
|
if(!channel.getName().equals(oldChannel.getName())) {
|
|
|
LambdaQueryWrapper<Channel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(Channel::getName, channel.getName());
|
|
|
- queryWrapper.gt(Channel::getLevel, 1);
|
|
|
+ queryWrapper.eq(Channel::getLevel, 0);
|
|
|
int nameCount = channelService.count(queryWrapper);
|
|
|
if(nameCount > 0) {
|
|
|
return AjaxResult.error("经销商名称" + channel.getName() + "已存在!");
|
|
@@ -188,17 +197,17 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
}
|
|
|
mobileChange = true;
|
|
|
}
|
|
|
- // 3.校验佣金比例,不能高于其父渠道的佣金比例,不能低于其子渠道的最大佣金比例
|
|
|
+ // 3.校验佣金比例,不能高于其父经销商的佣金比例,不能低于其子经销商的最大佣金比例
|
|
|
Channel parentChannel = channelService.getById(oldChannel.getParentId());
|
|
|
if(null != parentChannel) {
|
|
|
if(null != parentChannel.getCommRate()
|
|
|
&& channel.getCommRate().compareTo(parentChannel.getCommRate()) > 0) {
|
|
|
- return AjaxResult.error("佣金比例不能高于父渠道的佣金比例");
|
|
|
+ return AjaxResult.error("佣金比例不能高于父经销商的佣金比例");
|
|
|
}
|
|
|
channel.setLevel(parentChannel.getLevel()+1);
|
|
|
channel.setChannelNo(parentChannel.getChannelNo()+".");
|
|
|
}else {
|
|
|
- return AjaxResult.error("父渠道不存在");
|
|
|
+ return AjaxResult.error("父经销商不存在");
|
|
|
}
|
|
|
try {
|
|
|
channelService.updateChannel(channel, mobileChange);
|
|
@@ -225,7 +234,7 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
}
|
|
|
try {
|
|
|
channelService.lambdaUpdate().set(Channel::getStatus, status).eq(Channel::getChannelId, channelId).update();
|
|
|
- // 查询渠道信息
|
|
|
+ // 查询经销商信息
|
|
|
// Channel channel = channelService.getById(channelId);
|
|
|
// if(null != channel && null != channel.getUserId()) {
|
|
|
// SysUser sysUser = new SysUser();
|
|
@@ -239,4 +248,38 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
return AjaxResult.success("操作成功");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询经销商详情
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询经销商详情信息", notes = "经销商管理编辑子经销商查询经销商详情")
|
|
|
+ @PostMapping("/detail")
|
|
|
+ public AjaxResult getChannelDetail(@RequestBody JSONObject jsonObject) {
|
|
|
+ String channelId = (null != jsonObject && jsonObject.containsKey("channelId"))?jsonObject.getString("channelId"):"";
|
|
|
+ if (StringUtils.isBlank(channelId)) {
|
|
|
+ return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
+ }
|
|
|
+ ChannelVO channelVO = channelService.getChannelVoById(Long.valueOf(channelId));
|
|
|
+ if(null == channelVO || null == channelVO.getChannelId()) {
|
|
|
+ return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
+ }
|
|
|
+ if(null != channelVO && StringUtils.isNotBlank(channelVO.getChannelNo())) {
|
|
|
+ // int siteCnt = channelService.getChannelSiteCnt(channelVO.getChannelNo());
|
|
|
+ LambdaQueryWrapper<ChannelUserRel> userCntQueryWrapper = new LambdaQueryWrapper<ChannelUserRel>();
|
|
|
+ userCntQueryWrapper.eq(ChannelUserRel::getChannelId, channelVO.getChannelId());
|
|
|
+ int userCnt = channelUserRelService.count(userCntQueryWrapper);
|
|
|
+ channelVO.setUserCnt(userCnt);
|
|
|
+ }
|
|
|
+ // 查询经销商销售额、佣金收入、订单数等
|
|
|
+ ChannelOperDataVO channelOperDataVO = channelService.getChannelTotalOperData(channelVO.getChannelNo());
|
|
|
+ LambdaQueryWrapper<ChannelOrder> queryWrapper = new LambdaQueryWrapper<ChannelOrder>();
|
|
|
+ queryWrapper.eq(ChannelOrder::getChannelId, channelId);
|
|
|
+ int orderCnt = channelOrderService.count(queryWrapper);
|
|
|
+ channelOperDataVO.setOrderCnt(orderCnt);
|
|
|
+ channelVO.setOperData(channelOperDataVO);
|
|
|
+ return AjaxResult.success(channelVO);
|
|
|
+ }
|
|
|
+
|
|
|
}
|