|
|
@@ -17,6 +17,7 @@ import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.*;
|
|
|
import com.izouma.nineth.event.CreateAssetEvent;
|
|
|
+import com.izouma.nineth.event.TransferAssetEvent;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
@@ -299,7 +300,7 @@ public class OrderService {
|
|
|
} else {
|
|
|
if (collection.getSource() == CollectionSource.TRANSFER) {
|
|
|
Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
|
|
|
- assetService.transfer(asset, user);
|
|
|
+ assetService.transfer(asset, order.getPrice(), user, "转让", order.getId());
|
|
|
collectionRepo.delete(collection);
|
|
|
} else {
|
|
|
order.setStatus(OrderStatus.PROCESSING);
|
|
|
@@ -321,25 +322,20 @@ public class OrderService {
|
|
|
.orElseThrow(new BusinessException("藏品不存在"));
|
|
|
User user = userRepo.findById(order.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
if (order.getStatus() == OrderStatus.NOT_PAID) {
|
|
|
+ order.setStatus(OrderStatus.PROCESSING);
|
|
|
+ order.setPayTime(LocalDateTime.now());
|
|
|
+ order.setTransactionId(transactionId);
|
|
|
+ order.setPayMethod(payMethod);
|
|
|
if (order.getType() == CollectionType.BLIND_BOX) {
|
|
|
BlindBoxItem winItem = collectionService.draw(collection.getId());
|
|
|
-
|
|
|
- order.setStatus(OrderStatus.PROCESSING);
|
|
|
- order.setPayTime(LocalDateTime.now());
|
|
|
- order.setTransactionId(transactionId);
|
|
|
- order.setPayMethod(payMethod);
|
|
|
orderRepo.save(order);
|
|
|
assetService.createAsset(winItem, user, order.getId(), order.getPrice(), "出售");
|
|
|
} else {
|
|
|
if (collection.getSource() == CollectionSource.TRANSFER) {
|
|
|
Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
|
|
|
- assetService.transfer(asset, user);
|
|
|
+ assetService.transfer(asset, order.getPrice(), user, "转让", order.getId());
|
|
|
collectionRepo.delete(collection);
|
|
|
} else {
|
|
|
- order.setStatus(OrderStatus.PROCESSING);
|
|
|
- order.setPayTime(LocalDateTime.now());
|
|
|
- order.setTransactionId(transactionId);
|
|
|
- order.setPayMethod(payMethod);
|
|
|
orderRepo.save(order);
|
|
|
assetService.createAsset(collection, user, order.getId(), order.getPrice(), "出售");
|
|
|
}
|
|
|
@@ -363,6 +359,21 @@ public class OrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @EventListener
|
|
|
+ public void onTransferAsset(TransferAssetEvent event) {
|
|
|
+ Asset asset = event.getAsset();
|
|
|
+ Order order = orderRepo.findById(asset.getOrderId()).orElseThrow(new BusinessException("订单不存在"));
|
|
|
+ if (event.isSuccess()) {
|
|
|
+ order.setTxHash(asset.getTxHash());
|
|
|
+ order.setGasUsed(asset.getGasUsed());
|
|
|
+ order.setBlockNumber(asset.getBlockNumber());
|
|
|
+ order.setStatus(OrderStatus.FINISH);
|
|
|
+ orderRepo.save(order);
|
|
|
+ } else {
|
|
|
+ log.error("创建asset失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void cancel(Long id) {
|
|
|
Order order = orderRepo.findById(id).orElseThrow(new BusinessException("订单不存在"));
|
|
|
cancel(order);
|