KMProductModel.swift 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. //
  2. // KMProductModel.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/11/6.
  6. //
  7. import Foundation
  8. import Combine
  9. @objc enum KMCompareTableType : Int {
  10. case trial = 0 // 试用比较表
  11. case dmg_Base // DMG 基础版
  12. case dmg_MacWindows // DMG Mac&Windows双平台高级版永久
  13. case lite_Base // Lite 基础版
  14. case lite_MacWindows // Lite Mac&Windows双平台高级版永久
  15. case pro_Base // Pro 基础版
  16. case pro_Advanced // Pro Mac单平台高级版永久
  17. }
  18. @objc enum KMCompareProductType : Int {
  19. case free = 0 // 免费
  20. case freeTrial // 试用
  21. case allPlatformStandard // 全平台标准版年订阅
  22. case dualPlatformAdvanced // Mac&Windows双平台高级版永久
  23. case allPlatformAdvanced_6 // 全平台高级版6个月订阅
  24. case allPlatformAdvanced_12 // 全平台高级版12个月订阅
  25. case macPlatformAdvanced // MAC单平台高级版永久
  26. }
  27. @objc enum KMPurchasedProductType : Int {
  28. case fourDevicesAllAccessPackNew6months_lite = 0 // 4_devices_all_access_pack_new_6months(订阅)
  29. case fourDevicesAllAccessPackNew12months_lite // 4_devices_all_access_pack_12months(订阅)
  30. // case allAccessPackNew6months_lite // all_access_pack_new_6months(订阅)
  31. // case allAccessPack12months_lite // all_access_pack_12months(订阅)
  32. // case allAccessPack6months_lite // all_access_pack_6months(订阅)
  33. case aiAllAccessPack1month_lite // ai_all_access_pack_1month(订阅)
  34. case aiAllAccessPack12month_lite // ai_all_access_pack_12month(订阅)
  35. case allAccessPackPermanent_lite // all_access_pack_permanent(永久)
  36. case advancedAddDevicesAllAccessPack12months_lite // advanced_add_devices_all_access_pack_12months(订阅)
  37. case advancedAdd2DevicesAllAccessPack12months_lite // advanced_add_2_devices_all_access_pack_12months(订阅)
  38. case aiAllAccessPack1month_pro // ai_all_access_pack_1month(订阅)
  39. case aiAllAccessPack12month_pro // ai_all_access_pack_1month(订阅)
  40. case pdfToOfficePackPermanent_pro // pdf_to_office_pack_permanent(永久)
  41. case fourDevicesAllAccessPack12months_pro // 4_devices_all_access_pack_12months(全平台高级年订阅)
  42. case standardAddDevicesAllAccessPack12months_pro // standard_add_devices_all_access_pack_12months(订阅)
  43. case advancedAddDevicesAllAccessPack12months_pro // advanced_add_devices_all_access_pack_12months(订阅)
  44. case advancedAdd2DevicesAllAccessPack12months_pro // advanced_add_2_devices_all_access_pack_12months(订阅)
  45. }
  46. typealias AppstorePurchaseComplete = (_ success: Bool,_ msg: String) -> Void
  47. @objcMembers
  48. class KMProductModel: ObservableObject {
  49. /**
  50. 比较表类型
  51. */
  52. @Published var state: KMCompareTableType = .trial
  53. /**
  54. 高级版半年 或 年订阅,true为年订阅,false为半年订阅,默认true为年订阅
  55. */
  56. @Published var isPurchaseSwitch: Bool = true
  57. // MARK: DMG Public Property
  58. /**
  59. DMG 版本所有已经上架产品记录(暂时无教育优惠)
  60. */
  61. var dmgProductDatas: KMMemberProductResult?
  62. /**
  63. DMG 版本 已经登录用户 最后一次价格获取
  64. */
  65. var dmgLastGetProductPriceInfos: KMMemberProductResult?
  66. /**
  67. DMG 版本 已经登录用户 最后一次批量价格获取
  68. */
  69. var dmgLastGetBatchProductPriceInfos: KMMemberProductResult?
  70. /**
  71. DMG 版本 已经登录用户 最后一次验证商品优惠券价格获取
  72. */
  73. var dmgLastCheckCouponProductPriceInfos: KMMemberProductResult?
  74. /**
  75. DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
  76. */
  77. var dmgLastCreatOrderProductInfos: KMMemberProductResult?
  78. /**
  79. DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
  80. */
  81. var dmgLastCreatSubscriberProductInfos: KMMemberProductResult?
  82. // MARK: DMG Public Method
  83. func checkConnectionAvailable() -> Void {
  84. if KMMemberCenterManager.manager.isConnectionAvailable() == false {
  85. let alert = NSAlert()
  86. alert.alertStyle = .critical
  87. alert.messageText = NSLocalizedString("Error Information", comment: "")
  88. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  89. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  90. alert.runModal()
  91. return
  92. }
  93. }
  94. /**
  95. @abstract 获取服务器架上所有商品 (得到的价格是原始价格)
  96. @param
  97. */
  98. func getDMGProductDatas() -> Void {
  99. checkConnectionAvailable()
  100. KMMemberCenterManager.manager.getListingProducts(isEducation: 0) { [weak self] success, result in
  101. guard let productsArrays : KMMemberProductResult = result else { return }
  102. self?.dmgProductDatas = productsArrays
  103. }
  104. if KMMemberInfo.shared.isLogin {
  105. getDMGProductPriceInfosForMember(productId: "SP2024102100002", isEducation: 0) { [weak self] success, result in
  106. }
  107. }
  108. }
  109. /**
  110. @abstract 获取登录用户价格(建立订单时需要用到)
  111. @param productId 购买的产品id
  112. @param isEducation 是否教育优惠
  113. @param complete 回调
  114. */
  115. func getDMGProductPriceInfosForMember(productId: String, isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
  116. checkConnectionAvailable()
  117. //暂时无教育优惠,先固定传 0
  118. KMMemberCenterManager.manager.getProductPriceForBuy(productId: productId, isEducation: 0, userId:KMMemberInfo.shared.userID) { [weak self] success, result in
  119. if success {
  120. guard let productsArrays : KMMemberProductResult = result else {
  121. complete(false, result)
  122. return
  123. }
  124. self?.dmgLastGetProductPriceInfos = productsArrays
  125. complete(true, productsArrays)
  126. } else {
  127. complete(false, result)
  128. }
  129. }
  130. }
  131. /**
  132. @abstract 获取批量阶段购买价格(建立订单时需要用到)
  133. @param productId 购买的产品id
  134. @param num 批量个数
  135. @param complete 回调
  136. */
  137. func getDMGBatchProductPriceInfosForMember(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  138. checkConnectionAvailable()
  139. KMMemberCenterManager.manager.getBatchProductPrice(productId: productId, num: num) { [weak self] success, result in
  140. if success {
  141. guard let productsArrays : KMMemberProductResult = result else {
  142. complete(false, result)
  143. return
  144. }
  145. self?.dmgLastGetBatchProductPriceInfos = productsArrays
  146. complete(true, productsArrays)
  147. } else {
  148. complete(false, result)
  149. }
  150. }
  151. }
  152. /**
  153. @abstract 验证商品优惠券(建立订单时需要用到)
  154. @param productId 购买的产品id
  155. @param code 优惠券
  156. @param complete 回调
  157. */
  158. func getDMGCheckCouponProductPriceInfosForMember(productId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
  159. checkConnectionAvailable()
  160. KMMemberCenterManager.manager.checkCoupon(productId: productId, userId: KMMemberInfo.shared.userID, code: code) { [weak self] success, result in
  161. if success {
  162. guard let productsArrays : KMMemberProductResult = result else {
  163. complete(false, result)
  164. return
  165. }
  166. self?.dmgLastCheckCouponProductPriceInfos = productsArrays
  167. complete(true, productsArrays)
  168. } else {
  169. complete(false, result)
  170. }
  171. }
  172. }
  173. /**
  174. @abstract 获取订单列表
  175. @param orderStatus 0全部1待支付
  176. @param complete 回调
  177. */
  178. func getDMGProductListInfosForMember(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
  179. checkConnectionAvailable()
  180. KMMemberCenterManager.manager.getOrderListByStatus(orderStatus: orderStatus) { [weak self] success, result in
  181. if success {
  182. guard let productsArrays : KMMemberProductResult = result else {
  183. complete(false, result)
  184. return
  185. }
  186. complete(true, productsArrays)
  187. } else {
  188. complete(false, result)
  189. }
  190. }
  191. }
  192. /**
  193. @abstract 创建订单(买断)
  194. @param productId 产品id
  195. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  196. @param price 价格
  197. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  198. @param couponCode 优惠卷
  199. @param num 批量购买数量
  200. @param complete 回调
  201. */
  202. func creatOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  203. checkConnectionAvailable()
  204. KMMemberCenterManager.manager.createOrder(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
  205. if success {
  206. guard let productsArrays : KMMemberProductResult = result else {
  207. complete(false, result)
  208. return
  209. }
  210. self?.dmgLastCreatOrderProductInfos = productsArrays
  211. complete(true, productsArrays)
  212. } else {
  213. complete(false, result)
  214. }
  215. }
  216. }
  217. /**
  218. @abstract 创建订单(订阅)
  219. @param productId 产品id
  220. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  221. @param price 价格
  222. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  223. @param couponCode 优惠卷
  224. @param num 批量购买数量
  225. @param complete 回调
  226. */
  227. func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  228. checkConnectionAvailable()
  229. KMMemberCenterManager.manager.createSubscriber(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
  230. if success {
  231. guard let productsArrays : KMMemberProductResult = result else {
  232. complete(false, result)
  233. return
  234. }
  235. self?.dmgLastCreatSubscriberProductInfos = productsArrays
  236. complete(true, productsArrays)
  237. } else {
  238. complete(false, result)
  239. }
  240. }
  241. }
  242. // MARK: Public Method
  243. /**
  244. @abstract 根据当前权益获取比较表类型
  245. @param
  246. */
  247. func getCurrentComparisonTableType() -> Void {
  248. if KMMemberInfo.shared.canTrail {
  249. state = .trial
  250. } else {
  251. #if VERSION_FREE
  252. #if VERSION_DMG
  253. // DMG
  254. if KMMemberInfo.shared.vip_levels == "1" {
  255. state = .dmg_Base
  256. } else if KMMemberInfo.shared.vip_levels == "2" {
  257. state = .dmg_MacWindows
  258. }
  259. #else
  260. // AppStore 免费版本
  261. if KMMemberInfo.shared.vip_levels == "1" {
  262. state = .lite_Base
  263. } else if KMMemberInfo.shared.vip_levels == "2" {
  264. state = .lite_MacWindows
  265. }
  266. #endif
  267. #else
  268. // AppStore 付费版
  269. if KMMemberInfo.shared.vip_levels == "1" {
  270. state = .pro_Base
  271. } else if KMMemberInfo.shared.vip_levels == "2" {
  272. state = .pro_Advanced
  273. }
  274. #endif
  275. }
  276. }
  277. /**
  278. 对应商品价格
  279. */
  280. func getProductPrice(_ type: KMPurchasedProductType) -> String {
  281. if type == .fourDevicesAllAccessPackNew6months_lite {
  282. if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, product.isOffers {
  283. return product.offersPrice()
  284. } else {
  285. return IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.price()
  286. }
  287. } else if type == .fourDevicesAllAccessPackNew12months_lite {
  288. if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, product.isOffers {
  289. return product.offersPrice()
  290. } else {
  291. return IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.price()
  292. }
  293. } else if type == .aiAllAccessPack1month_lite {
  294. if let product = IAPProductsManager.default().aiAllAccessPack1month_lite, product.isOffers {
  295. return product.offersPrice()
  296. } else {
  297. return IAPProductsManager.default().aiAllAccessPack1month_lite.price()
  298. }
  299. } else if type == .aiAllAccessPack12month_lite {
  300. if let product = IAPProductsManager.default().aiAllAccessPack12month_lite, product.isOffers {
  301. return product.offersPrice()
  302. } else {
  303. return IAPProductsManager.default().aiAllAccessPack12month_lite.price()
  304. }
  305. } else if type == .allAccessPackPermanent_lite {
  306. if let product = IAPProductsManager.default().allAccessPackPermanent_lite, product.isOffers {
  307. return product.offersPrice()
  308. } else {
  309. return IAPProductsManager.default().allAccessPackPermanent_lite.price()
  310. }
  311. } else if type == .advancedAddDevicesAllAccessPack12months_lite {
  312. if let product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, product.isOffers {
  313. return product.offersPrice()
  314. } else {
  315. return IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite.price()
  316. }
  317. } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
  318. if let product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, product.isOffers {
  319. return product.offersPrice()
  320. } else {
  321. return IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite.price()
  322. }
  323. } else if type == .aiAllAccessPack1month_pro {
  324. if let product = IAPProductsManager.default().aiAllAccessPack1month_pro, product.isOffers {
  325. return product.offersPrice()
  326. } else {
  327. return IAPProductsManager.default().aiAllAccessPack1month_pro.price()
  328. }
  329. } else if type == .aiAllAccessPack12month_pro {
  330. if let product = IAPProductsManager.default().aiAllAccessPack12month_pro, product.isOffers {
  331. return product.offersPrice()
  332. } else {
  333. return IAPProductsManager.default().aiAllAccessPack12month_pro.price()
  334. }
  335. } else if type == .pdfToOfficePackPermanent_pro {
  336. if let product = IAPProductsManager.default().pdfToOfficePackPermanent_pro, product.isOffers {
  337. return product.offersPrice()
  338. } else {
  339. return IAPProductsManager.default().pdfToOfficePackPermanent_pro.price()
  340. }
  341. } else if type == .fourDevicesAllAccessPack12months_pro {
  342. if let product = IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, product.isOffers {
  343. return product.offersPrice()
  344. } else {
  345. return IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.price()
  346. }
  347. } else if type == .standardAddDevicesAllAccessPack12months_pro {
  348. if let product = IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, product.isOffers {
  349. return product.offersPrice()
  350. } else {
  351. return IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro.price()
  352. }
  353. } else if type == .advancedAddDevicesAllAccessPack12months_pro {
  354. if let product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, product.isOffers {
  355. return product.offersPrice()
  356. } else {
  357. return IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro.price()
  358. }
  359. } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
  360. if let product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, product.isOffers {
  361. return product.offersPrice()
  362. } else {
  363. return IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro.price()
  364. }
  365. }
  366. return ""
  367. }
  368. func appstorePurchaseAction(_ tag: Int, _ complete: @escaping AppstorePurchaseComplete) -> Void {
  369. if state == .dmg_Base {
  370. } else if state == .dmg_MacWindows {
  371. } else if state == .lite_Base {
  372. if tag == 0 {
  373. if isPurchaseSwitch { membershipPurchase(.fourDevicesAllAccessPackNew12months_lite) }
  374. else { membershipPurchase(.fourDevicesAllAccessPackNew6months_lite) }
  375. } else if tag == 3 {
  376. membershipPurchase(.allAccessPackPermanent_lite)
  377. } else {
  378. membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
  379. }
  380. } else if state == .lite_MacWindows {
  381. if tag == 2 {
  382. let platforms = KMMemberInfo.shared.vip_platforms
  383. let platformsArray = platforms
  384. .components(separatedBy: ",")
  385. .map { $0.trimmingCharacters(in: .whitespaces) }
  386. if platformsArray.count == 1 {
  387. membershipPurchase(.advancedAddDevicesAllAccessPack12months_lite)
  388. } else if platformsArray.count == 2 {
  389. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
  390. } else {
  391. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
  392. }
  393. }
  394. } else if state == .pro_Base {
  395. if KMMemberInfo.shared.userScenarioType == .pro_type3 {
  396. if tag == 2 {
  397. membershipPurchase(.standardAddDevicesAllAccessPack12months_pro)
  398. } else if tag == 3 {
  399. membershipPurchase(.pdfToOfficePackPermanent_pro)
  400. }
  401. }
  402. } else if state == .pro_Advanced {
  403. if KMMemberInfo.shared.userScenarioType == .pro_type1 {
  404. membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
  405. } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
  406. membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
  407. }
  408. } else {
  409. if tag == 2 {
  410. membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
  411. }
  412. }
  413. }
  414. var isCancelAutoRenew: Bool {
  415. return IAPProductsManager.default().isCancelAutoRenew()
  416. }
  417. var isShowSale: Bool {
  418. if #available(macOS 10.14.4, *), isCancelAutoRenew {
  419. let manager = IAPProductsManager.default()
  420. let isSubscribed_newlyMonth = manager?.allAccessPackNew6months_lite.isSubscribed ?? false
  421. let isSubscribed_year = manager?.allAccessPack12months_lite.isSubscribed ?? false
  422. if isSubscribed_newlyMonth || isSubscribed_year {
  423. return false
  424. }
  425. if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first, !(info.show! as NSString).boolValue {
  426. return false
  427. }
  428. return true
  429. }
  430. return false
  431. }
  432. // MARK: Private Method
  433. /**
  434. 会员购买
  435. */
  436. private func membershipPurchase(_ type: KMPurchasedProductType) -> Void {
  437. if type == .fourDevicesAllAccessPackNew6months_lite || type == .fourDevicesAllAccessPackNew12months_lite {
  438. if isPurchaseSwitch {
  439. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: isCancelAutoRenew)
  440. } else {
  441. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: isCancelAutoRenew)
  442. }
  443. } else if type == .aiAllAccessPack1month_lite {
  444. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_lite, discount: isCancelAutoRenew)
  445. } else if type == .aiAllAccessPack12month_lite {
  446. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: isCancelAutoRenew)
  447. } else if type == .allAccessPackPermanent_lite {
  448. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().allAccessPackPermanent_lite, discount: isCancelAutoRenew)
  449. } else if type == .advancedAddDevicesAllAccessPack12months_lite {
  450. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
  451. } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
  452. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
  453. } else if type == .aiAllAccessPack1month_pro {
  454. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_pro, discount: isCancelAutoRenew)
  455. } else if type == .aiAllAccessPack12month_pro {
  456. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_pro, discount: isCancelAutoRenew)
  457. } else if type == .pdfToOfficePackPermanent_pro {
  458. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().pdfToOfficePackPermanent_pro, discount: isCancelAutoRenew)
  459. } else if type == .fourDevicesAllAccessPack12months_pro {
  460. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  461. } else if type == .standardAddDevicesAllAccessPack12months_pro {
  462. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  463. } else if type == .advancedAddDevicesAllAccessPack12months_pro {
  464. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  465. } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
  466. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  467. }
  468. }
  469. // MARK: Action Method
  470. /**
  471. 恢复购买
  472. */
  473. func productRestore() -> Void {
  474. IAPProductsManager.default().restoreSubscriptions()
  475. }
  476. func privacyPolicyAction() -> Void {
  477. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/privacy-policy")!)
  478. }
  479. func termOfSerAction() -> Void {
  480. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/terms_of_service")!)
  481. }
  482. // MARK: Get & Set
  483. /**
  484. 当前比较表产品列表内容
  485. */
  486. var products: [KMCompareProductType] {
  487. if state == .trial {
  488. return [.free, .freeTrial]
  489. } else if state == .dmg_Base {
  490. return [.free, .allPlatformStandard, .allPlatformAdvanced_12, .dualPlatformAdvanced]
  491. } else if state == .dmg_MacWindows {
  492. return [.allPlatformAdvanced_12]
  493. } else if state == .lite_Base {
  494. return [.free, .allPlatformAdvanced_6, .allPlatformAdvanced_12, .dualPlatformAdvanced]
  495. } else if state == .lite_MacWindows {
  496. return [.allPlatformAdvanced_12]
  497. } else if state == .pro_Base {
  498. return [.allPlatformAdvanced_12, .macPlatformAdvanced]
  499. } else if state == .pro_Advanced {
  500. return [.allPlatformAdvanced_12]
  501. }
  502. return []
  503. }
  504. /**
  505. 比较表数据源
  506. */
  507. var dataSource: [Any] {
  508. if isPurchaseSwitch {
  509. // 试用 全平台标准版年订阅 全平台高级版6/12个月订阅 Mac&Windows双平台高级版永久 MAC单平台高级版永久
  510. //MAC单平台标准版永久
  511. return [
  512. "Benefit",
  513. ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
  514. ["Maximum number of accessible devices", "2 devices", "4 devices", "4 devices", "2 devices", "1 devices"],
  515. "PDF to Office",
  516. ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
  517. ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  518. ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  519. "Edit PDF",
  520. ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
  521. ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
  522. "OCR",
  523. ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
  524. "Organize Pages",
  525. ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
  526. ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
  527. "Advanced Editing Tools",
  528. ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
  529. ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
  530. ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
  531. ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
  532. ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
  533. ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
  534. ["Extract Images", "X", "✓", "✓", "✓", "✓"],
  535. ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  536. ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
  537. "Fill & Sign",
  538. ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
  539. ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
  540. "Security",
  541. ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
  542. ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
  543. ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
  544. "Create PDF",
  545. ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
  546. ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
  547. "Annotations",
  548. ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
  549. ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
  550. ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
  551. ["Table", "X", "✓", "✓", "✓", "✓"],
  552. "View PDF",
  553. ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
  554. ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
  555. ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
  556. ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
  557. "Subscription Based Solution",
  558. ["Access all premium features in app", "X", "12 months", "12 months", "∞", "∞"],
  559. ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
  560. ["Ad-free", "X", "✓", "✓", "✓", "✓"]
  561. ]
  562. } else {
  563. return [
  564. "Benefit",
  565. ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
  566. ["Maximum number of accessible devices", "2 devices", "4 devices", "4 devices", "2 devices", "1 devices"],
  567. "PDF to Office",
  568. ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
  569. ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  570. ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  571. "Edit PDF",
  572. ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
  573. ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
  574. "OCR",
  575. ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
  576. "Organize Pages",
  577. ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
  578. ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
  579. "Advanced Editing Tools",
  580. ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
  581. ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
  582. ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
  583. ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
  584. ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
  585. ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
  586. ["Extract Images", "X", "✓", "✓", "✓", "✓"],
  587. ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  588. ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
  589. "Fill & Sign",
  590. ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
  591. ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
  592. "Security",
  593. ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
  594. ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
  595. ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
  596. "Create PDF",
  597. ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
  598. ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
  599. "Annotations",
  600. ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
  601. ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
  602. ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
  603. ["Table", "X", "✓", "✓", "✓", "✓"],
  604. "View PDF",
  605. ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
  606. ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
  607. ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
  608. ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
  609. "Subscription Based Solution",
  610. ["Access all premium features in app", "X", "6 months", "6 months", "∞", "∞"],
  611. ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
  612. ["Ad-free", "X", "✓", "✓", "✓", "✓"]
  613. ]
  614. }
  615. }
  616. }