Jelajahi Sumber

【综合】票据模型优化

tangchao 2 bulan lalu
induk
melakukan
00773b2e93

+ 1 - 1
PDF Office/PDF Master/Class/Account/CheckIn/Tools/KMCheckInManager.swift

@@ -165,7 +165,7 @@ let kKMTrailCancelStateDidChange = Notification.Name("KMTrailCancelStateDidChang
         if member.isLogin == false {
             return
         }
-        if member.is_advanced_year_subscribed() && member.vip_payType == 1 {
+        if member.is_advanced_year_subscribe() && member.isCancelSubscribe() == false {
             // 高级版年订阅有试用 续订
             return
         }

+ 22 - 0
PDF Office/PDF Master/Class/Purchase/IAPReceiptModel.h

@@ -128,6 +128,28 @@ NS_ASSUME_NONNULL_BEGIN
 
 @end
 
+@interface IAPReceiptTool: NSObject
+
+// 是否为新用户 
++ (BOOL)isNewUserWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
+
+// 是否有享受过 推介优惠 [免费试用]
++ (BOOL)hasTrialWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
+
+// 是否有享受过 推介优惠
++ (BOOL)hasIntroOfferWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
+
+// 获取订阅群组的所有票据
++ (NSArray <IAPReceiptInfoModel *> *)fetchReceiptsWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
+
+// 获取对应商品的所有票据
++ (NSArray <IAPReceiptInfoModel *> *)fetchProductReceiptsWithModel:(IAPReceiptModel *)model withProductCode:(NSString *)productCode;
+
+// 获取所有的票据
++ (NSArray <IAPReceiptInfoModel *> *)fetchReceiptsWithModel:(IAPReceiptModel *)model;
+
+@end
+
 /** status
  21000      未使用HTTPPOST请求方式向AppStore发送请求
  21001      此状态代码不再由AppStore发送

+ 68 - 3
PDF Office/PDF Master/Class/Purchase/IAPReceiptModel.m

@@ -112,9 +112,9 @@
     for (IAPReceiptInfoModel *model in self.latestReceiptInfoModels) {
         if ([model.product_id isEqualToString:@"com.pdfreaderpro.mac_free.member.all_access_pack_new_12months.001"]) {
             trail = model.is_trial_period;
-            
+
             NSString *expires_date_ms = model.expires_date_ms;
-            
+
             long long expiresDate = [expires_date_ms longLongValue]/1000;
             long long currentDate = [[NSDate date] timeIntervalSince1970];
             BOOL _isActive = (expiresDate > currentDate) ? YES : NO;
@@ -124,7 +124,7 @@
             count += 1;
         }
     }
-    
+
     if (trail && isActive == false && count == 1) {
         return YES;
     }
@@ -132,3 +132,68 @@
 }
 
 @end
+
+@implementation IAPReceiptTool
+
++ (BOOL)isNewUserWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
+    if ([self hasTrialWithModel:model withGroupIdentifier:groupIdentifier]) {
+        return false;
+    }
+    if ([self hasIntroOfferWithModel:model withGroupIdentifier:groupIdentifier]) {
+        return false;
+    }
+    return true;
+}
+
++ (BOOL)hasTrialWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
+    for (IAPReceiptInfoModel *m in [self fetchReceiptsWithModel:model withGroupIdentifier:groupIdentifier]) {
+        if (m.is_trial_period) {
+            return true;
+        }
+    }
+    return false;
+}
+
++ (BOOL)hasIntroOfferWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
+    for (IAPReceiptInfoModel *m in [self fetchReceiptsWithModel:model withGroupIdentifier:groupIdentifier]) {
+        if (m.is_in_intro_offer_period) {
+            return true;
+        }
+    }
+    return false;
+}
+
++ (NSArray<IAPReceiptInfoModel *> *)fetchReceiptsWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
+    NSMutableArray *results = [NSMutableArray arrayWithCapacity:4];
+    for (IAPReceiptInfoModel *m in [self fetchReceiptsWithModel:model]) {
+        if ([m.subscription_group_identifier isEqualToString:groupIdentifier] == false) {
+            continue;
+        }
+        [results addObject:m];
+    }
+    return [results copy];
+}
+
++ (NSArray<IAPReceiptInfoModel *> *)fetchProductReceiptsWithModel:(IAPReceiptModel *)model withProductCode:(NSString *)productCode {
+    NSMutableArray *results = [NSMutableArray arrayWithCapacity:4];
+    for (IAPReceiptInfoModel *m in [self fetchReceiptsWithModel:model]) {
+        if ([m.product_id isEqualToString:productCode] == false) {
+            continue;
+        }
+        [results addObject:m];
+    }
+    return [results copy];
+}
+
++ (NSArray<IAPReceiptInfoModel *> *)fetchReceiptsWithModel:(IAPReceiptModel *)model {
+    NSMutableArray *results = [NSMutableArray arrayWithCapacity:4];
+    for (IAPReceiptInfoModel *m in model.latestReceiptInfoModels) {
+        [results addObject:m];
+    }
+    for (IAPReceiptInfoModel *m in model.receiptModel.inAppModels) {
+        [results addObject:m];
+    }
+    return [results copy];
+}
+
+@end