licailing преди 3 години
родител
ревизия
e1421ace42

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

@@ -26,6 +26,4 @@ public class CreateOrderEvent implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long    invitor;
     private boolean vip;
-    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 {
             Order order = orderService.create(event.getUserId(), event.getCollectionId(), event.getQty(),
                     event.getAddressId(), event.getUserCouponId(), event.getInvitor(), event.getId(),
-                    event.isVip(), event.getVipPurchase(), event.getVipPoint());
+                    event.isVip());
             map.put("success", true);
             map.put("data", order);
         } catch (Exception e) {

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

@@ -111,15 +111,14 @@ public class OrderService {
 
         Long id = snowflakeIdWorker.nextId();
         SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
-                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip, vipPurchase,
-                        vipPoint), 100000);
+                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip), 100000);
 
         log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
         return String.valueOf(id);
     }
 
     public Order create(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
-                        Long id, boolean vip, int vipPurchase, int vipPoint) {
+                        Long id, boolean vip) {
         long t = System.currentTimeMillis();
         qty = 1;
         int stock = Optional.ofNullable(collectionService.decreaseStock(collectionId, qty))
@@ -191,10 +190,10 @@ public class OrderService {
                         throw new BusinessException("当前还未开售");
                     }
                 }
-
+                User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
                 if (vip) {
                     int purchase = orderRepo.countByUserIdAndCollectionIdAndVipTrueAndStatusIn(userId, collectionId, Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
-                    if (vipPurchase - purchase <= 0) {
+                    if (user.getVipPurchase() - purchase <= 0) {
                         throw new BusinessException("vip名额已使用完毕!");
                     }
                 } else {
@@ -203,7 +202,7 @@ public class OrderService {
 //                    if (sub > 0) {
 //                        throw new BusinessException("再拉新" + sub + "人即可购买");
 //                    }
-                    if (vipPoint < 1) {
+                    if (user.getVipPoint() < 1) {
                         throw new BusinessException("没有购买名额");
                     }
                     usePoint = 1;

+ 5 - 0
src/test/java/com/izouma/nineth/repo/UserRepoTest.java

@@ -51,4 +51,9 @@ public class UserRepoTest {
                 .build());
         System.out.println(list);
     }
+
+    @Test
+    public void test() {
+        System.out.println(userRepo.findById(150843L).orElse(null));
+    }
 }

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

@@ -245,7 +245,7 @@ public class OrderServiceTest extends ApplicationTests {
     @Test
     public void test() {
         orderService.create(9972L, 83346L, 1, null, null, null,
-                112342311L, false, 2, 1);
+                112342311L, false);
     }
 
     @Test