Parcourir la source

trading

(cherry picked from commit 370e8abebe91eca4273458485e3455d92304b124)
xiongzhu il y a 3 ans
Parent
commit
bc78cfd484

+ 1 - 1
src/main/java/com/izouma/nineth/listener/OrderNotifyListener.java

@@ -21,7 +21,7 @@ import org.springframework.stereotype.Service;
         consumerGroup = "${general.order-notify-group}",
         topic = "${general.order-notify-topic}",
         consumeMode = ConsumeMode.CONCURRENTLY, consumeThreadMax = 2)
-@ConditionalOnProperty(value = "general.notify-server", havingValue = "true")
+@ConditionalOnProperty(value = "general.notify-server", havingValue = "true", matchIfMissing = true)
 public class OrderNotifyListener implements RocketMQListener<OrderNotifyEvent> {
     private OrderService       orderService;
     private MintOrderService   mintOrderService;

+ 9 - 5
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -151,7 +151,9 @@ public class AssetService {
         if (asset.getStatus() != AssetStatus.NORMAL) {
             throw new BusinessException("当前状态不可展示");
         }
-        User owner = userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
+        User owner = asset.isSafeTransfer() ?
+                userRepo.findById(asset.getOwnerId()).orElseThrow(new BusinessException("用户不存在"))
+                : userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
         Collection collection = Collection.builder()
                 .name(asset.getName())
                 .pic(asset.getPic())
@@ -207,7 +209,9 @@ public class AssetService {
         if (ChronoUnit.DAYS.between(asset.getCreatedAt(), LocalDateTime.now()) < holdDays) {
             throw new BusinessException("需持有满" + holdDays + "天才能寄售上架");
         }
-        User owner = userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
+        User owner = asset.isSafeTransfer() ?
+                userRepo.findById(asset.getOwnerId()).orElseThrow(new BusinessException("用户不存在"))
+                : userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
         if (!passwordEncoder.matches(tradeCode, owner.getTradeCode())) {
             throw new BusinessException("交易密码错误");
         }
@@ -382,9 +386,9 @@ public class AssetService {
                 .fromUser(asset.getOwner())
                 .fromUserId(asset.getOwnerId())
                 .fromAvatar(asset.getOwnerAvatar())
-                .toUser(toUser.getNickname())
-                .toUserId(toUser.getId())
-                .toAvatar(toUser.getAvatar())
+                .toUser(newOwner.getNickname())
+                .toUserId(newOwner.getId())
+                .toAvatar(newOwner.getAvatar())
                 .operation(reason.getDescription())
                 .price(TransferReason.GIFT == reason ? null : price)
                 .build();

+ 3 - 3
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -188,7 +188,7 @@ public class OrderService {
         }
 
         Long id = snowflakeIdWorker.nextId();
-        redisTemplate.opsForValue().set("safeTransfer::" + id, "1", 10, TimeUnit.MINUTES);
+        redisTemplate.opsForValue().set("safeTransfer::" + id, safeTransfer, 10, TimeUnit.MINUTES);
         SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
                 new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip),
                 100000);
@@ -667,7 +667,6 @@ public class OrderService {
                     .orElseThrow(new BusinessException("藏品不存在"));
 
             User user = userRepo.findById(order.getUserId()).orElseThrow(new BusinessException("用户不存在"));
-            boolean safeTransfer = Objects.equals("1", redisTemplate.opsForValue().get("safeTransfer::" + orderId));
             if (order.getStatus() == OrderStatus.NOT_PAID) {
                 order.setStatus(OrderStatus.PROCESSING);
                 order.setPayTime(LocalDateTime.now());
@@ -699,7 +698,8 @@ public class OrderService {
                     if (collection.getSource() == CollectionSource.TRANSFER) {
                         orderRepo.save(order);
                         Asset asset = assetRepo.findById(collection.getAssetId()).orElse(null);
-                        assetService.transfer(asset, order.getPrice(), user, TransferReason.TRANSFER, order.getId());
+                        boolean safeTransfer = Objects.equals(true, redisTemplate.opsForValue().get("safeTransfer::" + orderId));
+                        assetService.transfer(asset, order.getPrice(), user, TransferReason.TRANSFER, order.getId(), safeTransfer);
                         order.setStatus(OrderStatus.FINISH);
                         orderRepo.save(order);
                         collectionRepo.delete(collection);