|
@@ -12,7 +12,6 @@ import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.izouma.nineth.config.AlipayProperties;
|
|
import com.izouma.nineth.config.AlipayProperties;
|
|
|
import com.izouma.nineth.config.WxPayProperties;
|
|
import com.izouma.nineth.config.WxPayProperties;
|
|
|
-import com.izouma.nineth.domain.Collection;
|
|
|
|
|
import com.izouma.nineth.domain.*;
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.*;
|
|
import com.izouma.nineth.enums.*;
|
|
@@ -26,8 +25,6 @@ import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.EncoderException;
|
|
import org.apache.commons.codec.EncoderException;
|
|
|
import org.apache.commons.codec.net.URLCodec;
|
|
import org.apache.commons.codec.net.URLCodec;
|
|
|
-import org.apache.commons.lang3.RandomUtils;
|
|
|
|
|
-import org.apache.commons.lang3.Range;
|
|
|
|
|
import org.springframework.context.event.EventListener;
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.core.env.Environment;
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
@@ -39,7 +36,10 @@ import org.springframework.ui.Model;
|
|
|
import javax.transaction.Transactional;
|
|
import javax.transaction.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
@@ -107,8 +107,6 @@ public class OrderService {
|
|
|
collection.setSale(collection.getSale() + qty);
|
|
collection.setSale(collection.getSale() + qty);
|
|
|
collectionRepo.save(collection);
|
|
collectionRepo.save(collection);
|
|
|
|
|
|
|
|
- minter.setSales(minter.getSales() + 1);
|
|
|
|
|
-
|
|
|
|
|
BigDecimal gasFee = sysConfigService.getBigDecimal("gas_fee");
|
|
BigDecimal gasFee = sysConfigService.getBigDecimal("gas_fee");
|
|
|
Order order = Order.builder()
|
|
Order order = Order.builder()
|
|
|
.userId(userId)
|
|
.userId(userId)
|
|
@@ -249,9 +247,11 @@ public class OrderService {
|
|
|
order.setPayMethod(payMethod);
|
|
order.setPayMethod(payMethod);
|
|
|
if (order.getType() == CollectionType.BLIND_BOX) {
|
|
if (order.getType() == CollectionType.BLIND_BOX) {
|
|
|
BlindBoxItem winItem = collectionService.draw(collection.getId());
|
|
BlindBoxItem winItem = collectionService.draw(collection.getId());
|
|
|
|
|
+ order.setWinCollectionId(winItem.getCollectionId());
|
|
|
orderRepo.save(order);
|
|
orderRepo.save(order);
|
|
|
assetService.createAsset(winItem, user, order.getId(), order.getPrice(), "出售",
|
|
assetService.createAsset(winItem, user, order.getId(), order.getPrice(), "出售",
|
|
|
collectionService.getNextNumber(winItem.getCollectionId()));
|
|
collectionService.getNextNumber(winItem.getCollectionId()));
|
|
|
|
|
+ addSales(winItem.getMinterId());
|
|
|
} else {
|
|
} else {
|
|
|
if (collection.getSource() == CollectionSource.TRANSFER) {
|
|
if (collection.getSource() == CollectionSource.TRANSFER) {
|
|
|
Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
|
|
Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
|
|
@@ -262,6 +262,7 @@ public class OrderService {
|
|
|
assetService.createAsset(collection, user, order.getId(), order.getPrice(), "出售",
|
|
assetService.createAsset(collection, user, order.getId(), order.getPrice(), "出售",
|
|
|
collectionService.getNextNumber(order.getCollectionId()));
|
|
collectionService.getNextNumber(order.getCollectionId()));
|
|
|
}
|
|
}
|
|
|
|
|
+ addSales(collection.getMinterId());
|
|
|
}
|
|
}
|
|
|
} else if (order.getStatus() == OrderStatus.CANCELLED) {
|
|
} else if (order.getStatus() == OrderStatus.CANCELLED) {
|
|
|
}
|
|
}
|
|
@@ -314,6 +315,7 @@ public class OrderService {
|
|
|
Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
|
|
Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
|
|
|
if (asset != null) {
|
|
if (asset != null) {
|
|
|
asset.setStatus(AssetStatus.NORMAL);
|
|
asset.setStatus(AssetStatus.NORMAL);
|
|
|
|
|
+ assetRepo.save(asset);
|
|
|
}
|
|
}
|
|
|
collection.setOnShelf(true);
|
|
collection.setOnShelf(true);
|
|
|
}
|
|
}
|
|
@@ -321,9 +323,6 @@ public class OrderService {
|
|
|
collection.setStock(collection.getStock() + 1);
|
|
collection.setStock(collection.getStock() + 1);
|
|
|
collectionRepo.save(collection);
|
|
collectionRepo.save(collection);
|
|
|
|
|
|
|
|
- minter.setSales(minter.getSales() - 1);
|
|
|
|
|
- userRepo.save(minter);
|
|
|
|
|
-
|
|
|
|
|
order.setStatus(OrderStatus.CANCELLED);
|
|
order.setStatus(OrderStatus.CANCELLED);
|
|
|
order.setCancelTime(LocalDateTime.now());
|
|
order.setCancelTime(LocalDateTime.now());
|
|
|
orderRepo.save(order);
|
|
orderRepo.save(order);
|
|
@@ -347,6 +346,14 @@ public class OrderService {
|
|
|
public void refundCancelled(Order order) {
|
|
public void refundCancelled(Order order) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public synchronized void addSales(Long userId) {
|
|
|
|
|
+ if (userId != null) {
|
|
|
|
|
+ userRepo.findById(userId).ifPresent(user -> {
|
|
|
|
|
+ user.setSales(user.getSales() + 1);
|
|
|
|
|
+ userRepo.save(user);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public void setNumber() {
|
|
public void setNumber() {
|
|
|
for (Collection collection : collectionRepo.findAll()) {
|
|
for (Collection collection : collectionRepo.findAll()) {
|
|
@@ -360,4 +367,18 @@ public class OrderService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void setSales() {
|
|
|
|
|
+ List<Collection> collections = collectionRepo.findAll();
|
|
|
|
|
+ List<User> minters = userRepo.findAllById(collections.stream().map(Collection::getMinterId)
|
|
|
|
|
+ .collect(Collectors.toSet()));
|
|
|
|
|
+ for (User minter : minters) {
|
|
|
|
|
+ List<Collection> list = collections.stream().filter(c -> minter.getId().equals(c.getMinterId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ minter.setSales((int) orderRepo.findByCollectionIdIn(list.stream().map(Collection::getId)
|
|
|
|
|
+ .collect(Collectors.toSet())).stream()
|
|
|
|
|
+ .filter(o -> o.getStatus() != OrderStatus.CANCELLED).count());
|
|
|
|
|
+ userRepo.save(minter);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|