KMMemberInfo.swift 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. //
  2. // KMMemberInfo.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/10/22.
  6. //
  7. import Cocoa
  8. // 用户场景类型
  9. @objc enum KMUserScenarioType : Int {
  10. case lite_type1 = 0 // 免费版 无旧买断 免费未试用 (右上角导航栏按钮 - “登录领福利” + “试用”)
  11. case lite_type2 // 免费版 无旧买断 免费试用中 (右上角导航栏按钮 - “登录领福利”)
  12. case lite_type3 // 免费版 无旧买断 试用过期或取消 (右上角导航栏按钮 - “登录领福利” + 开通会员)
  13. case lite_type4 // 免费版 无旧买断 可升级订阅 (右上角导航栏按钮 - “登录领福利”)
  14. case lite_type5 // 免费版 无旧买断 多平台永久 (右上角导航栏按钮 - “登录领福利” + 升级全平台)
  15. case lite_type6 // 免费版 无旧买断 全平台年订阅 (右上角导航栏按钮 - “登录领福利”)
  16. case lite_type7 // 免费版 无旧买断 会员到期 (右上角导航栏按钮 - “登录领福利” + 续费)
  17. case lite_type8 // 免费版 无旧买断 订阅未过期且取消订阅 (右上角导航栏按钮 - “登录领福利” + 续费)
  18. case lite_type9 // 免费版 有旧买断 免费未试用+订阅过期+多平台永久 (右上角导航栏按钮 - “登录领福利” + “升级至Pro”)
  19. case lite_type10 // 免费版 有旧买断 免费试用中 (右上角导航栏按钮 - “登录领福利”)
  20. case lite_type11 // 免费版 有旧买断 试用过期或取消 (右上角导航栏按钮 - “登录领福利” + 开通会员)
  21. case lite_type12 // 免费版 有旧买断 订阅中 (右上角导航栏按钮 - “登录领福利”)
  22. case lite_type13 // 免费版 有旧买断 订阅未过期且取消订阅 (右上角导航栏按钮 - “登录领福利” + 续费)
  23. case pro_type1 // 付费版 有旧PDF To Office未订阅 (右上角导航栏按钮 - “登录领福利” + 升级(全平台))
  24. case pro_type2 // 付费版 有旧PDF To Office 订阅且未过期 (右上角导航栏按钮 - “登录领福利”)
  25. case pro_type3 // 付费版 无旧PDF To Office未订阅 (右上角导航栏按钮 - “登录领福利” + 升级(全平台/高级版永久))
  26. case pro_type4 // 付费版 无旧PDF To Office 高级版永久 (右上角导航栏按钮 - Info + 升级(全平台))
  27. case pro_type5 // 付费版 无旧PDF To Office 订阅且未过期 (右上角导航栏按钮 - Info)
  28. }
  29. // 当前权益类型
  30. @objc enum KMCurrentUserEquityType : Int {
  31. case lite_free = 0 // 免费版 免费
  32. case lite_old
  33. }
  34. // 当前注销状态
  35. @objc enum KMCurrentLogoutStatus : Int {
  36. case null = 0 //
  37. case prompt_unsubscribe
  38. case prompt_signout
  39. case closeAccount
  40. case closeVerification
  41. case closeApply
  42. }
  43. @objcMembers class KMMemberInfo: NSObject {
  44. static let shared = KMMemberInfo()
  45. var isLogin: Bool = false
  46. var currentLogoutStatus: KMCurrentLogoutStatus = .null
  47. /**
  48. 登录
  49. */
  50. private var _refresh_token: String = "" // 刷新Token
  51. private var _access_token: String = "" // 访问Token
  52. private var _token_type: String = "" // Token 类型
  53. private var _expires_in: String = ""
  54. private var _scope: String = ""
  55. /**
  56. 登录
  57. */
  58. var userID: String = "" // 用户ID
  59. var userEmail: String = "" // 用户邮箱
  60. var fullName: String = "" // 用户名称
  61. var _activeVips: [KMMemberUserInfoActiveVIP] = [] // 活跃的会员
  62. var _activeAis: [KMMemberUserInfoActiveVIP] = [] // 活跃的AI
  63. var vip_id: String = "" // id
  64. var vip_userId: String = "" // 用户id
  65. var vip_status: Int = 0 // 状态 0注册1订阅中2订阅过期3试用中4试用过期
  66. var vip_endDate: String = "" // 到期时间
  67. var vip_payType: Int = 0 // 0未开启自动续订 1自动续订
  68. var vip_productName: String = "" // 产品名字
  69. var vip_levels: String = "1" // 会员等级 1是免费 2是标准 3是高级
  70. var vip_platforms: String = "" // 支持的平台
  71. var vip_point: Int = 0 // 剩余ai点数(svip才有)
  72. var vip_maxDeviceNum: Int = 0 // 最大登录设备限制数
  73. var vip_paymentModel: String = "" // 支付方式 付费模式(1自动续订(vip svip) 2单次付费(永久会员))
  74. var vip_isAi: String = "" // 是否是ai产品(0否1是)
  75. var vip_cycle: Int = 0 // 订阅周期:1、月(30天);2、季(90天);3、半年(183天);4、年(365天)
  76. var ai_id: String = "" // id
  77. var ai_userId: String = "" // 用户id
  78. var ai_status: Int = 0 // 状态 0注册1订阅中2订阅过期3试用中4试用过期
  79. var ai_endDate: String = "" // 到期时间
  80. var ai_payType: Int = 0 // 0未开启自动续订 1自动续订
  81. var ai_productName: String = "" // 产品名字
  82. var ai_levels: String = "" // 会员等级 1是免费 2是标准 3是高级
  83. var ai_platforms: String = "" // 支持的平台
  84. var ai_point: Int = 0 // 剩余ai点数(svip才有)
  85. var ai_maxDeviceNum: Int = 0 // 最大登录设备限制数
  86. var ai_paymentModel: String = "" // 支付方式 付费模式(1自动续订(vip svip) 2单次付费(永久会员))
  87. var ai_isAi: String = "" // 是否是ai产品(0否1是)
  88. var ai_cycle: Int = 0 // 订阅周期:1、月(30天);2、季(90天);3、半年(183天);4、年(365天)
  89. var aiPoint: Int = 0 // AI 点数
  90. var validFlag: String = "" // 注销(0), * 正常(1), * 停用(2), * 注销中(5);
  91. var isHaveAIDiscount: String = "" // 是否有ai折扣
  92. var canTrail: Bool = false // 是否能试用
  93. // var currentTime: String = "" // 当前注销时间
  94. // var logOffTime: String = "" // 注销时间
  95. // MARK: Get & Set
  96. var refresh_token: String {
  97. get {
  98. let token = UserDefaults.standard.value(forKey: "MemberRefreshToken")
  99. if token is String {
  100. return token as! String
  101. }
  102. return _refresh_token
  103. }
  104. set {
  105. _refresh_token = newValue
  106. UserDefaults.standard.setValue(newValue, forKey: "MemberRefreshToken")
  107. UserDefaults.standard.synchronize()
  108. }
  109. }
  110. var access_token: String {
  111. get {
  112. let token = UserDefaults.standard.value(forKey: "MemberAccessToken")
  113. if token is String {
  114. return token as! String
  115. }
  116. return _access_token
  117. }
  118. set {
  119. _access_token = newValue
  120. UserDefaults.standard.setValue(newValue, forKey: "MemberAccessToken")
  121. UserDefaults.standard.synchronize()
  122. }
  123. }
  124. var token_type: String {
  125. get {
  126. return _token_type
  127. }
  128. set {
  129. _token_type = newValue
  130. }
  131. }
  132. var activeVips: [KMMemberUserInfoActiveVIP] {
  133. get {
  134. return _activeVips
  135. }
  136. set {
  137. _activeVips = newValue
  138. for index in 0..<_activeVips.count {
  139. let vip = _activeVips[index]
  140. if index == 0 {
  141. vip_id = vip.id
  142. vip_userId = vip.userId
  143. vip_status = vip.status
  144. vip_endDate = vip.endDate
  145. vip_payType = vip.payType
  146. vip_productName = vip.productName
  147. vip_levels = vip.levels
  148. vip_platforms = vip.platforms
  149. vip_point = vip.point
  150. vip_maxDeviceNum = vip.maxDeviceNum
  151. vip_paymentModel = vip.paymentModel
  152. vip_isAi = vip.isAi
  153. vip_cycle = vip.cycle
  154. } else {
  155. if let vipLevelsInt = Int(vip_levels), let vipOtherLevelsInt = Int(vip.levels), vipLevelsInt < vipOtherLevelsInt {
  156. vip_id = vip.id
  157. vip_userId = vip.userId
  158. vip_status = vip.status
  159. vip_endDate = vip.endDate
  160. vip_payType = vip.payType
  161. vip_productName = vip.productName
  162. vip_levels = vip.levels
  163. vip_platforms = vip.platforms
  164. vip_point = vip.point
  165. vip_maxDeviceNum = vip.maxDeviceNum
  166. vip_paymentModel = vip.paymentModel
  167. vip_isAi = vip.isAi
  168. vip_cycle = vip.cycle
  169. }
  170. }
  171. }
  172. }
  173. }
  174. var activeAis: [KMMemberUserInfoActiveVIP] {
  175. get {
  176. return _activeAis
  177. }
  178. set {
  179. _activeAis = newValue
  180. for index in 0..<_activeAis.count {
  181. let vip = _activeAis[index]
  182. if index == 0 {
  183. ai_id = vip.id
  184. ai_userId = vip.userId
  185. ai_status = vip.status
  186. ai_endDate = vip.endDate
  187. ai_payType = vip.payType
  188. ai_productName = vip.productName
  189. ai_levels = vip.levels
  190. ai_platforms = vip.platforms
  191. ai_point = vip.point
  192. ai_maxDeviceNum = vip.maxDeviceNum
  193. ai_paymentModel = vip.paymentModel
  194. ai_isAi = vip.isAi
  195. ai_cycle = vip.cycle
  196. } else {
  197. if let vipLevelsInt = Int(ai_levels), let vipOtherLevelsInt = Int(vip.levels), vipLevelsInt < vipOtherLevelsInt {
  198. ai_id = vip.id
  199. ai_userId = vip.userId
  200. ai_status = vip.status
  201. ai_endDate = vip.endDate
  202. ai_payType = vip.payType
  203. ai_productName = vip.productName
  204. ai_levels = vip.levels
  205. ai_platforms = vip.platforms
  206. ai_point = vip.point
  207. ai_maxDeviceNum = vip.maxDeviceNum
  208. ai_paymentModel = vip.paymentModel
  209. ai_isAi = vip.isAi
  210. ai_cycle = vip.cycle
  211. }
  212. }
  213. }
  214. }
  215. }
  216. // 用户当前的状态
  217. var userScenarioType: KMUserScenarioType {
  218. get {
  219. let oldAIPoints = AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes // 旧版AI点数
  220. let dateFormatter = DateFormatter()
  221. dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
  222. var startTime = Date()
  223. if KMMemberInfo.shared.vip_endDate.count > 0 {
  224. if let data = dateFormatter.date(from: KMMemberInfo.shared.vip_endDate) {
  225. startTime = data
  226. }
  227. }
  228. let currentTime = Date()
  229. let platforms = KMMemberInfo.shared.vip_platforms
  230. let platformsArray = platforms
  231. .components(separatedBy: ",")
  232. .map { $0.trimmingCharacters(in: .whitespaces) }
  233. #if VERSION_FREE
  234. #if VERSION_DMG
  235. // DMG
  236. if KMMemberInfo.shared.isLogin {
  237. } else {
  238. }
  239. #else
  240. // AppStore 免费版本
  241. if IAPProductsManager.default().allAccessPack6months_lite.isSubscribed == true ||
  242. IAPProductsManager.default().allAccessPackNew6months_lite.isSubscribed == true ||
  243. IAPProductsManager.default().allAccessPack12months_lite.isSubscribed == true {
  244. // 有旧订阅
  245. return .lite_type12
  246. } else if (IAPProductsManager.default().allAccessProduct.isSubscribed == true) {
  247. // 有旧买断
  248. if KMMemberInfo.shared.canTrail && KMMemberInfo.shared.vip_levels == "1" {
  249. return .lite_type9
  250. }
  251. if KMMemberInfo.shared.vip_status == 3 {
  252. return .lite_type10
  253. } else if KMMemberInfo.shared.vip_status == 4 {
  254. return .lite_type11
  255. } else if(KMMemberInfo.shared.vip_status == 1 && KMMemberInfo.shared.vip_paymentModel == "1") {
  256. // 订阅中
  257. return .lite_type12
  258. }
  259. if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_payType == 0 && KMMemberInfo.shared.vip_status == 1 {
  260. return .lite_type13
  261. }
  262. return .lite_type9
  263. } else {
  264. if !KMMemberInfo.shared.isLogin {
  265. return .lite_type1
  266. }
  267. // 无旧订阅、买断
  268. if KMMemberInfo.shared.canTrail && KMMemberInfo.shared.vip_levels == "1" {
  269. return .lite_type1
  270. }
  271. if KMMemberInfo.shared.vip_status == 3 {
  272. return .lite_type2
  273. } else if KMMemberInfo.shared.vip_status == 4 {
  274. return .lite_type3
  275. } else if KMMemberInfo.shared.vip_status == 2 {
  276. return .lite_type7
  277. } else if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_payType == 0 && KMMemberInfo.shared.vip_status == 1 {
  278. return .lite_type8
  279. }
  280. if KMMemberInfo.shared.vip_paymentModel == "2" {
  281. return .lite_type5
  282. } else {
  283. if KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 {
  284. return .lite_type6
  285. } else {
  286. return .lite_type4
  287. }
  288. }
  289. }
  290. #endif
  291. #else
  292. // AppStore 付费版
  293. if IAPProductsManager.default().pdfToOfficeProduct.isSubscribed == true {
  294. if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_status == 1 { //订阅中
  295. return .pro_type2
  296. } else {
  297. return .pro_type1
  298. }
  299. } else {
  300. if KMMemberInfo.shared.vip_paymentModel == "2" && KMMemberInfo.shared.vip_status == 1 { //买断
  301. return .pro_type4
  302. } else {
  303. if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_status == 1 {//订阅中
  304. return .pro_type5
  305. } else {
  306. return .pro_type3
  307. }
  308. }
  309. }
  310. #endif
  311. return .lite_type1
  312. }
  313. }
  314. // 是否允许全部功能
  315. var isMemberAllFunction: Bool {
  316. get {
  317. #if VERSION_FREE
  318. #if VERSION_DMG
  319. // DMG
  320. if KMMemberInfo.shared.isLogin {
  321. }
  322. #else
  323. // AppStore 免费版本
  324. if KMMemberInfo.shared.isLogin {
  325. if IAPProductsManager.default().isAvailableAllFunction() == true {
  326. return true
  327. } else {
  328. let platforms = KMMemberInfo.shared.vip_platforms
  329. let platformsArray = platforms
  330. .components(separatedBy: ",")
  331. .map { $0.trimmingCharacters(in: .whitespaces) }
  332. if userScenarioType == .lite_type5 ||
  333. userScenarioType == .lite_type4 ||
  334. userScenarioType == .lite_type8 {
  335. if(platformsArray.contains("mac")) {
  336. return true
  337. }
  338. } else if userScenarioType == .lite_type2 ||
  339. userScenarioType == .lite_type6 {
  340. return true
  341. }
  342. return false
  343. }
  344. } else {
  345. if IAPProductsManager.default().allAccessPackPermanent_lite.isSubscribed == true || IAPProductsManager.default().isAvailableAllFunction() == true {
  346. return true
  347. }
  348. return false
  349. }
  350. #endif
  351. #else
  352. // AppStore 付费版
  353. return true
  354. #endif
  355. return false
  356. }
  357. }
  358. // 是否允许使用转档
  359. var isPermitConvert: Bool {
  360. get {
  361. #if VERSION_FREE
  362. #if VERSION_DMG
  363. // DMG
  364. if KMMemberInfo.shared.isLogin {
  365. }
  366. return false
  367. #else
  368. // AppStore 免费版本
  369. if KMMemberInfo.shared.isLogin {
  370. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  371. return true
  372. } else {
  373. let platforms = KMMemberInfo.shared.vip_platforms
  374. let platformsArray = platforms
  375. .components(separatedBy: ",")
  376. .map { $0.trimmingCharacters(in: .whitespaces) }
  377. if(userScenarioType == .lite_type2) {
  378. return true
  379. } else if userScenarioType == .lite_type5 ||
  380. userScenarioType == .lite_type4 ||
  381. userScenarioType == .lite_type8 {
  382. if(platformsArray.contains("mac")) { //购买了
  383. return true
  384. }
  385. } else if userScenarioType == .lite_type6 || userScenarioType == .lite_type12 {
  386. if KMMemberInfo.shared.vip_levels == "3" { //高级版本支持转档功能,但不支持升级
  387. return true
  388. }
  389. }
  390. return false
  391. }
  392. } else {
  393. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  394. return true
  395. }
  396. return false
  397. }
  398. #endif
  399. #else
  400. // AppStore 付费版
  401. if KMMemberInfo.shared.isLogin {
  402. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  403. return true
  404. } else {
  405. let platforms = KMMemberInfo.shared.vip_platforms
  406. let platformsArray = platforms
  407. .components(separatedBy: ",")
  408. .map { $0.trimmingCharacters(in: .whitespaces) }
  409. if userScenarioType == .pro_type5 {
  410. if(platformsArray.contains("mac")) { //购买了mac
  411. return true
  412. }
  413. } else if userScenarioType == .pro_type1 ||
  414. userScenarioType == .pro_type2 ||
  415. userScenarioType == .pro_type4 {
  416. return true
  417. }
  418. return false
  419. }
  420. } else {
  421. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  422. return true
  423. }
  424. return false
  425. }
  426. #endif
  427. }
  428. }
  429. // 是否允许使用AI
  430. var isPermitAI: Bool {
  431. if KMMemberInfo.shared.isLogin {
  432. if KMMemberInfo.shared.aiPoint > 0 {
  433. return true
  434. }
  435. if AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes > 0 {
  436. return true
  437. }
  438. return false
  439. } else {
  440. if AIInfoManager.default().aiInfoValid {
  441. return true
  442. }
  443. return false
  444. }
  445. }
  446. //允许继续购买AI
  447. var allowPurchaseAI: Bool {
  448. if KMMemberInfo.shared.isLogin {
  449. if KMMemberInfo.shared.ai_status == 1 {
  450. return false
  451. }
  452. } else {
  453. if AIInfoManager.default().aiInfoValid {
  454. return false
  455. }
  456. }
  457. return true
  458. }
  459. // MARK: Public Method
  460. func memberUserInfo(model: KMMemberUserInfo) -> Void {
  461. userID = model.id
  462. userEmail = model.email
  463. fullName = model.fullName
  464. aiPoint = model.aiPoint
  465. validFlag = model.validFlag
  466. isHaveAIDiscount = model.isHaveAIDiscount
  467. if model.canTrail == "1" {
  468. canTrail = true
  469. } else {
  470. canTrail = false
  471. }
  472. activeVips = model.activeVIP
  473. activeAis = model.activeAI
  474. }
  475. func advancedFunctionUsage() -> Void {
  476. let platforms = KMMemberInfo.shared.vip_platforms
  477. let platformsArray = platforms
  478. .components(separatedBy: ",")
  479. .map { $0.trimmingCharacters(in: .whitespaces) }
  480. if KMMemberInfo.shared.isLogin {
  481. productCompareShow()
  482. } else {
  483. KMLoginWindowsController.shared.openWindow() { [weak self] success in
  484. guard let self = self else { return }
  485. if success {
  486. self.productCompareShow()
  487. }
  488. }
  489. }
  490. }
  491. func productCompareShow() -> Void {
  492. let platforms = KMMemberInfo.shared.vip_platforms
  493. let platformsArray = platforms
  494. .components(separatedBy: ",")
  495. .map { $0.trimmingCharacters(in: .whitespaces) }
  496. #if VERSION_FREE
  497. #if VERSION_DMG
  498. // DMG
  499. #else
  500. // AppStore 免费版本
  501. KMProductCompareWC.shared.orientation = true
  502. // 无旧订阅、买断
  503. if userScenarioType == .lite_type1 {
  504. // 试用比较表
  505. KMProductCompareWC.shared.orientationType = .trial
  506. KMProductCompareWC.shared.showWindow(nil)
  507. } else if userScenarioType == .lite_type3 ||
  508. userScenarioType == .lite_type7 {
  509. // 购买比较表
  510. KMProductCompareWC.shared.orientationType = .lite_Base
  511. KMProductCompareWC.shared.showWindow(nil)
  512. } else if userScenarioType == .lite_type5 {
  513. // 升级比较表
  514. // 有账号(单、多平台)高级永久权益,升级全平台权益
  515. if platformsArray.count == 1 {
  516. // 单平台升级
  517. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  518. } else {
  519. // 多平台升级
  520. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  521. }
  522. KMProductCompareWC.shared.showWindow(nil)
  523. } else if userScenarioType == .lite_type2 ||
  524. userScenarioType == .lite_type4 ||
  525. userScenarioType == .lite_type6 ||
  526. userScenarioType == .lite_type8 {
  527. // 订阅中,Android单平台高级版月订阅或者全平台标准版年订阅,不能升级,提示联系客服
  528. if !platformsArray.contains("mac") ||
  529. KMMemberInfo.shared.vip_levels != "3" {
  530. let alert = NSAlert()
  531. alert.alertStyle = .critical
  532. alert.informativeText = NSLocalizedString("Contact Us", comment: "")
  533. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  534. alert.runModal()
  535. }
  536. }
  537. // 有旧买断
  538. if userScenarioType == .lite_type9 ||
  539. userScenarioType == .lite_type11 {
  540. // 升级比较表
  541. if KMMemberInfo.shared.vip_paymentModel == "2" &&
  542. KMMemberInfo.shared.vip_levels != "1" {
  543. // 有账号(单、多平台)高级永久权益,升级全平台权益
  544. if (platformsArray.count == 1) {
  545. // 单平台升级
  546. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  547. } else {
  548. // 多平台升级
  549. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  550. }
  551. } else {
  552. // 有本地单平台高级永久权益,升级全平台权益
  553. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  554. }
  555. KMProductCompareWC.shared.showWindow(nil)
  556. }
  557. #endif
  558. #else
  559. // AppStore 付费版
  560. KMProductCompareWC.shared.orientation = true
  561. // 无旧订阅
  562. if userScenarioType == .pro_type3 {
  563. // 升级比较表
  564. // 有本地单平台标准永久权益,升级全平台、升级单平台高级权益
  565. KMProductCompareWC.shared.orientationType = .pro_Base
  566. KMProductCompareWC.shared.showWindow(nil)
  567. } else if userScenarioType == .pro_type4 {
  568. // 升级比较表
  569. // 有账号(单、多平台)高级永久权益,升级全平台权益
  570. if (platformsArray.count == 1) {
  571. // 单平台升级
  572. KMProductCompareWC.shared.orientationType = .pro_Advanced
  573. } else {
  574. // 多平台升级
  575. KMProductCompareWC.shared.orientationType = .pro_Advanced
  576. }
  577. KMProductCompareWC.shared.showWindow(nil)
  578. } else if userScenarioType == .pro_type5 {
  579. // 订阅中,Android单平台高级版月订阅或者全平台标准版年订阅,不能升级,提示联系客服
  580. if !platformsArray.contains("mac") ||
  581. KMMemberInfo.shared.vip_levels != "3" {
  582. let alert = NSAlert()
  583. alert.alertStyle = .critical
  584. alert.informativeText = NSLocalizedString("Contact Us", comment: "")
  585. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  586. alert.runModal()
  587. }
  588. }
  589. // 有旧订阅
  590. if userScenarioType == .pro_type1 {
  591. // 升级比较表
  592. if KMMemberInfo.shared.vip_paymentModel == "2" &&
  593. KMMemberInfo.shared.vip_levels != "1" {
  594. // 有账号(单、多平台)高级永久权益,升级全平台权益
  595. if (platformsArray.count == 1) {
  596. // 单平台升级
  597. KMProductCompareWC.shared.orientationType = .pro_Advanced
  598. } else {
  599. // 多平台升级
  600. KMProductCompareWC.shared.orientationType = .pro_Advanced
  601. }
  602. } else {
  603. // 有本地单平台高级永久权益,升级全平台权益
  604. KMProductCompareWC.shared.orientationType = .pro_Advanced
  605. }
  606. KMProductCompareWC.shared.showWindow(nil)
  607. }
  608. #endif
  609. }
  610. func aiSubscription() -> Bool {
  611. let oldAIPoints = AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes // 旧版AI点数
  612. if oldAIPoints > 0 {
  613. return true
  614. } else {
  615. if KMMemberInfo.shared.isLogin {
  616. if KMMemberInfo.shared.aiPoint > 0 {
  617. return true
  618. } else {
  619. if KMMemberInfo.shared.ai_status == 1 {
  620. if KMMemberInfo.shared.aiPoint == 0 {
  621. let alert = NSAlert()
  622. alert.alertStyle = .critical
  623. alert.informativeText = NSLocalizedString("No Value Present", comment: "")
  624. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  625. alert.runModal()
  626. return false
  627. }
  628. } else {
  629. AIPurchaseWindowController.currentWC().showWindow(nil)
  630. return false
  631. }
  632. }
  633. } else {
  634. KMLoginWindowsController.shared.openWindow() { success in
  635. if success {
  636. AIPurchaseWindowController.currentWC().showWindow(nil)
  637. }
  638. }
  639. return false
  640. }
  641. }
  642. return false
  643. }
  644. func clearMemberInfoCache() -> Void {
  645. currentLogoutStatus = .null
  646. _refresh_token = ""
  647. _access_token = ""
  648. _token_type = ""
  649. _expires_in = ""
  650. _scope = ""
  651. userID = ""
  652. userEmail = ""
  653. fullName = ""
  654. _activeVips = []
  655. _activeAis = []
  656. vip_id = ""
  657. vip_userId = ""
  658. vip_status = 0
  659. vip_endDate = ""
  660. vip_payType = 0
  661. vip_productName = ""
  662. vip_levels = "1"
  663. vip_platforms = ""
  664. vip_point = 0
  665. vip_maxDeviceNum = 0
  666. vip_paymentModel = ""
  667. vip_isAi = ""
  668. vip_cycle = 0
  669. ai_id = ""
  670. ai_userId = ""
  671. ai_status = 0
  672. ai_endDate = ""
  673. ai_payType = 0
  674. ai_productName = ""
  675. ai_levels = ""
  676. ai_platforms = ""
  677. ai_point = 0
  678. ai_maxDeviceNum = 0
  679. ai_paymentModel = ""
  680. ai_isAi = ""
  681. ai_cycle = 0
  682. aiPoint = 0
  683. validFlag = ""
  684. isHaveAIDiscount = ""
  685. canTrail = false
  686. }
  687. }