|
@@ -51,6 +51,7 @@ enum KMMemberCenterErrorCodeType: Int, CaseIterable {
|
|
}
|
|
}
|
|
|
|
|
|
typealias KMMemberCenterComplete = (_ success: Bool, _ result: KMMemberCenterResult?) -> Void
|
|
typealias KMMemberCenterComplete = (_ success: Bool, _ result: KMMemberCenterResult?) -> Void
|
|
|
|
+typealias KMMemberProductComplete = (_ success: Bool, _ result: KMMemberProductResult?) -> Void
|
|
|
|
|
|
class KMMemberCenterManager: NSObject {
|
|
class KMMemberCenterManager: NSObject {
|
|
static let manager = KMMemberCenterManager()
|
|
static let manager = KMMemberCenterManager()
|
|
@@ -715,46 +716,336 @@ class KMMemberCenterManager: NSObject {
|
|
|
|
|
|
// MARK: 商品模块
|
|
// MARK: 商品模块
|
|
|
|
|
|
-// /**
|
|
|
|
-// @abstract 获取上架中的产品
|
|
|
|
-// @param complete 回调
|
|
|
|
-// */
|
|
|
|
-// func getListingProducts(_ complete: @escaping KMMemberCenterComplete) {
|
|
|
|
-//
|
|
|
|
-// let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
|
|
|
|
-// let params: [String: Any] = ["isEducation": actionType,
|
|
|
|
-// "platformId": 0]
|
|
|
|
-// KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
|
|
|
|
-//
|
|
|
|
-// } completion: { [weak self] (task, responseObject, error) in
|
|
|
|
-// var dic: NSDictionary = [:]
|
|
|
|
-// if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
|
-// dic = responseObject
|
|
|
|
-// } else {
|
|
|
|
-// var info = responseObject
|
|
|
|
-// if let error = error {
|
|
|
|
-// if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
|
-// info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// dic = (info as? NSDictionary) ?? [:]
|
|
|
|
-// }
|
|
|
|
-// let code: Int = dic["code"] as? Int ?? 0
|
|
|
|
-// let message: String = dic["msg"] as? String ?? ""
|
|
|
|
-// let result_Bool: Bool = dic["result"] as? Bool ?? false
|
|
|
|
-//
|
|
|
|
-// let result = KMMemberCenterResult(code: code, msg: message, result: result_Bool)
|
|
|
|
-// if code == 200 {
|
|
|
|
-// complete(true, result)
|
|
|
|
-// } else {
|
|
|
|
-// complete(false, result)
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
|
|
+ /**
|
|
|
|
+ @abstract 获取上架中的产品
|
|
|
|
+ @param isEducation 是否教育优惠
|
|
|
|
+ @param complete 回调
|
|
|
|
+ */
|
|
|
|
+ func getListingProducts(isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
|
|
|
|
+
|
|
|
|
+ let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getListingProducts"
|
|
|
|
+ var platformId = "2"
|
|
|
|
+#if VERSION_FREE
|
|
|
|
+
|
|
|
|
+#if VERSION_DMG
|
|
|
|
+ // DMG
|
|
|
|
+ platformId = "2"
|
|
|
|
+#else
|
|
|
|
+ // AppStore 免费版本
|
|
|
|
+#endif
|
|
|
|
+ platformId = "3"
|
|
|
|
+#else
|
|
|
|
+ // AppStore 付费版
|
|
|
|
+ platformId = "5"
|
|
|
|
+#endif
|
|
|
|
+ let params: [String: Any] = ["isEducation": isEducation,
|
|
|
|
+ "platformId": platformId]
|
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
|
|
|
|
+
|
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
|
+ dic = responseObject
|
|
|
|
+ } else {
|
|
|
|
+ var info = responseObject
|
|
|
|
+ if let error = error {
|
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
|
+ }
|
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
|
+ let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
|
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
|
+
|
|
|
|
+ var results: [KMListingProducts] = []
|
|
|
|
+ for dict1 in result_Array {
|
|
|
|
+ var id = ""
|
|
|
|
+ var productName = ""
|
|
|
|
+ var price = ""
|
|
|
|
+ var maxDeviceNum = 0
|
|
|
|
+ var levels = ""
|
|
|
|
+ var platforms = ""
|
|
|
|
+ var productLineId = 0
|
|
|
|
+ var paymentModel = 0
|
|
|
|
+ var cycle = 0
|
|
|
|
+ var code = ""
|
|
|
|
+ var cnyPrice = ""
|
|
|
|
+ if let token = dict1["id"] { id = token as! String }
|
|
|
|
+ if let token = dict1["productName"] { productName = token as! String }
|
|
|
|
+ if let token = dict1["price"] { price = token as! String }
|
|
|
|
+ if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as! Int }
|
|
|
|
+ if let token = dict1["levels"] { levels = token as! String }
|
|
|
|
+ if let token = dict1["platforms"] { platforms = token as! String }
|
|
|
|
+ if let token = dict1["productLineId"] { productLineId = token as! Int }
|
|
|
|
+ if let token = dict1["paymentModel"] { paymentModel = token as! Int }
|
|
|
|
+ if let token = dict1["cycle"] { cycle = token as! Int }
|
|
|
|
+ if let token = dict1["code"] { code = token as! String }
|
|
|
|
+ if let token = dict1["cnyPrice"] { cnyPrice = token as! String }
|
|
|
|
+ let products = KMListingProducts(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, code: code, cnyPrice: cnyPrice)
|
|
|
|
+ results.append(products)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
|
|
|
|
+ if code == 200 {
|
|
|
|
+ complete(true, result)
|
|
|
|
+ } else {
|
|
|
|
+ complete(false, result)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ @abstract 获取已登录用户购买商品价格
|
|
|
|
+ @param productId 购买的产品id
|
|
|
|
+ @param isEducation 是否教育优惠
|
|
|
|
+ @param complete 回调
|
|
|
|
+ */
|
|
|
|
+ func getProductPriceForBuy(productId: String, isEducation: Int, userId: String, _ complete: @escaping KMMemberProductComplete) {
|
|
|
|
+
|
|
|
|
+ let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getProductPriceForBuy"
|
|
|
|
+ let params: [String: Any] = ["productId": productId,
|
|
|
|
+ "isEducation": isEducation,
|
|
|
|
+ "userId": userId]
|
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
|
|
|
|
+
|
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
|
+ dic = responseObject
|
|
|
|
+ } else {
|
|
|
|
+ var info = responseObject
|
|
|
|
+ if let error = error {
|
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
|
+ }
|
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
|
+ let result_Array: [NSDictionary] = dic["result"] as? [NSDictionary] ?? [[:]]
|
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
|
+
|
|
|
|
+ var results: [KMListingProducts] = []
|
|
|
|
+ for dict1 in result_Array {
|
|
|
|
+ var id = ""
|
|
|
|
+ var productName = ""
|
|
|
|
+ var price = ""
|
|
|
|
+ var maxDeviceNum = 0
|
|
|
|
+ var levels = ""
|
|
|
|
+ var platforms = ""
|
|
|
|
+ var productLineId = 0
|
|
|
|
+ var paymentModel = 0
|
|
|
|
+ var cycle = 0
|
|
|
|
+ var code = ""
|
|
|
|
+ var cnyPrice = ""
|
|
|
|
+ if let token = dict1["id"] { id = token as! String }
|
|
|
|
+ if let token = dict1["productName"] { productName = token as! String }
|
|
|
|
+ if let token = dict1["price"] { price = token as! String }
|
|
|
|
+ if let token = dict1["maxDeviceNum"] { maxDeviceNum = token as! Int }
|
|
|
|
+ if let token = dict1["levels"] { levels = token as! String }
|
|
|
|
+ if let token = dict1["platforms"] { platforms = token as! String }
|
|
|
|
+ if let token = dict1["productLineId"] { productLineId = token as! Int }
|
|
|
|
+ if let token = dict1["paymentModel"] { paymentModel = token as! Int }
|
|
|
|
+ if let token = dict1["cycle"] { cycle = token as! Int }
|
|
|
|
+ if let token = dict1["code"] { code = token as! String }
|
|
|
|
+ if let token = dict1["cnyPrice"] { cnyPrice = token as! String }
|
|
|
|
+ let products = KMListingProducts(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, code: code, cnyPrice: cnyPrice)
|
|
|
|
+ results.append(products)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let result = KMMemberProductResult(code: code, msg: message, listingProducts: results)
|
|
|
|
+ if code == 200 {
|
|
|
|
+ complete(true, result)
|
|
|
|
+ } else {
|
|
|
|
+ complete(false, result)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ @abstract 获取批量阶段购买价格
|
|
|
|
+ @param productId 购买的产品id
|
|
|
|
+ @param isEducation 是否教育优惠
|
|
|
|
+ @param complete 回调
|
|
|
|
+ */
|
|
|
|
+ func getBatchProductPrice(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
|
|
|
|
+
|
|
|
|
+ let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/getBatchProductPrice"
|
|
|
|
+ let params: [String: Any] = ["productId": productId,
|
|
|
|
+ "num": num]
|
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
|
|
|
|
+
|
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
|
+ dic = responseObject
|
|
|
|
+ } else {
|
|
|
|
+ var info = responseObject
|
|
|
|
+ if let error = error {
|
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
|
+ }
|
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
|
+ let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
|
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
|
+
|
|
|
|
+ var productId = ""
|
|
|
|
+ var totalPrice = ""
|
|
|
|
+ var price = ""
|
|
|
|
+ var batchPrice = ""
|
|
|
|
+ var cnyPrice = ""
|
|
|
|
+ var cnyBatchPrice = ""
|
|
|
|
+ var cnyTotalPrice = ""
|
|
|
|
+ if let token = result["productId"] { productId = token as! String }
|
|
|
|
+ if let token = result["totalPrice"] { totalPrice = token as! String }
|
|
|
|
+ if let token = result["price"] { price = token as! String }
|
|
|
|
+ if let token = result["batchPrice"] { batchPrice = token as! String }
|
|
|
|
+ if let token = result["cnyPrice"] { cnyPrice = token as! String }
|
|
|
|
+ if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as! String }
|
|
|
|
+ if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as! String }
|
|
|
|
+ let products = KMBatchProductPrice(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
|
|
|
|
+
|
|
|
|
+ let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
|
|
|
|
+ if code == 200 {
|
|
|
|
+ complete(true, result1)
|
|
|
|
+ } else {
|
|
|
|
+ complete(false, result1)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ @abstract 验证商品优惠券,返回商品优惠后价格
|
|
|
|
+ @param productId 购买的产品id
|
|
|
|
+ @param isEducation 是否教育优惠
|
|
|
|
+ @param complete 回调
|
|
|
|
+ */
|
|
|
|
+ func checkCoupon(productId: String, userId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
|
|
|
|
+ let token: String = KMMemberInfo.shared.access_token
|
|
|
|
+ if token == "" {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkCoupon"
|
|
|
|
+ let params: [String: Any] = ["productId": productId,
|
|
|
|
+ "userId": userId,
|
|
|
|
+ "code": code]
|
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
|
|
|
|
+ requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
|
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
|
+ dic = responseObject
|
|
|
|
+ } else {
|
|
|
|
+ var info = responseObject
|
|
|
|
+ if let error = error {
|
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
|
+ }
|
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
|
+ let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
|
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
|
+
|
|
|
|
+ var id = ""
|
|
|
|
+ var productName = ""
|
|
|
|
+ var price = ""
|
|
|
|
+ var maxDeviceNum = 0
|
|
|
|
+ var displayPrice = ""
|
|
|
|
+ var levels = ""
|
|
|
|
+ var platforms = ""
|
|
|
|
+ var productLineId = 0
|
|
|
|
+ var paymentModel = 0
|
|
|
|
+ var cycle = 0
|
|
|
|
+ var cnyPrice = ""
|
|
|
|
+ var displayCnyPrice = ""
|
|
|
|
+ if let token = result["id"] { id = token as! String }
|
|
|
|
+ if let token = result["productName"] { productName = token as! String }
|
|
|
|
+ if let token = result["price"] { price = token as! String }
|
|
|
|
+ if let token = result["maxDeviceNum"] { maxDeviceNum = token as! Int }
|
|
|
|
+ if let token = result["displayPrice"] { displayPrice = token as! String }
|
|
|
|
+ if let token = result["levels"] { levels = token as! String }
|
|
|
|
+ if let token = result["platforms"] { platforms = token as! String }
|
|
|
|
+ if let token = result["productLineId"] { productLineId = token as! Int }
|
|
|
|
+ if let token = result["paymentModel"] { paymentModel = token as! Int }
|
|
|
|
+ if let token = result["cycle"] { cycle = token as! Int }
|
|
|
|
+ if let token = result["cnyPrice"] { cnyPrice = token as! String }
|
|
|
|
+ if let token = result["displayCnyPrice"] { displayCnyPrice = token as! String }
|
|
|
|
+
|
|
|
|
+ let products = KMCheckCoupon(id: id, productName: productName, price: price, maxDeviceNum: maxDeviceNum, displayPrice: displayPrice, levels: levels, platforms: platforms, productLineId: productLineId, paymentModel: paymentModel, cycle: cycle, cnyPrice: cnyPrice, displayCnyPrice: displayCnyPrice)
|
|
|
|
+ let result1 = KMMemberProductResult(code: code, msg: message, checkCoupon: products)
|
|
|
|
+ if code == 200 {
|
|
|
|
+ complete(true, result1)
|
|
|
|
+ } else {
|
|
|
|
+ complete(false, result1)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ @abstract 获取批量阶段购买价格
|
|
|
|
+ @param productId 购买的产品id
|
|
|
|
+ @param isEducation 是否教育优惠
|
|
|
|
+ @param complete 回调
|
|
|
|
+ */
|
|
|
|
+ func checkEducation(email: String, _ complete: @escaping KMMemberProductComplete) {
|
|
|
|
+
|
|
|
|
+ let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkEducation"
|
|
|
|
+ let params: [String: Any] = ["email": email]
|
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
|
|
|
|
+
|
|
|
|
+ } completion: { [weak self] (task, responseObject, error) in
|
|
|
|
+ var dic: NSDictionary = [:]
|
|
|
|
+ if error == nil, let responseObject = responseObject as? NSDictionary {
|
|
|
|
+ dic = responseObject
|
|
|
|
+ } else {
|
|
|
|
+ var info = responseObject
|
|
|
|
+ if let error = error {
|
|
|
|
+ if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
|
|
|
|
+ info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ dic = (info as? NSDictionary) ?? [:]
|
|
|
|
+ }
|
|
|
|
+ let code: Int = dic["code"] as? Int ?? 0
|
|
|
|
+ let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
|
|
|
|
+ let message: String = dic["msg"] as? String ?? ""
|
|
|
|
+
|
|
|
|
+ var productId = ""
|
|
|
|
+ var totalPrice = ""
|
|
|
|
+ var price = ""
|
|
|
|
+ var batchPrice = ""
|
|
|
|
+ var cnyPrice = ""
|
|
|
|
+ var cnyBatchPrice = ""
|
|
|
|
+ var cnyTotalPrice = ""
|
|
|
|
+ if let token = result["productId"] { productId = token as! String }
|
|
|
|
+ if let token = result["totalPrice"] { totalPrice = token as! String }
|
|
|
|
+ if let token = result["price"] { price = token as! String }
|
|
|
|
+ if let token = result["batchPrice"] { batchPrice = token as! String }
|
|
|
|
+ if let token = result["cnyPrice"] { cnyPrice = token as! String }
|
|
|
|
+ if let token = result["cnyBatchPrice"] { cnyBatchPrice = token as! String }
|
|
|
|
+ if let token = result["cnyTotalPrice"] { cnyTotalPrice = token as! String }
|
|
|
|
+ let products = KMBatchProductPrice(productId: productId, totalPrice: totalPrice, price: price, batchPrice: batchPrice, cnyPrice: cnyPrice, cnyBatchPrice: cnyBatchPrice, cnyTotalPrice: cnyTotalPrice)
|
|
|
|
+
|
|
|
|
+ let result1 = KMMemberProductResult(code: code, msg: message, batchProductPrice: products)
|
|
|
|
+ if code == 200 {
|
|
|
|
+ complete(true, result1)
|
|
|
|
+ } else {
|
|
|
|
+ complete(false, result1)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
// MARK: 个人中心模块
|
|
// MARK: 个人中心模块
|
|
|
|
|
|
// MARK: 订单模块
|
|
// MARK: 订单模块
|
|
|
|
+
|
|
|
|
|
|
// MARK: 评估模块
|
|
// MARK: 评估模块
|
|
|
|
|