KMProductModel.swift 65 KB

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