|
|
@@ -65,9 +65,11 @@ public class AuctionOrderService {
|
|
|
@Autowired
|
|
|
private SmsService smsService;
|
|
|
@Autowired
|
|
|
- private UserBalanceRepo userBalanceRepo;
|
|
|
+ private UserBalanceService userBalanceService;
|
|
|
@Autowired
|
|
|
- private BalanceRecordRepo balanceRecordRepo;
|
|
|
+ private ShowroomService showroomService;
|
|
|
+ @Autowired
|
|
|
+ private CollectionRepo collectionRepo;
|
|
|
@Autowired
|
|
|
private ShowroomRepo showroomRepo;
|
|
|
|
|
|
@@ -285,32 +287,11 @@ public class AuctionOrderService {
|
|
|
}
|
|
|
|
|
|
//用户冲余额
|
|
|
- UserBalance userBalance = userBalanceRepo.findByUserId(asset.getOwnerId())
|
|
|
- .orElse(UserBalance.builder()
|
|
|
- .balance(BigDecimal.ZERO)
|
|
|
- .lastBalance(BigDecimal.ZERO)
|
|
|
- .userId(asset.getOwnerId())
|
|
|
- .build());
|
|
|
-
|
|
|
BigDecimal amount = order.getTotalPrice()
|
|
|
.multiply(BigDecimal.valueOf(100 - order.getRoyalties() - order.getServiceCharge()))
|
|
|
.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
|
|
|
|
|
- userBalance.setLastBalance(userBalance.getBalance());
|
|
|
- userBalance.setBalance(userBalance.getBalance().add(amount));
|
|
|
- userBalanceRepo.save(userBalance);
|
|
|
- log.info("拍卖冲用户余额{},¥{}", asset.getOwnerId(), amount);
|
|
|
-
|
|
|
- balanceRecordRepo.save(BalanceRecord.builder()
|
|
|
- .time(LocalDateTime.now())
|
|
|
- .userId(asset.getOwnerId())
|
|
|
- .orderId(order.getId())
|
|
|
- .amount(amount)
|
|
|
- .balance(userBalance.getBalance())
|
|
|
- .lastBalance(userBalance.getLastBalance())
|
|
|
- .type(BalanceType.SELL)
|
|
|
- .build());
|
|
|
-
|
|
|
+ userBalanceService.addBalance(asset.getOwnerId(), amount, id, BalanceType.AUCTION);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -519,35 +500,56 @@ public class AuctionOrderService {
|
|
|
auctionOrderRepo.save(auctionOrder);
|
|
|
}
|
|
|
|
|
|
- public void privilege(AuctionOrder order) {
|
|
|
- int maxCollection = sysConfigService.getInt("max_collection");
|
|
|
-
|
|
|
- //Bider特殊拍卖展厅服务
|
|
|
- Showroom.builder()
|
|
|
- .userId(order.getUserId())
|
|
|
- .nickname(order.getNickname())
|
|
|
- .status(AuthStatus.SUCCESS)
|
|
|
- .type("AUCTION")
|
|
|
- .maxCollection(maxCollection)
|
|
|
- .build();
|
|
|
+ public void privilege(AuctionOrder order, User user) {
|
|
|
+ if (showroomRepo.findByUserIdAndType(order.getUserId(), "AUCTION").isEmpty()) {
|
|
|
+ //Bidder特殊拍卖展厅服务 创建一个bidder展厅藏品
|
|
|
+ Long collectionId = (long) sysConfigService.getInt("bidder_collection_id");
|
|
|
+ List<Asset> assets = assetRepo.findAllByUserIdAndCollectionIdAndStatus(order.getUserId(), collectionId, AssetStatus.NORMAL);
|
|
|
+ Asset asset;
|
|
|
+ if (assets.isEmpty()) {
|
|
|
+ Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("无藏品"));
|
|
|
+ if (!CollectionType.SHOWROOM.equals(collection.getType())) {
|
|
|
+ throw new BusinessException("不是展厅藏品");
|
|
|
+ }
|
|
|
+ //创建资产
|
|
|
+ asset = assetService.createAsset(collection, user, order.getId(), BigDecimal.ZERO, "拍卖赠送", null);
|
|
|
+ } else {
|
|
|
+ asset = assets.get(0);
|
|
|
+ }
|
|
|
+ //创建展厅
|
|
|
+ showroomService.save(asset, "AUCTION");
|
|
|
+ }
|
|
|
|
|
|
//一个月的优先拍卖权
|
|
|
PurchaserPrivilege.builder()
|
|
|
.userId(order.getUserId())
|
|
|
- .title("元宇宙Bider")
|
|
|
+ .title("元宇宙Bidder")
|
|
|
.priority(true)
|
|
|
.priorityExpireAt(LocalDateTime.now().plusMonths(1))
|
|
|
.build();
|
|
|
|
|
|
+
|
|
|
+ //前20名分钱
|
|
|
BigDecimal totalPrice = order.getTotalPrice();
|
|
|
//手续费
|
|
|
- BigDecimal serviceCharge = totalPrice.multiply(new BigDecimal("20"))
|
|
|
+ int auctionServiceCharge = sysConfigService.getInt("auction_service_charge");
|
|
|
+ BigDecimal serviceCharge = totalPrice.multiply(new BigDecimal(auctionServiceCharge))
|
|
|
.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
|
|
|
|
|
//奖励费用
|
|
|
BigDecimal subtract = totalPrice.subtract(serviceCharge);
|
|
|
- subtract.multiply(new BigDecimal("50")).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
|
|
+ int auctionReward = sysConfigService.getInt("auction_reward");
|
|
|
+ BigDecimal reward = subtract.multiply(new BigDecimal(auctionReward)).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
|
|
|
+ List<Long> records = auctionRecordRepo.findByAuctionId(order.getAuctionId(), 20);
|
|
|
+ BigDecimal everyReward = reward.divide(new BigDecimal(records.size()), 2, RoundingMode.HALF_UP);
|
|
|
+ //分奖励
|
|
|
+ records.forEach(userId -> userBalanceService.addBalance(userId, everyReward, order.getId(), BalanceType.REWARD));
|
|
|
+
|
|
|
|
|
|
+ //拍卖者所得
|
|
|
+ BigDecimal amount = totalPrice.subtract(serviceCharge).subtract(reward);
|
|
|
+ userBalanceService.addBalance(order.getUserId(), amount, order.getId(), BalanceType.AUCTION);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|