KMProductModel.swift 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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. #if !VERSION_DMG
  10. import StoreKit
  11. #endif
  12. @objc enum KMCompareTableType : Int {
  13. case trial = 0 // 试用比较表
  14. case dmg_Base // DMG 购买比较表
  15. case dmg_Upgrades1 // DMG 升级比较表 39.99
  16. case dmg_Upgrades2 // DMG 升级比较表 49.99
  17. case lite_Base // Lite 基础版
  18. case lite_MacWindows // Lite Mac&Windows双平台高级版永久
  19. case pro_Base // Pro 基础版
  20. case pro_Advanced // Pro Mac单平台高级版永久
  21. }
  22. @objc enum KMCompareProductType : Int {
  23. case free = 0 // 免费
  24. case freeTrial // 试用
  25. case allPlatformStandard // 全平台标准版年订阅
  26. case dualPlatformAdvanced // Mac&Windows双平台高级版永久
  27. case allPlatformAdvanced_6 // 全平台高级版6个月订阅
  28. case allPlatformAdvanced_12 // 全平台高级版12个月订阅
  29. case macPlatformAdvanced // MAC单平台高级版永久
  30. }
  31. @objc enum KMPurchasedProductType : Int {
  32. case fourDevicesAllAccessPackNew6months_lite = 0 // 4_devices_all_access_pack_new_6months(订阅)
  33. case fourDevicesAllAccessPackNew12months_lite // 4_devices_all_access_pack_12months(订阅)
  34. // case allAccessPackNew6months_lite // all_access_pack_new_6months(订阅)
  35. // case allAccessPack12months_lite // all_access_pack_12months(订阅)
  36. // case allAccessPack6months_lite // all_access_pack_6months(订阅)
  37. case aiAllAccessPack1month_lite // ai_all_access_pack_1month(订阅)
  38. case aiAllAccessPack12month_lite // ai_all_access_pack_12month(订阅)
  39. case allAccessPackPermanent_lite // all_access_pack_permanent(永久)
  40. case advancedAddDevicesAllAccessPack12months_lite // advanced_add_devices_all_access_pack_12months(订阅)
  41. case advancedAdd2DevicesAllAccessPack12months_lite // advanced_add_2_devices_all_access_pack_12months(订阅)
  42. case aiAllAccessPack1month_pro // ai_all_access_pack_1month(订阅)
  43. case aiAllAccessPack12month_pro // ai_all_access_pack_1month(订阅)
  44. case pdfToOfficePackPermanent_pro // pdf_to_office_pack_permanent(永久)
  45. case fourDevicesAllAccessPack12months_pro // 4_devices_all_access_pack_12months(全平台高级年订阅)
  46. case standardAddDevicesAllAccessPack12months_pro // standard_add_devices_all_access_pack_12months(订阅)
  47. case advancedAddDevicesAllAccessPack12months_pro // advanced_add_devices_all_access_pack_12months(订阅)
  48. case advancedAdd2DevicesAllAccessPack12months_pro // advanced_add_2_devices_all_access_pack_12months(订阅)
  49. case pdfReaderProStandard_dmg // 全平台标准版年订阅
  50. case pdfReaderProAdvanced_dmg // 全平台高级版年订阅
  51. case pdfReaderProPermanent_dmg // Mac&Windows双平台高级版永久
  52. case pdfReaderProAIAnnual_dmg // AI 年订阅
  53. case pdfReaderProAIMonthly_dmg // AI 月订阅
  54. case pdfToOffice_dmg // 转档包 永久
  55. case add2Device_dmg // 多设备全平台
  56. case add3Device_dmg // 单平台升级高级版
  57. }
  58. typealias AppstorePurchaseComplete = (_ success: Bool,_ msg: String) -> Void
  59. @objcMembers
  60. class KMProductModel: ObservableObject {
  61. static let shared = KMProductModel()
  62. /**
  63. 比较表类型
  64. */
  65. @Published var state: KMCompareTableType = .trial
  66. /**
  67. 高级版半年 或 年订阅,true为年订阅,false为半年订阅,默认true为年订阅
  68. */
  69. @Published var isPurchaseSwitch: Bool = true
  70. // MARK: DMG Public Property
  71. /**
  72. DMG 版本所有已经上架产品记录(暂时无教育优惠)
  73. */
  74. var dmgProductDatas: KMMemberProductResult?
  75. /**
  76. DMG 版本 已经登录用户 最后一次价格获取
  77. */
  78. var dmgLastGetProductPriceInfos: KMMemberProductResult?
  79. /**
  80. DMG 版本 已经登录用户 最后一次批量价格获取
  81. */
  82. var dmgLastGetBatchProductPriceInfos: KMMemberProductResult?
  83. /**
  84. DMG 版本 已经登录用户 最后一次验证商品优惠券价格获取
  85. */
  86. var dmgLastCheckCouponProductPriceInfos: KMMemberProductResult?
  87. /**
  88. DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
  89. */
  90. var dmgLastCreatOrderProductInfos: KMMemberProductResult?
  91. /**
  92. DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
  93. */
  94. var dmgLastCreatSubscriberProductInfos: KMMemberProductResult?
  95. // MARK: DMG Public Method
  96. func checkConnectionAvailable() -> Void {
  97. if KMMemberCenterManager.manager.isConnectionAvailable() == false {
  98. let alert = NSAlert()
  99. alert.alertStyle = .critical
  100. alert.messageText = NSLocalizedString("Error Information", comment: "")
  101. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  102. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  103. alert.runModal()
  104. return
  105. }
  106. }
  107. /**
  108. @abstract 获取DMG服务器架上所有商品 (得到的价格是原始价格)
  109. @param
  110. */
  111. func getDMGProductDatas( _ complete: @escaping KMMemberProductComplete) -> Void {
  112. checkConnectionAvailable()
  113. KMMemberCenterManager.manager.getListingProducts(isEducation: 0) { [weak self] success, result in
  114. guard let productsArrays : KMMemberProductResult = result else { return }
  115. self?.dmgProductDatas = productsArrays
  116. complete(success, result)
  117. }
  118. if KMMemberInfo.shared.isLogin {
  119. // getDMGProductPriceInfosForMember(productId: "SP2024102300004", isEducation: 0) { [weak self] success, result in
  120. //
  121. //
  122. // }
  123. // getDMGBatchProductPriceInfosForMember(productId: "SP2024102300004", num: 10) { [weak self] success, result in
  124. //
  125. //
  126. // }
  127. // getDMGProductListInfosForMember(orderStatus: 0) { [weak self] success, result in
  128. //
  129. // }
  130. //创建买断订单
  131. // creatOrder(productId: "SP2024102300004", paymentMethod: 0, price: "119.99", discountFlag: 0, couponCode: "", num: 1) { [weak self] success, result in
  132. //
  133. // }
  134. //创建订阅订单(创建买断订单后会报错已经是购买用户,不能重复购买)
  135. // createSubscriber(productId: "SP2024102300003", paymentMethod: 0, price: "99.99", discountFlag: 0, couponCode: "", num: 1) { [weak self] success, result in
  136. //
  137. // }
  138. // getDMGProductOrderIdInfosForMember(orderId: "94b10d5f1ca193948e005503bff0df11") { [weak self] success, result in
  139. //
  140. // }
  141. }
  142. }
  143. /**
  144. @abstract 获取DMG产品价格(美元)
  145. */
  146. func getDMGPrice(productCode: String) -> String {
  147. guard let productModels = dmgProductDatas?.listingProducts else { return "" }
  148. for model in productModels {
  149. if model.code == productCode {
  150. if model.upgradePriceString?.isEmpty == false {
  151. return String(format: "%.2f", Float(model.upgradePriceString ?? "0") ?? 0)
  152. } else if model.displayPriceString?.isEmpty == false {
  153. if model.displayPriceString == "0.00" {
  154. return String(format: "%.2f", Float(model.priceString ?? "0") ?? 0)
  155. } else {
  156. return String(format: "%.2f", Float(model.displayPriceString ?? "0") ?? 0)
  157. }
  158. } else {
  159. return String(format: "%.2f", Float(model.priceString ?? "0") ?? 0)
  160. }
  161. }
  162. }
  163. return ""
  164. }
  165. /**
  166. @abstract 获取DMG产品价格(人民币)
  167. */
  168. func getDMGCNYPrice(productCode: String) -> String {
  169. guard let productModels = dmgProductDatas?.listingProducts else { return "" }
  170. for model in productModels {
  171. if model.code == productCode {
  172. if model.cnyUpgradePriceString?.isEmpty == false {
  173. return String(format: "%.2f", Float(model.cnyUpgradePriceString ?? "0") ?? 0)
  174. } else if model.displayCnyPriceString?.isEmpty == false {
  175. if model.displayCnyPriceString == "0.00" {
  176. return String(format: "%.2f", Float(model.cnyPriceString ?? "0") ?? 0)
  177. } else {
  178. return String(format: "%.2f", Float(model.displayCnyPriceString ?? "0") ?? 0)
  179. }
  180. } else {
  181. return String(format: "%.2f", Float(model.cnyPriceString ?? "0") ?? 0)
  182. }
  183. }
  184. }
  185. return ""
  186. }
  187. /**
  188. @abstract 获取DMG产品折扣价格(美元)
  189. */
  190. func getDMGDisplayPrice(productCode: String) -> String {
  191. guard let productModels = dmgProductDatas?.listingProducts else { return "" }
  192. for model in productModels {
  193. if model.code == productCode {
  194. return String(format: "%.2f", Float(model.displayPriceString ?? "0") ?? 0)
  195. }
  196. }
  197. return ""
  198. }
  199. /**
  200. @abstract 获取DMG产品折扣价格(人民币)
  201. */
  202. func getDMGDisplayCNYPrice(productCode: String) -> String {
  203. guard let productModels = dmgProductDatas?.listingProducts else { return "" }
  204. for model in productModels {
  205. if model.code == productCode {
  206. return String(format: "%.2f", Float(model.displayCnyPriceString ?? "0") ?? 0)
  207. }
  208. }
  209. return ""
  210. }
  211. /**
  212. @abstract 获取登录用户价格(建立订单时需要用到)
  213. @param productId 购买的产品id
  214. @param isEducation 是否教育优惠
  215. @param complete 回调
  216. */
  217. func getDMGProductPriceInfosForMember(productId: String, isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
  218. checkConnectionAvailable()
  219. //暂时无教育优惠,先固定传 0
  220. KMMemberCenterManager.manager.getProductPriceForBuy(productId: productId, isEducation: 0, userId:KMMemberInfo.shared.userID) { [weak self] success, result in
  221. if success {
  222. guard let productsArrays : KMMemberProductResult = result else {
  223. complete(false, result)
  224. return
  225. }
  226. self?.dmgLastGetProductPriceInfos = productsArrays
  227. complete(true, productsArrays)
  228. } else {
  229. complete(false, result)
  230. }
  231. }
  232. }
  233. /**
  234. @abstract 获取批量阶段购买价格(建立订单时需要用到)
  235. @param productId 购买的产品id
  236. @param num 批量个数
  237. @param complete 回调
  238. */
  239. func getDMGBatchProductPriceInfosForMember(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  240. checkConnectionAvailable()
  241. KMMemberCenterManager.manager.getBatchProductPrice(productId: productId, num: num) { [weak self] success, result in
  242. if success {
  243. guard let productsArrays : KMMemberProductResult = result else {
  244. complete(false, result)
  245. return
  246. }
  247. self?.dmgLastGetBatchProductPriceInfos = productsArrays
  248. complete(true, productsArrays)
  249. } else {
  250. complete(false, result)
  251. }
  252. }
  253. }
  254. /**
  255. @abstract 验证商品优惠券(建立订单时需要用到)
  256. @param productId 购买的产品id
  257. @param code 优惠券
  258. @param complete 回调
  259. */
  260. func getDMGCheckCouponProductPriceInfosForMember(productId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
  261. checkConnectionAvailable()
  262. KMMemberCenterManager.manager.checkCoupon(productId: productId, userId: KMMemberInfo.shared.userID, code: code) { [weak self] success, result in
  263. if success {
  264. guard let productsArrays : KMMemberProductResult = result else {
  265. complete(false, result)
  266. return
  267. }
  268. self?.dmgLastCheckCouponProductPriceInfos = productsArrays
  269. complete(true, productsArrays)
  270. } else {
  271. complete(false, result)
  272. }
  273. }
  274. }
  275. /**
  276. @abstract 获取订单列表
  277. @param orderStatus 0全部1待支付
  278. @param complete 回调
  279. */
  280. func getDMGProductListInfosForMember(orderStatus: Int, _ complete: @escaping KMMemberRequestInfoComplete) {
  281. checkConnectionAvailable()
  282. KMMemberCenterManager.manager.getOrderListByStatus(orderStatus: orderStatus) { [weak self] success, result in
  283. if success {
  284. guard let productsInfos : NSDictionary = result else {
  285. complete(false, result)
  286. return
  287. }
  288. complete(true, productsInfos)
  289. } else {
  290. complete(false, result)
  291. }
  292. }
  293. }
  294. /**
  295. @abstract 创建订单(买断)
  296. @param productId 产品id
  297. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  298. @param price 价格
  299. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  300. @param couponCode 优惠卷
  301. @param num 批量购买数量
  302. @param complete 回调
  303. */
  304. func creatOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  305. checkConnectionAvailable()
  306. KMMemberCenterManager.manager.createOrder(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
  307. if success {
  308. guard let productsArrays : KMMemberProductResult = result else {
  309. complete(false, result)
  310. return
  311. }
  312. self?.dmgLastCreatOrderProductInfos = productsArrays
  313. complete(true, productsArrays)
  314. } else {
  315. complete(false, result)
  316. }
  317. }
  318. }
  319. /**
  320. @abstract 创建订单(订阅)
  321. @param productId 产品id
  322. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  323. @param price 价格
  324. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  325. @param couponCode 优惠卷
  326. @param num 批量购买数量
  327. @param complete 回调
  328. */
  329. func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  330. checkConnectionAvailable()
  331. KMMemberCenterManager.manager.createSubscriber(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
  332. if success {
  333. guard let productsArrays : KMMemberProductResult = result else {
  334. complete(false, result)
  335. return
  336. }
  337. self?.dmgLastCreatSubscriberProductInfos = productsArrays
  338. complete(true, productsArrays)
  339. } else {
  340. complete(false, result)
  341. }
  342. }
  343. }
  344. /**
  345. @abstract 支付后查询订单状态
  346. @param productId 购买的产品id
  347. @param complete 回调
  348. */
  349. func getDMGProductOrderIdInfosForMember(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
  350. checkConnectionAvailable()
  351. KMMemberCenterManager.manager.getStateByOrderId(orderId: orderId) { [weak self] success, result in
  352. if success {
  353. guard let productsInfos : NSDictionary = result else {
  354. complete(false, result)
  355. return
  356. }
  357. complete(true, productsInfos)
  358. } else {
  359. complete(false, result)
  360. }
  361. }
  362. }
  363. // MARK: Public Method
  364. /**
  365. @abstract 根据当前权益获取比较表类型
  366. @param
  367. */
  368. func getCurrentComparisonTableType() -> Void {
  369. let userScenarioType = KMMemberInfo.shared.userScenarioType
  370. let platforms = KMMemberInfo.shared.vip_platforms
  371. let platformsArray = platforms
  372. .components(separatedBy: ",")
  373. .map { $0.trimmingCharacters(in: .whitespaces) }
  374. if userScenarioType == .lite_type1 ||
  375. userScenarioType == .lite_type3 ||
  376. userScenarioType == .lite_type11 ||
  377. userScenarioType == .lite_type4 ||
  378. userScenarioType == .lite_type5 ||
  379. userScenarioType == .lite_type9 ||
  380. userScenarioType == .lite_type13 ||
  381. userScenarioType == .lite_type7 ||
  382. userScenarioType == .lite_type8 {
  383. if userScenarioType == .lite_type1 {
  384. state = .trial
  385. } else if userScenarioType == .lite_type3 || userScenarioType == .lite_type11 {
  386. state = .lite_Base
  387. } else if userScenarioType == .lite_type4 || userScenarioType == .lite_type5 || userScenarioType == .lite_type9 || userScenarioType == .lite_type13 {
  388. state = .lite_MacWindows
  389. } else if userScenarioType == .lite_type7 || userScenarioType == .lite_type8 {
  390. if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 {
  391. state = .lite_MacWindows
  392. } else {
  393. state = .lite_Base
  394. }
  395. }
  396. } else if userScenarioType == .pro_type1 ||
  397. userScenarioType == .pro_type3 ||
  398. userScenarioType == .pro_type4 {
  399. if userScenarioType == .pro_type1 ||
  400. userScenarioType == .pro_type4 {
  401. state = .pro_Advanced
  402. } else if userScenarioType == .pro_type3 {
  403. state = .pro_Base
  404. }
  405. } else if userScenarioType == .dmg_type4 ||
  406. userScenarioType == .dmg_type5 ||
  407. userScenarioType == .dmg_type6 ||
  408. userScenarioType == .dmg_type7 ||
  409. userScenarioType == .dmg_type8 ||
  410. userScenarioType == .dmg_type9 ||
  411. userScenarioType == .dmg_type10 ||
  412. userScenarioType == .dmg_type11 ||
  413. userScenarioType == .dmg_type12 ||
  414. userScenarioType == .dmg_type13 ||
  415. userScenarioType == .dmg_type14 ||
  416. userScenarioType == .dmg_type15 ||
  417. userScenarioType == .dmg_type16 ||
  418. userScenarioType == .dmg_type17 ||
  419. userScenarioType == .dmg_type18 ||
  420. userScenarioType == .dmg_type19 ||
  421. userScenarioType == .dmg_type20 ||
  422. userScenarioType == .dmg_type21 ||
  423. userScenarioType == .dmg_type22 ||
  424. userScenarioType == .dmg_type23 ||
  425. userScenarioType == .dmg_type24 ||
  426. userScenarioType == .dmg_type25 ||
  427. userScenarioType == .dmg_type26 ||
  428. userScenarioType == .dmg_type27 ||
  429. userScenarioType == .dmg_type28 ||
  430. userScenarioType == .dmg_type29 ||
  431. userScenarioType == .dmg_type30 ||
  432. userScenarioType == .dmg_type31 ||
  433. userScenarioType == .dmg_type32 ||
  434. userScenarioType == .dmg_type33 ||
  435. userScenarioType == .dmg_type34 ||
  436. userScenarioType == .dmg_type35 ||
  437. userScenarioType == .dmg_type36 ||
  438. userScenarioType == .dmg_type37 ||
  439. userScenarioType == .dmg_type38 ||
  440. userScenarioType == .dmg_type39 ||
  441. userScenarioType == .dmg_type40 ||
  442. userScenarioType == .dmg_type41 ||
  443. userScenarioType == .dmg_type42 ||
  444. userScenarioType == .dmg_type43 ||
  445. userScenarioType == .dmg_type44 ||
  446. userScenarioType == .dmg_type45 ||
  447. userScenarioType == .dmg_type46 ||
  448. userScenarioType == .dmg_type47 ||
  449. userScenarioType == .dmg_type48 {
  450. if userScenarioType == .dmg_type4 ||
  451. userScenarioType == .dmg_type19 ||
  452. userScenarioType == .dmg_type34 {
  453. state = .trial
  454. } else if userScenarioType == .dmg_type5 ||
  455. userScenarioType == .dmg_type28 ||
  456. userScenarioType == .dmg_type43 {
  457. state = .dmg_Upgrades1
  458. } else if userScenarioType == .dmg_type6 ||
  459. userScenarioType == .dmg_type7 ||
  460. userScenarioType == .dmg_type29 ||
  461. userScenarioType == .dmg_type30 ||
  462. userScenarioType == .dmg_type44 ||
  463. userScenarioType == .dmg_type45 {
  464. state = .dmg_Upgrades2
  465. } else if userScenarioType == .dmg_type11 ||
  466. userScenarioType == .dmg_type18 ||
  467. userScenarioType == .dmg_type22 ||
  468. userScenarioType == .dmg_type33 ||
  469. userScenarioType == .dmg_type37 ||
  470. userScenarioType == .dmg_type48 {
  471. state = .dmg_Base
  472. }
  473. }
  474. }
  475. /**
  476. 对应商品价格
  477. */
  478. func getProductPrice(_ type: KMPurchasedProductType) -> String {
  479. #if VERSION_FREE
  480. #if VERSION_DMG
  481. // DMG
  482. if type == .pdfReaderProStandard_dmg {
  483. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  484. return String(format: "USD $%@", getDMGPrice(productCode: KMStandardAnnualSubscriptionCodeKey_DMG))
  485. } else {
  486. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMStandardAnnualSubscriptionCodeKey_DMG))
  487. }
  488. } else if type == .pdfReaderProAdvanced_dmg {
  489. if state == .dmg_Base {
  490. if isBlackFive {
  491. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  492. return String(format: "USD $%@", getDMGPrice(productCode: KMAdvancedAnnualSubscriptionBlackFiveCodeKey_DMG))
  493. } else {
  494. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMAdvancedAnnualSubscriptionBlackFiveCodeKey_DMG))
  495. }
  496. } else {
  497. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  498. return String(format: "USD $%@", getDMGPrice(productCode: KMAdvancedAnnualSubscriptionCodeKey_DMG))
  499. } else {
  500. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMAdvancedAnnualSubscriptionCodeKey_DMG))
  501. }
  502. }
  503. } else {
  504. if KMMemberInfo.shared.canTrail && state == .trial {
  505. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  506. return String(format: "USD $%@", getDMGPrice(productCode: KMAdvancedAnnualSubscriptionTrailCodeKey_DMG))
  507. } else {
  508. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMAdvancedAnnualSubscriptionTrailCodeKey_DMG))
  509. }
  510. } else {
  511. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  512. return String(format: "USD $%@", getDMGPrice(productCode: KMAdvancedAnnualSubscriptionCodeKey_DMG))
  513. } else {
  514. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMAdvancedAnnualSubscriptionCodeKey_DMG))
  515. }
  516. }
  517. }
  518. } else if type == .pdfReaderProPermanent_dmg {
  519. if state == .dmg_Base {
  520. if isBlackFive {
  521. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  522. return String(format: "USD $%@", getDMGPrice(productCode: KMAdvancedPermanentBlackFiveCodeKey_DMG))
  523. } else {
  524. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMAdvancedPermanentBlackFiveCodeKey_DMG))
  525. }
  526. } else {
  527. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  528. return String(format: "USD $%@", getDMGPrice(productCode: KMAdvancedPermanentCodeKey_DMG))
  529. } else {
  530. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMAdvancedPermanentCodeKey_DMG))
  531. }
  532. }
  533. } else {
  534. }
  535. } else if type == .pdfReaderProAIAnnual_dmg {
  536. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  537. return String(format: "USD $%@", getDMGPrice(productCode: KMAISubscriptionYearTrailCodeKey_DMG))
  538. } else {
  539. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMAISubscriptionYearTrailCodeKey_DMG))
  540. }
  541. } else if type == .pdfReaderProAIMonthly_dmg {
  542. if NSLocalizedString("USD", tableName: "MemberCenterLocalizable", comment: "") == "USD" {
  543. return String(format: "USD $%@", getDMGPrice(productCode: KMAISubscriptionMonthCodeKey_DMG))
  544. } else {
  545. return String(format: "CNY ¥%@", getDMGCNYPrice(productCode: KMAISubscriptionMonthCodeKey_DMG))
  546. }
  547. } else if type == .pdfToOffice_dmg {
  548. } else if type == .add2Device_dmg {
  549. } else if type == .add3Device_dmg {
  550. }
  551. #else
  552. // AppStore 免费版本
  553. if type == .fourDevicesAllAccessPackNew6months_lite {
  554. if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, product.isOffers {
  555. return product.offersPrice()
  556. } else {
  557. return IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.price()
  558. }
  559. } else if type == .fourDevicesAllAccessPackNew12months_lite {
  560. if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, product.isOffers {
  561. return product.offersPrice()
  562. } else {
  563. return IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.price()
  564. }
  565. } else if type == .aiAllAccessPack1month_lite {
  566. if let product = IAPProductsManager.default().aiAllAccessPack1month_lite, product.isOffers {
  567. return product.offersPrice()
  568. } else {
  569. return IAPProductsManager.default().aiAllAccessPack1month_lite.price()
  570. }
  571. } else if type == .aiAllAccessPack12month_lite {
  572. if let product = IAPProductsManager.default().aiAllAccessPack12month_lite, product.isOffers {
  573. return product.offersPrice()
  574. } else {
  575. return IAPProductsManager.default().aiAllAccessPack12month_lite.price()
  576. }
  577. } else if type == .allAccessPackPermanent_lite {
  578. if let product = IAPProductsManager.default().allAccessPackPermanent_lite, product.isOffers {
  579. return product.offersPrice()
  580. } else {
  581. return IAPProductsManager.default().allAccessPackPermanent_lite.price()
  582. }
  583. } else if type == .advancedAddDevicesAllAccessPack12months_lite {
  584. if let product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, product.isOffers {
  585. return product.offersPrice()
  586. } else {
  587. return IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite.price()
  588. }
  589. } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
  590. if let product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, product.isOffers {
  591. return product.offersPrice()
  592. } else {
  593. return IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite.price()
  594. }
  595. }
  596. #endif
  597. #else
  598. // AppStore 付费版
  599. if type == .aiAllAccessPack1month_pro {
  600. if let product = IAPProductsManager.default().aiAllAccessPack1month_pro, product.isOffers {
  601. return product.offersPrice()
  602. } else {
  603. return IAPProductsManager.default().aiAllAccessPack1month_pro.price()
  604. }
  605. } else if type == .aiAllAccessPack12month_pro {
  606. if let product = IAPProductsManager.default().aiAllAccessPack12month_pro, product.isOffers {
  607. return product.offersPrice()
  608. } else {
  609. return IAPProductsManager.default().aiAllAccessPack12month_pro.price()
  610. }
  611. } else if type == .pdfToOfficePackPermanent_pro {
  612. if let product = IAPProductsManager.default().pdfToOfficePackPermanent_pro, product.isOffers {
  613. return product.offersPrice()
  614. } else {
  615. return IAPProductsManager.default().pdfToOfficePackPermanent_pro.price()
  616. }
  617. } else if type == .fourDevicesAllAccessPack12months_pro {
  618. if let product = IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, product.isOffers {
  619. return product.offersPrice()
  620. } else {
  621. return IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.price()
  622. }
  623. } else if type == .standardAddDevicesAllAccessPack12months_pro {
  624. if let product = IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, product.isOffers {
  625. return product.offersPrice()
  626. } else {
  627. return IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro.price()
  628. }
  629. } else if type == .advancedAddDevicesAllAccessPack12months_pro {
  630. if let product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, product.isOffers {
  631. return product.offersPrice()
  632. } else {
  633. return IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro.price()
  634. }
  635. } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
  636. if let product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, product.isOffers {
  637. return product.offersPrice()
  638. } else {
  639. return IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro.price()
  640. }
  641. }
  642. #endif
  643. return ""
  644. }
  645. func appstorePurchaseAction(_ tag: Int, _ complete: @escaping AppstorePurchaseComplete) -> Void {
  646. if state == .dmg_Base {
  647. var code = ""
  648. if tag == 1 {
  649. code = KMStandardAnnualSubscriptionCodeKey_DMG
  650. } else if tag == 3 {
  651. if isBlackFive {
  652. code = KMAdvancedPermanentBlackFiveCodeKey_DMG
  653. } else {
  654. code = KMAdvancedPermanentCodeKey_DMG
  655. }
  656. } else {
  657. if isBlackFive {
  658. code = KMAdvancedAnnualSubscriptionBlackFiveCodeKey_DMG
  659. } else {
  660. code = KMAdvancedAnnualSubscriptionCodeKey_DMG
  661. }
  662. }
  663. #if VERSION_DMG
  664. let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(code)
  665. embeddedWC.showWindow(nil)
  666. embeddedWC.window?.center()
  667. #endif
  668. } else if state == .dmg_Upgrades1 {
  669. #if VERSION_DMG
  670. let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(KMAdvancedAnnualSubscriptionCodeKey_DMG)
  671. embeddedWC.showWindow(nil)
  672. embeddedWC.window?.center()
  673. #endif
  674. } else if state == .dmg_Upgrades2 {
  675. #if VERSION_DMG
  676. let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(KMAdvancedAnnualSubscriptionCodeKey_DMG)
  677. embeddedWC.showWindow(nil)
  678. embeddedWC.window?.center()
  679. #endif
  680. } else if state == .lite_Base {
  681. if tag == 0 {
  682. if isPurchaseSwitch { membershipPurchase(.fourDevicesAllAccessPackNew12months_lite) }
  683. else { membershipPurchase(.fourDevicesAllAccessPackNew6months_lite) }
  684. } else if tag == 3 {
  685. membershipPurchase(.allAccessPackPermanent_lite)
  686. } else {
  687. membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
  688. }
  689. } else if state == .lite_MacWindows {
  690. if tag == 2 {
  691. let platforms = KMMemberInfo.shared.vip_platforms
  692. let platformsArray = platforms
  693. .components(separatedBy: ",")
  694. .map { $0.trimmingCharacters(in: .whitespaces) }
  695. if KMMemberInfo.shared.userScenarioType == .lite_type5 {
  696. if platformsArray.count == 1 {
  697. membershipPurchase(.advancedAddDevicesAllAccessPack12months_lite)
  698. } else if platformsArray.count == 2 {
  699. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
  700. }
  701. } else {
  702. if platformsArray.count == 1 {
  703. membershipPurchase(.advancedAddDevicesAllAccessPack12months_lite)
  704. } else if platformsArray.count == 2 {
  705. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
  706. } else {
  707. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
  708. }
  709. }
  710. }
  711. } else if state == .pro_Base {
  712. if KMMemberInfo.shared.userScenarioType == .pro_type3 {
  713. if tag == 2 {
  714. membershipPurchase(.standardAddDevicesAllAccessPack12months_pro)
  715. } else if tag == 3 {
  716. membershipPurchase(.pdfToOfficePackPermanent_pro)
  717. }
  718. }
  719. } else if state == .pro_Advanced {
  720. let platforms = KMMemberInfo.shared.vip_platforms
  721. let platformsArray = platforms
  722. .components(separatedBy: ",")
  723. .map { $0.trimmingCharacters(in: .whitespaces) }
  724. if KMMemberInfo.shared.userScenarioType == .pro_type1 {
  725. if platformsArray.count == 1 {
  726. membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
  727. } else if platformsArray.count == 2 {
  728. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
  729. } else if KMMemberInfo.shared.vip_levels == "1" {
  730. membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
  731. } else {
  732. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
  733. }
  734. } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
  735. if platformsArray.count == 1 {
  736. membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
  737. } else if platformsArray.count == 2 {
  738. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
  739. } else {
  740. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
  741. }
  742. }
  743. } else {
  744. #if VERSION_FREE
  745. #if VERSION_DMG
  746. // DMG
  747. var code = ""
  748. if state == .dmg_Base {
  749. if isBlackFive {
  750. code = KMAdvancedAnnualSubscriptionBlackFiveCodeKey_DMG
  751. } else {
  752. code = KMAdvancedAnnualSubscriptionCodeKey_DMG
  753. }
  754. } else {
  755. if KMMemberInfo.shared.canTrail && state == .trial {
  756. code = KMAdvancedAnnualSubscriptionTrailCodeKey_DMG
  757. } else {
  758. code = KMAdvancedAnnualSubscriptionCodeKey_DMG
  759. }
  760. }
  761. let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(code)
  762. embeddedWC.showWindow(nil)
  763. embeddedWC.window?.center()
  764. #else
  765. // AppStore 免费版本
  766. if tag == 2 {
  767. membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
  768. }
  769. #endif
  770. #else
  771. // AppStore 付费版
  772. #endif
  773. }
  774. }
  775. func appStoreEquityVerification(_ notification: Notification,_ complete: @escaping KMMemberProductComplete) -> Void {
  776. #if VERSION_FREE
  777. #if VERSION_DMG
  778. // DMG
  779. #else
  780. // AppStore 免费版本
  781. if let userInfo = notification.object as? SKPaymentTransaction,
  782. let transactionId = userInfo.transactionIdentifier as? String,
  783. let productId = userInfo.payment.productIdentifier as? String {
  784. print("Transaction ID: \(transactionId)")
  785. print("product ID: \(productId)")
  786. var productCode = ""
  787. var isSubscribed = false
  788. if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_6months.001" {
  789. productCode = "advanced-annual-subscription-six-month"
  790. if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
  791. isSubscribed = true
  792. }
  793. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_annual.001" {
  794. productCode = "advanced-annual-subscription"
  795. if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
  796. isSubscribed = true
  797. }
  798. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_new_6months.001" {
  799. productCode = "advanced-annual-subscription-six-month"
  800. if IAPProductsManager.default().allAccessPackNew6months_lite.isSubscribed {
  801. isSubscribed = true
  802. }
  803. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_12months.001" {
  804. productCode = "advanced-annual-subscription"
  805. if IAPProductsManager.default().allAccessPack12months_lite.isSubscribed {
  806. isSubscribed = true
  807. }
  808. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_6months.001" {
  809. productCode = "advanced-annual-subscription-six-month"
  810. if IAPProductsManager.default().allAccessPack6months_lite.isSubscribed {
  811. isSubscribed = true
  812. }
  813. } else if productId == "com.pdfreaderpro.mac_free.member.ai_pack_1_month" {
  814. productCode = "ai-subscription-month"
  815. if IAPProductsManager.default().aiAllAccessPack1month_lite.isSubscribed {
  816. isSubscribed = true
  817. }
  818. } else if productId == "com.pdfreaderpro.mac_free.member.ai_pack_12_month" {
  819. productCode = "ai-subscription-year-trail"
  820. if IAPProductsManager.default().aiAllAccessPack12month_lite.isSubscribed {
  821. isSubscribed = true
  822. }
  823. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_permanent_license.001" {
  824. productCode = "advanced-permanent"
  825. if IAPProductsManager.default().allAccessPackPermanent_lite.isSubscribed {
  826. isSubscribed = true
  827. }
  828. } else if productId == "com.pdfreaderpro.mac_free.member.advanced_add_devices_all_access_pack_advanced_annual.001" {
  829. productCode = "advanced-annual-subscription-single-upgrade"
  830. if IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite.isSubscribed {
  831. isSubscribed = true
  832. }
  833. } else if productId == "com.pdfreaderpro.mac_free.member.advanced_add_2_devices_all_access_pack_advanced_annual.001" {
  834. productCode = "advanced-annual-subscription-multi-upgrade"
  835. if IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite.isSubscribed {
  836. isSubscribed = true
  837. }
  838. }
  839. if isSubscribed {
  840. KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
  841. DispatchQueue.main.async {
  842. if success {
  843. complete(true, result)
  844. } else {
  845. complete(false, result)
  846. }
  847. }
  848. }
  849. }
  850. } else {
  851. print(NSLocalizedString("Order does not exist.", tableName: "MemberCenterLocalizable", comment: ""))
  852. }
  853. #endif
  854. #else
  855. // AppStore 付费版
  856. if let userInfo = notification.object as? SKPaymentTransaction,
  857. let transactionId = userInfo.transactionIdentifier as? String,
  858. let productId = userInfo.payment.productIdentifier as? String {
  859. print("Transaction ID: \(transactionId)")
  860. print("product ID: \(productId)")
  861. var productCode = ""
  862. var isSubscribed = false
  863. if productId == "com.pdfreaderpro.mac.ai_pack_1_month" {
  864. productCode = "ai-subscription-month"
  865. if IAPProductsManager.default().aiAllAccessPack1month_pro.isSubscribed {
  866. isSubscribed = true
  867. }
  868. } else if productId == "com.pdfreaderpro.mac.ai_pack_12_month" {
  869. productCode = "ai-subscription-year-trail"
  870. if IAPProductsManager.default().aiAllAccessPack12month_pro.isSubscribed {
  871. isSubscribed = true
  872. }
  873. } else if productId == "com.pdfreaderpro.mac.pdf_to_office_pack_permanent_license.001" {
  874. productCode = "advanced-permanent-mac-upgrade"
  875. if IAPProductsManager.default().pdfToOfficePackPermanent_pro.isSubscribed {
  876. isSubscribed = true
  877. }
  878. } else if productId == "com.pdfreaderpro.mac.all_access_pack_advanced_annual.001" {
  879. productCode = "advanced-permanent-mac-upgrade"
  880. if IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.isSubscribed {
  881. isSubscribed = true
  882. }
  883. } else if productId == "com.pdfreaderpro.mac.standard_add_devices_all_access_pack_advanced_annual.001" {
  884. productCode = "advanced-annual-subscription-standard-upgrade"
  885. if IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro.isSubscribed {
  886. isSubscribed = true
  887. }
  888. } else if productId == "com.pdfreaderpro.mac.advanced_add_devices_all_access_pack_advanced_annual.001" {
  889. productCode = "advanced-annual-subscription-single-upgrade"
  890. if IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro.isSubscribed {
  891. isSubscribed = true
  892. }
  893. } else if productId == "com.pdfreaderpro.mac.advanced_add_2_devices_all_access_pack_advanced_annual.001" {
  894. productCode = "advanced-annual-subscription-multi-upgrade"
  895. if IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro.isSubscribed {
  896. isSubscribed = true
  897. }
  898. }
  899. if isSubscribed {
  900. KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
  901. if success {
  902. complete(true, result)
  903. } else {
  904. complete(false, result)
  905. }
  906. }
  907. }
  908. } else {
  909. print(NSLocalizedString("Order does not exist.", tableName: "MemberCenterLocalizable", comment: ""))
  910. }
  911. #endif
  912. }
  913. var isCancelAutoRenew: Bool {
  914. return IAPProductsManager.default().isCancelAutoRenew()
  915. }
  916. var isShowSale: Bool {
  917. if #available(macOS 10.14.4, *), isCancelAutoRenew {
  918. let manager = IAPProductsManager.default()
  919. let isSubscribed_newlyMonth = manager?.allAccessPackNew6months_lite.isSubscribed ?? false
  920. let isSubscribed_year = manager?.allAccessPack12months_lite.isSubscribed ?? false
  921. if isSubscribed_newlyMonth || isSubscribed_year {
  922. return false
  923. }
  924. if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first, !(info.show! as NSString).boolValue {
  925. return false
  926. }
  927. return true
  928. }
  929. return false
  930. }
  931. // MARK: Private Method
  932. /**
  933. 会员购买
  934. */
  935. private func membershipPurchase(_ type: KMPurchasedProductType) -> Void {
  936. #if !VERSION_DMG
  937. if type == .fourDevicesAllAccessPackNew6months_lite || type == .fourDevicesAllAccessPackNew12months_lite {
  938. if isPurchaseSwitch {
  939. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: isCancelAutoRenew)
  940. } else {
  941. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: isCancelAutoRenew)
  942. }
  943. } else if type == .aiAllAccessPack1month_lite {
  944. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_lite, discount: isCancelAutoRenew)
  945. } else if type == .aiAllAccessPack12month_lite {
  946. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: isCancelAutoRenew)
  947. } else if type == .allAccessPackPermanent_lite {
  948. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().allAccessPackPermanent_lite, discount: isCancelAutoRenew)
  949. } else if type == .advancedAddDevicesAllAccessPack12months_lite {
  950. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
  951. } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
  952. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
  953. } else if type == .aiAllAccessPack1month_pro {
  954. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_pro, discount: isCancelAutoRenew)
  955. } else if type == .aiAllAccessPack12month_pro {
  956. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_pro, discount: isCancelAutoRenew)
  957. } else if type == .pdfToOfficePackPermanent_pro {
  958. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().pdfToOfficePackPermanent_pro, discount: isCancelAutoRenew)
  959. } else if type == .fourDevicesAllAccessPack12months_pro {
  960. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  961. } else if type == .standardAddDevicesAllAccessPack12months_pro {
  962. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  963. } else if type == .advancedAddDevicesAllAccessPack12months_pro {
  964. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  965. } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
  966. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  967. }
  968. #endif
  969. }
  970. // MARK: Action Method
  971. /**
  972. 恢复购买
  973. */
  974. func productRestore() -> Void {
  975. IAPProductsManager.default().restoreSubscriptions()
  976. }
  977. func privacyPolicyAction() -> Void {
  978. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/privacy-policy")!)
  979. }
  980. func termOfSerAction() -> Void {
  981. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/terms_of_service")!)
  982. }
  983. // MARK: Get & Set
  984. /**
  985. 当前比较表产品列表内容
  986. */
  987. var products: [KMCompareProductType] {
  988. if state == .trial {
  989. return [.free, .freeTrial]
  990. } else if state == .dmg_Base {
  991. return [.free, .allPlatformStandard, .allPlatformAdvanced_12, .dualPlatformAdvanced]
  992. } else if state == .dmg_Upgrades1 {
  993. return [.allPlatformAdvanced_12]
  994. } else if state == .dmg_Upgrades1 {
  995. return [.allPlatformAdvanced_12]
  996. } else if state == .lite_Base {
  997. return [.free, .allPlatformAdvanced_6, .allPlatformAdvanced_12, .dualPlatformAdvanced]
  998. } else if state == .lite_MacWindows {
  999. return [.allPlatformAdvanced_12]
  1000. } else if state == .pro_Base {
  1001. return [.allPlatformAdvanced_12, .macPlatformAdvanced]
  1002. } else if state == .pro_Advanced {
  1003. return [.allPlatformAdvanced_12]
  1004. }
  1005. return []
  1006. }
  1007. /**
  1008. 比较表数据源
  1009. */
  1010. var dataSource: [Any] {
  1011. if isPurchaseSwitch {
  1012. // 试用 全平台标准版年订阅 全平台高级版6/12个月订阅 Mac&Windows双平台高级版永久 MAC单平台高级版永久
  1013. //MAC单平台标准版永久
  1014. return [
  1015. "Benefit",
  1016. ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
  1017. ["Maximum number of accessible devices", "4 devices", "4 devices", "4 devices", "1 device", "1 device"],
  1018. "PDF to Office",
  1019. ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
  1020. ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1021. ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1022. "Edit PDF",
  1023. ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
  1024. ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
  1025. "OCR",
  1026. ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
  1027. "Organize Pages",
  1028. ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
  1029. ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
  1030. "Advanced Editing Tools",
  1031. ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
  1032. ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
  1033. ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
  1034. ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
  1035. ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
  1036. ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
  1037. ["Extract Images", "X", "✓", "✓", "✓", "✓"],
  1038. ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1039. ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
  1040. "Fill & Sign",
  1041. ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
  1042. ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
  1043. "Security",
  1044. ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
  1045. ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
  1046. ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
  1047. "Create PDF",
  1048. ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
  1049. ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
  1050. "Annotations",
  1051. ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
  1052. ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
  1053. ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
  1054. ["Table", "X", "✓", "✓", "✓", "✓"],
  1055. "View PDF",
  1056. ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
  1057. ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
  1058. ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
  1059. ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
  1060. "Subscription Based Solution",
  1061. ["Access all premium features in app", "X", "12 months", "12 months", "∞", "∞"],
  1062. ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
  1063. ["Ad-free", "X", "✓", "✓", "✓", "✓"]
  1064. ]
  1065. } else {
  1066. return [
  1067. "Benefit",
  1068. ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
  1069. ["Maximum number of accessible devices", "4 devices", "4 devices", "4 devices", "1 device", "1 device"],
  1070. "PDF to Office",
  1071. ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
  1072. ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1073. ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1074. "Edit PDF",
  1075. ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
  1076. ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
  1077. "OCR",
  1078. ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
  1079. "Organize Pages",
  1080. ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
  1081. ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
  1082. "Advanced Editing Tools",
  1083. ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
  1084. ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
  1085. ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
  1086. ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
  1087. ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
  1088. ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
  1089. ["Extract Images", "X", "✓", "✓", "✓", "✓"],
  1090. ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1091. ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
  1092. "Fill & Sign",
  1093. ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
  1094. ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
  1095. "Security",
  1096. ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
  1097. ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
  1098. ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
  1099. "Create PDF",
  1100. ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
  1101. ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
  1102. "Annotations",
  1103. ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
  1104. ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
  1105. ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
  1106. ["Table", "X", "✓", "✓", "✓", "✓"],
  1107. "View PDF",
  1108. ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
  1109. ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
  1110. ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
  1111. ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
  1112. "Subscription Based Solution",
  1113. ["Access all premium features in app", "X", "6 months", "6 months", "∞", "∞"],
  1114. ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
  1115. ["Ad-free", "X", "✓", "✓", "✓", "✓"]
  1116. ]
  1117. }
  1118. }
  1119. /**
  1120. 是否黑五活动期
  1121. */
  1122. var isBlackFive: Bool {
  1123. if let loginContent = KMAdvertisementManager.manager.info.topRightInfoContent {
  1124. if loginContent.content?.isEmpty == false {
  1125. return true
  1126. }
  1127. }
  1128. return false
  1129. }
  1130. }