xiongzhu 4 năm trước cách đây
mục cha
commit
e01361dae9

+ 2 - 0
src/main/java/com/izouma/nineth/domain/User.java

@@ -75,6 +75,8 @@ public class User extends BaseEntity implements Serializable {
 
 
     private int followers;
     private int followers;
 
 
+    private int sales;
+
     private String intro;
     private String intro;
 
 
     private String bg;
     private String bg;

+ 9 - 0
src/main/java/com/izouma/nineth/dto/CollectionDTO.java

@@ -0,0 +1,9 @@
+package com.izouma.nineth.dto;
+
+import com.izouma.nineth.domain.Collection;
+import lombok.Data;
+
+@Data
+public class CollectionDTO extends Collection {
+    private boolean liked;
+}

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

@@ -57,6 +57,7 @@ public class OrderService {
         if (qty <= 0) throw new BusinessException("数量必须大于0");
         if (qty <= 0) throw new BusinessException("数量必须大于0");
         User user = userRepo.findByIdAndDelFalse(userId).orElseThrow(new BusinessException("用户不存在"));
         User user = userRepo.findByIdAndDelFalse(userId).orElseThrow(new BusinessException("用户不存在"));
         Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("藏品不存在"));
         Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("藏品不存在"));
+        User minter = userRepo.findById(collection.getMinterId()).orElseThrow(new BusinessException("铸造者不存在"));
 
 
         if (!collection.isOnShelf()) {
         if (!collection.isOnShelf()) {
             throw new BusinessException("藏品已下架");
             throw new BusinessException("藏品已下架");
@@ -73,14 +74,15 @@ public class OrderService {
         collection.setSale(collection.getSale() + qty);
         collection.setSale(collection.getSale() + qty);
         collectionRepo.save(collection);
         collectionRepo.save(collection);
 
 
-        User minter = userRepo.findById(collection.getMinterId()).orElse(null);
+        minter.setSales(minter.getSales() + 1);
+
         Order order = Order.builder()
         Order order = Order.builder()
                 .userId(userId)
                 .userId(userId)
                 .collectionId(collectionId)
                 .collectionId(collectionId)
                 .name(collection.getName())
                 .name(collection.getName())
                 .pic(collection.getPics())
                 .pic(collection.getPics())
-                .minter(Optional.ofNullable(minter).map(User::getNickname).orElse(collection.getMinter()))
-                .minterAvatar(Optional.ofNullable(minter).map(User::getAvatar).orElse(collection.getMinterAvatar()))
+                .minter(minter.getNickname())
+                .minterAvatar(minter.getAvatar())
                 .qty(qty)
                 .qty(qty)
                 .price(collection.getPrice())
                 .price(collection.getPrice())
                 .gasPrice(BigDecimal.valueOf(1))
                 .gasPrice(BigDecimal.valueOf(1))