|
|
@@ -143,4 +143,35 @@ public class AirDropService {
|
|
|
log.error("空投出错", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void drop(List<Collection> collections, String phone, LocalDateTime time) {
|
|
|
+// List<Collection> collections = collectionRepo.findAllById(collectionId);
|
|
|
+ User user = userRepo.findByPhoneAndDelFalse(phone).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ try {
|
|
|
+ for (Collection collection : collections) {
|
|
|
+ Asset asset;
|
|
|
+ if (collection.getType() == CollectionType.BLIND_BOX) {
|
|
|
+ BlindBoxItem winItem = collectionService.draw(collection.getId());
|
|
|
+ asset = assetService.createAsset(winItem, user, 0L, collection.getPrice(), "出售",
|
|
|
+ winItem.getTotal() > 1 ? collectionService.getNextNumber(winItem.getCollectionId()) : null,
|
|
|
+ collection.getHoldDays());
|
|
|
+ } else {
|
|
|
+ asset = assetService.createAsset(collection, user, 0L, collection.getPrice(), "出售",
|
|
|
+ collection.getTotal() > 1 ? collectionService.getNextNumber(collection.getId()) : null);
|
|
|
+ }
|
|
|
+ assetRepo.flush();
|
|
|
+ tokenHistoryRepo.flush();
|
|
|
+
|
|
|
+ asset.setCreatedAt(time.plusSeconds((long) (Math.random() * 120)));
|
|
|
+ assetRepo.save(asset);
|
|
|
+
|
|
|
+ for (TokenHistory tokenHistory : tokenHistoryRepo.findByTokenIdOrderByCreatedAtDesc(asset.getTokenId())) {
|
|
|
+ tokenHistory.setCreatedAt(asset.getCreatedAt());
|
|
|
+ tokenHistoryRepo.save(tokenHistory);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("空投出错", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|