|
@@ -26,14 +26,7 @@ import com.qs.mp.system.service.id.BizIdGenerator;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.DecimalFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Random;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import lombok.Data;
|
|
@@ -109,12 +102,17 @@ public class TicketBoxServiceImpl extends ServiceImpl<TicketBoxMapper, TicketBox
|
|
|
throw new ServiceException("盲票组ID不能为空");
|
|
|
}
|
|
|
// 设置更新盲票基本信息
|
|
|
- TicketBox ticketBox = new TicketBox();
|
|
|
+ TicketBox ticketBox = this.getById(param.getBoxId());
|
|
|
+ if (Objects.isNull(ticketBox)) {
|
|
|
+ throw new ServiceException("盲票信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
ticketBox.setBoxId(param.getBoxId());
|
|
|
ticketBox.setTitle(param.getTitle());
|
|
|
ticketBox.setPicUrl(param.getPicUrl());
|
|
|
ticketBox.setSalePrice(param.getSalePrice());
|
|
|
ticketBox.setPkgSalePrice(param.getPkgSalePrice());
|
|
|
+ ticketBox.setOriginPrice(param.getOriginPrice());
|
|
|
ticketBox.setSaleCommRate(param.getSaleCommRate());
|
|
|
ticketBox.setSaleChannelType(param.getSaleChannelType());
|
|
|
this.updateById(ticketBox);
|
|
@@ -169,6 +167,15 @@ public class TicketBoxServiceImpl extends ServiceImpl<TicketBoxMapper, TicketBox
|
|
|
throw new ServiceException("奖品列表不能为空");
|
|
|
}
|
|
|
|
|
|
+ // 线上票需要判断商品数量合法性
|
|
|
+ if (TicketTypeEnum.ONLINE.equals(ticketBox.getType())) {
|
|
|
+ int quantity = ticketAwardsParam.getPrizeList().stream().mapToInt(TicketAwardsPrizeParam::getQuantity).sum();
|
|
|
+ if (quantity != ticketAwardsParam.getQuantity()) {
|
|
|
+ throw new ServiceException("奖品总数值不相同");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
List<TicketAwardsPrize> ticketAwardsPrizeList = new ArrayList<>();
|
|
|
List<String> prizeIdList = ticketAwardsParam.getPrizeList().stream().map(ticketAwardsPrizeParam -> {
|
|
|
// 奖品id为空则封装要新增的奖品
|
|
@@ -205,14 +212,46 @@ public class TicketBoxServiceImpl extends ServiceImpl<TicketBoxMapper, TicketBox
|
|
|
}
|
|
|
ticketAwardsPrizeList.add(awardsPrize);
|
|
|
} else {
|
|
|
- // 更新排序权重字段
|
|
|
- ticketAwardsPrizeService.update(new LambdaUpdateWrapper<TicketAwardsPrize>().set(TicketAwardsPrize::getSortWeight, ticketAwardsPrizeParam.getSortWeight()).eq(TicketAwardsPrize::getPrizeId, ticketAwardsPrizeParam.getPrizeId()));
|
|
|
+ boolean rtn = true;
|
|
|
+ if (TicketTypeEnum.ONLINE.equals(ticketBox.getType())) {
|
|
|
+ TicketAwardsPrize ticketAwardsPrize = ticketAwardsPrizeService.getById(ticketAwardsPrizeParam.getPrizeId());
|
|
|
+ // 校验奖品数量不能少于已兑奖数量
|
|
|
+ if (ticketAwardsPrizeParam.getQuantity() < ticketAwardsPrize.getCashedQty()) {
|
|
|
+ throw new ServiceException("奖品数量不能少于已兑奖数量");
|
|
|
+ }
|
|
|
+ // 更新奖级信息等
|
|
|
+ rtn = ticketAwardsPrizeService.update(new LambdaUpdateWrapper<TicketAwardsPrize>()
|
|
|
+ .set(TicketAwardsPrize::getSortWeight, ticketAwardsPrizeParam.getSortWeight())
|
|
|
+ .set(TicketAwardsPrize::getQuantity, ticketAwardsPrizeParam.getQuantity())
|
|
|
+ .set(TicketAwardsPrize::getRemainQty, ticketAwardsPrizeParam.getQuantity() - ticketAwardsPrize.getCashedQty())
|
|
|
+ .eq(TicketAwardsPrize::getPrizeId, ticketAwardsPrizeParam.getPrizeId())
|
|
|
+ .eq(TicketAwardsPrize::getRemainQty, ticketAwardsPrize.getRemainQty()));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 更新排序权重字段
|
|
|
+ rtn = ticketAwardsPrizeService.update(new LambdaUpdateWrapper<TicketAwardsPrize>()
|
|
|
+ .set(TicketAwardsPrize::getSortWeight, ticketAwardsPrizeParam.getSortWeight())
|
|
|
+ .eq(TicketAwardsPrize::getPrizeId, ticketAwardsPrizeParam.getPrizeId()));
|
|
|
+ }
|
|
|
+ if (!rtn) {
|
|
|
+ throw new ServiceException("操作盲票频繁,请重试");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
return ticketAwardsPrizeParam.getPrizeId();
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
// 如果新的奖品id为空,则清除原来的所有奖品
|
|
|
if (CollectionUtils.isEmpty(prizeIdList)) {
|
|
|
+ if (TicketTypeEnum.ONLINE.equals(ticketBox.getType())) {
|
|
|
+ int cashedCount = ticketAwardsPrizeService.count(new LambdaQueryWrapper<TicketAwardsPrize>()
|
|
|
+ .eq(TicketAwardsPrize::getAwardsId, ticketAwardsParam.getAwardsId())
|
|
|
+ .ne(TicketAwardsPrize::getCashedQty, 0));
|
|
|
+ if (cashedCount != 0) {
|
|
|
+ throw new ServiceException("包含已兑奖记录的奖品不能从奖级中删除");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
ticketAwardsPrizeService.update(new LambdaUpdateWrapper<TicketAwardsPrize>().set(TicketAwardsPrize::getIsDeleted, 1).eq(TicketAwardsPrize::getAwardsId, ticketAwardsParam.getAwardsId()));
|
|
|
} else {
|
|
|
// 去重后,清除原来的奖品
|
|
@@ -229,6 +268,15 @@ public class TicketBoxServiceImpl extends ServiceImpl<TicketBoxMapper, TicketBox
|
|
|
oldPrizeIdList.removeAll(prizeIdList);
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(oldPrizeIdList)) {
|
|
|
+ if (TicketTypeEnum.ONLINE.equals(ticketBox.getType())) {
|
|
|
+ int cashedCount = ticketAwardsPrizeService.count(new LambdaQueryWrapper<TicketAwardsPrize>()
|
|
|
+ .in(TicketAwardsPrize::getPrizeId, oldPrizeIdList)
|
|
|
+ .ne(TicketAwardsPrize::getCashedQty, 0));
|
|
|
+ if (cashedCount != 0) {
|
|
|
+ throw new ServiceException("包含已兑奖记录的奖品不能从奖级中删除");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 删除原来的奖品信息
|
|
|
ticketAwardsPrizeService.update(new LambdaUpdateWrapper<TicketAwardsPrize>().set(TicketAwardsPrize::getIsDeleted, 1).in(TicketAwardsPrize::getPrizeId, oldPrizeIdList));
|
|
|
}
|