|
@@ -28,9 +28,11 @@ import com.qs.mp.common.enums.BusinessType;
|
|
|
import com.qs.mp.common.enums.ChannelRoleEnum;
|
|
|
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.user.service.IUserTicketOrderService;
|
|
|
import com.qs.mp.utils.ExcelUtil;
|
|
|
+import com.qs.mp.utils.SecurityUtils;
|
|
|
import com.qs.mp.web.controller.common.BaseApiController;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -38,6 +40,7 @@ import io.swagger.annotations.ApiResponse;
|
|
|
import io.swagger.annotations.ApiResponses;
|
|
|
import ma.glasnost.orika.MapperFacade;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
@@ -438,19 +441,67 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
return AjaxResult.success("经销商'" + channel.getName() + "'新增成功");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * parentId必传
|
|
|
+ * @param saleSiteEditParam
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@PreAuthorize("@ss.hasPermi('business:salesite:edit')")
|
|
|
@ApiOperation("修改门店信息")
|
|
|
@PostMapping("/edit")
|
|
|
public AjaxResult edit(@RequestBody SaleSiteEditParam saleSiteEditParam) {
|
|
|
+ boolean mobileChange = false; // 手机号码是否有变更
|
|
|
Channel channel = channelService.getById(saleSiteEditParam.getChannelId());
|
|
|
if (channel == null) {
|
|
|
return AjaxResult.error("门店信息不存在");
|
|
|
}
|
|
|
+ //手机号是否重复校验
|
|
|
+ if (!saleSiteEditParam.getMobile().equals(channel.getMobile())) {
|
|
|
+ mobileChange = true;
|
|
|
+ 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() + "已注册!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //校验佣金比例,不能高于其父经销商的佣金比例
|
|
|
+ Channel parentChannel = channelService.getById(saleSiteEditParam.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("父经销商不存在");
|
|
|
+ }
|
|
|
|
|
|
boolean rtn = channelService.update(new LambdaUpdateWrapper<Channel>()
|
|
|
- .set(Channel::getName, saleSiteEditParam.getName())
|
|
|
- .set(saleSiteEditParam.getCommFlag() != null, Channel::getCommFlag, saleSiteEditParam.getCommFlag())
|
|
|
- .eq(Channel::getChannelId, saleSiteEditParam.getChannelId()));
|
|
|
+ .set(Channel::getName, saleSiteEditParam.getName())
|
|
|
+ .set(Channel::getChannelNo, parentChannel.getChannelNo()+"."+channel.getChannelId())
|
|
|
+ .set(Channel::getParentId, saleSiteEditParam.getParentId())
|
|
|
+ .set(Channel::getMobile, saleSiteEditParam.getMobile())
|
|
|
+ .set(saleSiteEditParam.getCommFlag() != null, Channel::getCommFlag, saleSiteEditParam.getCommFlag())
|
|
|
+ .eq(Channel::getChannelId, saleSiteEditParam.getChannelId()));
|
|
|
+
|
|
|
+ if (mobileChange){
|
|
|
+ //修改用户信息
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ 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("更新失败,请联系管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if (!rtn) {
|
|
|
return AjaxResult.error("更新门店信息失败");
|
|
@@ -610,4 +661,61 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
return AjaxResult.success(channelVO);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 门店转渠道
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * 参数:{"channelId":"2439", parentId:"2438"}
|
|
|
+ * channelId当前门店id
|
|
|
+ * parentId父渠道id
|
|
|
+ */
|
|
|
+ @Log(title = "门店转渠道", businessType = BusinessType.UPDATE)
|
|
|
+ @ApiOperation(value = "门店转渠道", notes = "门店转渠道")
|
|
|
+ @PostMapping("/transform")
|
|
|
+ @PreAuthorize("@ss.hasPermi('business:salesite:edit')")
|
|
|
+ public AjaxResult channelTransformToShop(@RequestBody ChannelParam channelParam) {
|
|
|
+ if (null == channelParam || null == channelParam.getChannelId()) {
|
|
|
+ return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
+ }
|
|
|
+ //修改当前门店为渠道
|
|
|
+ Channel channel = channelService.getById(channelParam.getChannelId());
|
|
|
+ if (null == channel || null == channel.getChannelId()) {
|
|
|
+ return AjaxResult.error("门店'" + channel.getName() + "'转渠道失败,门店ID异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改门店为渠道
|
|
|
+ //查询上级代理信息
|
|
|
+ Channel parentChannel = channelService.getById(channelParam.getParentId());
|
|
|
+ boolean mobileChange = false; // 手机号码是否有变更
|
|
|
+ channel.setParentId(0L);
|
|
|
+ channel.setLevel(1);
|
|
|
+ channel.setChannelNo(channel.getChannelId().toString());
|
|
|
+ //佣金比例暂定为0
|
|
|
+ channel.setCommRate(BigDecimal.ZERO);
|
|
|
+ /**
|
|
|
+ //校验佣金比例,不能高于其父经销商的佣金比例
|
|
|
+ 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("父经销商不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ */
|
|
|
+ channelService.updateChannel(channel, mobileChange);
|
|
|
+
|
|
|
+ //修改用户信息及岗位、角色关联
|
|
|
+ channelService.alterUserPostAndRole(channel, ChannelRoleEnum.CHANNEL);
|
|
|
+
|
|
|
+ return AjaxResult.success("门店'" + channel.getName() + "'变更为渠道成功");
|
|
|
+ }
|
|
|
+
|
|
|
}
|