|
|
@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@@ -41,6 +42,9 @@ public class AirDropService {
|
|
|
}
|
|
|
|
|
|
public AirDrop create(AirDrop record) {
|
|
|
+ if (record.getTargets().isEmpty()) throw new BusinessException("空投对象不能为空");
|
|
|
+ if (record.getTargets().stream().mapToInt(DropTarget::getNum).sum() > 300)
|
|
|
+ throw new BusinessException("空投数量不能超过300");
|
|
|
if (AirDropType.coupon == record.getType()) {
|
|
|
Coupon coupon = couponRepo.findById(record.getCouponId()).orElseThrow(new BusinessException("兑换券不存在"));
|
|
|
record.getUserIds().stream().parallel().forEach(userId -> {
|
|
|
@@ -60,51 +64,67 @@ public class AirDropService {
|
|
|
if (!record.isIgnoreStockCheck() && collection.getStock() < record.getUserIds().size()) {
|
|
|
throw new BusinessException("藏品库存不足");
|
|
|
}
|
|
|
- List<User> users = userRepo.findByIdInAndDelFalse(record.getUserIds());
|
|
|
- for (User user : users) {
|
|
|
+
|
|
|
+ List<User> users = userRepo.findByIdInAndDelFalse(record.getTargets().stream()
|
|
|
+ .map(DropTarget::getUserId).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ for (DropTarget target : record.getTargets()) {
|
|
|
+ User user = users.stream().filter(u -> u.getId().equals(target.getUserId()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ if (user == null) continue;
|
|
|
try {
|
|
|
- if (collection.getType() == CollectionType.BLIND_BOX) {
|
|
|
- BlindBoxItem winItem = collectionService.draw(collection.getId());
|
|
|
- if (record.isSimulateOrder()) {
|
|
|
- assetService.createAsset(winItem, user, 0L, collection.getPrice(), "出售",
|
|
|
- winItem.getTotal() > 1 ? collectionService.getNextNumber(winItem.getCollectionId()) : null,
|
|
|
- collection.getHoldDays());
|
|
|
- } else {
|
|
|
- //查看有无vip权限
|
|
|
- CollectionPrivilege collectionPrivilege = collectionPrivilegeRepo.findByCollectionId(record.getCollectionId());
|
|
|
- if (ObjectUtils.isNotEmpty(collectionPrivilege)) {
|
|
|
- if (collectionPrivilege.isVip()) {
|
|
|
- //更新vip信息
|
|
|
- userRepo.updateVipPurchase(user.getId(), 1);
|
|
|
+ for (int i = 0; i < target.getNum(); i++) {
|
|
|
+ if (collection.getType() == CollectionType.BLIND_BOX) {
|
|
|
+ BlindBoxItem winItem = collectionService.draw(collection.getId());
|
|
|
+ if (record.isSimulateOrder()) {
|
|
|
+ assetService.createAsset(winItem, user, 0L, collection.getPrice(), "出售",
|
|
|
+ winItem.getTotal() > 1 ?
|
|
|
+ collectionService.getNextNumber(winItem.getCollectionId()) : null,
|
|
|
+ collection.getHoldDays());
|
|
|
+ } else {
|
|
|
+ //查看有无vip权限
|
|
|
+ CollectionPrivilege collectionPrivilege = collectionPrivilegeRepo
|
|
|
+ .findByCollectionId(record.getCollectionId());
|
|
|
+ if (ObjectUtils.isNotEmpty(collectionPrivilege)) {
|
|
|
+ if (collectionPrivilege.isVip()) {
|
|
|
+ //更新vip信息
|
|
|
+ userRepo.updateVipPurchase(user.getId(), 1);
|
|
|
+ }
|
|
|
}
|
|
|
+ assetService.createAsset(winItem, user, null, null, "空投",
|
|
|
+ winItem.getTotal() > 1 ?
|
|
|
+ collectionService.getNextNumber(winItem.getCollectionId()) : null,
|
|
|
+ collection.getHoldDays());
|
|
|
}
|
|
|
- assetService.createAsset(winItem, user, null, null, "空投",
|
|
|
- collectionService.getNextNumber(winItem.getCollectionId()), collection.getHoldDays());
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (record.isSimulateOrder()) {
|
|
|
- assetService.createAsset(collection, user, 0L, collection.getPrice(), "出售",
|
|
|
- collection.getTotal() > 1 ? collectionService.getNextNumber(collection.getId()) : null);
|
|
|
} else {
|
|
|
- //查看有无vip权限
|
|
|
- CollectionPrivilege collectionPrivilege = collectionPrivilegeRepo.findByCollectionId(record.getCollectionId());
|
|
|
- if (ObjectUtils.isNotEmpty(collectionPrivilege)) {
|
|
|
- if (collectionPrivilege.isVip()) {
|
|
|
- //更新vip信息
|
|
|
- userRepo.updateVipPurchase(user.getId(), 1);
|
|
|
+ if (record.isSimulateOrder()) {
|
|
|
+ assetService.createAsset(collection, user, 0L, collection.getPrice(),
|
|
|
+ "出售", collection.getTotal() > 1 ?
|
|
|
+ collectionService.getNextNumber(collection.getId()) : null);
|
|
|
+ } else {
|
|
|
+ //查看有无vip权限
|
|
|
+ CollectionPrivilege collectionPrivilege = collectionPrivilegeRepo
|
|
|
+ .findByCollectionId(record.getCollectionId());
|
|
|
+ if (ObjectUtils.isNotEmpty(collectionPrivilege)) {
|
|
|
+ if (collectionPrivilege.isVip()) {
|
|
|
+ //更新vip信息
|
|
|
+ userRepo.updateVipPurchase(user.getId(), 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Asset asset = assetService.createAsset(collection, user, null, null,
|
|
|
+ "空投", collection.getTotal() > 1 ?
|
|
|
+ collectionService.getNextNumber(collection.getId()) : null);
|
|
|
+ //创建展厅
|
|
|
+ if (collection.getType() == CollectionType.SHOWROOM) {
|
|
|
+ showroomService.save(asset);
|
|
|
}
|
|
|
}
|
|
|
- Asset asset = assetService.createAsset(collection, user, null, null, "空投", collectionService.getNextNumber(collection.getId()));
|
|
|
- //创建展厅
|
|
|
- if (collection.getType() == CollectionType.SHOWROOM) {
|
|
|
- showroomService.save(asset);
|
|
|
- }
|
|
|
- }
|
|
|
// Asset asset = assetService.createAsset(collection, user, null, null, "空投", collectionService.getNextNumber(collection.getId()));
|
|
|
|
|
|
+ }
|
|
|
+ collectionService.decreaseStock(collection.getId(), 1);
|
|
|
+ collectionService.increaseSale(collection.getId(), 1);
|
|
|
}
|
|
|
- collectionService.decreaseStock(collection.getId(), 1);
|
|
|
- collectionService.increaseSale(collection.getId(), 1);
|
|
|
} catch (Exception e) {
|
|
|
log.error("空投出错", e);
|
|
|
}
|