add
无故事王国
2024-06-03 3d8ce4866799bea7e66699acdeb86b60b0ba033c
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
//
//  Services.swift
//  YixiuShop
//
//  Created by Sweet on 2019/9/30.
//  Copyright © 2019 jackLove. All rights reserved.
//
 
import UIKit
import RxSwift
import Alamofire
import JQTools
 
#if DEBUG
let All_Url = "http://192.168.110.237:9000"
#else
let All_Url = "http://192.168.110.237:9000"
#endif
 
class Services: NSObject {
 
}
 
extension Services{
                class func weekList(quarter:Int)->Observable<BaseResponse<[ListenWeekModel]>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/study/weekList")
                                params.append(key: "quarter", value: quarter)
                                return NetworkRequest.request(params: params, method: .get, progress: false)
                }
}
 
// MARK: -- 登录部分
extension Services{
                class func sendPhoneCode(phone:String)->Observable<BaseResponse<SimpleModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/user/sendPhoneCode")
                                params.append(key: "phone", value: phone)
                                return NetworkRequest.request(params: params, method: .get, progress: true)
                }
 
                class func login(phone:String,code:String)->Observable<BaseResponse<LoginModel>>{
                                                let params = ParamsAppender.build(url: All_Url)
                                                params.interface(url: "/study/base/user/studyLogin")
                                params.append(key: "phone", value: phone)
                                params.append(key: "phoneCode", value: code)
                                return NetworkRequest.request(params: params, method: .post,encoding: JSONEncoding.default, progress: true)
                }
}
 
// MARK: -- 首页
extension Services{
 
}
 
 
// MARK: -- 商品
extension Services{
                class func goodRecommend()->Observable<BaseResponse<[RecommendModel]>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/study/goodRecommend")
                                return NetworkRequest.request(params: params, method: .get, progress: false)
                }
 
                class func goodsList(keywords:String,page:Int,pageSize:Int = 20,type:[String])->Observable<BaseResponse<BaseResponseList<MarketModel>>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/goodListStudy")
                                                .append(key: "keywords", value: keywords)
                                                .append(key: "pageNumber", value: page)
                                                .append(key: "pageSize", value: pageSize)
                                                .append(key: "type", value: type)
                                return NetworkRequest.request(params: params, method: .post,encoding: JSONEncoding.default, progress: false)
                }
 
                class func getIntegral()->Observable<BaseResponse<Int>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/study/getIntegralStudy")
                                return NetworkRequest.request(params: params, method: .get, progress: false)
                }
 
                class func goodTypeStudy()->Observable<BaseResponse<[MarketTypeModel]>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/goodTypeStudy")
                                return NetworkRequest.request(params: params, method: .get, progress: false)
                }
 
                class func goodsDetail(goodsId:Int)->Observable<BaseResponse<MarketDetailModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/goodDetail")
                                                .append(key: "goodId", value: goodsId)
                                return NetworkRequest.request(params: params, method: .get, progress: true)
                }
 
                class func addressList()->Observable<BaseResponse<[AddressModel]>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/shopAddress")
                                return NetworkRequest.request(params: params, method: .get, progress: false)
                }
 
                class func deleteAddress(id:Int)->Observable<BaseResponse<SimpleModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/addressDelete")
                                                .append(key: "id", value: id)
                                return NetworkRequest.request(params: params, method: .get, progress: true)
                }
 
                class func redeemNow(goodId:Int)->Observable<BaseResponse<MarketDetailModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/redeemNow")
                                                .append(key: "goodId", value: goodId)
                                return NetworkRequest.request(params: params, method: .get, progress: true)
                }
 
                class func addressTree()->Observable<BaseResponse<[AddressTreeModel]>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/addressTree")
                                return NetworkRequest.request(params: params, method: .get, progress: true)
                }
 
                class func addressSaveOrUpdate(id:Int?,province:AddressTreeModel?,city:AddressTreeModel?,country:AddressTreeModel?,userName:String?,userPhone:String?,isDefault:Bool,detailAddress:String)->Observable<BaseResponse<SimpleModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/addressSaveOrUpdate")
                                                .append(key: "id", value: id)
                                                .append(key: "address", value: detailAddress)
                                                .append(key: "city", value: city?.name)
                                                .append(key: "cityCode", value: city?.code)
                                                .append(key: "province", value: province?.name)
                                                .append(key: "provinceCode", value: province?.code)
                                                .append(key: "recipient", value: userName)
                                                .append(key: "recipientPhone", value: userPhone)
                                                .append(key: "isDefault", value: (isDefault == true) ? 1:0)
                                return NetworkRequest.request(params: params, method: .post,encoding: JSONEncoding.default, progress: true)
                }
 
                class func setDefaultStudy(id:Int)->Observable<BaseResponse<SimpleModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/setDefaultStudy")
                                                .append(key: "id", value: id)
                                return NetworkRequest.request(params: params, method: .get, progress: true)
                }
 
                class func goodsExchangeStudy(goodsId:Int,number:Int,orderNumber:String,recipientId:Int,remark:String)->Observable<BaseResponse<SimpleModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/goodExchangeStudy")
                                                .append(key: "goodId", value: goodsId)
                                                .append(key: "number", value: number)
                                                .append(key: "orderNumber", value: orderNumber)
                                                .append(key: "recipientId", value: recipientId)
                                                .append(key: "remark", value: remark)
                                return NetworkRequest.request(params: params, method: .post,encoding: JSONEncoding.default, progress: true)
                }
 
                class func userInfo()->Observable<BaseResponse<UserInfoModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/user/userInfo")
                                return NetworkRequest.request(params: params, method: .get, progress: false)
                }
 
                class func integralDetail(pageNum:Int,pageSize:Int = 20,time:String?)->Observable<BaseResponse<BaseResponseList<IntegralModel>>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/study/integralDetail")
                                                .append(key: "pageNum", value: pageNum)
                                                .append(key: "pageSize", value: pageSize)
                                                .append(key: "time", value: time)
                                return NetworkRequest.request(params: params, method: .get, progress: false)
                }
 
                class func exchangeRecord()->Observable<BaseResponse<[ExchangeRecordModel]>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/goods/base/goods/exchangeRecord")
                                return NetworkRequest.request(params: params, method: .get, progress: false)
                }
 
                class func studyGamesRecord()->Observable<BaseResponse<StudyGamesModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/study/record")
                                return NetworkRequest.request(params: params, method: .get, progress: true)
                }
 
                class func logoutStudy()->Observable<BaseResponse<SimpleModel>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/user/logoutStudy")
                                return NetworkRequest.request(params: params, method: .post,encoding: JSONEncoding.default, progress: true)
                }
 
}
 
extension Services{
                class func getAgreement(type:AgreementType)->Observable<BaseResponse<String>>{
                                let params = ParamsAppender.build(url: All_Url)
                                params.interface(url: "/study/base/user/getProtocol")
                                params.append(key: "type", value: type.rawValue)
                                return NetworkRequest.request(params: params, method: .post, progress: true)
                }
}
 
 
extension Services{
                static func startNetworkMonitor(){
                                let manager = NetworkReachabilityManager(host: All_Url)
                                manager?.startListening(onUpdatePerforming: { status in
                                                switch status {
                                                                case .notReachable:alertError(msg: "当前网络不可用")
                                                                case .reachable(let type):
                                                                                switch type{
                                                                                                case .ethernetOrWiFi:alert(msg: "当前为Wi-Fi网络")
                                                                                                case .cellular:alert(msg: "当前为移动网络")
                                                                                }
                                                                default:break
                                                }
                                })
                }
}