瀏覽代碼

转赠限制

xiongzhu 4 年之前
父節點
當前提交
beaa3feea7
共有 1 個文件被更改,包括 17 次插入12 次删除
  1. 17 12
      src/main/java/com/izouma/nineth/service/GiftOrderService.java

+ 17 - 12
src/main/java/com/izouma/nineth/service/GiftOrderService.java

@@ -45,6 +45,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -55,17 +56,17 @@ import java.util.Map;
 @Slf4j
 public class GiftOrderService {
 
-    private AssetRepo        assetRepo;
-    private UserRepo         userRepo;
-    private SysConfigService sysConfigService;
-    private GiftOrderRepo    giftOrderRepo;
-    private AlipayProperties alipayProperties;
-    private AlipayClient     alipayClient;
-    private WxPayProperties  wxPayProperties;
-    private WxPayService     wxPayService;
-    private Environment      env;
-    private AssetService     assetService;
-    private AdapayProperties adapayProperties;
+    private AssetRepo         assetRepo;
+    private UserRepo          userRepo;
+    private SysConfigService  sysConfigService;
+    private GiftOrderRepo     giftOrderRepo;
+    private AlipayProperties  alipayProperties;
+    private AlipayClient      alipayClient;
+    private WxPayProperties   wxPayProperties;
+    private WxPayService      wxPayService;
+    private Environment       env;
+    private AssetService      assetService;
+    private AdapayProperties  adapayProperties;
     private GeneralProperties generalProperties;
 
     @Transactional
@@ -74,6 +75,10 @@ public class GiftOrderService {
         if (!asset.getUserId().equals(userId)) {
             throw new BusinessException("无权限");
         }
+        int holdDays = sysConfigService.getInt("hold_days");
+        if (ChronoUnit.DAYS.between(asset.getCreatedAt(), LocalDateTime.now()) < holdDays) {
+            throw new BusinessException("需持有满" + holdDays + "天才能寄售上架");
+        }
         if (toUserId.equals(userId)) {
             throw new BusinessException("不能送给自己");
         }
@@ -207,7 +212,7 @@ public class GiftOrderService {
         paymentParams.put("pay_amt", order.getGasPrice().setScale(2, RoundingMode.HALF_UP).toPlainString());
         paymentParams.put("app_id", adapayProperties.getAppId());
         paymentParams.put("pay_channel", payChannel);
-        paymentParams.put("goods_title","转赠GAS费");
+        paymentParams.put("goods_title", "转赠GAS费");
         paymentParams.put("goods_desc", "转赠GAS费");
         paymentParams.put("time_expire", DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
                 .format(LocalDateTime.now().plusMinutes(5)));