licailing před 4 roky
rodič
revize
5d7089c1a3

+ 8 - 0
src/main/java/com/izouma/nineth/domain/Collection.java

@@ -171,4 +171,12 @@ public class Collection extends BaseEntity {
     @ApiModelProperty("注册背景")
     @ApiModelProperty("注册背景")
     private String registerBg;
     private String registerBg;
 
 
+    @ApiModelProperty("白名单额度")
+    private Integer vipQuota;
+
+    @ApiModelProperty("延迟销售")
+    private Boolean timeDelay;
+
+    @ApiModelProperty("销售时间")
+    private LocalDateTime saleTime;
 }
 }

+ 3 - 0
src/main/java/com/izouma/nineth/domain/Order.java

@@ -205,4 +205,7 @@ public class Order extends BaseEntityNoID {
 
 
     @ApiModelProperty("是否vip")
     @ApiModelProperty("是否vip")
     private boolean vip;
     private boolean vip;
+
+    @ApiModelProperty("vip积分购买")
+    private Integer vipPoint;
 }
 }

+ 29 - 0
src/main/java/com/izouma/nineth/domain/PointRecord.java

@@ -0,0 +1,29 @@
+package com.izouma.nineth.domain;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+import javax.persistence.Index;
+import javax.persistence.Table;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@Entity
+@Table(name = "point_record", indexes = {
+        @Index(columnList = "userId"),
+        @Index(columnList = "collectionId")
+})
+public class PointRecord extends BaseEntity {
+    private Long userId;
+
+    private Long collectionId;
+
+    private int point;
+
+    private String type;
+}

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

@@ -32,6 +32,7 @@ import java.util.Set;
         @Index(columnList = "collectionInvitor"),
         @Index(columnList = "collectionInvitor"),
         @Index(columnList = "admin"),
         @Index(columnList = "admin"),
         @Index(columnList = "minter"),
         @Index(columnList = "minter"),
+        @Index(columnList = "createdAt"),
         @Index(columnList = "settleAccountId")
         @Index(columnList = "settleAccountId")
 })
 })
 @AllArgsConstructor
 @AllArgsConstructor
@@ -143,6 +144,11 @@ public class User extends BaseEntity implements Serializable {
 
 
     private boolean minter;
     private boolean minter;
 
 
+    @Column(columnDefinition = "bit default false")
     @ApiModelProperty("使用藏品图片")
     @ApiModelProperty("使用藏品图片")
     private boolean useCollectionPic;
     private boolean useCollectionPic;
+
+    @Column(columnDefinition = "int(11) default 0")
+    @ApiModelProperty("白名单积分")
+    private int vipPoint;
 }
 }

+ 1 - 0
src/main/java/com/izouma/nineth/event/CreateOrderEvent.java

@@ -27,4 +27,5 @@ public class CreateOrderEvent implements Serializable {
     private Long    invitor;
     private Long    invitor;
     private boolean vip;
     private boolean vip;
     private int     vipPurchase;
     private int     vipPurchase;
+    private int     vipPoint;
 }
 }

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

