|
|
@@ -102,7 +102,6 @@ public class MintOrderService {
|
|
|
MintOrder order = mintOrderRepo.save(MintOrder.builder()
|
|
|
.userId(userId)
|
|
|
.phone(user.getPhone())
|
|
|
-// .material(materials)
|
|
|
.consume(true)
|
|
|
.status(MintOrderStatus.AIR_DROP)
|
|
|
.build());
|
|
|
@@ -158,21 +157,25 @@ public class MintOrderService {
|
|
|
*/
|
|
|
// @Transactional
|
|
|
public MintOrder create(User user, List<Long> assetId, Long mintActivityId, Long addressId) {
|
|
|
- try {
|
|
|
-
|
|
|
- // 参加的活动
|
|
|
- MintActivity mintActivity = mintActivityRepo.findByIdAndDelFalse(mintActivityId)
|
|
|
- .orElseThrow(new BusinessException("无此铸造活动"));
|
|
|
+ // 参加的活动
|
|
|
+ MintActivity mintActivity = mintActivityRepo.findByIdAndDelFalse(mintActivityId)
|
|
|
+ .orElseThrow(new BusinessException("无此铸造活动"));
|
|
|
|
|
|
- if (mintActivity.isScheduleSale()) {
|
|
|
- if (mintActivity.getStartTime().isAfter(LocalDateTime.now())) {
|
|
|
- throw new BusinessException("当前还未开售");
|
|
|
- }
|
|
|
- }
|
|
|
- if (!mintActivity.isOnShelf()) {
|
|
|
- throw new BusinessException("活动已下架");
|
|
|
+ if (mintActivity.isScheduleSale()) {
|
|
|
+ if (mintActivity.getStartTime().isAfter(LocalDateTime.now())) {
|
|
|
+ throw new BusinessException("当前还未开售");
|
|
|
}
|
|
|
+ }
|
|
|
+ if (!mintActivity.isOnShelf()) {
|
|
|
+ throw new BusinessException("活动已下架");
|
|
|
+ }
|
|
|
|
|
|
+ UserAddress userAddress = null;
|
|
|
+ if (addressId != null) {
|
|
|
+ userAddress = userAddressRepo.findById(addressId).orElseThrow(new BusinessException("地址信息不存在"));
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
int stock = Optional.ofNullable(mintActivityService.decreaseStock(mintActivityId, 1))
|
|
|
.map(Math::toIntExact)
|
|
|
.orElseThrow(new BusinessException("很遗憾,铸造活动已无库存"));
|
|
|
@@ -235,13 +238,16 @@ public class MintOrderService {
|
|
|
assetRepo.save(asset);
|
|
|
});
|
|
|
} else {
|
|
|
+ // 转让的用户
|
|
|
+ userRepo.findByIdAndDelFalse(1435297L).orElseThrow(new BusinessException("无法铸造"));
|
|
|
+
|
|
|
// 消耗改为转赠
|
|
|
assets.forEach(asset -> {
|
|
|
+ if (!asset.getUserId().equals(user.getId())) {
|
|
|
+ throw new BusinessException("此藏品不属于你");
|
|
|
+ }
|
|
|
// 取消公开展示
|
|
|
if (asset.isPublicShow()) {
|
|
|
- if (!asset.getUserId().equals(user.getId())) {
|
|
|
- throw new BusinessException("此藏品不属于你");
|
|
|
- }
|
|
|
if (asset.isConsignment()) {
|
|
|
if (asset.getPublicCollectionId() != null) {
|
|
|
List<Order> orders = orderRepo.findByCollectionId(asset.getPublicCollectionId());
|
|
|
@@ -256,21 +262,21 @@ public class MintOrderService {
|
|
|
collectionRepo.delete(collection);
|
|
|
// 如果展厅有此藏品
|
|
|
showCollectionRepo.deleteAllByCollectionId(asset.getPublicCollectionId());
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
|
|
|
+ // 统一处理
|
|
|
+ assets.forEach(asset -> {
|
|
|
+ if (asset.isPublicShow()) {
|
|
|
asset.setPublicShow(false);
|
|
|
asset.setPublicCollectionId(null);
|
|
|
}
|
|
|
asset.setStatus(AssetStatus.MINTING);
|
|
|
assetRepo.save(asset);
|
|
|
});
|
|
|
- // 转让的用户
|
|
|
- userRepo.findByIdAndDelFalse(1435297L).orElseThrow(new BusinessException("无法铸造"));
|
|
|
}
|
|
|
|
|
|
- UserAddress userAddress = null;
|
|
|
- if (addressId != null) {
|
|
|
- userAddress = userAddressRepo.findById(addressId).orElseThrow(new BusinessException("地址信息不存在"));
|
|
|
- }
|
|
|
|
|
|
// 铸造订单
|
|
|
MintOrder mintOrder = mintOrderRepo.save(MintOrder.builder()
|
|
|
@@ -304,8 +310,6 @@ public class MintOrderService {
|
|
|
|
|
|
mintMaterialRepo.saveAll(materials);
|
|
|
|
|
|
- //销量
|
|
|
-// mintActivityService.increaseSale(mintActivityId, 1);
|
|
|
if (mintOrder.getGasPrice().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
this.mintNotify(mintOrder.getId(), PayMethod.WEIXIN, null);
|
|
|
}
|
|
|
@@ -543,12 +547,10 @@ public class MintOrderService {
|
|
|
|
|
|
// 加库存
|
|
|
mintActivityService.increaseStock(order.getMintActivityId(), 1);
|
|
|
-// mintActivityService.decreaseSale(order.getMintActivityId(), 1);
|
|
|
|
|
|
rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), order.getMintActivityId(), 10000);
|
|
|
log.info("取消订单{}", order.getId());
|
|
|
} catch (Exception e) {
|
|
|
- mintActivityService.decreaseStock(order.getMintActivityId(), 1);
|
|
|
log.error("订单取消错误 orderId: " + order.getId(), e);
|
|
|
}
|
|
|
releaseOrderLock(order.getId());
|