|
@@ -63,7 +63,9 @@ import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -215,9 +217,11 @@ public class OrderService {
|
|
|
if (collection.getMaxCount() > 0) {
|
|
if (collection.getMaxCount() > 0) {
|
|
|
int count;
|
|
int count;
|
|
|
if (StringUtils.isNotBlank(collection.getCountId())) {
|
|
if (StringUtils.isNotBlank(collection.getCountId())) {
|
|
|
- count = orderRepo.countByUserIdAndCountIdAndStatusIn(userId, collection.getCountId(), Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
|
|
|
|
+ count = orderRepo.countByUserIdAndCountIdAndStatusIn(userId, collection.getCountId(), Arrays
|
|
|
|
|
+ .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
} else {
|
|
} else {
|
|
|
- count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userId, collectionId, Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
|
|
|
|
+ count = orderRepo.countByUserIdAndCollectionIdAndStatusIn(userId, collectionId, Arrays
|
|
|
|
|
+ .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
}
|
|
}
|
|
|
if (count >= collection.getMaxCount()) {
|
|
if (count >= collection.getMaxCount()) {
|
|
|
throw new BusinessException("限购" + collection.getMaxCount() + "件");
|
|
throw new BusinessException("限购" + collection.getMaxCount() + "件");
|
|
@@ -247,7 +251,9 @@ public class OrderService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (vip) {
|
|
if (vip) {
|
|
|
- int purchase = orderRepo.countByUserIdAndCollectionIdAndVipTrueAndStatusIn(userId, collectionId, Arrays.asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
|
|
|
|
+ int purchase = orderRepo
|
|
|
|
|
+ .countByUserIdAndCollectionIdAndVipTrueAndStatusIn(userId, collectionId, Arrays
|
|
|
|
|
+ .asList(OrderStatus.FINISH, OrderStatus.NOT_PAID, OrderStatus.PROCESSING));
|
|
|
if (user.getVipPurchase() - purchase <= 0) {
|
|
if (user.getVipPurchase() - purchase <= 0) {
|
|
|
throw new BusinessException("vip名额已使用完毕!");
|
|
throw new BusinessException("vip名额已使用完毕!");
|
|
|
}
|
|
}
|
|
@@ -293,7 +299,8 @@ public class OrderService {
|
|
|
.contactName(Optional.ofNullable(userAddress).map(UserAddress::getName).orElse(null))
|
|
.contactName(Optional.ofNullable(userAddress).map(UserAddress::getName).orElse(null))
|
|
|
.contactPhone(Optional.ofNullable(userAddress).map(UserAddress::getPhone).orElse(null))
|
|
.contactPhone(Optional.ofNullable(userAddress).map(UserAddress::getPhone).orElse(null))
|
|
|
.address(Optional.ofNullable(userAddress).map(u ->
|
|
.address(Optional.ofNullable(userAddress).map(u ->
|
|
|
- u.getProvinceName() + " " + u.getCityName() + " " + u.getDistrictName() + " " + u.getAddress())
|
|
|
|
|
|
|
+ u.getProvinceName() + " " + u.getCityName() + " " + u.getDistrictName() + " " + u
|
|
|
|
|
+ .getAddress())
|
|
|
.orElse(null))
|
|
.orElse(null))
|
|
|
.status(OrderStatus.NOT_PAID)
|
|
.status(OrderStatus.NOT_PAID)
|
|
|
.assetId(collection.getAssetId())
|
|
.assetId(collection.getAssetId())
|
|
@@ -476,7 +483,8 @@ public class OrderService {
|
|
|
paymentParams.put("goods_desc", collection.getName());
|
|
paymentParams.put("goods_desc", collection.getName());
|
|
|
paymentParams.put("time_expire", DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
|
|
paymentParams.put("time_expire", DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
|
|
|
.format(LocalDateTime.now().plusMinutes(3)));
|
|
.format(LocalDateTime.now().plusMinutes(3)));
|
|
|
- paymentParams.put("notify_url", adapayProperties.getNotifyUrl() + "/order/" + adapayProperties.getMerchant() + "/" + order.getId());
|
|
|
|
|
|
|
+ paymentParams.put("notify_url", adapayProperties.getNotifyUrl() + "/order/" + adapayProperties
|
|
|
|
|
+ .getMerchant() + "/" + order.getId());
|
|
|
|
|
|
|
|
List<Map<String, Object>> divMembers = new ArrayList<>();
|
|
List<Map<String, Object>> divMembers = new ArrayList<>();
|
|
|
BigDecimal totalAmount = order.getTotalPrice().subtract(order.getGasPrice());
|
|
BigDecimal totalAmount = order.getTotalPrice().subtract(order.getGasPrice());
|
|
@@ -541,7 +549,8 @@ public class OrderService {
|
|
|
case "alipay_qr":
|
|
case "alipay_qr":
|
|
|
return MapUtils.getString(MapUtils.getMap(response, "expend"), "qrcode_url");
|
|
return MapUtils.getString(MapUtils.getMap(response, "expend"), "qrcode_url");
|
|
|
case "wx_pub":
|
|
case "wx_pub":
|
|
|
- JSONObject payParams = JSON.parseObject(MapUtils.getString(MapUtils.getMap(response, "expend"), "pay_info"));
|
|
|
|
|
|
|
+ JSONObject payParams = JSON
|
|
|
|
|
+ .parseObject(MapUtils.getString(MapUtils.getMap(response, "expend"), "pay_info"));
|
|
|
payParams.put("timestamp", payParams.get("timeStamp"));
|
|
payParams.put("timestamp", payParams.get("timeStamp"));
|
|
|
payParams.remove("timeStamp");
|
|
payParams.remove("timeStamp");
|
|
|
return payParams;
|
|
return payParams;
|
|
@@ -625,7 +634,8 @@ public class OrderService {
|
|
|
orderRepo.save(order);
|
|
orderRepo.save(order);
|
|
|
throw new BusinessException("抽卡失败, 已退款 " + orderId);
|
|
throw new BusinessException("抽卡失败, 已退款 " + orderId);
|
|
|
}
|
|
}
|
|
|
- log.info("抽卡成功 orderId: {}, collectionId: {}, winCollectionId: {}", orderId, collection.getId(), winItem.getCollectionId());
|
|
|
|
|
|
|
+ log.info("抽卡成功 orderId: {}, collectionId: {}, winCollectionId: {}", orderId, collection
|
|
|
|
|
+ .getId(), winItem.getCollectionId());
|
|
|
order.setWinCollectionId(winItem.getCollectionId());
|
|
order.setWinCollectionId(winItem.getCollectionId());
|
|
|
orderRepo.save(order);
|
|
orderRepo.save(order);
|
|
|
|
|
|
|
@@ -667,7 +677,8 @@ public class OrderService {
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
Asset asset = assetService.createAsset(collection, user, order.getId(), order.getPrice(), "出售",
|
|
Asset asset = assetService.createAsset(collection, user, order.getId(), order.getPrice(), "出售",
|
|
|
- collection.getTotal() > 1 ? collectionService.getNextNumber(order.getCollectionId()) : null);
|
|
|
|
|
|
|
+ collection.getTotal() > 1 ? collectionService
|
|
|
|
|
+ .getNextNumber(order.getCollectionId()) : null);
|
|
|
|
|
|
|
|
if (collection.getType() == CollectionType.SHOWROOM) {
|
|
if (collection.getType() == CollectionType.SHOWROOM) {
|
|
|
showroomService.save(asset);
|
|
showroomService.save(asset);
|
|
@@ -922,9 +933,12 @@ public class OrderService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void calcSettle(LocalDateTime start, LocalDateTime end, OutputStream outputStream) {
|
|
public void calcSettle(LocalDateTime start, LocalDateTime end, OutputStream outputStream) {
|
|
|
- List<Order> orders = orderRepo.findByCreatedAtBetweenAndSourceAndStatusIn(start, end, CollectionSource.TRANSFER, Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH));
|
|
|
|
|
|
|
+ List<Order> orders = orderRepo
|
|
|
|
|
+ .findByCreatedAtBetweenAndSourceAndStatusIn(start, end, CollectionSource.TRANSFER, Arrays
|
|
|
|
|
+ .asList(OrderStatus.PROCESSING, OrderStatus.FINISH));
|
|
|
List<Asset> assets = assetRepo.findAllById(orders.stream().map(Order::getAssetId).collect(Collectors.toSet()));
|
|
List<Asset> assets = assetRepo.findAllById(orders.stream().map(Order::getAssetId).collect(Collectors.toSet()));
|
|
|
- List<UserBankCard> bankCards = userBankCardRepo.findByUserIdIn(assets.stream().map(Asset::getUserId).collect(Collectors.toSet()));
|
|
|
|
|
|
|
+ List<UserBankCard> bankCards = userBankCardRepo
|
|
|
|
|
+ .findByUserIdIn(assets.stream().map(Asset::getUserId).collect(Collectors.toSet()));
|
|
|
List<MarketSettlement> settlements = new ArrayList<>();
|
|
List<MarketSettlement> settlements = new ArrayList<>();
|
|
|
for (Order order : orders) {
|
|
for (Order order : orders) {
|
|
|
BigDecimal amount = order.getTotalPrice()
|
|
BigDecimal amount = order.getTotalPrice()
|
|
@@ -934,10 +948,13 @@ public class OrderService {
|
|
|
.subtract(BigDecimal.valueOf(order.getRoyalties()))
|
|
.subtract(BigDecimal.valueOf(order.getRoyalties()))
|
|
|
.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP))
|
|
.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP))
|
|
|
.setScale(2, RoundingMode.HALF_UP);
|
|
.setScale(2, RoundingMode.HALF_UP);
|
|
|
- Long userId = assets.stream().filter(a -> a.getId().equals(order.getAssetId())).map(Asset::getUserId).findAny().orElse(null);
|
|
|
|
|
|
|
+ Long userId = assets.stream().filter(a -> a.getId().equals(order.getAssetId())).map(Asset::getUserId)
|
|
|
|
|
+ .findAny().orElse(null);
|
|
|
if (userId != null) {
|
|
if (userId != null) {
|
|
|
- UserBankCard userBankCard = bankCards.stream().filter(b -> b.getUserId().equals(userId)).findAny().orElse(null);
|
|
|
|
|
- MarketSettlement marketSettlement = settlements.stream().filter(s -> s.getUserId().equals(userId)).findAny().orElse(null);
|
|
|
|
|
|
|
+ UserBankCard userBankCard = bankCards.stream().filter(b -> b.getUserId().equals(userId)).findAny()
|
|
|
|
|
+ .orElse(null);
|
|
|
|
|
+ MarketSettlement marketSettlement = settlements.stream().filter(s -> s.getUserId().equals(userId))
|
|
|
|
|
+ .findAny().orElse(null);
|
|
|
if (marketSettlement == null) {
|
|
if (marketSettlement == null) {
|
|
|
marketSettlement = new MarketSettlement(userId,
|
|
marketSettlement = new MarketSettlement(userId,
|
|
|
Optional.ofNullable(userBankCard).map(UserBankCard::getRealName).orElse(null),
|
|
Optional.ofNullable(userBankCard).map(UserBankCard::getRealName).orElse(null),
|
|
@@ -952,4 +969,15 @@ public class OrderService {
|
|
|
}
|
|
}
|
|
|
EasyExcel.write(outputStream, MarketSettlement.class).sheet("sheet").doWrite(settlements);
|
|
EasyExcel.write(outputStream, MarketSettlement.class).sheet("sheet").doWrite(settlements);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ?")
|
|
|
|
|
+ public void setBlackList() {
|
|
|
|
|
+ List<Long> userIds = orderRepo
|
|
|
|
|
+ .checkBlackList(LocalDate.now().atStartOfDay(), LocalDate.now().atTime(LocalTime.MAX));
|
|
|
|
|
+ userIds.forEach(userId -> {
|
|
|
|
|
+ redisTemplate.opsForValue().set(RedisKeys.BLACK_LIST + userId, 1, Duration.ofSeconds(60 * 120));
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|