CNLiveVitaeViewModel.swift
8.15 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
//
// CNLiveVitaeViewModel.swift
// metaCode
//
// Created by zx on 2024/7/12.
// 数字简历
import Foundation
import CNLiveRequestBastKit
class CNLiveVitaeViewModel:NSObject{
/*
查看简历
参数 vsid 实名对象id
参数 type 1简历信息 2官方认证 3证书 4工作经历 4获奖情况
*/
static func getVitae(vsid:String,type:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(vsid, forKey: "vsid")
param.setValue("\(type)", forKey: "type")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/userApi/getVitae", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
if resp["errorCode"] as! Int == 0{
let dataDic = resp["data"] as! NSDictionary
let shopDetailModel = newDictionaryToModel(dataDic as! [String : Any], CNLiveVitaeModel.self)
resultBlock(shopDetailModel,.success)
}else{
resultBlock(NSNull(),.failed)
}
}else{
resultBlock(NSNull(),.failed)
}
}
}
/*
保存简历/更新简历
参数 vsid 实名对象id
参数 type 1简历信息 2官方认证 3证书 4工作经历 4获奖情况
*/
static func saveVitae(city:String,icon:String,isSave:Bool,id:String,phone:String,profession:String,professionId:String,selfIntroduction:String,showAddress:Bool,showAge:Bool,showAwards:Bool,showPhone:Bool,updateTime:String,vsid:String,workTime:String,resultBlock: @escaping downSlideResultBlock) {
let values = NSMutableDictionary()
values.addEntries(from: ["city":city])
values.addEntries(from: ["icon":icon])
//简历为nil保存简历时 不传id; 更新简历时id传简历的vitaeid
if !isSave{
values.addEntries(from: ["id":id])
}
values.addEntries(from: ["phone":phone])
values.addEntries(from: ["profession":profession])
values.addEntries(from: ["professionId":professionId])
values.addEntries(from: ["selfIntroduction":selfIntroduction])
values.addEntries(from: ["showAddress":showAddress])
values.addEntries(from: ["showAge":showAge])
values.addEntries(from: ["showAwards":showAwards])
values.addEntries(from: ["showPhone":showPhone])
values.addEntries(from: ["updateTime":updateTime])
values.addEntries(from: ["vsid":vsid])
values.addEntries(from: ["workTime":workTime])
do {
let request = URLRequest.init(url: URL.init(string: APPBaseMCUrl+"/userApi/saveVitae")!) as! NSMutableURLRequest
request.httpMethod = "POST"
request.timeoutInterval = 10
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let data = try JSONSerialization.data(withJSONObject: values, options: .prettyPrinted)
request.httpBody = data
showLoading(message: "")
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.setAllowRequestDefaultArgument(false)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setBuildCustomUrlRequest(request as URLRequest) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
resultBlock(true,.success)
} else {
showMessage(message: resp["errorMessage"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "上传失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
} catch {
showMessage(message: "上传失败")
resultBlock(NSNull(),.failed)
}
}
/// 获取省市区县列表
/// @param id
static func getCityListWithId(id:String,resultBlock: @escaping downSlideResultBlock){
let param = NSMutableDictionary()
param.setValue(id, forKey: "id")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId_wjj, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .POST, urlString: "https://managemall.cnlive.com"+"/Api/Index3/getCityList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let res = (result as! Dictionary<String, Any>)["data"] as! Dictionary<String, Any>
let listModel = newDictionaryToModel(res, CNLiveAddrAreaListModel.self)
resultBlock(listModel as Any,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
/*
获取证书列表
参数 vsid 实名对象id
参数 page NSInteger
参数 pageSize NSInteger
*/
static func getCerList(vsid:String,page:NSInteger,pageSize:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(vsid, forKey: "vsid")
param.setValue("\(page)", forKey: "page")
param.setValue("\(pageSize)", forKey: "pageSize")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/userApi/certificates", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
if resp["errorCode"] as! Int == 0{
let dataDic = resp["data"] as! NSDictionary
let shopDetailModel = newDictionaryToModel(dataDic as! [String : Any], CNLiveVitaeCertificateListModel.self) as! CNLiveVitaeCertificateListModel
resultBlock(shopDetailModel.list ?? [CNLiveVitaeCertificateModel](),.success)
}else{
resultBlock(NSNull(),.failed)
}
}else{
resultBlock(NSNull(),.failed)
}
}
}
}