|
@@ -52,6 +52,7 @@ enum KMMemberCenterErrorCodeType: Int, CaseIterable {
|
|
|
|
|
|
typealias KMMemberCenterComplete = (_ success: Bool, _ result: KMMemberCenterResult?) -> Void
|
|
|
typealias KMMemberProductComplete = (_ success: Bool, _ result: KMMemberProductResult?) -> Void
|
|
|
+typealias KMMemberRequestInfoComplete = (_ success: Bool, _ info: NSDictionary?) -> Void
|
|
|
|
|
|
class KMMemberCenterManager: NSObject {
|
|
|
static let manager = KMMemberCenterManager()
|
|
@@ -466,6 +467,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
func getInviteNum(_ complete: @escaping KMMemberCenterComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -506,6 +508,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
func userInfo(_ complete: @escaping KMMemberCenterComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -624,6 +627,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
func userLogout(_ complete: @escaping KMMemberCenterComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
let uuid: String = GetHardwareUUID() ?? ""
|
|
@@ -663,6 +667,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
func userRightList(_ complete: @escaping KMMemberCenterComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -733,6 +738,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
func userLogOffForUser(code: String, _ complete: @escaping KMMemberCenterComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -778,6 +784,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
func userRevokeCancel(_ complete: @escaping KMMemberCenterComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -964,7 +971,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
/**
|
|
|
@abstract 获取批量阶段购买价格
|
|
|
@param productId 购买的产品id
|
|
|
- @param isEducation 是否教育优惠
|
|
|
+ @param num 批量个数
|
|
|
@param complete 回调
|
|
|
*/
|
|
|
func getBatchProductPrice(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
|
|
@@ -1019,12 +1026,14 @@ class KMMemberCenterManager: NSObject {
|
|
|
/**
|
|
|
@abstract 验证商品优惠券,返回商品优惠后价格
|
|
|
@param productId 购买的产品id
|
|
|
- @param isEducation 是否教育优惠
|
|
|
+ @param userId 用户ID
|
|
|
+ @param code 优惠券
|
|
|
@param complete 回调
|
|
|
*/
|
|
|
func checkCoupon(productId: String, userId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkCoupon"
|
|
@@ -1148,14 +1157,62 @@ class KMMemberCenterManager: NSObject {
|
|
|
@param orderId 订单id
|
|
|
@param complete 回调
|
|
|
*/
|
|
|
- func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberProductComplete) {
|
|
|
+ func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getStateByOrderId"
|
|
|
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
|
|
|
+ if code == 200 {
|
|
|
+ complete(true, dic)
|
|
|
+ } else {
|
|
|
+ complete(false, dic)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ @abstract 创建订单(买断)
|
|
|
+ @param productId 产品id
|
|
|
+ @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
|
|
|
+ @param price 价格
|
|
|
+ @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
|
|
|
+ @param couponCode 优惠卷
|
|
|
+ @param num 批量购买数量
|
|
|
+ @param complete 回调
|
|
|
+ */
|
|
|
+ func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
|
|
|
+ let token: String = KMMemberInfo.shared.access_token
|
|
|
+ if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
|
|
|
+ let params: [String: Any] = ["productId": productId,
|
|
|
+ "paymentMethod": paymentMethod,
|
|
|
+ "price": price,
|
|
|
+ "discountFlag": discountFlag,
|
|
|
+ "couponCode": couponCode,
|
|
|
+ "num": num]
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { 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 {
|
|
@@ -1173,20 +1230,25 @@ class KMMemberCenterManager: NSObject {
|
|
|
let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
|
|
|
let message: String = dic["msg"] as? String ?? ""
|
|
|
|
|
|
- var status = ""
|
|
|
- if let token = result["status"] { status = token as! String }
|
|
|
-
|
|
|
- let result1 = KMMemberProductResult(code: code, msg: message, result: status)
|
|
|
+ var thirdOrderNo = ""
|
|
|
+ var orderId = ""
|
|
|
+ var payHref = ""
|
|
|
if code == 200 {
|
|
|
+ if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
|
|
|
+ if let token = result["orderId"] { orderId = token as! String }
|
|
|
+ if let token = result["payHref"] { payHref = token as! String }
|
|
|
+ let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
|
|
|
+ let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
|
|
|
complete(true, result1)
|
|
|
} else {
|
|
|
+ let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
|
|
|
complete(false, result1)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- @abstract 创建订单(买断、订阅)
|
|
|
+ @abstract 创建订单(订阅)
|
|
|
@param productId 产品id
|
|
|
@param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
|
|
|
@param price 价格
|
|
@@ -1195,9 +1257,10 @@ class KMMemberCenterManager: NSObject {
|
|
|
@param num 批量购买数量
|
|
|
@param complete 回调
|
|
|
*/
|
|
|
- func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
|
|
|
+ func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
|
|
@@ -1251,6 +1314,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
func getOrderListByStatus(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getOrderListByStatus"
|
|
@@ -1291,6 +1355,43 @@ class KMMemberCenterManager: NSObject {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ @abstract 关闭订单
|
|
|
+ @param orderId 订单id
|
|
|
+ @param complete 回调
|
|
|
+ */
|
|
|
+ func closeByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
|
|
|
+ let token: String = KMMemberInfo.shared.access_token
|
|
|
+ if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/closeOrder"
|
|
|
+ KMRequestServer.requestServer.request(urlString: urlString, method: .post, 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
|
|
|
+
|
|
|
+ if code == 200 {
|
|
|
+ complete(true, dic)
|
|
|
+ } else {
|
|
|
+ complete(false, dic)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: 苹果支付
|
|
|
|
|
|
/**
|
|
@@ -1301,6 +1402,7 @@ class KMMemberCenterManager: NSObject {
|
|
|
func appStoreEquityVerification(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
|
|
|
let token: String = KMMemberInfo.shared.access_token
|
|
|
if token == "" {
|
|
|
+ complete(false, nil)
|
|
|
return
|
|
|
}
|
|
|
let urlString = configuration.activityBaseURL() + "/member-system-website/applePay/appStoreEquityVerification"
|