|
@@ -3,15 +3,17 @@ 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.admin.domain.Coupon;
|
|
|
+import com.qs.mp.admin.domain.CouponTicket;
|
|
|
+import com.qs.mp.admin.domain.param.CouponParam;
|
|
|
+import com.qs.mp.admin.domain.param.GoodsParam;
|
|
|
+import com.qs.mp.admin.domain.vo.CouponVO;
|
|
|
+import com.qs.mp.admin.service.ICouponService;
|
|
|
+import com.qs.mp.admin.service.ICouponTicketService;
|
|
|
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.ChannelRoleEnum;
|
|
|
+import com.qs.mp.common.enums.CouponStatusEnum;
|
|
|
import com.qs.mp.common.enums.ErrorCodeEnum;
|
|
|
import com.qs.mp.system.domain.SysUser;
|
|
|
import com.qs.mp.system.service.ISysUserService;
|
|
@@ -39,17 +41,17 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @create 2022-03-09 23:45:48
|
|
|
* @describe 代金券管理前端控制器
|
|
|
*/
|
|
|
-@Api("渠道管理API")
|
|
|
+@Api("代金券管理API")
|
|
|
@RestController
|
|
|
@RequestMapping("/api/v1/mp/admin/coupon/*")
|
|
|
@Component
|
|
|
public class CouponMgrController extends BaseApiController {
|
|
|
|
|
|
@Autowired
|
|
|
- private IChannelService channelService;
|
|
|
+ private ICouponService couponService;
|
|
|
|
|
|
@Autowired
|
|
|
- private IChannelUserRelService channelUserRelService;
|
|
|
+ private ICouponTicketService couponTicketService;
|
|
|
|
|
|
@Autowired
|
|
|
private ISysUserService userService;
|
|
@@ -58,188 +60,125 @@ public class CouponMgrController extends BaseApiController {
|
|
|
private MapperFacade mapperFacade;
|
|
|
|
|
|
/**
|
|
|
- * 获取我的下级渠道列表信息,支持翻页
|
|
|
+ * 获取我的下级代金券列表信息,支持翻页
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/list")
|
|
|
- public TableDataInfo listChannel(@RequestBody Channel channel) {
|
|
|
- List<ChannelVO> list = new ArrayList<ChannelVO>();
|
|
|
+ public TableDataInfo listCoupon(@RequestBody Coupon coupon) {
|
|
|
+ List<Coupon> list = new ArrayList<Coupon>();
|
|
|
startPage();
|
|
|
- QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
|
|
|
- if(null!=channel && null != channel.getParentId()) {
|
|
|
- queryWrapper.eq("t1.parent_id", channel.getParentId());
|
|
|
- }
|
|
|
- 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");
|
|
|
- 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.getChannelTotalUserCnt(channelVO.getChannelNo());
|
|
|
- channelVO.setSiteCnt(siteCnt);
|
|
|
- channelVO.setUserCnt(userCnt);
|
|
|
- // 查询用户信息
|
|
|
- // SysUser sysUser = userService.selectUserById(channelVO.getUserId());
|
|
|
- // channelVO.setSysUser(sysUser);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ LambdaQueryWrapper<Coupon> queryWrapper = new LambdaQueryWrapper<Coupon>();
|
|
|
+ queryWrapper.like(null != coupon && StringUtils.isNotBlank(coupon.getTitle()), Coupon::getTitle, coupon.getTitle());
|
|
|
+ queryWrapper.like(null != coupon && StringUtils.isNotBlank(coupon.getStatus().getValue()), Coupon::getStatus, coupon.getStatus().getValue());
|
|
|
+ queryWrapper.orderByAsc(Coupon::getCreatedTime);
|
|
|
+ list = couponService.list(queryWrapper);
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 新增子渠道信息
|
|
|
+ * 新增代金券信息
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation(value = "新增子渠道信息", notes = "渠道端新增子渠道")
|
|
|
+ @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);
|
|
|
+ public AjaxResult couponCreate(@Validated @RequestBody CouponParam couponParam) {
|
|
|
+ if (StringUtils.isNotBlank(couponParam.getCouponId())) {
|
|
|
+ return AjaxResult.error("该代金券已存在");
|
|
|
+ }
|
|
|
+ Coupon coupon = mapperFacade.map(couponParam, Coupon.class);
|
|
|
+ // 1、校验名称是否重复(代金券表)
|
|
|
+ LambdaQueryWrapper<Coupon> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Coupon::getTitle, coupon.getTitle());
|
|
|
+ int nameCount = couponService.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("");
|
|
|
+ return AjaxResult.error("代金券名称" + coupon.getTitle() + "已存在!");
|
|
|
+ }
|
|
|
+ // 使用范围
|
|
|
+ List<CouponTicket> ticketList = new ArrayList<>();
|
|
|
+ if(StringUtils.isNotBlank(couponParam.getBoxIds())) {
|
|
|
+ String[] boxIdArray = couponParam.getBoxIds().split(",");
|
|
|
+ for (int i = 0; i < boxIdArray.length; i++) {
|
|
|
+ String boxId = boxIdArray[i];
|
|
|
+ CouponTicket couponTicket = new CouponTicket();
|
|
|
+ couponTicket.setBoxId(boxId);
|
|
|
+ }
|
|
|
}
|
|
|
// 3.插入数据
|
|
|
try {
|
|
|
- channelService.saveChannel(channel,ChannelRoleEnum.CHANNEL);
|
|
|
+ couponService.saveCoupon(coupon,ticketList);
|
|
|
} catch (Exception e) {
|
|
|
- return AjaxResult.error("渠道'" + channel.getName() + "'新增失败" + e.getMessage());
|
|
|
+ return AjaxResult.error("代金券'" + coupon.getTitle() + "'新增失败" + e.getMessage());
|
|
|
}
|
|
|
|
|
|
- return AjaxResult.success("渠道'" + channel.getName() + "'新增成功");
|
|
|
+ return AjaxResult.success("代金券'" + coupon.getTitle() + "'新增成功");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 编辑子渠道信息
|
|
|
+ * 编辑代金券信息
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation(value = "编辑子渠道信息", notes = "渠道端编辑子渠道")
|
|
|
+ @ApiOperation(value = "编辑代金券信息", notes = "代金券端编辑代金券")
|
|
|
@PostMapping("/update")
|
|
|
- public AjaxResult channelUpdate(@Validated @RequestBody ChannelParam channelParam) {
|
|
|
- if (null == channelParam || null == channelParam.getChannelId()) {
|
|
|
+ public AjaxResult couponUpdate(@Validated @RequestBody CouponParam couponParam) {
|
|
|
+ if (null == couponParam || StringUtils.isBlank(couponParam.getCouponId())) {
|
|
|
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);
|
|
|
+ Coupon coupon = mapperFacade.map(couponParam, Coupon.class);
|
|
|
+ // 1、校验修改代金券是否为当前用户的代金券
|
|
|
+ Coupon oldCoupon = couponService.getById(coupon.getCouponId());
|
|
|
+ if(null == oldCoupon || null == oldCoupon.getCouponId()) {
|
|
|
+ return AjaxResult.error("代金券'" + oldCoupon.getTitle() + "'编辑失败,代金券ID异常");
|
|
|
+ }
|
|
|
+ // 2.校验名称是否重复(代金券表);
|
|
|
+ if(!coupon.getTitle().equals(oldCoupon.getTitle())) {
|
|
|
+ LambdaQueryWrapper<Coupon> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Coupon::getTitle, coupon.getTitle());
|
|
|
+ int nameCount = couponService.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() + "已注册!");
|
|
|
+ return AjaxResult.error("代金券名称" + coupon.getTitle() + "已存在!");
|
|
|
}
|
|
|
- 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("不能低于其子渠道的最大佣金比例");
|
|
|
- }
|
|
|
+ // 使用范围
|
|
|
+ List<CouponTicket> ticketList = new ArrayList<>();
|
|
|
+ if(StringUtils.isNotBlank(couponParam.getBoxIds())) {
|
|
|
+ String[] boxIdArray = couponParam.getBoxIds().split(",");
|
|
|
+ for (int i = 0; i < boxIdArray.length; i++) {
|
|
|
+ String boxId = boxIdArray[i];
|
|
|
+ CouponTicket couponTicket = new CouponTicket();
|
|
|
+ couponTicket.setBoxId(boxId);
|
|
|
+ couponTicket.setCouponId(coupon.getCouponId());
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
- channelService.updateChannel(channel, mobileChange);
|
|
|
+ couponService.updateCoupon(coupon, ticketList);
|
|
|
} catch (Exception e) {
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
}
|
|
|
- return AjaxResult.success("渠道'" + channel.getName() + "'编辑成功");
|
|
|
+ return AjaxResult.success("代金券'" + coupon.getTitle() + "'编辑成功");
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 停用、启用渠道
|
|
|
+ * 停用、启用代金券
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- @ApiOperation(value = "停用、启用渠道信息", notes = "渠道管理编辑子渠道")
|
|
|
+ @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)) {
|
|
|
+ public AjaxResult couponStatus(@RequestBody CouponParam couponParam) {
|
|
|
+ String couponId = (null != couponParam && StringUtils.isNotBlank(couponParam.getCouponId()))?couponParam.getCouponId():"";
|
|
|
+ CouponStatusEnum status = null != couponParam ?couponParam.getStatus():null;
|
|
|
+ if (StringUtils.isBlank(couponId)
|
|
|
+ || null == status) {
|
|
|
return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
}
|
|
|
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();
|
|
|
-// sysUser.setUserId(channel.getUserId());
|
|
|
-// sysUser.setStatus(status);
|
|
|
-// userService.updateUserStatus(sysUser);
|
|
|
-// }
|
|
|
+ couponService.lambdaUpdate().set(Coupon::getStatus, couponParam.getStatus()).eq(Coupon::getCouponId, couponId).update();
|
|
|
+ // 查询代金券信息
|
|
|
} catch (Exception e) {
|
|
|
return AjaxResult.error("操作失败");
|
|
|
}
|