KMProductModel.swift 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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 {
  730. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
  731. }
  732. } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
  733. if platformsArray.count == 1 {
  734. membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
  735. } else if platformsArray.count == 2 {
  736. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
  737. } else {
  738. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
  739. }
  740. }
  741. } else {
  742. #if VERSION_FREE
  743. #if VERSION_DMG
  744. // DMG
  745. var code = ""
  746. if state == .dmg_Base {
  747. if isBlackFive {
  748. code = KMAdvancedAnnualSubscriptionBlackFiveCodeKey_DMG
  749. } else {
  750. code = KMAdvancedAnnualSubscriptionCodeKey_DMG
  751. }
  752. } else {
  753. if KMMemberInfo.shared.canTrail && state == .trial {
  754. code = KMAdvancedAnnualSubscriptionTrailCodeKey_DMG
  755. } else {
  756. code = KMAdvancedAnnualSubscriptionCodeKey_DMG
  757. }
  758. }
  759. let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(code)
  760. embeddedWC.showWindow(nil)
  761. embeddedWC.window?.center()
  762. #else
  763. // AppStore 免费版本
  764. if tag == 2 {
  765. membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
  766. }
  767. #endif
  768. #else
  769. // AppStore 付费版
  770. #endif
  771. }
  772. }
  773. func appStoreEquityVerification(_ notification: Notification,_ complete: @escaping KMMemberProductComplete) -> Void {
  774. #if VERSION_FREE
  775. #if VERSION_DMG
  776. // DMG
  777. #else
  778. // AppStore 免费版本
  779. if let userInfo = notification.object as? SKPaymentTransaction,
  780. let transactionId = userInfo.transactionIdentifier as? String,
  781. let productId = userInfo.payment.productIdentifier as? String {
  782. print("Transaction ID: \(transactionId)")
  783. print("product ID: \(productId)")
  784. var productCode = ""
  785. var isSubscribed = false
  786. if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_6months.001" {
  787. productCode = "advanced-annual-subscription-six-month"
  788. if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
  789. isSubscribed = true
  790. }
  791. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_annual.001" {
  792. productCode = "advanced-annual-subscription"
  793. if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
  794. isSubscribed = true
  795. }
  796. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_new_6months.001" {
  797. productCode = "advanced-annual-subscription-six-month"
  798. if IAPProductsManager.default().allAccessPackNew6months_lite.isSubscribed {
  799. isSubscribed = true
  800. }
  801. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_12months.001" {
  802. productCode = "advanced-annual-subscription"
  803. if IAPProductsManager.default().allAccessPack12months_lite.isSubscribed {
  804. isSubscribed = true
  805. }
  806. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_6months.001" {
  807. productCode = "advanced-annual-subscription-six-month"
  808. if IAPProductsManager.default().allAccessPack6months_lite.isSubscribed {
  809. isSubscribed = true
  810. }
  811. } else if productId == "com.pdfreaderpro.mac_free.member.ai_pack_1_month" {
  812. productCode = "ai-subscription-month"
  813. if IAPProductsManager.default().aiAllAccessPack1month_lite.isSubscribed {
  814. isSubscribed = true
  815. }
  816. } else if productId == "com.pdfreaderpro.mac_free.member.ai_pack_12_month" {
  817. productCode = "ai-subscription-year-trail"
  818. if IAPProductsManager.default().aiAllAccessPack12month_lite.isSubscribed {
  819. isSubscribed = true
  820. }
  821. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_permanent_license.001" {
  822. productCode = "advanced-permanent"
  823. if IAPProductsManager.default().allAccessPackPermanent_lite.isSubscribed {
  824. isSubscribed = true
  825. }
  826. } else if productId == "com.pdfreaderpro.mac_free.member.advanced_add_devices_all_access_pack_advanced_annual.001" {
  827. productCode = "advanced-annual-subscription-single-upgrade"
  828. if IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite.isSubscribed {
  829. isSubscribed = true
  830. }
  831. } else if productId == "com.pdfreaderpro.mac_free.member.advanced_add_2_devices_all_access_pack_advanced_annual.001" {
  832. productCode = "advanced-annual-subscription-multi-upgrade"
  833. if IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite.isSubscribed {
  834. isSubscribed = true
  835. }
  836. }
  837. if isSubscribed {
  838. KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
  839. DispatchQueue.main.async {
  840. if success {
  841. complete(true, result)
  842. } else {
  843. complete(false, result)
  844. }
  845. }
  846. }
  847. }
  848. } else {
  849. print(NSLocalizedString("Order does not exist.", tableName: "MemberCenterLocalizable", comment: ""))
  850. }
  851. #endif
  852. #else
  853. // AppStore 付费版
  854. if let userInfo = notification.object as? SKPaymentTransaction,
  855. let transactionId = userInfo.transactionIdentifier as? String,
  856. let productId = userInfo.payment.productIdentifier as? String {
  857. print("Transaction ID: \(transactionId)")
  858. print("product ID: \(productId)")
  859. var productCode = ""
  860. var isSubscribed = false
  861. if productId == "com.pdfreaderpro.mac.ai_pack_1_month" {
  862. productCode = "ai-subscription-month"
  863. if IAPProductsManager.default().aiAllAccessPack1month_pro.isSubscribed {
  864. isSubscribed = true
  865. }
  866. } else if productId == "com.pdfreaderpro.mac.ai_pack_12_month" {
  867. productCode = "ai-subscription-year-trail"
  868. if IAPProductsManager.default().aiAllAccessPack12month_pro.isSubscribed {
  869. isSubscribed = true
  870. }
  871. } else if productId == "com.pdfreaderpro.mac.pdf_to_office_pack_permanent_license.001" {
  872. productCode = "advanced-permanent-mac-upgrade"
  873. if IAPProductsManager.default().pdfToOfficePackPermanent_pro.isSubscribed {
  874. isSubscribed = true
  875. }
  876. } else if productId == "com.pdfreaderpro.mac.all_access_pack_advanced_annual.001" {
  877. productCode = "advanced-permanent-mac-upgrade"
  878. if IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.isSubscribed {
  879. isSubscribed = true
  880. }
  881. } else if productId == "com.pdfreaderpro.mac.standard_add_devices_all_access_pack_advanced_annual.001" {
  882. productCode = "advanced-annual-subscription-standard-upgrade"
  883. if IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro.isSubscribed {
  884. isSubscribed = true
  885. }
  886. } else if productId == "com.pdfreaderpro.mac.advanced_add_devices_all_access_pack_advanced_annual.001" {
  887. productCode = "advanced-annual-subscription-single-upgrade"
  888. if IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro.isSubscribed {
  889. isSubscribed = true
  890. }
  891. } else if productId == "com.pdfreaderpro.mac.advanced_add_2_devices_all_access_pack_advanced_annual.001" {
  892. productCode = "advanced-annual-subscription-multi-upgrade"
  893. if IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro.isSubscribed {
  894. isSubscribed = true
  895. }
  896. }
  897. if isSubscribed {
  898. KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
  899. if success {
  900. complete(true, result)
  901. } else {
  902. complete(false, result)
  903. }
  904. }
  905. }
  906. } else {
  907. print(NSLocalizedString("Order does not exist.", tableName: "MemberCenterLocalizable", comment: ""))
  908. }
  909. #endif
  910. }
  911. var isCancelAutoRenew: Bool {
  912. return IAPProductsManager.default().isCancelAutoRenew()
  913. }
  914. var isShowSale: Bool {
  915. if #available(macOS 10.14.4, *), isCancelAutoRenew {
  916. let manager = IAPProductsManager.default()
  917. let isSubscribed_newlyMonth = manager?.allAccessPackNew6months_lite.isSubscribed ?? false
  918. let isSubscribed_year = manager?.allAccessPack12months_lite.isSubscribed ?? false
  919. if isSubscribed_newlyMonth || isSubscribed_year {
  920. return false
  921. }
  922. if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first, !(info.show! as NSString).boolValue {
  923. return false
  924. }
  925. return true
  926. }
  927. return false
  928. }
  929. // MARK: Private Method
  930. /**
  931. 会员购买
  932. */
  933. private func membershipPurchase(_ type: KMPurchasedProductType) -> Void {
  934. #if !VERSION_DMG
  935. if type == .fourDevicesAllAccessPackNew6months_lite || type == .fourDevicesAllAccessPackNew12months_lite {
  936. if isPurchaseSwitch {
  937. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: isCancelAutoRenew)
  938. } else {
  939. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: isCancelAutoRenew)
  940. }
  941. } else if type == .aiAllAccessPack1month_lite {
  942. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_lite, discount: isCancelAutoRenew)
  943. } else if type == .aiAllAccessPack12month_lite {
  944. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: isCancelAutoRenew)
  945. } else if type == .allAccessPackPermanent_lite {
  946. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().allAccessPackPermanent_lite, discount: isCancelAutoRenew)
  947. } else if type == .advancedAddDevicesAllAccessPack12months_lite {
  948. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
  949. } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
  950. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
  951. } else if type == .aiAllAccessPack1month_pro {
  952. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_pro, discount: isCancelAutoRenew)
  953. } else if type == .aiAllAccessPack12month_pro {
  954. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_pro, discount: isCancelAutoRenew)
  955. } else if type == .pdfToOfficePackPermanent_pro {
  956. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().pdfToOfficePackPermanent_pro, discount: isCancelAutoRenew)
  957. } else if type == .fourDevicesAllAccessPack12months_pro {
  958. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  959. } else if type == .standardAddDevicesAllAccessPack12months_pro {
  960. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  961. } else if type == .advancedAddDevicesAllAccessPack12months_pro {
  962. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  963. } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
  964. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  965. }
  966. #endif
  967. }
  968. // MARK: Action Method
  969. /**
  970. 恢复购买
  971. */
  972. func productRestore() -> Void {
  973. IAPProductsManager.default().restoreSubscriptions()
  974. }
  975. func privacyPolicyAction() -> Void {
  976. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/privacy-policy")!)
  977. }
  978. func termOfSerAction() -> Void {
  979. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/terms_of_service")!)
  980. }
  981. // MARK: Get & Set
  982. /**
  983. 当前比较表产品列表内容
  984. */
  985. var products: [KMCompareProductType] {
  986. if state == .trial {
  987. return [.free, .freeTrial]
  988. } else if state == .dmg_Base {
  989. return [.free, .allPlatformStandard, .allPlatformAdvanced_12, .dualPlatformAdvanced]
  990. } else if state == .dmg_Upgrades1 {
  991. return [.allPlatformAdvanced_12]
  992. } else if state == .dmg_Upgrades1 {
  993. return [.allPlatformAdvanced_12]
  994. } else if state == .lite_Base {
  995. return [.free, .allPlatformAdvanced_6, .allPlatformAdvanced_12, .dualPlatformAdvanced]
  996. } else if state == .lite_MacWindows {
  997. return [.allPlatformAdvanced_12]
  998. } else if state == .pro_Base {
  999. return [.allPlatformAdvanced_12, .macPlatformAdvanced]
  1000. } else if state == .pro_Advanced {
  1001. return [.allPlatformAdvanced_12]
  1002. }
  1003. return []
  1004. }
  1005. /**
  1006. 比较表数据源
  1007. */
  1008. var dataSource: [Any] {
  1009. if isPurchaseSwitch {
  1010. // 试用 全平台标准版年订阅 全平台高级版6/12个月订阅 Mac&Windows双平台高级版永久 MAC单平台高级版永久
  1011. //MAC单平台标准版永久
  1012. return [
  1013. "Benefit",
  1014. ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
  1015. ["Maximum number of accessible devices", "4 devices", "4 devices", "4 devices", "1 device", "1 device"],
  1016. "PDF to Office",
  1017. ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
  1018. ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1019. ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1020. "Edit PDF",
  1021. ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
  1022. ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
  1023. "OCR",
  1024. ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
  1025. "Organize Pages",
  1026. ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
  1027. ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
  1028. "Advanced Editing Tools",
  1029. ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
  1030. ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
  1031. ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
  1032. ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
  1033. ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
  1034. ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
  1035. ["Extract Images", "X", "✓", "✓", "✓", "✓"],
  1036. ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1037. ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
  1038. "Fill & Sign",
  1039. ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
  1040. ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
  1041. "Security",
  1042. ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
  1043. ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
  1044. ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
  1045. "Create PDF",
  1046. ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
  1047. ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
  1048. "Annotations",
  1049. ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
  1050. ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
  1051. ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
  1052. ["Table", "X", "✓", "✓", "✓", "✓"],
  1053. "View PDF",
  1054. ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
  1055. ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
  1056. ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
  1057. ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
  1058. "Subscription Based Solution",
  1059. ["Access all premium features in app", "X", "12 months", "12 months", "∞", "∞"],
  1060. ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
  1061. ["Ad-free", "X", "✓", "✓", "✓", "✓"]
  1062. ]
  1063. } else {
  1064. return [
  1065. "Benefit",
  1066. ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
  1067. ["Maximum number of accessible devices", "4 devices", "4 devices", "4 devices", "1 device", "1 device"],
  1068. "PDF to Office",
  1069. ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
  1070. ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1071. ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1072. "Edit PDF",
  1073. ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
  1074. ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
  1075. "OCR",
  1076. ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
  1077. "Organize Pages",
  1078. ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
  1079. ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
  1080. "Advanced Editing Tools",
  1081. ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
  1082. ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
  1083. ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
  1084. ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
  1085. ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
  1086. ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
  1087. ["Extract Images", "X", "✓", "✓", "✓", "✓"],
  1088. ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  1089. ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
  1090. "Fill & Sign",
  1091. ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
  1092. ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
  1093. "Security",
  1094. ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
  1095. ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
  1096. ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
  1097. "Create PDF",
  1098. ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
  1099. ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
  1100. "Annotations",
  1101. ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
  1102. ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
  1103. ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
  1104. ["Table", "X", "✓", "✓", "✓", "✓"],
  1105. "View PDF",
  1106. ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
  1107. ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
  1108. ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
  1109. ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
  1110. "Subscription Based Solution",
  1111. ["Access all premium features in app", "X", "6 months", "6 months", "∞", "∞"],
  1112. ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
  1113. ["Ad-free", "X", "✓", "✓", "✓", "✓"]
  1114. ]
  1115. }
  1116. }
  1117. /**
  1118. 是否黑五活动期
  1119. */
  1120. var isBlackFive: Bool {
  1121. if let loginContent = KMAdvertisementManager.manager.info.topRightInfoContent {
  1122. if loginContent.content?.isEmpty == false {
  1123. return true
  1124. }
  1125. }
  1126. return false
  1127. }
  1128. }