|
|
@@ -270,7 +270,7 @@ public class AssetService {
|
|
|
assetRepo.save(asset);
|
|
|
}
|
|
|
|
|
|
- public synchronized void consignment(Long id, BigDecimal price, String tradeCode) {
|
|
|
+ public synchronized void consignment(Long id, BigDecimal price, String tradeCode, boolean safeFlag) {
|
|
|
Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
|
|
|
if (!asset.getUserId().equals(SecurityUtils.getAuthenticatedUser().getId())) {
|
|
|
throw new BusinessException("此藏品不属于你");
|
|
|
@@ -298,9 +298,25 @@ public class AssetService {
|
|
|
if (ChronoUnit.DAYS.between(asset.getCreatedAt(), LocalDateTime.now()) < holdDays) {
|
|
|
throw new BusinessException("需持有满" + holdDays + "天才能寄售上架");
|
|
|
}
|
|
|
- User owner = asset.isSafeFlag() ?
|
|
|
- userRepo.findById(asset.getOwnerId()).orElseThrow(new BusinessException("用户不存在"))
|
|
|
- : userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ User owner;
|
|
|
+ if (safeFlag && !asset.isSafeFlag()) {
|
|
|
+ owner = createFakeUser();
|
|
|
+ asset.setOwner(owner.getNickname());
|
|
|
+ asset.setOwnerId(owner.getId());
|
|
|
+ asset.setOwnerAvatar(owner.getAvatar());
|
|
|
+ tokenHistoryRepo.findByTokenIdOrderByCreatedAtDesc(asset.getTokenId()).stream()
|
|
|
+ .filter(t -> t.getToUserId().equals(asset.getUserId())).findFirst()
|
|
|
+ .ifPresent(tokenHistory -> {
|
|
|
+ tokenHistory.setToUserId(owner.getId());
|
|
|
+ tokenHistory.setToUser(owner.getNickname());
|
|
|
+ tokenHistory.setToAvatar(owner.getAvatar());
|
|
|
+ tokenHistoryRepo.save(tokenHistory);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ owner = asset.isSafeFlag() ?
|
|
|
+ userRepo.findById(asset.getOwnerId()).orElseThrow(new BusinessException("用户不存在"))
|
|
|
+ : userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ }
|
|
|
if (!passwordEncoder.matches(tradeCode, userRepo.findTradeCode(asset.getUserId()))) {
|
|
|
throw new BusinessException("交易密码错误");
|
|
|
}
|