Bladeren bron

Merge branch 'dev' into 特权藏品

licailing 4 jaren geleden
bovenliggende
commit
6c1c6392d3

+ 2 - 1
src/main/java/com/izouma/nineth/enums/PayMethod.java

@@ -2,7 +2,8 @@ package com.izouma.nineth.enums;
 
 
 public enum PayMethod {
 public enum PayMethod {
     WEIXIN("微信"),
     WEIXIN("微信"),
-    ALIPAY("支付宝");
+    ALIPAY("支付宝"),
+    FREE("无GAS费");
 
 
     private final String description;
     private final String description;
 
 

+ 59 - 2
src/main/java/com/izouma/nineth/service/GiftOrderService.java

@@ -70,8 +70,63 @@ public class GiftOrderService {
     private SnowflakeIdWorker snowflakeIdWorker;
     private SnowflakeIdWorker snowflakeIdWorker;
     private ErrorOrderRepo    errorOrderRepo;
     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
     @Transactional
     public GiftOrder gift(Long userId, Long assetId, Long toUserId) {
     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("资产不存在"));
         Asset asset = assetRepo.findById(assetId).orElseThrow(new BusinessException("资产不存在"));
         if (!asset.getUserId().equals(userId)) {
         if (!asset.getUserId().equals(userId)) {
             throw new BusinessException("无权限");
             throw new BusinessException("无权限");
@@ -131,7 +186,8 @@ public class GiftOrderService {
 
 
             assetService.transfer(asset, asset.getPrice(), newOwner, "转赠", null);
             assetService.transfer(asset, asset.getPrice(), newOwner, "转赠", null);
         } else {
         } else {
-            log.error("转赠回调出错 状态错误 orderid={} transactionid={} status={}", orderId, transactionId, giftOrder.getStatus());
+            log.error("转赠回调出错 状态错误 orderid={} transactionid={} status={}", orderId, transactionId, giftOrder
+                    .getStatus());
             errorOrderRepo.save(ErrorOrder.builder()
             errorOrderRepo.save(ErrorOrder.builder()
                     .orderId(orderId)
                     .orderId(orderId)
                     .transactionId(transactionId)
                     .transactionId(transactionId)
@@ -268,7 +324,8 @@ public class GiftOrderService {
             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;

+ 6 - 0
src/main/java/com/izouma/nineth/web/AssetController.java

@@ -108,6 +108,12 @@ public class AssetController extends BaseController {
         return giftOrderService.gift(SecurityUtils.getAuthenticatedUser().getId(), assetId, toUserId);
         return giftOrderService.gift(SecurityUtils.getAuthenticatedUser().getId(), assetId, toUserId);
     }
     }
 
 
+    @PostMapping("/giftWithoutGasFee")
+    @ApiOperation("转赠(无gas费)")
+    public GiftOrder giftWithoutGasFee(@RequestParam Long assetId, @RequestParam Long toUserId) {
+        return giftOrderService.giftWithoutGasFee(SecurityUtils.getAuthenticatedUser().getId(), assetId, toUserId);
+    }
+
     @GetMapping("/tokenHistory")
     @GetMapping("/tokenHistory")
     @ApiOperation("交易历史")
     @ApiOperation("交易历史")
     public List<TokenHistory> tokenHistory(@RequestParam(required = false) String tokenId, @RequestParam(required = false) Long assetId) {
     public List<TokenHistory> tokenHistory(@RequestParam(required = false) String tokenId, @RequestParam(required = false) Long assetId) {