@@ -37,7 +37,7 @@ public class CreateOrderListener implements RocketMQListener<CreateOrderEvent> {
         try {
         try {
             Order order = orderService.create(event.getUserId(), event.getCollectionId(), event.getQty(),
             Order order = orderService.create(event.getUserId(), event.getCollectionId(), event.getQty(),
                     event.getAddressId(), event.getUserCouponId(), event.getInvitor(), event.getId(),
                     event.getAddressId(), event.getUserCouponId(), event.getInvitor(), event.getId(),
-                    event.isVip(), event.getVipPurchase());
+                    event.isVip(), event.getVipPurchase(), event.getVipPoint());
             map.put("success", true);
             map.put("success", true);
             map.put("data", order);
             map.put("data", order);
         } catch (Exception e) {
         } catch (Exception e) {

+ 4 - 2
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -30,12 +30,14 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
             "c.schedule_sale = ?5, c.sort = ?6, c.detail = ?7, c.privileges = ?8, " +
             "c.schedule_sale = ?5, c.sort = ?6, c.detail = ?7, c.privileges = ?8, " +
             "c.properties = ?9, c.model3d = ?10, c.max_count = ?11, c.count_id = ?12, c.scan_code = ?13, " +
             "c.properties = ?9, c.model3d = ?10, c.max_count = ?11, c.count_id = ?12, c.scan_code = ?13, " +
             "c.no_sold_out = ?14, c.assignment = ?15, c.coupon_payment = ?16, c.share_bg = ?17," +
             "c.no_sold_out = ?14, c.assignment = ?15, c.coupon_payment = ?16, c.share_bg = ?17," +
-            "c.register_bg = ?18 where c.id = ?1", nativeQuery = true)
+            "c.register_bg = ?18, c.vip_quoto = ?19, c.time_delay = ?20, c.sale_time = ?21 " +
+            "where c.id = ?1", nativeQuery = true)
     @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
     @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
     void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
     void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
                 boolean schedule, int sort, String detail, String privileges,
                 boolean schedule, int sort, String detail, String privileges,
                 String properties, String model3d, int maxCount, String countId, boolean scanCode,
                 String properties, String model3d, int maxCount, String countId, boolean scanCode,
-                boolean noSoldOut, int assignment, boolean couponPayment, String shareBg, String registerBg);
+                boolean noSoldOut, int assignment, boolean couponPayment, String shareBg, String registerBg,
+                Integer vipQuota, Boolean timeDelay, LocalDateTime saleTime);
 
 
     @Cacheable("collection")
     @Cacheable("collection")
     Optional<Collection> findById(@Nonnull Long id);
     Optional<Collection> findById(@Nonnull Long id);

+ 8 - 0
src/main/java/com/izouma/nineth/repo/PointRecordRepo.java

@@ -0,0 +1,8 @@
+package com.izouma.nineth.repo;
+
+import com.izouma.nineth.domain.PointRecord;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface PointRecordRepo extends JpaRepository<PointRecord, Long> {
+    int countByUserIdAndCollectionId(Long userId, Long collectionId);
+}

+ 6 - 0
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -180,4 +180,10 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
     List<User> findAllByCreatedAtIsAfterAndAuthoritiesContains(LocalDateTime createdAt, Authority authorities);
     List<User> findAllByCreatedAtIsAfterAndAuthoritiesContains(LocalDateTime createdAt, Authority authorities);
 
 
     List<User> findBySettleAccountIdIsNotNull();
     List<User> findBySettleAccountIdIsNotNull();
+
+    @Transactional
+    @Modifying
+    @Query("update User set vipPoint = vipPoint + ?2 where id = ?1")
+    void updateVipPoint(Long id, int num);
+
 }
 }

+ 2 - 1
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -151,7 +151,8 @@ public class CollectionService {
                 record.getDetail(), JSON.toJSONString(record.getPrivileges()),
                 record.getDetail(), JSON.toJSONString(record.getPrivileges()),
                 JSON.toJSONString(record.getProperties()), JSON.toJSONString(record.getModel3d()),
                 JSON.toJSONString(record.getProperties()), JSON.toJSONString(record.getModel3d()),
                 record.getMaxCount(), record.getCountId(), record.isScanCode(), record.isNoSoldOut(),
                 record.getMaxCount(), record.getCountId(), record.isScanCode(), record.isNoSoldOut(),
-                record.getAssignment(), record.isCouponPayment(), record.getShareBg(), record.getRegisterBg());
+                record.getAssignment(), record.isCouponPayment(), record.getShareBg(), record.getRegisterBg(),
+                record.getVipQuota(), record.getTimeDelay(), record.getSaleTime());
 
 
         record = collectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
         record = collectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
         onShelfTask(record);
         onShelfTask(record);

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

