|
|
@@ -1,5 +1,6 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -106,6 +107,8 @@ public class OrderService {
|
|
|
private final UserPropertyRepo userPropertyRepo;
|
|
|
private final UserBalanceService userBalanceService;
|
|
|
private final ProxyManager<String> buckets;
|
|
|
+ private final HeatInfoRepo heatInfoRepo;
|
|
|
+ private final ShowroomRepo showroomRepo;
|
|
|
|
|
|
public OrderService(OrderRepo orderRepo, CollectionRepo collectionRepo, UserAddressRepo userAddressRepo,
|
|
|
UserRepo userRepo, Environment env, AlipayClient alipayClient,
|
|
|
@@ -149,14 +152,17 @@ public class OrderService {
|
|
|
this.userPropertyRepo = userPropertyRepo;
|
|
|
this.userBalanceService = userBalanceService;
|
|
|
this.buckets = proxyManager;
|
|
|
+ this.heatInfoRepo = heatInfoRepo;
|
|
|
+ this.showroomRepo = showroomRepo;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public Page<Order> all(PageQuery pageQuery) {
|
|
|
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, boolean vip, int vipPurchase, int vipPoint) {
|
|
|
+ String sign, boolean vip, Long showroomId) {
|
|
|
String qs = null;
|
|
|
try {
|
|
|
qs = AESEncryptUtil.decrypt(sign);
|
|
|
@@ -190,7 +196,7 @@ public class OrderService {
|
|
|
|
|
|
Long id = snowflakeIdWorker.nextId();
|
|
|
SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
|
|
|
- new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip), 100000);
|
|
|
+ new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip, showroomId), 100000);
|
|
|
|
|
|
log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
|
|
|
return String.valueOf(id);
|
|
|
@@ -206,7 +212,7 @@ public class OrderService {
|
|
|
}
|
|
|
|
|
|
public Order create(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
|
|
|
- Long id, boolean vip) {
|
|
|
+ Long id, boolean vip, Long showroomId) {
|
|
|
long t = System.currentTimeMillis();
|
|
|
qty = 1;
|
|
|
int stock = Optional.ofNullable(collectionService.decreaseStock(collectionId, qty))
|
|
|
@@ -399,6 +405,17 @@ public class OrderService {
|
|
|
userRepo.addVipPoint(userId, -usePoint);
|
|
|
cacheService.clearUserMy(userId);
|
|
|
}
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotEmpty(showroomId)) {
|
|
|
+ //通过展厅的购买数量
|
|
|
+ heatInfoRepo.save(HeatInfo.builder()
|
|
|
+ .showroomId(showroomId)
|
|
|
+ .userId(userId)
|
|
|
+ .type(HeatType.BUY)
|
|
|
+ .value(0)
|
|
|
+ .orderId(order.getId())
|
|
|
+ .build());
|
|
|
+ }
|
|
|
rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), collectionId, 10000);
|
|
|
log.info("订单创建完成, id={}, {}ms", order.getId(), System.currentTimeMillis() - t);
|
|
|
return order;
|
|
|
@@ -716,7 +733,6 @@ public class OrderService {
|
|
|
smsService.sellOut(userRepo.findPhoneById(asset.getUserId()));
|
|
|
}
|
|
|
|
|
|
- userBalanceService.realtimeSettleOrder(order);
|
|
|
} else {
|
|
|
orderRepo.save(order);
|
|
|
//藏品其他信息/是否vip
|
|
|
@@ -740,6 +756,17 @@ public class OrderService {
|
|
|
if (collection.getAssetId() == null) {
|
|
|
collectionService.increaseSale(order.getCollectionId(), order.getQty());
|
|
|
}
|
|
|
+
|
|
|
+ //通过展厅购买加热力值
|
|
|
+ List<HeatInfo> heatInfos = heatInfoRepo.findByUserIdAndOrderIdAndType(order.getUserId(), orderId, HeatType.BUY);
|
|
|
+ if (CollUtil.isNotEmpty(heatInfos)) {
|
|
|
+ HeatInfo heatInfo = heatInfos.get(0);
|
|
|
+ int weight = sysConfigService.getInt("heat_buy_weight");
|
|
|
+ heatInfo.setValue(weight);
|
|
|
+ heatInfoRepo.save(heatInfo);
|
|
|
+ showroomRepo.addHeat(heatInfo.getShowroomId(), weight);
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
throw new BusinessException("状态错误 " + order.getStatus());
|
|
|
}
|
|
|
@@ -836,7 +863,7 @@ public class OrderService {
|
|
|
}
|
|
|
//加上积分
|
|
|
if (ObjectUtils.isNotEmpty(order.getVipPoint()) && order.getVipPoint() > 0) {
|
|
|
- userRepo.updateVipPoint(order.getUserId(), order.getVipPoint());
|
|
|
+ userRepo.addVipPoint(order.getUserId(), order.getVipPoint());
|
|
|
cacheService.clearUserMy(order.getUserId());
|
|
|
log.info("取消加积分用户ID:{},订单ID:{},积分:{}", order.getUserId(), order.getId(), order.getVipPoint());
|
|
|
}
|
|
|
@@ -844,6 +871,7 @@ public class OrderService {
|
|
|
collectionService.decreaseQuota(order.getCollectionId(), 1);
|
|
|
log.info("取消加藏品额度CollectionId:{}", order.getCollectionId());
|
|
|
}
|
|
|
+
|
|
|
rocketMQTemplate.syncSend(generalProperties.getUpdateQuotaTopic(), order.getCollectionId(), 10000);
|
|
|
log.info("取消订单{}", order.getId());
|
|
|
} catch (Exception e) {
|