CNLiveShopViewModel.swift
9.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//
// CNLiveShopViewModel.swift
// metaCode
//
// Created by open on 2023/10/31.
//
import Foundation
import CNLiveRequestBastKit
typealias resultShopBlock = (_ result: Any,_ respStatue :CNLiveMineResponseType) -> Void
class CNLiveShopViewModel: NSObject {
/// 请求获取订单列表数据
/// - Parameters:
/// - state: 0全部 1待发货 2配送中 3代付款 4订单退款
/// - resultShopBlock: 返回
static func requestOrderList(state: String, page: NSInteger, resultBlock: @escaping resultShopBlock) {
if state == "6" {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
param.setValue("\(page)", forKey: "page")
let custom_param = NSMutableDictionary()
custom_param.setValue(APPId_wjj, forKey: "appId")
custom_param.setValue(APPKey_wjj, forKey: "appKey")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseWjjBUrl+"/api/v1/refundList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["code"] ?? "0")"
if (errorCode == "200") {
if resp["data"] is NSNull {
resultBlock(Array<Any>(),.success)
} else {
let array = resp["data"] as! NSArray
let tempArray = NSMutableArray()
for item in array {
let listModel = dictionaryToModel(item as! [String : Any], ShopOrderListModel.self,"") as! ShopOrderListModel
listModel.isRefund = "1"
tempArray.add(listModel)
}
resultBlock(tempArray, .success)
}
} else {
showMessage(message: resp["message"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "获取失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
} else {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
param.setValue("\(page)", forKey: "page")
param.setValue("", forKey: "delivery")
param.setValue(state, forKey: "state")
param.setValue("", forKey: "keyword")
let custom_param = NSMutableDictionary()
custom_param.setValue(APPId_wjj, forKey: "appId")
custom_param.setValue(APPKey_wjj, forKey: "appKey")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseWjjBUrl+"/api/v1/orders", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["code"] ?? "0")"
if (errorCode == "200") {
if resp["data"] is NSNull {
resultBlock(Array<Any>(),.success)
} else {
let array = resp["data"] as! NSArray
let tempArray = NSMutableArray()
for item in array {
let listModel = dictionaryToModel(item as! [String : Any], ShopOrderListModel.self,"") as! ShopOrderListModel
tempArray.add(listModel)
}
resultBlock(tempArray, .success)
}
} else {
showMessage(message: resp["message"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "获取失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
}
}
/// 通知自提
/// - Parameters:
/// - orderId: 订单id
/// - resultBlock: 返回
static func requestNotifyOrder(orderId: String, resultBlock: @escaping resultShopBlock) {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
param.setValue(orderId, forKey: "id")
let custom_param = NSMutableDictionary()
custom_param.setValue(APPId_wjj, forKey: "appId")
custom_param.setValue(APPKey_wjj, forKey: "appKey")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseWjjBUrl+"/api/v1/notifyOrder", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["code"] ?? "0")"
if (errorCode == "200") {
resultBlock("",.success)
} else {
showMessage(message: resp["message"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "获取失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
}
/// 获取订单详情数据
/// - Parameters:
/// - orderId: 订单id
/// - resultBlock: 返回
static func requestOrderDetail(orderId: String, resultBlock: @escaping resultShopBlock) {
let param = NSMutableDictionary()
param.setValue(orderId, forKey: "id")
let custom_param = NSMutableDictionary()
custom_param.setValue(APPId_wjj, forKey: "appId")
custom_param.setValue(APPKey_wjj, forKey: "appKey")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseWjjBUrl+"/api/v1/order", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["code"] ?? "0")"
if (errorCode == "200") {
if resp["data"] is NSNull {
resultBlock(NSNull(),.failed)
} else {
let model = dictionaryToModel(resp as! [String : Any], ShopOrderDetailModel.self,"data") as! ShopOrderDetailModel
var is_send_all: Bool = true
for goodsModel in model.order_detail {
if Int(goodsModel.send_num!)! > 0 {
is_send_all = false
}
}
model.is_send_all = is_send_all
resultBlock(model,.success)
}
} else {
showMessage(message: resp["message"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "获取失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
}
}