CNLiveHomePageViewModel.swift
10.6 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// CNLiveHomePageViewModel.swift
// metaCode
//
// Created by zx on 2024/1/8.
//
import Foundation
import CNLiveRequestBastKit
class CNLiveHomePageViewModel:NSObject{
/// 获取首页原生页面数据
static func requestGetHomePageConfigList( resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/commonApi/homePageConfigList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic, CNLiveHomePageModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 短剧主页-专辑收藏(追剧)
static func postAlbumCollect(aid:String,type:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("\(type)", forKey: "type")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseCMSUrl+"/contentApi/albumCollect", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
resultBlock(NSNull(),.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页我的专辑收藏数据
static func requestGetHomePageMyAlbum(page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("\(page)", forKey: "page")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/myAlbum", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataArr = resp["data"] as! Array<Any>
var resArr = []
if dataArr.count > 0{
//有在追短剧
for dataDic in dataArr {
let dataMdl = newDictionaryToModel(dataDic as! [String : Any], CNLiveAlbumMsgModel.self)
resArr.append(dataMdl)
}
}else{
//没有在追短剧
}
resultBlock(resArr,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-全部专辑列表,区块内容分页
static func getBlockContents(blockId:String,page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(blockId, forKey: "blockId")
param.setValue("\(page)", forKey: "page")
// param.setValue("10", forKey: "pageSize")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getBlockContents", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic , CNLiveAlbumBaseModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-专辑详情简介
static func getAlbumMsg(aid:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/contentApi/getAlbumMsg", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic, CNLiveAlbumMsgModel.self)
resultBlock(dataMdl,.success)
}
else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 获取首页-专辑视频列表详情
static func getAlbumList(aid:String, page:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(aid, forKey: "aid")
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue("\(page)", forKey: "page")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseCMSUrl+"/ugcApi/albumList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
let dataDic = resp["data"] as! Dictionary<String, Any>
let dataMdl = newDictionaryToModel(dataDic , CNLiveAlbumListBaseModel.self)
resultBlock(dataMdl,.success)
// let dataDic = resp["data"] as! Dictionary<String, Any>
// let dataList = dataDic["list"] as! Array<Any>
// var listArr = Array<Any>()
// for listDic in dataList{
// let dataMdl = newDictionaryToModel(listDic as! [String : Any], CNLiveAlbumListModel.self)
// listArr.append(dataMdl)
// }
//
// resultBlock(listArr,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
}
/// 积分支付
static func orderVideoByPoint(prdId:String,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
param.setValue(APPId_wjj, forKey: "sp_id")
param.setValue(prdId, forKey: "prdId")
param.setValue("apple", forKey: "frmId")
param.setValue(CNLiveHomePageViewModel.getRandomOrderId(), forKey: "srvOrderId")
let customParam = NSMutableDictionary()
customParam.setValue(APPId, forKey: "appId")
customParam.setValue(APPKey, forKey: "appKey")
CNLiveNetworking.setupShowResult(true)
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupCustomParam(customParam as? [String : String])
CNLiveNetworking.requestNetwork(with: .POST, urlString: "\(CNLiveEnvironmentManager.shared.img_token_url)/pom/orderVideoByPoint", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
//兑换成功
resultBlock(NSNull(),.success)
}else if (errorCode == "4002") {
//积分不足
resultBlock("积分不足",.failed)
}else
{
resultBlock("兑换失败,请稍候再试!",.failed)
}
}
}
}
static func getRandomOrderId() -> String {
// appId+渠道+年月日+毫秒数后10位+2位数的随机数
var randomOrderId = ""
//年月日
let formatter = DateFormatter()
formatter.dateFormat = "yyyyMMdd"
let currentDate = Date()
let currentDateString = formatter.string(from: currentDate)
//取毫秒时间戳
let timestamp13 = String(format: "%ld",self.getNow13Timestamp())//timeStamp)
//拼接
randomOrderId = String(format: "%@%@%@%d", APPId_wjj, currentDateString, timestamp13, Int.random(in: 0..<10))
return randomOrderId
}
static func getNow13Timestamp() -> Int {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
formatter.timeZone = TimeZone(identifier: "Asia/Beijing")
let dateNow = Date()
let timeStamp = Int(dateNow.timeIntervalSince1970)
return timeStamp*1000
}
}