@@ -97,7 +97,7 @@ public class OrderService {
     }
     }
 
 
     public String mqCreate(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
     public String mqCreate(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
-                           String sign, boolean vip, int vipPurchase) {
+                           String sign, boolean vip, int vipPurchase, int vipPoint) {
         String qs = null;
         String qs = null;
         try {
         try {
             qs = AESEncryptUtil.decrypt(sign);
             qs = AESEncryptUtil.decrypt(sign);
@@ -111,13 +111,15 @@ public class OrderService {
 
 
         Long id = snowflakeIdWorker.nextId();
         Long id = snowflakeIdWorker.nextId();
         SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
         SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
-                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip, vipPurchase), 100000);
+                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip, vipPurchase,
+                        vipPoint), 100000);
+
         log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
         log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
         return String.valueOf(id);
         return String.valueOf(id);
     }
     }
 
 
     public Order create(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
     public Order create(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
-                        Long id, boolean vip, int vipPurchase) {
+                        Long id, boolean vip, int vipPurchase, int vipPoint) {
         long t = System.currentTimeMillis();
         long t = System.currentTimeMillis();
         qty = 1;
         qty = 1;
         int stock = Optional.ofNullable(collectionService.decreaseStock(collectionId, qty))
         int stock = Optional.ofNullable(collectionService.decreaseStock(collectionId, qty))
@@ -181,6 +183,7 @@ public class OrderService {
             }
             }
 
 
             //查询是否有拉新任务,只算官方购买
             //查询是否有拉新任务,只算官方购买
+            int usePoint = 0;
             if (collection.getSource() != CollectionSource.TRANSFER && collection.getAssignment() > 0) {
             if (collection.getSource() != CollectionSource.TRANSFER && collection.getAssignment() > 0) {
                 if (vip) {
                 if (vip) {
                     int purchase = orderRepo.countByUserIdAndCollectionIdAndVipTrueAndStatusIn(userId, collectionId, Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
                     int purchase = orderRepo.countByUserIdAndCollectionIdAndVipTrueAndStatusIn(userId, collectionId, Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
@@ -188,11 +191,15 @@ public class OrderService {
                         throw new BusinessException("vip名额已使用完毕!");
                         throw new BusinessException("vip名额已使用完毕!");
                     }
                     }
                 } else {
                 } else {
-                    long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, userId);
-                    int sub = collection.getAssignment() - (int) count;
-                    if (sub > 0) {
-                        throw new BusinessException("再拉新" + sub + "人即可购买");
+//                    long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, userId);
+//                    int sub = collection.getAssignment() - (int) count;
+//                    if (sub > 0) {
+//                        throw new BusinessException("再拉新" + sub + "人即可购买");
+//                    }
+                    if (vipPoint < 1) {
+                        throw new BusinessException("没有购买名额");
                     }
                     }
+                    usePoint = 1;
                 }
                 }
             }
             }
 
 
@@ -234,6 +241,7 @@ public class OrderService {
                     .invitor(invitor)
                     .invitor(invitor)
                     .countId(collection.getCountId())
                     .countId(collection.getCountId())
                     .vip(vip)
                     .vip(vip)
+                    .vipPoint(usePoint)
                     .build();
                     .build();
             if (coupon != null) {
             if (coupon != null) {
                 coupon.setUsed(true);
                 coupon.setUsed(true);
@@ -256,6 +264,11 @@ public class OrderService {
             if (order.getTotalPrice().equals(BigDecimal.ZERO)) {
             if (order.getTotalPrice().equals(BigDecimal.ZERO)) {
                 notifyOrder(order.getId(), PayMethod.WEIXIN, null);
                 notifyOrder(order.getId(), PayMethod.WEIXIN, null);
             }
             }
+
+            if (usePoint > 0) {
+                // 扣除积分
+                userRepo.updateVipPoint(userId, -usePoint);
+            }
             rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), collectionId, 10000);
             rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), collectionId, 10000);
             log.info("订单创建完成, id={}, {}ms", order.getId(), System.currentTimeMillis() - t);
             log.info("订单创建完成, id={}, {}ms", order.getId(), System.currentTimeMillis() - t);
             return order;
             return order;
@@ -704,6 +717,11 @@ public class OrderService {
                     userCouponRepo.save(coupon);
                     userCouponRepo.save(coupon);
                 });
                 });
             }
             }
