Răsfoiți Sursa

铸造订单bug

licailing 3 ani în urmă
părinte
comite
4ba50d3bbc
1 a modificat fișierele cu 28 adăugiri și 26 ștergeri
  1. 28 26
      src/main/java/com/izouma/nineth/service/MintOrderService.java

+ 28 - 26
src/main/java/com/izouma/nineth/service/MintOrderService.java

@@ -102,7 +102,6 @@ public class MintOrderService {
         MintOrder order = mintOrderRepo.save(MintOrder.builder()
         MintOrder order = mintOrderRepo.save(MintOrder.builder()
                 .userId(userId)
                 .userId(userId)
                 .phone(user.getPhone())
                 .phone(user.getPhone())
-//                .material(materials)
                 .consume(true)
                 .consume(true)
                 .status(MintOrderStatus.AIR_DROP)
                 .status(MintOrderStatus.AIR_DROP)
                 .build());
                 .build());
@@ -158,21 +157,25 @@ public class MintOrderService {
      */
      */
 //    @Transactional
 //    @Transactional
     public MintOrder create(User user, List<Long> assetId, Long mintActivityId, Long addressId) {
     public MintOrder create(User user, List<Long> assetId, Long mintActivityId, Long addressId) {
-        try {
-
-            // 参加的活动
-            MintActivity mintActivity = mintActivityRepo.findByIdAndDelFalse(mintActivityId)
-                    .orElseThrow(new BusinessException("无此铸造活动"));
+        // 参加的活动
+        MintActivity mintActivity = mintActivityRepo.findByIdAndDelFalse(mintActivityId)
+                .orElseThrow(new BusinessException("无此铸造活动"));
 
 
-            if (mintActivity.isScheduleSale()) {
-                if (mintActivity.getStartTime().isAfter(LocalDateTime.now())) {
-                    throw new BusinessException("当前还未开售");
-                }
-            }
-            if (!mintActivity.isOnShelf()) {
-                throw new BusinessException("活动已下架");
+        if (mintActivity.isScheduleSale()) {
+            if (mintActivity.getStartTime().isAfter(LocalDateTime.now())) {
+                throw new BusinessException("当前还未开售");
             }
             }
+        }
+        if (!mintActivity.isOnShelf()) {
+            throw new BusinessException("活动已下架");
+        }
 
 
+        UserAddress userAddress = null;
+        if (addressId != null) {
+            userAddress = userAddressRepo.findById(addressId).orElseThrow(new BusinessException("地址信息不存在"));
+        }
+
+        try {
             int stock = Optional.ofNullable(mintActivityService.decreaseStock(mintActivityId, 1))
             int stock = Optional.ofNullable(mintActivityService.decreaseStock(mintActivityId, 1))
                     .map(Math::toIntExact)
                     .map(Math::toIntExact)
                     .orElseThrow(new BusinessException("很遗憾,铸造活动已无库存"));
                     .orElseThrow(new BusinessException("很遗憾,铸造活动已无库存"));
@@ -235,13 +238,16 @@ public class MintOrderService {
                     assetRepo.save(asset);
                     assetRepo.save(asset);
                 });
                 });
             } else {
             } else {
+                // 转让的用户
+                userRepo.findByIdAndDelFalse(1435297L).orElseThrow(new BusinessException("无法铸造"));
+
                 // 消耗改为转赠
                 // 消耗改为转赠
                 assets.forEach(asset -> {
                 assets.forEach(asset -> {
+                    if (!asset.getUserId().equals(user.getId())) {
+                        throw new BusinessException("此藏品不属于你");
+                    }
                     // 取消公开展示
                     // 取消公开展示
                     if (asset.isPublicShow()) {
                     if (asset.isPublicShow()) {
-                        if (!asset.getUserId().equals(user.getId())) {
-                            throw new BusinessException("此藏品不属于你");
-                        }
                         if (asset.isConsignment()) {
                         if (asset.isConsignment()) {
                             if (asset.getPublicCollectionId() != null) {
                             if (asset.getPublicCollectionId() != null) {
                                 List<Order> orders = orderRepo.findByCollectionId(asset.getPublicCollectionId());
                                 List<Order> orders = orderRepo.findByCollectionId(asset.getPublicCollectionId());
@@ -256,21 +262,21 @@ public class MintOrderService {
                         collectionRepo.delete(collection);
                         collectionRepo.delete(collection);
                         // 如果展厅有此藏品
                         // 如果展厅有此藏品
                         showCollectionRepo.deleteAllByCollectionId(asset.getPublicCollectionId());
                         showCollectionRepo.deleteAllByCollectionId(asset.getPublicCollectionId());
+                    }
+
+                });
 
 
+                // 统一处理
+                assets.forEach(asset -> {
+                    if (asset.isPublicShow()) {
                         asset.setPublicShow(false);
                         asset.setPublicShow(false);
                         asset.setPublicCollectionId(null);
                         asset.setPublicCollectionId(null);
                     }
                     }
                     asset.setStatus(AssetStatus.MINTING);
                     asset.setStatus(AssetStatus.MINTING);
                     assetRepo.save(asset);
                     assetRepo.save(asset);
                 });
                 });
-                // 转让的用户
-                userRepo.findByIdAndDelFalse(1435297L).orElseThrow(new BusinessException("无法铸造"));
             }
             }
 
 
-            UserAddress userAddress = null;
-            if (addressId != null) {
-                userAddress = userAddressRepo.findById(addressId).orElseThrow(new BusinessException("地址信息不存在"));
-            }
 
 
             // 铸造订单
             // 铸造订单
             MintOrder mintOrder = mintOrderRepo.save(MintOrder.builder()
             MintOrder mintOrder = mintOrderRepo.save(MintOrder.builder()
@@ -304,8 +310,6 @@ public class MintOrderService {
 
 
             mintMaterialRepo.saveAll(materials);
             mintMaterialRepo.saveAll(materials);
 
 
-            //销量
-//        mintActivityService.increaseSale(mintActivityId, 1);
             if (mintOrder.getGasPrice().compareTo(BigDecimal.ZERO) == 0) {
             if (mintOrder.getGasPrice().compareTo(BigDecimal.ZERO) == 0) {
                 this.mintNotify(mintOrder.getId(), PayMethod.WEIXIN, null);
                 this.mintNotify(mintOrder.getId(), PayMethod.WEIXIN, null);
             }
             }
@@ -543,12 +547,10 @@ public class MintOrderService {
 
 
             // 加库存
             // 加库存
             mintActivityService.increaseStock(order.getMintActivityId(), 1);
             mintActivityService.increaseStock(order.getMintActivityId(), 1);
-//        mintActivityService.decreaseSale(order.getMintActivityId(), 1);
 
 
             rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), order.getMintActivityId(), 10000);
             rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), order.getMintActivityId(), 10000);
             log.info("取消订单{}", order.getId());
             log.info("取消订单{}", order.getId());
         } catch (Exception e) {
         } catch (Exception e) {
-            mintActivityService.decreaseStock(order.getMintActivityId(), 1);
             log.error("订单取消错误 orderId: " + order.getId(), e);
             log.error("订单取消错误 orderId: " + order.getId(), e);
         }
         }
         releaseOrderLock(order.getId());
         releaseOrderLock(order.getId());