|
@@ -2,12 +2,15 @@ package com.qs.mp.admin.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.qs.mp.admin.domain.Coupon;
|
|
|
+import com.qs.mp.admin.domain.CouponChannel;
|
|
|
import com.qs.mp.admin.domain.CouponTicket;
|
|
|
import com.qs.mp.admin.domain.Goods;
|
|
|
import com.qs.mp.admin.domain.GoodsSku;
|
|
|
import com.qs.mp.admin.domain.Ticket;
|
|
|
import com.qs.mp.admin.mapper.CouponMapper;
|
|
|
+import com.qs.mp.admin.service.ICouponChannelService;
|
|
|
import com.qs.mp.admin.service.ICouponService;
|
|
|
import com.qs.mp.admin.service.ICouponTicketService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -30,6 +33,7 @@ import com.qs.mp.user.service.IUserTicketOrderItemService;
|
|
|
|
|
|
import com.qs.mp.user.service.IUserTicketOrderService;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
@@ -76,6 +80,9 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
|
|
@Autowired
|
|
|
private IChannelService channelService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICouponChannelService couponChannelService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void distributeByMarketing(Long userId, String couponId) {
|
|
@@ -140,13 +147,28 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void saveCoupon(Coupon coupon, List<CouponTicket> ticketList) {
|
|
|
+ public void saveCoupon(Coupon coupon, List<CouponTicket> ticketList,List<Long> channelIdList) {
|
|
|
boolean res = couponService.save(coupon);
|
|
|
if (!res) {
|
|
|
throw new ServiceException("请联系管理员");
|
|
|
}
|
|
|
- if (res && null != ticketList
|
|
|
- && ticketList.size() > 0) {
|
|
|
+
|
|
|
+ // 指定门店
|
|
|
+ if (CollectionUtils.isNotEmpty(channelIdList)) {
|
|
|
+ List<CouponChannel> channelList = new ArrayList<>();
|
|
|
+ for (Long channelId : channelIdList) {
|
|
|
+ CouponChannel couponChannel = new CouponChannel();
|
|
|
+ couponChannel.setChannelId(channelId);
|
|
|
+ couponChannel.setCouponId(coupon.getCouponId());
|
|
|
+ channelList.add(couponChannel);
|
|
|
+ }
|
|
|
+ if (!couponChannelService.saveBatch(channelList)) {
|
|
|
+ throw new ServiceException("保存指定门店失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 指定盲票
|
|
|
+ if (CollectionUtils.isNotEmpty(ticketList)) {
|
|
|
for (CouponTicket couponTicket : ticketList) {
|
|
|
if (null != couponTicket) {
|
|
|
couponTicket.setCouponId(coupon.getCouponId());
|
|
@@ -154,39 +176,67 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
|
|
}
|
|
|
boolean skuRes = couponTicketService.saveBatch(ticketList);
|
|
|
if (!skuRes) {
|
|
|
- throw new ServiceException("请联系管理员");
|
|
|
+ throw new ServiceException("保存指定盲票失败");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void updateCoupon(Coupon coupon, List<CouponTicket> ticketList) {
|
|
|
+ public void updateCoupon(Coupon coupon, List<CouponTicket> ticketList, List<Long> channelIdList) {
|
|
|
boolean res = couponService.updateById(coupon);
|
|
|
if (!res) {
|
|
|
throw new ServiceException("请联系管理员");
|
|
|
}
|
|
|
- // 多SKU
|
|
|
- if (res && null != ticketList
|
|
|
- && ticketList.size() > 0) {
|
|
|
+
|
|
|
+ // 删除指定票
|
|
|
+ LambdaQueryWrapper<CouponTicket> couponTicketQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ couponTicketQueryWrapper.eq(CouponTicket::getCouponId, coupon.getCouponId());
|
|
|
+ if (couponTicketService.count(couponTicketQueryWrapper) > 0) {
|
|
|
+ boolean delRes = couponTicketService.remove(couponTicketQueryWrapper);
|
|
|
+ if (!delRes) {
|
|
|
+ throw new ServiceException("删除原指定盲票关联失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 删除指定门店
|
|
|
+ LambdaQueryWrapper<CouponChannel> couponChannelLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ couponChannelLambdaQueryWrapper.eq(CouponChannel::getCouponId, coupon.getCouponId());
|
|
|
+ if (couponChannelService.count(couponChannelLambdaQueryWrapper) > 0) {
|
|
|
+ boolean delRes = couponChannelService.remove(couponChannelLambdaQueryWrapper);
|
|
|
+ if (!delRes) {
|
|
|
+ throw new ServiceException("删除原指定门店关联失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存指定门店
|
|
|
+ if (CollectionUtils.isNotEmpty(channelIdList)) {
|
|
|
+ List<CouponChannel> channelList = new ArrayList<>();
|
|
|
+ for (Long channelId : channelIdList) {
|
|
|
+ CouponChannel couponChannel = new CouponChannel();
|
|
|
+ couponChannel.setChannelId(channelId);
|
|
|
+ couponChannel.setCouponId(coupon.getCouponId());
|
|
|
+ channelList.add(couponChannel);
|
|
|
+ }
|
|
|
+ if (!couponChannelService.saveBatch(channelList)) {
|
|
|
+ throw new ServiceException("保存指定门店失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 保存指定盲票
|
|
|
+ if (CollectionUtils.isNotEmpty(ticketList)) {
|
|
|
for (CouponTicket couponTicket : ticketList) {
|
|
|
if (null != couponTicket) {
|
|
|
- couponTicket.setCouponId(couponTicket.getCouponId());
|
|
|
+ couponTicket.setCouponId(coupon.getCouponId());
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- LambdaQueryWrapper<CouponTicket> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(CouponTicket::getCouponId, coupon.getCouponId());
|
|
|
- boolean delRes = couponTicketService.remove(queryWrapper);
|
|
|
- if (delRes) {
|
|
|
boolean skuRes = couponTicketService.saveBatch(ticketList);
|
|
|
if (!skuRes) {
|
|
|
- throw new ServiceException("请联系管理员");
|
|
|
+ throw new ServiceException("更新指定盲票失败");
|
|
|
}
|
|
|
- } else {
|
|
|
- throw new ServiceException("请联系管理员");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|