|
|
@@ -70,8 +70,63 @@ public class GiftOrderService {
|
|
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
private ErrorOrderRepo errorOrderRepo;
|
|
|
|
|
|
+ @Transactional
|
|
|
+ public GiftOrder giftWithoutGasFee(Long userId, Long assetId, Long toUserId) {
|
|
|
+ Asset asset = assetRepo.findById(assetId).orElseThrow(new BusinessException("资产不存在"));
|
|
|
+ if (!asset.getUserId().equals(userId)) {
|
|
|
+ throw new BusinessException("无权限");
|
|
|
+ }
|
|
|
+
|
|
|
+ int holdDays;
|
|
|
+ if (ObjectUtils.isEmpty(asset.getHoldDays())) {
|
|
|
+ holdDays = sysConfigService.getInt("hold_days");
|
|
|
+ } else {
|
|
|
+ holdDays = asset.getHoldDays();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ChronoUnit.DAYS.between(asset.getCreatedAt(), LocalDateTime.now()) < holdDays) {
|
|
|
+ throw new BusinessException("需持有满" + holdDays + "天才能转赠");
|
|
|
+ }
|
|
|
+ if (toUserId.equals(userId)) {
|
|
|
+ throw new BusinessException("不能送给自己");
|
|
|
+ }
|
|
|
+ if (!(asset.getStatus() == AssetStatus.NORMAL)) {
|
|
|
+ throw new BusinessException("当前状态不可转赠");
|
|
|
+ }
|
|
|
+ if (asset.isConsignment()) {
|
|
|
+ throw new BusinessException("请先取消寄售");
|
|
|
+ }
|
|
|
+ if (asset.isPublicShow()) {
|
|
|
+ assetService.cancelPublic(asset);
|
|
|
+ }
|
|
|
+
|
|
|
+ asset.setStatus(AssetStatus.GIFTING);
|
|
|
+ assetRepo.save(asset);
|
|
|
+
|
|
|
+ GiftOrder giftOrder = GiftOrder.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .assetId(assetId)
|
|
|
+ .toUserId(toUserId)
|
|
|
+ .gasPrice(sysConfigService.getBigDecimal("gas_fee"))
|
|
|
+ .status(OrderStatus.NOT_PAID)
|
|
|
+ .build();
|
|
|
+ giftOrder.setPayMethod(PayMethod.FREE);
|
|
|
+ giftOrder.setStatus(OrderStatus.FINISH);
|
|
|
+ giftOrder.setTransactionId(null);
|
|
|
+ giftOrder.setPayTime(LocalDateTime.now());
|
|
|
+ giftOrder.setPayMethod(PayMethod.FREE);
|
|
|
+
|
|
|
+ User newOwner = userRepo.findById(giftOrder.getToUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ assetService.transfer(asset, asset.getPrice(), newOwner, "转赠", null);
|
|
|
+
|
|
|
+ return giftOrderRepo.save(giftOrder);
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
public GiftOrder gift(Long userId, Long assetId, Long toUserId) {
|
|
|
+ if (BigDecimal.ZERO.compareTo(sysConfigService.getBigDecimal("gift_gas_fee")) == 0) {
|
|
|
+ return giftWithoutGasFee(userId, assetId, toUserId);
|
|
|
+ }
|
|
|
Asset asset = assetRepo.findById(assetId).orElseThrow(new BusinessException("资产不存在"));
|
|
|
if (!asset.getUserId().equals(userId)) {
|
|
|
throw new BusinessException("无权限");
|
|
|
@@ -131,7 +186,8 @@ public class GiftOrderService {
|
|
|
|
|
|
assetService.transfer(asset, asset.getPrice(), newOwner, "转赠", null);
|
|
|
} else {
|
|
|
- log.error("转赠回调出错 状态错误 orderid={} transactionid={} status={}", orderId, transactionId, giftOrder.getStatus());
|
|
|
+ log.error("转赠回调出错 状态错误 orderid={} transactionid={} status={}", orderId, transactionId, giftOrder
|
|
|
+ .getStatus());
|
|
|
errorOrderRepo.save(ErrorOrder.builder()
|
|
|
.orderId(orderId)
|
|
|
.transactionId(transactionId)
|
|
|
@@ -268,7 +324,8 @@ public class GiftOrderService {
|
|
|
case "alipay_qr":
|
|
|
return MapUtils.getString(MapUtils.getMap(response, "expend"), "qrcode_url");
|
|
|
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.remove("timeStamp");
|
|
|
return payParams;
|