KMMemberInfo.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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. return true
  387. }
  388. return false
  389. }
  390. } else {
  391. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  392. return true
  393. }
  394. return false
  395. }
  396. #endif
  397. #else
  398. // AppStore 付费版
  399. if KMMemberInfo.shared.isLogin {
  400. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  401. return true
  402. } else {
  403. let platforms = KMMemberInfo.shared.vip_platforms
  404. let platformsArray = platforms
  405. .components(separatedBy: ",")
  406. .map { $0.trimmingCharacters(in: .whitespaces) }
  407. if userScenarioType == .pro_type5 {
  408. if(platformsArray.contains("mac")) { //购买了mac
  409. return true
  410. }
  411. } else if userScenarioType == .pro_type1 ||
  412. userScenarioType == .pro_type2 ||
  413. userScenarioType == .pro_type4 {
  414. return true
  415. }
  416. return false
  417. }
  418. } else {
  419. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  420. return true
  421. }
  422. return false
  423. }
  424. #endif
  425. }
  426. }
  427. // 是否允许使用AI
  428. var isPermitAI: Bool {
  429. if KMMemberInfo.shared.isLogin {
  430. if KMMemberInfo.shared.aiPoint > 0 {
  431. return true
  432. }
  433. if AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes > 0 {
  434. return true
  435. }
  436. return false
  437. } else {
  438. if AIInfoManager.default().aiInfoValid {
  439. return true
  440. }
  441. return false
  442. }
  443. }
  444. //允许继续购买AI
  445. var allowPurchaseAI: Bool {
  446. if KMMemberInfo.shared.isLogin {
  447. if KMMemberInfo.shared.ai_status == 1 {
  448. return false
  449. }
  450. } else {
  451. if AIInfoManager.default().aiInfoValid {
  452. return false
  453. }
  454. }
  455. return true
  456. }
  457. // MARK: Public Method
  458. func memberUserInfo(model: KMMemberUserInfo) -> Void {
  459. userID = model.id
  460. userEmail = model.email
  461. fullName = model.fullName
  462. aiPoint = model.aiPoint
  463. validFlag = model.validFlag
  464. isHaveAIDiscount = model.isHaveAIDiscount
  465. if model.canTrail == "1" {
  466. canTrail = true
  467. } else {
  468. canTrail = false
  469. }
  470. activeVips = model.activeVIP
  471. activeAis = model.activeAI
  472. }
  473. func advancedFunctionUsage() -> Void {
  474. let platforms = KMMemberInfo.shared.vip_platforms
  475. let platformsArray = platforms
  476. .components(separatedBy: ",")
  477. .map { $0.trimmingCharacters(in: .whitespaces) }
  478. if KMMemberInfo.shared.isLogin {
  479. productCompareShow()
  480. } else {
  481. KMLoginWindowsController.shared.openWindow() { [weak self] success in
  482. guard let self = self else { return }
  483. if success {
  484. self.productCompareShow()
  485. }
  486. }
  487. }
  488. }
  489. func productCompareShow() -> Void {
  490. let platforms = KMMemberInfo.shared.vip_platforms
  491. let platformsArray = platforms
  492. .components(separatedBy: ",")
  493. .map { $0.trimmingCharacters(in: .whitespaces) }
  494. #if VERSION_FREE
  495. #if VERSION_DMG
  496. // DMG
  497. #else
  498. // AppStore 免费版本
  499. KMProductCompareWC.shared.orientation = true
  500. // 无旧订阅、买断
  501. if userScenarioType == .lite_type1 {
  502. // 试用比较表
  503. KMProductCompareWC.shared.orientationType = .trial
  504. KMProductCompareWC.shared.showWindow(nil)
  505. } else if userScenarioType == .lite_type3 ||
  506. userScenarioType == .lite_type7 {
  507. // 购买比较表
  508. KMProductCompareWC.shared.orientationType = .lite_Base
  509. KMProductCompareWC.shared.showWindow(nil)
  510. } else if userScenarioType == .lite_type5 {
  511. // 升级比较表
  512. // 有账号(单、多平台)高级永久权益,升级全平台权益
  513. if platformsArray.count == 1 {
  514. // 单平台升级
  515. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  516. } else {
  517. // 多平台升级
  518. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  519. }
  520. KMProductCompareWC.shared.showWindow(nil)
  521. } else if userScenarioType == .lite_type2 ||
  522. userScenarioType == .lite_type4 ||
  523. userScenarioType == .lite_type6 ||
  524. userScenarioType == .lite_type8 {
  525. // 订阅中,Android单平台高级版月订阅,不能升级,提示联系客服
  526. if !platformsArray.contains("mac") {
  527. let alert = NSAlert()
  528. alert.alertStyle = .critical
  529. alert.informativeText = NSLocalizedString("Contact Us", comment: "")
  530. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  531. alert.runModal()
  532. }
  533. }
  534. // 有旧买断
  535. if userScenarioType == .lite_type9 ||
  536. userScenarioType == .lite_type11 {
  537. // 升级比较表
  538. if KMMemberInfo.shared.vip_paymentModel == "2" &&
  539. KMMemberInfo.shared.vip_levels != "1" {
  540. // 有账号(单、多平台)高级永久权益,升级全平台权益
  541. if (platformsArray.count == 1) {
  542. // 单平台升级
  543. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  544. } else {
  545. // 多平台升级
  546. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  547. }
  548. } else {
  549. // 有本地单平台高级永久权益,升级全平台权益
  550. KMProductCompareWC.shared.orientationType = .lite_MacWindows
  551. }
  552. KMProductCompareWC.shared.showWindow(nil)
  553. }
  554. #endif
  555. #else
  556. // AppStore 付费版
  557. KMProductCompareWC.shared.orientation = true
  558. // 无旧订阅
  559. if userScenarioType == .pro_type3 {
  560. // 升级比较表
  561. // 有本地单平台标准永久权益,升级全平台、升级单平台高级权益
  562. KMProductCompareWC.shared.orientationType = .pro_Base
  563. KMProductCompareWC.shared.showWindow(nil)
  564. } else if userScenarioType == .pro_type4 {
  565. // 升级比较表
  566. // 有账号(单、多平台)高级永久权益,升级全平台权益
  567. if (platformsArray.count == 1) {
  568. // 单平台升级
  569. KMProductCompareWC.shared.orientationType = .pro_Advanced
  570. } else {
  571. // 多平台升级
  572. KMProductCompareWC.shared.orientationType = .pro_Advanced
  573. }
  574. KMProductCompareWC.shared.showWindow(nil)
  575. } else if userScenarioType == .pro_type5 {
  576. // 订阅中,Android单平台高级版月订阅,不能升级,提示联系客服
  577. if !platformsArray.contains("mac") {
  578. let alert = NSAlert()
  579. alert.alertStyle = .critical
  580. alert.informativeText = NSLocalizedString("Contact Us", comment: "")
  581. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  582. alert.runModal()
  583. }
  584. }
  585. // 有旧订阅
  586. if userScenarioType == .pro_type1 {
  587. // 升级比较表
  588. if KMMemberInfo.shared.vip_paymentModel == "2" &&
  589. KMMemberInfo.shared.vip_levels != "1" {
  590. // 有账号(单、多平台)高级永久权益,升级全平台权益
  591. if (platformsArray.count == 1) {
  592. // 单平台升级
  593. KMProductCompareWC.shared.orientationType = .pro_Advanced
  594. } else {
  595. // 多平台升级
  596. KMProductCompareWC.shared.orientationType = .pro_Advanced
  597. }
  598. } else {
  599. // 有本地单平台高级永久权益,升级全平台权益
  600. KMProductCompareWC.shared.orientationType = .pro_Advanced
  601. }
  602. KMProductCompareWC.shared.showWindow(nil)
  603. }
  604. #endif
  605. }
  606. func aiSubscription() -> Bool {
  607. let oldAIPoints = AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes // 旧版AI点数
  608. if oldAIPoints > 0 {
  609. return true
  610. } else {
  611. if KMMemberInfo.shared.isLogin {
  612. if KMMemberInfo.shared.aiPoint > 0 {
  613. return true
  614. } else {
  615. if KMMemberInfo.shared.ai_status == 1 {
  616. if KMMemberInfo.shared.aiPoint == 0 {
  617. let alert = NSAlert()
  618. alert.alertStyle = .critical
  619. alert.informativeText = NSLocalizedString("No Value Present", comment: "")
  620. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  621. alert.runModal()
  622. return false
  623. }
  624. } else {
  625. AIPurchaseWindowController.currentWC().showWindow(nil)
  626. return false
  627. }
  628. }
  629. } else {
  630. KMLoginWindowsController.shared.openWindow() { success in
  631. if success {
  632. AIPurchaseWindowController.currentWC().showWindow(nil)
  633. }
  634. }
  635. return false
  636. }
  637. }
  638. return false
  639. }
  640. func clearMemberInfoCache() -> Void {
  641. currentLogoutStatus = .null
  642. _refresh_token = ""
  643. _access_token = ""
  644. _token_type = ""
  645. _expires_in = ""
  646. _scope = ""
  647. userID = ""
  648. userEmail = ""
  649. fullName = ""
  650. _activeVips = []
  651. _activeAis = []
  652. vip_id = ""
  653. vip_userId = ""
  654. vip_status = 0
  655. vip_endDate = ""
  656. vip_payType = 0
  657. vip_productName = ""
  658. vip_levels = "1"
  659. vip_platforms = ""
  660. vip_point = 0
  661. vip_maxDeviceNum = 0
  662. vip_paymentModel = ""
  663. vip_isAi = ""
  664. vip_cycle = 0
  665. ai_id = ""
  666. ai_userId = ""
  667. ai_status = 0
  668. ai_endDate = ""
  669. ai_payType = 0
  670. ai_productName = ""
  671. ai_levels = ""
  672. ai_platforms = ""
  673. ai_point = 0
  674. ai_maxDeviceNum = 0
  675. ai_paymentModel = ""
  676. ai_isAi = ""
  677. ai_cycle = 0
  678. aiPoint = 0
  679. validFlag = ""
  680. isHaveAIDiscount = ""
  681. canTrail = false
  682. }
  683. }