wangqifan 2 лет назад
Родитель
Сommit
27e37daaa8

+ 4 - 0
src/main/java/com/izouma/nineth/repo/AssetRepo.java

@@ -110,6 +110,10 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
             "and status = 'NORMAL' limit 1")
     Long findDiscount(Long userId, Collection<Long> ids);
 
+    @Query(nativeQuery = true, value = "select collection_id from asset where user_id = ?1 and collection_id in ?2 " +
+            "and status = 'NORMAL'")
+    Set<Long> findDiscounts(Long userId, Collection<Long> ids);
+
     List<Asset> findByStatus(AssetStatus status);
 
     List<Asset> findAllByUserIdAndTypeAndOpenedAndCompanyId(Long userId, CollectionType type, Boolean opened, Long companyId);

+ 26 - 0
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -1276,6 +1276,32 @@ public class AssetService {
         return servicecharge;
     }
 
+    public double getDomainServiceCharge(Long userId) {
+//        if (servicecharge == 3) {
+//            return 3;
+//        }
+//        LongArrayConverter converter = new LongArrayConverter();
+//        String discountMinter = sysConfigService.getString("discount_minter");
+//        List<Long> minterIds = converter.convertToEntityAttribute(discountMinter);
+//        if (minterIds.contains(minterId)) {
+        String discountCollection = sysConfigService.getString("domain_discount");
+        JSONObject json = JSONObject.parseObject(discountCollection);
+        Set<String> keys = json.keySet();
+        List<Long> collectionIds = keys.stream().map(Long::parseLong).collect(Collectors.toList());
+        Set<Long> holdCollections = assetRepo.findDiscounts(userId, collectionIds);
+        double result = sysConfigService.getBigDecimal("domain_service_charge").doubleValue();
+        if (holdCollections.size() > 0) {
+            for (Long id : holdCollections) {
+                double discount = json.getDouble(id.toString());
+                if (discount < result) {
+                    result = discount;
+                }
+            }
+        }
+//        }
+        return result;
+    }
+
 
     @Async
     public void hcChain() throws ExecutionException, InterruptedException {

+ 1 - 1
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -399,7 +399,7 @@ public class OrderService {
                 Long sellerId = asset.getOwnerId();
                 order.setRoyalties(assetService.getRoyalties(minter.getId(), collection.getRoyalties(), sellerId));
                 if (asset.getType().equals(CollectionType.DOMAIN)) {
-                    order.setServiceCharge(sysConfigService.getBigDecimal("domain_service_charge").doubleValue());
+                    order.setServiceCharge(assetService.getDomainServiceCharge(sellerId));
                 } else {
                     order.setServiceCharge(assetService.getServicecharge(collection.getServiceCharge(), sellerId));
                 }

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

@@ -262,7 +262,7 @@ public class AssetController extends BaseController {
     public double getServicecharge(@RequestParam Long id) {
         Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         if (asset.getType().equals(CollectionType.DOMAIN)) {
-            return sysConfigService.getBigDecimal("domain_service_charge").doubleValue();
+            return assetService.getDomainServiceCharge(SecurityUtils.getAuthenticatedUser().getId());
         }
         return assetService.getServicecharge(asset.getServiceCharge(), SecurityUtils.getAuthenticatedUser()
                 .getId());