|
|
@@ -91,7 +91,8 @@ public class OrderService {
|
|
|
return orderRepo.findAll(JpaUtils.toSpecification(pageQuery, Order.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
|
|
|
- public String mqCreate(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor, String sign) {
|
|
|
+ public String mqCreate(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
|
|
|
+ String sign, boolean vip, int vipPurchase) {
|
|
|
String qs = null;
|
|
|
try {
|
|
|
qs = AESEncryptUtil.decrypt(sign);
|
|
|
@@ -105,12 +106,13 @@ public class OrderService {
|
|
|
|
|
|
Long id = snowflakeIdWorker.nextId();
|
|
|
SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
|
|
|
- new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor), 100000);
|
|
|
+ new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip, vipPurchase), 100000);
|
|
|
log.info("发送订单到队列: {}, result={}", id, result);
|
|
|
return String.valueOf(id);
|
|
|
}
|
|
|
|
|
|
- public Order create(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor, Long id) {
|
|
|
+ public Order create(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
|
|
|
+ Long id, boolean vip, int vipPurchase) {
|
|
|
long t = System.currentTimeMillis();
|
|
|
qty = 1;
|
|
|
int stock = Optional.ofNullable(collectionService.decreaseStock(collectionId, qty))
|
|
|
@@ -174,10 +176,17 @@ public class OrderService {
|
|
|
|
|
|
//查询是否有拉新任务,只算官方购买
|
|
|
if (collection.getSource() != CollectionSource.TRANSFER && collection.getAssignment() > 0) {
|
|
|
- long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, userId);
|
|
|
- int sub = collection.getAssignment() - (int) count;
|
|
|
- if (sub > 0) {
|
|
|
- throw new BusinessException("再拉新" + sub + "人即可购买");
|
|
|
+ if (vip) {
|
|
|
+ int purchase = orderRepo.countByUserIdAndCollectionIdAndVipTrueAndStatusIn(userId, collectionId, Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
+ if (vipPurchase - purchase <= 0) {
|
|
|
+ throw new BusinessException("vip名额已使用完毕!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ long count = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, userId);
|
|
|
+ int sub = collection.getAssignment() - (int) count;
|
|
|
+ if (sub > 0) {
|
|
|
+ throw new BusinessException("再拉新" + sub + "人即可购买");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -218,6 +227,7 @@ public class OrderService {
|
|
|
.couponId(userCouponId)
|
|
|
.invitor(invitor)
|
|
|
.countId(collection.getCountId())
|
|
|
+ .vip(vip)
|
|
|
.build();
|
|
|
if (coupon != null) {
|
|
|
coupon.setUsed(true);
|