Commit cab92121 authored by pete谢兆麟's avatar pete谢兆麟

首次人脉授权信息接口联调

parent b3e79596
...@@ -27,8 +27,20 @@ class YHInformationAuthorizationStepOneViewController: YHBaseViewController { ...@@ -27,8 +27,20 @@ class YHInformationAuthorizationStepOneViewController: YHBaseViewController {
} }
func getData() { func getData() {
items = viewModel.getBaseDataSource() viewModel.requestUserInfo {[weak self] success, error in
tableView.reloadData() guard let self = self else { return }
self.items = viewModel.getBaseDataSource()
self.tableView.reloadData()
let url = URL(string: self.viewModel.model.avatar)
self.photoImageView.kf.setImage(with: url)
if self.viewModel.isCanNext() {
nextButton.isEnabled = true
nextButton.backgroundColor = UIColor.brandMainColor
} else {
nextButton.isEnabled = false
nextButton.backgroundColor = UIColor.brandMainColor.withAlphaComponent(0.4)
}
}
} }
func setView() { func setView() {
...@@ -164,16 +176,27 @@ class YHInformationAuthorizationStepOneViewController: YHBaseViewController { ...@@ -164,16 +176,27 @@ class YHInformationAuthorizationStepOneViewController: YHBaseViewController {
YHImagePickerView.show() {[weak self] image in YHImagePickerView.show() {[weak self] image in
guard let self = self else { return } guard let self = self else { return }
self.photoImageView.image = image self.photoImageView.image = image
self.viewModel.uploadImage(image, true) {[weak self] success, error in
guard let self = self else { return }
self.viewModel.model.avatar = success ?? ""
}
} }
} }
@objc func changeHead() { @objc func changeHead() {
viewModel.requestChangeHead {[weak self] success, error in
guard let self = self else { return }
let url = URL(string: self.viewModel.model.avatar)
self.photoImageView.kf.setImage(with: url)
}
} }
@objc func nextStep() { @objc func nextStep() {
let vc = YHInformationAuthorizationStepTwoViewController() viewModel.requestSaveUserInfo {[weak self] success, error in
self.navigationController?.pushViewController(vc) guard let self = self else { return }
let vc = YHInformationAuthorizationStepTwoViewController()
self.navigationController?.pushViewController(vc)
}
} }
} }
...@@ -196,7 +219,8 @@ extension YHInformationAuthorizationStepOneViewController: UITableViewDelegate, ...@@ -196,7 +219,8 @@ extension YHInformationAuthorizationStepOneViewController: UITableViewDelegate,
nextButton.backgroundColor = UIColor.brandMainColor.withAlphaComponent(0.4) nextButton.backgroundColor = UIColor.brandMainColor.withAlphaComponent(0.4)
} }
if model.id != .id1 && model.id != .id3 && model.id != .id5 { if model.id != .id1 && model.id != .id3 && model.id != .id5 {
self.getData() self.items = viewModel.getBaseDataSource()
self.tableView.reloadData()
} }
} }
return cell return cell
......
...@@ -24,8 +24,16 @@ class YHInformationAuthorizationStepTwoViewController: UIViewController { ...@@ -24,8 +24,16 @@ class YHInformationAuthorizationStepTwoViewController: UIViewController {
} }
func getData() { func getData() {
items = viewModel.getBaseSetDataSource() if stepFlag {
tableView.reloadData() items = viewModel.getBaseSetDataSource()
tableView.reloadData()
} else {
viewModel.requestUserAuthorization {[weak self] success, error in
guard let self = self else { return }
items = viewModel.getBaseSetDataSource()
tableView.reloadData()
}
}
} }
func setView() { func setView() {
...@@ -106,7 +114,10 @@ class YHInformationAuthorizationStepTwoViewController: UIViewController { ...@@ -106,7 +114,10 @@ class YHInformationAuthorizationStepTwoViewController: UIViewController {
} }
@objc func nextStep() { @objc func nextStep() {
viewModel.requestAuthorizationSubmit {[weak self] success, error in
guard let self = self else { return }
self.navigationController?.popViewController(animated: true)
}
} }
} }
......
...@@ -153,9 +153,11 @@ class YHPeopleViewController: YHBaseViewController { ...@@ -153,9 +153,11 @@ class YHPeopleViewController: YHBaseViewController {
return return
} }
let view = YHPeopleSuccessView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight)) // let view = YHPeopleSuccessView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight))
let window = UIApplication.shared.yhKeyWindow() // let window = UIApplication.shared.yhKeyWindow()
window?.addSubview(view) // window?.addSubview(view)
let vc = YHInformationAuthorizationStepOneViewController()
self.navigationController?.pushViewController(vc)
} }
func resetAnimation() { func resetAnimation() {
......
...@@ -56,8 +56,26 @@ class YHMainUserInformationModel: YHBaseModel { ...@@ -56,8 +56,26 @@ class YHMainUserInformationModel: YHBaseModel {
} }
class YHMainUserInformationSetModel: YHBaseModel { class YHMainUserInformationSetModel: YHBaseModel {
var isRea: Bool = true var uid: String = ""
var isWork: Bool = true var information_to_card: Int = 2
var isSchool: Bool = true var authorization_basic_information: Int = 2
var public_education_experience: Int = 2
var public_work_experience: Int = 2
var isclick_card: Int = 2
}
class YHUserInformationDetailModel: YHBaseModel {
var username: String = ""
var avatar: String = ""
var address: YHUserInformationDetailAddressModel = YHUserInformationDetailAddressModel()
var college: String = ""
var industry: String = ""
var position: String = ""
}
class YHUserInformationDetailAddressModel: YHBaseModel {
var country: String = ""
var province: String = ""
var city: String = ""
} }
...@@ -11,26 +11,23 @@ import UIKit ...@@ -11,26 +11,23 @@ import UIKit
class YHInformationAuthorizeViewModel: YHBaseViewModel { class YHInformationAuthorizeViewModel: YHBaseViewModel {
var mainModel: YHMainUserInformationModel = YHMainUserInformationModel() var mainModel: YHMainUserInformationModel = YHMainUserInformationModel()
var setModel: YHMainUserInformationSetModel = YHMainUserInformationSetModel() var setModel: YHMainUserInformationSetModel = YHMainUserInformationSetModel()
var model: YHUserInformationDetailModel = YHUserInformationDetailModel()
override init() { override init() {
super.init() super.init()
} }
func getBaseDataSource() -> [YHUserInformationModel] { func getBaseDataSource() -> [YHUserInformationModel] {
let item1 = YHUserInformationModel(id: .id1, title: "真实姓名", isUserKeyBoard: true, prompts: "请输入您的真实姓名", message: mainModel.username) let item1 = YHUserInformationModel(id: .id1, title: "真实姓名", isUserKeyBoard: true, prompts: "请输入您的真实姓名", message: model.username)
let item2 = YHUserInformationModel(id: .id6, title: "所在地", isUserKeyBoard: false, prompts: "请选择您的所在地", message: mainModel.country, type: .country, value: mainModel.area) let item2 = YHUserInformationModel(id: .id6, title: "所在地", isUserKeyBoard: false, prompts: "请选择您的所在地", message: model.address.country, type: .country)
var string = "" var string = ""
let array = mainModel.area if model.address.province.count != 0 {
for item in array { string = model.address.province + "/" + model.address.city
if string.count != 0 {
string = string + "/" + item
} else {
string = string + item
}
} }
let item3 = YHUserInformationModel(id: .id2, title: "所在地-省市", isUserKeyBoard: false, prompts: "请选择您的所在地", message: string, type: .address, value: mainModel.area)
let item4 = YHUserInformationModel(id: .id3, title: "毕业院校", isUserKeyBoard: true, prompts: "请输入您的毕业院校", message: mainModel.school) let item3 = YHUserInformationModel(id: .id2, title: "所在地-省市", isUserKeyBoard: false, prompts: "请选择您的所在地", message: string, type: .address)
let item5 = YHUserInformationModel(id: .id4, title: "所属行业", isUserKeyBoard: false, prompts: "请选择您的所属行业", message: mainModel.industry, type: .id) let item4 = YHUserInformationModel(id: .id3, title: "毕业院校", isUserKeyBoard: true, prompts: "请输入您的毕业院校", message: model.college)
let item6 = YHUserInformationModel(id: .id5, title: "职位", isUserKeyBoard: true, prompts: "请输入您的职位", message: mainModel.position) let item5 = YHUserInformationModel(id: .id4, title: "所属行业", isUserKeyBoard: false, prompts: "请选择您的所属行业", message: model.industry, type: .id)
let item6 = YHUserInformationModel(id: .id5, title: "职位", isUserKeyBoard: true, prompts: "请输入您的职位", message: model.position)
if mainModel.country.contains("中国") { if mainModel.country.contains("中国") {
return [item1, item2, item3, item4, item5, item6] return [item1, item2, item3, item4, item5, item6]
} }
...@@ -41,40 +38,47 @@ class YHInformationAuthorizeViewModel: YHBaseViewModel { ...@@ -41,40 +38,47 @@ class YHInformationAuthorizeViewModel: YHBaseViewModel {
guard let type = item.id else { return } guard let type = item.id else { return }
switch type { switch type {
case .id1: case .id1:
mainModel.username = item.message ?? "" model.username = item.message ?? ""
case .id2: case .id2:
mainModel.area = item.value ?? [] model.address.province = item.value?.first ?? ""
model.address.city = item.value?.last ?? ""
case .id3: case .id3:
mainModel.school = item.message ?? "" model.college = item.message ?? ""
case .id4: case .id4:
mainModel.industry = item.message ?? "" model.industry = item.message ?? ""
case .id5: case .id5:
mainModel.position = item.message ?? "" model.position = item.message ?? ""
case .id6: case .id6:
mainModel.country = item.message ?? "" model.address.country = item.message ?? ""
default: default:
break break
} }
} }
func isCanNext() -> Bool { func isCanNext() -> Bool {
let username = mainModel.username let username = model.username
let school = mainModel.school let school = model.college
let area = mainModel.area let country = model.address.country
let industry = mainModel.industry let provice = model.address.province
let position = mainModel.position let city = model.address.city
let industry = model.industry
let position = model.position
guard username.count > 0 else { return false } guard username.count > 0 else { return false }
guard school.count > 0 else { return false } guard school.count > 0 else { return false }
guard industry.count > 0 else { return false } guard industry.count > 0 else { return false }
guard position.count > 0 else { return false } guard position.count > 0 else { return false }
guard area.count > 0 else { return false } guard country.count > 0 else { return false }
if mainModel.country.contains("中国") {
guard provice.count > 0 else { return false }
guard city.count > 0 else { return false }
}
return true return true
} }
func getBaseSetDataSource() -> [YHSettingItem] { func getBaseSetDataSource() -> [YHSettingItem] {
let item1 = YHSettingItem(type: .people, title: "授权AI人脉匹配", subTitle: "开启后,您的信息将用于AI人脉匹配,为您构建高质量的人脉网络", isSelect: setModel.isRea, isShowAlert: true) let item1 = YHSettingItem(type: .people, title: "授权AI人脉匹配", subTitle: "开启后,您的信息将用于AI人脉匹配,为您构建高质量的人脉网络", isSelect: setModel.authorization_basic_information == 2 ? true : false, isShowAlert: true)
let item2 = YHSettingItem(type: .school, title: "允许向好友公开您的教育经历", subTitle: "开启后,您的教育经历将在您的个人名片上对已交换名片的好友可见", isSelect: setModel.isSchool, isShowAlert: true) let item2 = YHSettingItem(type: .school, title: "允许向好友公开您的教育经历", subTitle: "开启后,您的教育经历将在您的个人名片上对已交换名片的好友可见", isSelect: setModel.public_education_experience == 2 ? true : false, isShowAlert: true)
let item3 = YHSettingItem(type: .work, title: "允许向好友公开您的工作经历", subTitle: "开启后,您的工作经历将在您的个人名片上对已交换名片的好友可见", isSelect: setModel.isWork, isShowAlert: true) let item3 = YHSettingItem(type: .work, title: "允许向好友公开您的工作经历", subTitle: "开启后,您的工作经历将在您的个人名片上对已交换名片的好友可见", isSelect: setModel.public_work_experience == 2 ? true : false, isShowAlert: true)
return [item1, item2, item3] return [item1, item2, item3]
} }
...@@ -83,11 +87,121 @@ class YHInformationAuthorizeViewModel: YHBaseViewModel { ...@@ -83,11 +87,121 @@ class YHInformationAuthorizeViewModel: YHBaseViewModel {
case .normal: break case .normal: break
case .people: case .people:
setModel.isRea = item.isSelect setModel.authorization_basic_information = item.isSelect ? 2 : 1
case .school: case .school:
setModel.isSchool = item.isSelect setModel.public_education_experience = item.isSelect ? 2 : 1
case .work: case .work:
setModel.isWork = item.isSelect setModel.public_work_experience = item.isSelect ? 2 : 1
}
}
func requestUserInfo(callBackBlock:@escaping (_ success: Bool, _ error: YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.People.userInfo
let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else { return }
if json.code == 200 {
let dic = json.data
guard let result = YHUserInformationDetailModel.deserialize(from: dic as? Dictionary) else {
callBackBlock(false,nil)
return
}
self.model = result
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
func requestUserAuthorization(callBackBlock:@escaping (_ success: Bool, _ error: YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.People.userAuthorization
let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else { return }
if json.code == 200 {
let dic = json.data
guard let result = YHMainUserInformationSetModel.deserialize(from: dic as? Dictionary) else {
callBackBlock(false,nil)
return
}
self.setModel = result
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
func requestSaveUserInfo(callBackBlock:@escaping (_ success: Bool, _ error: YHErrorModel?)->()) {
let address: [String: Any] = ["country": model.address.country,
"province": model.address.province,
"city": model.address.city]
let params: [String: Any] = ["avatar": model.avatar,
"username": model.username,
"college": model.college,
"industry": model.industry,
"position": model.position,
"address": address]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.People.userSubmit
let _ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, code in
//1. json字符串 转 对象
guard let _ = self else { return }
if json.code == 200 {
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
func requestChangeHead(callBackBlock:@escaping (_ success: Bool, _ error: YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.People.change
let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else { return }
if json.code == 200 {
let dic = json.data
guard let result = YHChangeHeadModel.deserialize(from: dic as? Dictionary) else {
callBackBlock(false,nil)
return
}
self.model.avatar = result.avatar
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
func requestAuthorizationSubmit(callBackBlock:@escaping (_ success: Bool, _ error: YHErrorModel?)->()) {
let params: [String: Any] = ["authorization_basic_information": setModel.authorization_basic_information,
"public_education_experience": setModel.public_education_experience,
"public_work_experience": setModel.public_work_experience]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.People.authorizationSubmit
let _ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, code in
//1. json字符串 转 对象
guard let _ = self else { return }
if json.code == 200 {
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
} }
} }
} }
...@@ -320,6 +320,8 @@ class YHAllApiName { ...@@ -320,6 +320,8 @@ class YHAllApiName {
static let change = "super-app/avatar/change" static let change = "super-app/avatar/change"
static let userSubmit = "super-app/user-base/submit" static let userSubmit = "super-app/user-base/submit"
static let authorizationSubmit = "super-app/authorization/submit" static let authorizationSubmit = "super-app/authorization/submit"
static let userInfo = "super-app/user-base/info"
static let userAuthorization = "super-app/user/authorization"
} }
} }
...@@ -69,7 +69,7 @@ class YHOSSManager: NSObject, URLSessionDelegate { ...@@ -69,7 +69,7 @@ class YHOSSManager: NSObject, URLSessionDelegate {
} }
func putObject(image: UIImage, _ isPublic: Bool = false, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) { func putObject(image: UIImage, _ isPublic: Bool = false, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
let request = OSSPutObjectRequest() let request = OSSPutObjectACLRequest()
let size = Int(2 * 1024 * 1024) let size = Int(2 * 1024 * 1024)
guard let imageData = image.compressOriginalImage(size) else { guard let imageData = image.compressOriginalImage(size) else {
callBackBlock(nil, YHErrorModel()) callBackBlock(nil, YHErrorModel())
...@@ -87,6 +87,7 @@ class YHOSSManager: NSObject, URLSessionDelegate { ...@@ -87,6 +87,7 @@ class YHOSSManager: NSObject, URLSessionDelegate {
let currentDateMMdd = dateFormatter.string(from: Date()) let currentDateMMdd = dateFormatter.string(from: Date())
self.fileName.append(name) self.fileName.append(name)
if isPublic { if isPublic {
request.acl = "public-read-write"
request.objectKey = "5000000" + "/" + currentDateMMdd + "/" + "\(name)" request.objectKey = "5000000" + "/" + currentDateMMdd + "/" + "\(name)"
} else { } else {
request.objectKey = "4001001" + "/" + currentDateMMdd + "/" + "\(name)" request.objectKey = "4001001" + "/" + currentDateMMdd + "/" + "\(name)"
...@@ -121,7 +122,7 @@ class YHOSSManager: NSObject, URLSessionDelegate { ...@@ -121,7 +122,7 @@ class YHOSSManager: NSObject, URLSessionDelegate {
} }
func putFile(file: String, _ isPublic: Bool = false, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) { func putFile(file: String, _ isPublic: Bool = false, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
let request = OSSPutObjectRequest() let request = OSSPutObjectACLRequest()
guard let fileData = try? Data(contentsOf: URL(string: file) ?? URL(fileURLWithPath: "")) else { guard let fileData = try? Data(contentsOf: URL(string: file) ?? URL(fileURLWithPath: "")) else {
callBackBlock(nil, YHErrorModel()) callBackBlock(nil, YHErrorModel())
return return
...@@ -138,6 +139,7 @@ class YHOSSManager: NSObject, URLSessionDelegate { ...@@ -138,6 +139,7 @@ class YHOSSManager: NSObject, URLSessionDelegate {
dateFormatter.dateFormat = "yyyyMMdd" dateFormatter.dateFormat = "yyyyMMdd"
let currentDateMMdd = dateFormatter.string(from: Date()) let currentDateMMdd = dateFormatter.string(from: Date())
if isPublic { if isPublic {
request.acl = "public-read-write"
request.objectKey = "5000000" + "/" + currentDateMMdd + "/" + "\(name)" request.objectKey = "5000000" + "/" + currentDateMMdd + "/" + "\(name)"
} else { } else {
request.objectKey = "4001001" + "/" + currentDateMMdd + "/" + "\(name)" request.objectKey = "4001001" + "/" + currentDateMMdd + "/" + "\(name)"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment