|
@@ -238,6 +238,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
private var license1 = ""
|
|
private var license1 = ""
|
|
private var licenseAI1 = ""
|
|
private var licenseAI1 = ""
|
|
private var isApplyCoupon: Bool = false
|
|
private var isApplyCoupon: Bool = false
|
|
|
|
+
|
|
|
|
+ private var isWindowDidLoad: Bool = false
|
|
|
|
|
|
@objc static func currentWC(_ productInfo: KMListingProductsModel) -> KMPurchaseEmbeddedWindowController {
|
|
@objc static func currentWC(_ productInfo: KMListingProductsModel) -> KMPurchaseEmbeddedWindowController {
|
|
if currentWindowController != nil {
|
|
if currentWindowController != nil {
|
|
@@ -280,8 +282,59 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
confirmPayment(isConfirm: false)
|
|
confirmPayment(isConfirm: false)
|
|
self.window?.delegate = self;
|
|
self.window?.delegate = self;
|
|
|
|
|
|
|
|
+ isWindowDidLoad = true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override func close() {
|
|
|
|
+ super.close()
|
|
|
|
+
|
|
|
|
+ self.clearEventData()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // MARK: DMG Action
|
|
|
|
+ func isMoreCountViewShouldHidden(_ productinfo: KMListingProductsModel) -> Bool {
|
|
|
|
+ //买断版本才能一次购买多个,并且购买多个时,不会自动绑定,需要在后台给自己绑定才能有会员权益
|
|
|
|
+ if productinfo.paymentModel == 2 {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func updateKMDMGProductType(_ productinfo: KMListingProductsModel) -> Void {
|
|
|
|
+ switch productinfo.code {
|
|
|
|
+ case "advanced-annual-subscription-trail":
|
|
|
|
+ _dmgProductType = .advanced_annual_subscription_trail
|
|
|
|
+ break
|
|
|
|
+ case "standard-annual-subscription":
|
|
|
|
+ _dmgProductType = .standard_annual_subscription
|
|
|
|
+ break
|
|
|
|
+ case "advanced-annual-subscription":
|
|
|
|
+ _dmgProductType = .advanced_annual_subscription
|
|
|
|
+ break
|
|
|
|
+ case "advanced-permanent":
|
|
|
|
+ _dmgProductType = .advanced_permanent
|
|
|
|
+ break
|
|
|
|
+ case "ai-subscription-month":
|
|
|
|
+ _dmgProductType = .ai_subscription_month
|
|
|
|
+ break
|
|
|
|
+ case "ai-subscription-year-trail":
|
|
|
|
+ _dmgProductType = .ai_subscription_year_trail
|
|
|
|
+ break
|
|
|
|
+ case "advanced-permanent-blackFive":
|
|
|
|
+ _dmgProductType = .advanced_permanent_blackFive
|
|
|
|
+ break
|
|
|
|
+ case "advanced-annual-subscription-blackFive":
|
|
|
|
+ _dmgProductType = .advanced_annual_subscription_blackFive
|
|
|
|
+ break
|
|
|
|
+ default:
|
|
|
|
+ _dmgProductType = .advanced_annual_subscription_trail
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func updateProduct_Info() -> Void {
|
|
if KMMemberInfo.shared.isLogin {
|
|
if KMMemberInfo.shared.isLogin {
|
|
- let model = KMProductModel()
|
|
|
|
|
|
+ let model = KMProductModel.shared
|
|
model.getDMGProductPriceInfosForMember(productId: product_Info.id, isEducation: 0) { [weak self] success, result in
|
|
model.getDMGProductPriceInfosForMember(productId: product_Info.id, isEducation: 0) { [weak self] success, result in
|
|
if success {
|
|
if success {
|
|
guard let productResults : KMMemberProductResult = result else {
|
|
guard let productResults : KMMemberProductResult = result else {
|
|
@@ -304,21 +357,6 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- override func close() {
|
|
|
|
- super.close()
|
|
|
|
-
|
|
|
|
- self.clearEventData()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // MARK: DMG Action
|
|
|
|
- func isMoreCountViewShouldHidden(_ productinfo: KMListingProductsModel) -> Bool {
|
|
|
|
- //买断版本才能一次购买多个,并且购买多个时,不会自动绑定,需要在后台给自己绑定才能有会员权益
|
|
|
|
- if productinfo.paymentModel == 2 {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// MARK: UI
|
|
// MARK: UI
|
|
|
|
|
|
private func xibInitialization() -> Void {
|
|
private func xibInitialization() -> Void {
|
|
@@ -365,6 +403,55 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
let productName = product_Info.productName
|
|
let productName = product_Info.productName
|
|
pdfReaderProLabel.stringValue = productName
|
|
pdfReaderProLabel.stringValue = productName
|
|
}
|
|
}
|
|
|
|
+ if _dmgProductType == .standard_annual_subscription {
|
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
|
+ extendedView.isHidden = true
|
|
|
|
+
|
|
|
|
+ let productName = product_Info.productName
|
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
|
+ }
|
|
|
|
+ if _dmgProductType == .advanced_annual_subscription {
|
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
|
+ extendedView.isHidden = true
|
|
|
|
+
|
|
|
|
+ let productName = product_Info.productName
|
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
|
+ }
|
|
|
|
+ if _dmgProductType == .advanced_permanent {
|
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
|
+ extendedView.isHidden = true
|
|
|
|
+
|
|
|
|
+ let productName = product_Info.productName
|
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
|
+ }
|
|
|
|
+ if _dmgProductType == .ai_subscription_month {
|
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
|
+ extendedView.isHidden = true
|
|
|
|
+
|
|
|
|
+ let productName = product_Info.productName
|
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
|
+ }
|
|
|
|
+ if _dmgProductType == .ai_subscription_year_trail {
|
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
|
+ extendedView.isHidden = true
|
|
|
|
+
|
|
|
|
+ let productName = product_Info.productName
|
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
|
+ }
|
|
|
|
+ if _dmgProductType == .advanced_permanent_blackFive {
|
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
|
+ extendedView.isHidden = true
|
|
|
|
+
|
|
|
|
+ let productName = product_Info.productName
|
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
|
+ }
|
|
|
|
+ if _dmgProductType == .advanced_annual_subscription_blackFive {
|
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
|
+ extendedView.isHidden = true
|
|
|
|
+
|
|
|
|
+ let productName = product_Info.productName
|
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
// if productType == .ipaConvert || productType == .ipaAI {
|
|
// if productType == .ipaConvert || productType == .ipaAI {
|
|
@@ -610,47 +697,150 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
}
|
|
}
|
|
|
|
|
|
private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
|
|
private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
|
|
- if _dmgProductType == .advanced_annual_subscription_trail {
|
|
|
|
|
|
+ var listPrice: Float = 0.0
|
|
|
|
+ var discount: Float = 0.0
|
|
|
|
+ var paySum: Float = 0.0
|
|
|
|
+ var discount1: Float = 0.0
|
|
|
|
+ var original1: Float = 0.0
|
|
|
|
+ var abbreviation = "USD"
|
|
|
|
+ if NSLocalizedString("USD", comment: "") == "CNY" {
|
|
|
|
+ abbreviation = "CNY"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if _dmgProductType == .advanced_annual_subscription_trail ||
|
|
|
|
+ _dmgProductType == .advanced_annual_subscription_blackFive ||
|
|
|
|
+ _dmgProductType == .advanced_permanent_blackFive ||
|
|
|
|
+ _dmgProductType == .ai_subscription_year_trail {
|
|
|
|
+ // 全平台高级版年订阅 99.9 美金,带免费试用
|
|
|
|
+ // 全平台高级版年订阅 99.9 美金,黑五订单
|
|
|
|
+ // Mac & Win 双平台高级永久 119.99 美金,黑五订单
|
|
|
|
+ // AI 年订阅 125.99 美金,带免费试用
|
|
aiAddOnView.isHidden = true
|
|
aiAddOnView.isHidden = true
|
|
extendedView.isHidden = true
|
|
extendedView.isHidden = true
|
|
|
|
|
|
- let tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
|
|
|
+ var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
|
+ if product_Info.cycle == 4 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
|
+ }
|
|
|
|
+ if product_Info.cycle == 3 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
|
|
|
|
+ }
|
|
|
|
+ if product_Info.cycle == 2 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
|
|
|
|
+ }
|
|
|
|
+ if product_Info.cycle == 1 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
|
|
|
|
+ }
|
|
|
|
+ if product_Info.cycle == 0 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
|
|
|
|
+ }
|
|
var fullString = String(format: tipsString, product_Info.price)
|
|
var fullString = String(format: tipsString, product_Info.price)
|
|
let preferredLanguage = Locale.preferredLanguages.first ?? "en"
|
|
let preferredLanguage = Locale.preferredLanguages.first ?? "en"
|
|
if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
fullString = String(format: tipsString, product_Info.cnyPrice)
|
|
fullString = String(format: tipsString, product_Info.cnyPrice)
|
|
}
|
|
}
|
|
- var abbreviation = "USD"
|
|
|
|
- if NSLocalizedString("USD", comment: "") == "CNY" {
|
|
|
|
- abbreviation = "CNY"
|
|
|
|
- }
|
|
|
|
|
|
|
|
prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
|
|
prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
|
|
|
|
|
|
- var listPrice: Float = 0.0
|
|
|
|
- var discount: Float = 0.0
|
|
|
|
- var paySum: Float = 0.0
|
|
|
|
- var discount1: Float = product_Info.displayPrice.floatValue
|
|
|
|
- var original1: Float = product_Info.price.floatValue
|
|
|
|
|
|
+ discount1 = product_Info.displayPrice.floatValue
|
|
|
|
+ original1 = product_Info.price.floatValue
|
|
if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
discount1 = product_Info.displayCnyPrice.floatValue
|
|
discount1 = product_Info.displayCnyPrice.floatValue
|
|
original1 = product_Info.cnyPrice.floatValue
|
|
original1 = product_Info.cnyPrice.floatValue
|
|
}
|
|
}
|
|
|
|
+
|
|
listPrice = original1 * Float(amountTextField1.stringValue)!
|
|
listPrice = original1 * Float(amountTextField1.stringValue)!
|
|
paySum = discount1 * Float(amountTextField1.stringValue)!
|
|
paySum = discount1 * Float(amountTextField1.stringValue)!
|
|
discount = listPrice - paySum
|
|
discount = listPrice - paySum
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if _dmgProductType == .advanced_annual_subscription ||
|
|
|
|
+ _dmgProductType == .standard_annual_subscription ||
|
|
|
|
+ _dmgProductType == .advanced_permanent ||
|
|
|
|
+ _dmgProductType == .ai_subscription_month {
|
|
|
|
+ // 全平台高级版年订阅 99.9 美金,无试用
|
|
|
|
+ // 全平台标准版年订阅 79.9 美金
|
|
|
|
+ // Mac & Win 双平台高级永久 119.99 美金
|
|
|
|
+ // AI 月订阅 14.99 美金
|
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
|
+ extendedView.isHidden = true
|
|
|
|
|
|
- originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
|
|
|
|
- if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
|
|
|
|
- discountPriceLabel1.isHidden = true
|
|
|
|
|
|
+ var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
|
+ if product_Info.cycle == 4 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
|
+ }
|
|
|
|
+ if product_Info.cycle == 3 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
|
|
|
|
+ }
|
|
|
|
+ if product_Info.cycle == 2 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
|
|
|
|
+ }
|
|
|
|
+ if product_Info.cycle == 1 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
|
|
|
|
+ }
|
|
|
|
+ if product_Info.cycle == 0 {
|
|
|
|
+ tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
|
|
|
|
+ }
|
|
|
|
+ var fullString = String(format: tipsString, product_Info.price)
|
|
|
|
+ let preferredLanguage = Locale.preferredLanguages.first ?? "en"
|
|
|
|
+ if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
|
|
+ fullString = String(format: tipsString, product_Info.cnyPrice)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
|
|
|
|
+
|
|
|
|
+ discount1 = product_Info.price.floatValue //优惠价格拿原价
|
|
|
|
+ original1 = product_Info.price.floatValue
|
|
|
|
+ if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
|
|
+ discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
|
|
|
|
+ original1 = product_Info.cnyPrice.floatValue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ listPrice = original1 * Float(amountTextField1.stringValue)!
|
|
|
|
+ paySum = discount1 * Float(amountTextField1.stringValue)!
|
|
|
|
+ discount = listPrice - paySum
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
|
|
|
|
+ if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
|
|
|
|
+ discountPriceLabel1.isHidden = true
|
|
|
|
+ } else {
|
|
|
|
+ discountPriceLabel1.isHidden = false
|
|
|
|
+ let attributedString = NSMutableAttributedString(string: String(format: "%@ %@", abbreviation, String(format: "%.2f", original1)))
|
|
|
|
+ attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
|
|
|
|
+ attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
|
|
|
|
+ discountPriceLabel1.attributedStringValue = attributedString
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if self.discountScale != "" || self.discountAmount != "" {
|
|
|
|
+ if self.discountScale != "" {
|
|
|
|
+ paySum = paySum * Float(self.discountScale)!
|
|
|
|
+ discount = listPrice - paySum
|
|
} else {
|
|
} else {
|
|
- discountPriceLabel1.isHidden = false
|
|
|
|
- let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
|
|
|
|
- attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
|
|
|
|
- attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
|
|
|
|
- discountPriceLabel1.attributedStringValue = attributedString
|
|
|
|
|
|
+ var discountAmountF = Float(self.discountAmount)
|
|
|
|
+ if NSLocalizedString("USD", comment: "") == "CNY" {
|
|
|
|
+ discountAmountF = discountAmountF! * 6.5
|
|
|
|
+ }
|
|
|
|
+ paySum = paySum - discountAmountF!
|
|
|
|
+ discount = listPrice - paySum
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
|
|
|
|
+ discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
|
|
|
|
+ paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
|
|
|
|
+
|
|
|
|
+ if discount == 0 {
|
|
|
|
+ discountView.isHidden = true
|
|
|
|
+ couponView.isHidden = false
|
|
|
|
+ } else {
|
|
|
|
+ discountView.isHidden = false
|
|
|
|
+ if self.discountScale == "" && self.discountAmount == "" {
|
|
|
|
+ couponView.isHidden = true
|
|
|
|
+ } else {
|
|
|
|
+ couponView.isHidden = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
|
|
}
|
|
}
|
|
|
|
|
|
private func priceRefresh() -> Void {
|
|
private func priceRefresh() -> Void {
|
|
@@ -1311,10 +1501,14 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
}
|
|
}
|
|
set {
|
|
set {
|
|
_product_Info = newValue
|
|
_product_Info = newValue
|
|
- xibInitialization()
|
|
|
|
- priceRefresh(productsModel: _product_Info)
|
|
|
|
-
|
|
|
|
- confirmPayment(isConfirm: false)
|
|
|
|
|
|
+ updateKMDMGProductType(_product_Info)
|
|
|
|
+ if isWindowDidLoad {
|
|
|
|
+
|
|
|
|
+ xibInitialization()
|
|
|
|
+ priceRefresh(productsModel: _product_Info)
|
|
|
|
+
|
|
|
|
+ confirmPayment(isConfirm: false)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1324,10 +1518,13 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
}
|
|
}
|
|
set {
|
|
set {
|
|
_dmgProductType = newValue
|
|
_dmgProductType = newValue
|
|
- xibInitialization()
|
|
|
|
- priceRefresh()
|
|
|
|
-
|
|
|
|
- confirmPayment(isConfirm: false)
|
|
|
|
|
|
+ if isWindowDidLoad {
|
|
|
|
+
|
|
|
|
+ xibInitialization()
|
|
|
|
+ priceRefresh(productsModel: _product_Info)
|
|
|
|
+
|
|
|
|
+ confirmPayment(isConfirm: false)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|