|
|
@@ -97,7 +97,7 @@ public class OrderService {
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
try {
|
|
|
qs = AESEncryptUtil.decrypt(sign);
|
|
|
@@ -111,13 +111,15 @@ public class OrderService {
|
|
|
|
|
|
Long id = snowflakeIdWorker.nextId();
|
|
|
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);
|
|
|
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) {
|
|
|
+ Long id, boolean vip, int vipPurchase, int vipPoint) {
|
|
|
long t = System.currentTimeMillis();
|
|
|
qty = 1;
|
|
|
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 (vip) {
|
|
|
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名额已使用完毕!");
|
|
|
}
|
|
|
} 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)
|
|
|
.countId(collection.getCountId())
|
|
|
.vip(vip)
|
|
|
+ .vipPoint(usePoint)
|
|
|
.build();
|
|
|
if (coupon != null) {
|
|
|
coupon.setUsed(true);
|
|
|
@@ -256,6 +264,11 @@ public class OrderService {
|
|
|
if (order.getTotalPrice().equals(BigDecimal.ZERO)) {
|
|
|
notifyOrder(order.getId(), PayMethod.WEIXIN, null);
|
|
|
}
|
|
|
+
|
|
|
+ if (usePoint > 0) {
|
|
|
+ // 扣除积分
|
|
|
+ userRepo.updateVipPoint(userId, -usePoint);
|
|
|
+ }
|
|
|
rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), collectionId, 10000);
|
|
|
log.info("订单创建完成, id={}, {}ms", order.getId(), System.currentTimeMillis() - t);
|
|
|
return order;
|
|
|
@@ -704,6 +717,11 @@ public class OrderService {
|
|
|
userCouponRepo.save(coupon);
|
|
|
});
|
|
|
}
|
|
|
+ //加上积分
|
|
|
+ if (order.getVipPoint() > 0) {
|
|
|
+ userRepo.updateVipPoint(order.getUserId(), order.getVipPoint());
|
|
|
+ }
|
|
|
+
|
|
|
rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), order.getCollectionId(), 10000);
|
|
|
log.info("取消订单{}", order.getId());
|
|
|
} catch (Exception e) {
|