|
|
@@ -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;
|
|
|
@@ -48,7 +49,6 @@ import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.redis.core.BoundSetOperations;
|
|
|
import org.springframework.data.redis.core.BoundValueOperations;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
@@ -105,6 +105,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,
|
|
|
@@ -117,7 +119,8 @@ public class OrderService {
|
|
|
SmsService smsService, ErrorOrderRepo errorOrderRepo, ShowCollectionRepo showCollectionRepo,
|
|
|
ShowroomService showroomService, CollectionPrivilegeRepo collectionPrivilegeRepo,
|
|
|
UserBankCardRepo userBankCardRepo, CacheService cacheService, UserPropertyRepo userPropertyRepo,
|
|
|
- UserBalanceService userBalanceService, ProxyManager<String> proxyManager) {
|
|
|
+ UserBalanceService userBalanceService, ProxyManager<String> proxyManager,
|
|
|
+ HeatInfoRepo heatInfoRepo, ShowroomRepo showroomRepo) {
|
|
|
this.orderRepo = orderRepo;
|
|
|
this.collectionRepo = collectionRepo;
|
|
|
this.userAddressRepo = userAddressRepo;
|
|
|
@@ -148,14 +151,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, boolean safeFlag) {
|
|
|
+ String sign, boolean vip, boolean safeFlag, Long showroomId) {
|
|
|
String qs = null;
|
|
|
try {
|
|
|
qs = AESEncryptUtil.decrypt(sign);
|
|
|
@@ -190,7 +196,7 @@ public class OrderService {
|
|
|
Long id = snowflakeIdWorker.nextId();
|
|
|
redisTemplate.opsForValue().set("safeFlag::" + id, safeFlag, 10, TimeUnit.MINUTES);
|
|
|
SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
|
|
|
- new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip),
|
|
|
+ new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip, showroomId),
|
|
|
100000);
|
|
|
|
|
|
log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
|
|
|
@@ -207,7 +213,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))
|
|
|
@@ -393,6 +399,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;
|
|
|
@@ -738,6 +755,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());
|
|
|
}
|