+            //加上积分
+            if (order.getVipPoint() > 0) {
+                userRepo.updateVipPoint(order.getUserId(), order.getVipPoint());
+            }
+
             rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), order.getCollectionId(), 10000);
             rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), order.getCollectionId(), 10000);
             log.info("取消订单{}", order.getId());
             log.info("取消订单{}", order.getId());
         } catch (Exception e) {
         } catch (Exception e) {

+ 22 - 1
src/main/java/com/izouma/nineth/service/UserService.java

@@ -77,6 +77,7 @@ public class UserService {
     private CollectionRepo        collectionRepo;
     private CollectionRepo        collectionRepo;
     private AdapayProperties      adapayProperties;
     private AdapayProperties      adapayProperties;
     private AdapayMerchantService adapayMerchantService;
     private AdapayMerchantService adapayMerchantService;
+    private PointRecordRepo       pointRecordRepo;
 
 
     public User update(User user) {
     public User update(User user) {
         User orig = userRepo.findById(user.getId()).orElseThrow(new BusinessException("无记录"));
         User orig = userRepo.findById(user.getId()).orElseThrow(new BusinessException("无记录"));
@@ -165,8 +166,9 @@ public class UserService {
             invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
             invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
         }
         }
         smsService.verify(phone, code);
         smsService.verify(phone, code);
+        Collection collection = null;
         if (collectionId != null) {
         if (collectionId != null) {
-            Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("无藏品"));
+            collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("无藏品"));
             if (!collection.isOnShelf() || !collection.isSalable()) {
             if (!collection.isOnShelf() || !collection.isSalable()) {
                 collectionId = null;
                 collectionId = null;
             } else if (collection.isScheduleSale()) {
             } else if (collection.isScheduleSale()) {
@@ -191,6 +193,25 @@ public class UserService {
         if (invite != null) {
         if (invite != null) {
             inviteRepo.increaseNum(invite.getId());
             inviteRepo.increaseNum(invite.getId());
         }
         }
+
+        // 加积分
+        if (collectionId != null && invitor != null) {
+            if (collection.getVipQuota() > 0) {
+                int point = pointRecordRepo.countByUserIdAndCollectionId(invitor, collectionId);
+                if (point <= 0) {
+                    long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
+                    if (count >= collection.getAssignment()) {
+                        userRepo.updateVipPoint(invitor, 1);
+                        pointRecordRepo.save(PointRecord.builder()
+                                .collectionId(collectionId)
+                                .userId(invitor)
+                                .type("VIP_POINT")
+                                .point(1)
+                                .build());
+                    }
+                }
+            }
+        }
         return user;
         return user;
     }
     }
 
 

+ 1 - 1
src/main/java/com/izouma/nineth/web/OrderController.java

@@ -112,7 +112,7 @@ public class OrderController extends BaseController {
         final User user = SecurityUtils.getAuthenticatedUser();
         final User user = SecurityUtils.getAuthenticatedUser();
         return new HashMap<>() {{
         return new HashMap<>() {{
             put("id", orderService.mqCreate(user.getId(), collectionId, qty, addressId, couponId, invitor, sign,
             put("id", orderService.mqCreate(user.getId(), collectionId, qty, addressId, couponId, invitor, sign,
-                    vip, user.getVipPurchase()));
+                    vip, user.getVipPurchase(), user.getVipPoint()));
         }};
         }};
     }
     }
 
 

+ 1 - 1
src/test/java/com/izouma/nineth/service/OrderServiceTest.java

@@ -245,7 +245,7 @@ public class OrderServiceTest extends ApplicationTests {
     @Test
     @Test
     public void test() {
     public void test() {
         orderService.create(9850L, 196308L, 1, null, null, null,
         orderService.create(9850L, 196308L, 1, null, null, null,
-                945378720611303424L, true, 2);
+                945378720611303424L, true, 2, 1);
     }
     }
 
 
     @Test
     @Test