ShoppingCarViewModel.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. //
  2. // ShoppingCarViewModel.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/10/30.
  6. //
  7. import UIKit
  8. import RxCocoa
  9. import RxSwift
  10. class ShoppingCarViewModel: MCBaseViewModel {
  11. //MARK: - 获取时间范围
  12. var HomeTimeGetModel : HomeGetTimeRangRequestModel = HomeGetTimeRangRequestModel.init()
  13. var TimeRangDetail : HomeTimeRangModel?
  14. var HomeTimeRequset : MCDataRequest?
  15. func signalGetHomeTime() -> Observable<Int>? {
  16. if let _ = HomeTimeRequset{
  17. return nil
  18. }
  19. return Observable.create {(disposable) -> Disposable in
  20. self.HomeTimeRequset = MCHttpUtil.request(self.HomeTimeGetModel, responseClass: HomeTimeRangModel.self, success: {[unowned self] (data) in
  21. self.TimeRangDetail = data.data
  22. self.HomeTimeRequset = nil
  23. disposable.onNext(data.responseData?.count ?? 0)
  24. disposable.onCompleted()
  25. }, error: {[weak self] (error) in
  26. self?.HomeTimeRequset = nil
  27. disposable.onError(error)
  28. })
  29. return Disposables.create()
  30. }
  31. }
  32. //MARK: - 获取购物车详情
  33. var getShoppingCarMsgResultMeal : GetShoppingCarMsgResultMeal = GetShoppingCarMsgResultMeal.init()
  34. var ShopCarAllModelList : [ShopMealMsgModel]?
  35. var getShopCarResult : MCDataRequest?
  36. func signalgetShoppingCarMsg() -> Observable<Int>? {
  37. if let _ = getShopCarResult{
  38. return nil
  39. }
  40. return Observable.create {(disposable) -> Disposable in
  41. self.getShopCarResult = MCHttpUtil.request(self.getShoppingCarMsgResultMeal, responseClass: Array<ShopMealMsgModel>.self, success: {[unowned self] (data) in
  42. self.ShopCarAllModelList = []
  43. self.ShopCarAllModelList?.append(contentsOf: data.data ?? [])
  44. self.getShopCarResult = nil
  45. disposable.onNext(data.responseData?.count ?? 0)
  46. disposable.onCompleted()
  47. }, error: {[weak self] (error) in
  48. self?.getShopCarResult = nil
  49. disposable.onError(error)
  50. })
  51. return Disposables.create()
  52. }
  53. }
  54. //MARK: - 获取购物车价格
  55. var getShopCarPriceRModel : GetShoppingCarPriceRequestModel = GetShoppingCarPriceRequestModel.init()
  56. var shopCarPriceDetail : ShopCarPriceDetailModel?
  57. var getShopCarRequset : MCDataRequest?
  58. func signalGetShopCarPrice() -> Observable<Int>? {
  59. if let _ = getShopCarRequset{
  60. return nil
  61. }
  62. return Observable.create {(disposable) -> Disposable in
  63. self.getShopCarRequset = MCHttpUtil.request(self.getShopCarPriceRModel, responseClass: ShopCarPriceDetailModel.self, success: {[unowned self] (data) in
  64. self.shopCarPriceDetail = data.data
  65. self.getShopCarRequset = nil
  66. disposable.onNext(data.responseData?.count ?? 0)
  67. disposable.onCompleted()
  68. }, error: {[weak self] (error) in
  69. self?.getShopCarRequset = nil
  70. disposable.onError(error)
  71. })
  72. return Disposables.create()
  73. }
  74. }
  75. //MARK: - 获取配送时段
  76. var getTimeRequestModel : GetDeliveryTimeRequestModel = GetDeliveryTimeRequestModel.init()
  77. var deliveryTimeList : [DeliveryTimeModel]?//详情数据
  78. var getDeliveryTimeRequest : MCDataRequest?
  79. /// 获取配送时段
  80. /// - Returns: <#description#>
  81. func signalGetDeliveryTime() -> Observable<Int>? {
  82. if let _ = getDeliveryTimeRequest{
  83. return nil
  84. }
  85. return Observable.create {(disposable) -> Disposable in
  86. self.getDeliveryTimeRequest = MCHttpUtil.request(self.getTimeRequestModel, responseClass: Array<DeliveryTimeModel>.self, success: {[unowned self] (data) in
  87. self.deliveryTimeList = []
  88. self.deliveryTimeList?.append(contentsOf: data.data ?? [])
  89. self.getDeliveryTimeRequest = nil
  90. disposable.onNext(data.responseData?.count ?? 0)
  91. disposable.onCompleted()
  92. }, error: {[weak self] (error) in
  93. self?.getDeliveryTimeRequest = nil
  94. disposable.onError(error)
  95. })
  96. return Disposables.create()
  97. }
  98. }
  99. //MARK: - 修改套餐
  100. var editShoppingCarRequestModel : EditorShoppingCarRequestModel = EditorShoppingCarRequestModel.init()
  101. var editShoppingCarRequest : MCDataRequest?
  102. /// 修改套餐
  103. /// - Returns: <#description#>
  104. func signalEditShopCar() -> Observable<Int>? {
  105. if let _ = editShoppingCarRequest{
  106. return nil
  107. }
  108. return Observable.create {(disposable) -> Disposable in
  109. self.editShoppingCarRequest = MCHttpUtil.request(self.editShoppingCarRequestModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
  110. self.editShoppingCarRequest = nil
  111. disposable.onNext(data.responseData?.count ?? 0)
  112. disposable.onCompleted()
  113. }, error: {[weak self] (error) in
  114. self?.editShoppingCarRequest = nil
  115. disposable.onError(error)
  116. })
  117. return Disposables.create()
  118. }
  119. }
  120. //MARK: - 清空购物车
  121. /// 清空购物车Model
  122. var cleanShopcarModel : CleanShopcarModel = CleanShopcarModel.init()
  123. var cleanShopcarRequest : MCDataRequest?
  124. /// 清空购物车Model
  125. /// - Returns: <#description#>
  126. func signalCleanShopCar() -> Observable<Int>? {
  127. if let _ = cleanShopcarRequest{
  128. return nil
  129. }
  130. return Observable.create {(disposable) -> Disposable in
  131. self.cleanShopcarRequest = MCHttpUtil.request(self.cleanShopcarModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
  132. self.cleanShopcarRequest = nil
  133. disposable.onNext(data.responseData?.count ?? 0)
  134. disposable.onCompleted()
  135. }, error: {[weak self] (error) in
  136. self?.cleanShopcarRequest = nil
  137. disposable.onError(error)
  138. })
  139. return Disposables.create()
  140. }
  141. }
  142. //MARK: - 获取默认地址
  143. var getDefualAddressModel : GetDefAddressRequestModel = GetDefAddressRequestModel.init()
  144. var defualAddressModel : AddressModel?
  145. var getDefualAddRequest : MCDataRequest?
  146. /// 获取默认地址
  147. /// - Returns: <#description#>
  148. func signalGetDefualAdd() -> Observable<Int>? {
  149. if let _ = getDefualAddRequest{
  150. return nil
  151. }
  152. return Observable.create {(disposable) -> Disposable in
  153. self.editShoppingCarRequest = MCHttpUtil.request(self.getDefualAddressModel, responseClass: AddressModel.self, success: {[unowned self] (data) in
  154. self.defualAddressModel = data.data
  155. self.getDefualAddRequest = nil
  156. disposable.onNext(data.responseData?.count ?? 0)
  157. disposable.onCompleted()
  158. }, error: {[weak self] (error) in
  159. self?.getDefualAddRequest = nil
  160. disposable.onError(error)
  161. })
  162. return Disposables.create()
  163. }
  164. }
  165. /// 结算方式
  166. var paySetModel : PaySettleTypeModel?
  167. /// 支付方式Model
  168. var payMentModel : PayMentTypeModel?
  169. //MARK: - 生成订单
  170. var addOrderModel : AddOrderModel = AddOrderModel.init()
  171. var orderIdModel : OrderIDmModel?
  172. var addOrderRequest : MCDataRequest?
  173. /// 生成订单
  174. /// - Returns: <#description#>
  175. func signalAddOrderRequest() -> Observable<Int>? {
  176. if let _ = addOrderRequest{
  177. return nil
  178. }
  179. self.addOrderModel.settleId = self.paySetModel?.id
  180. self.addOrderModel.payTypeId = self.payMentModel?.id
  181. return Observable.create {(disposable) -> Disposable in
  182. self.addOrderRequest = MCHttpUtil.request(self.addOrderModel, responseClass: OrderIDmModel.self, success: {[unowned self] (data) in
  183. self.orderIdModel = data.data
  184. disposable.onNext(data.responseData?.count ?? 0)
  185. disposable.onCompleted()
  186. }, error: {[weak self] (error) in
  187. self?.addOrderRequest = nil
  188. disposable.onError(error)
  189. })
  190. return Disposables.create()
  191. }
  192. }
  193. //MARK: - 配置支付信息
  194. var getPayConfigurationModel : GetPayConfiguration = GetPayConfiguration.init()
  195. var payConfiguration : PayConfigurationModel?
  196. var getPayConfigurationRequest : MCDataRequest?
  197. /// 配置支付信息
  198. /// - Returns: <#description#>
  199. func signalGetPayConfiguration() -> Observable<Int>? {
  200. if let _ = getPayConfigurationRequest{
  201. return nil
  202. }
  203. return Observable.create {(disposable) -> Disposable in
  204. self.getPayConfigurationRequest = MCHttpUtil.request(self.getPayConfigurationModel, responseClass: PayConfigurationModel.self, success: {[unowned self] (data) in
  205. self.payConfiguration = data.data
  206. self.getPayConfigurationRequest = nil
  207. disposable.onNext(data.responseData?.count ?? 0)
  208. disposable.onCompleted()
  209. }, error: {[weak self] (error) in
  210. self?.getPayConfigurationRequest = nil
  211. disposable.onError(error)
  212. })
  213. return Disposables.create()
  214. }
  215. }
  216. //MARK: - 根据支付方式获取价格
  217. var getPriceWithTypeModel : GetPriceWithTypeModel = GetPriceWithTypeModel.init()
  218. var priceWithTypeModel : PriceWithTypeModel?
  219. var getPriceWithTypeRequest : MCDataRequest?
  220. /// 根据支付方式获取价格
  221. /// - Returns: <#description#>
  222. func signalGetPriceWithTypeRequest() -> Observable<Int>? {
  223. self.getPriceWithTypeModel.settleId = self.paySetModel?.id
  224. if let _ = getPriceWithTypeRequest{
  225. return nil
  226. }
  227. return Observable.create {(disposable) -> Disposable in
  228. self.getPriceWithTypeRequest = MCHttpUtil.request(self.getPriceWithTypeModel, responseClass: PriceWithTypeModel.self, success: {[unowned self] (data) in
  229. self.priceWithTypeModel = data.data
  230. self.getPriceWithTypeRequest = nil
  231. disposable.onNext(data.responseData?.count ?? 0)
  232. disposable.onCompleted()
  233. }, error: {[weak self] (error) in
  234. self?.getPriceWithTypeRequest = nil
  235. disposable.onError(error)
  236. })
  237. return Disposables.create()
  238. }
  239. }
  240. //MARK: - 获取结算方式
  241. var getPaySettleTypeModel : GetPaySettleTypeModel = GetPaySettleTypeModel.init()
  242. /// 结算方式列表
  243. var paySettleList : [PaySettleTypeModel]?
  244. var getPaySettleRequest : MCDataRequest?
  245. /// 获取结算方式
  246. /// - Returns: <#description#>
  247. func signalGetPaySettleType() -> Observable<Int>? {
  248. if let _ = getPaySettleRequest{
  249. return nil
  250. }
  251. return Observable.create {(disposable) -> Disposable in
  252. self.getPaySettleRequest = MCHttpUtil.request(self.getPaySettleTypeModel, responseClass: Array<PaySettleTypeModel>.self, success: {[unowned self] (data) in
  253. self.paySettleList = []
  254. self.paySettleList?.append(contentsOf: data.data ?? [])
  255. self.getPaySettleRequest = nil
  256. disposable.onNext(data.responseData?.count ?? 0)
  257. disposable.onCompleted()
  258. }, error: {[weak self] (error) in
  259. self?.getPaySettleRequest = nil
  260. disposable.onError(error)
  261. })
  262. return Disposables.create()
  263. }
  264. }
  265. //MARK: - 获取支付方式
  266. var getPayPayMentTypeModel : GetPayPaymentTypeModel = GetPayPaymentTypeModel.init()
  267. /// 结算方式列表
  268. var payMentList : [PayMentTypeModel]?
  269. var getPayMentRequest : MCDataRequest?
  270. /// 获取支付方式
  271. /// - Returns: <#description#>
  272. func signalGetPayMentType() -> Observable<Int>? {
  273. if let _ = getPayMentRequest{
  274. return nil
  275. }
  276. return Observable.create {(disposable) -> Disposable in
  277. self.getPayMentRequest = MCHttpUtil.request(self.getPayPayMentTypeModel, responseClass: Array<PayMentTypeModel>.self, success: {[unowned self] (data) in
  278. self.payMentList = []
  279. self.payMentList?.append(contentsOf: data.data ?? [])
  280. self.getPayMentRequest = nil
  281. disposable.onNext(data.responseData?.count ?? 0)
  282. disposable.onCompleted()
  283. }, error: {[weak self] (error) in
  284. self?.getPayMentRequest = nil
  285. disposable.onError(error)
  286. })
  287. return Disposables.create()
  288. }
  289. }
  290. //MARK: - 获取是否密码支付or StripePay
  291. var getIsStripePayModel : GetIsStripePayModel = GetIsStripePayModel.init()
  292. /// 拉起支付密码支付
  293. var isStripePayModel : IsStripePayModel?
  294. var getIsStripePayRequest : MCDataRequest?
  295. /// 获取是否密码支付or StripePay
  296. /// - Returns: <#description#>
  297. func signalGetIsStripePayRequest() -> Observable<Int>? {
  298. if let _ = getIsStripePayRequest{
  299. return nil
  300. }
  301. return Observable.create {(disposable) -> Disposable in
  302. self.getIsStripePayRequest = MCHttpUtil.request(self.getIsStripePayModel, responseClass: IsStripePayModel.self, success: {[unowned self] (data) in
  303. self.isStripePayModel = data.data
  304. self.getIsStripePayRequest = nil
  305. disposable.onNext(data.responseData?.count ?? 0)
  306. disposable.onCompleted()
  307. }, error: {[weak self] (error) in
  308. self?.getIsStripePayRequest = nil
  309. disposable.onError(error)
  310. })
  311. return Disposables.create()
  312. }
  313. }
  314. //MARK: - 密码支付
  315. var pswPayModel : PSWPayRequestModel = PSWPayRequestModel.init()
  316. var pswPayRequest : MCDataRequest?
  317. /// 密码支付
  318. /// - Returns: <#description#>
  319. func signalPSWPay() -> Observable<Int>? {
  320. if let _ = pswPayRequest{
  321. return nil
  322. }
  323. return Observable.create {(disposable) -> Disposable in
  324. self.pswPayRequest = MCHttpUtil.request(self.pswPayModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
  325. self.pswPayRequest = nil
  326. disposable.onNext(data.responseData?.count ?? 0)
  327. disposable.onCompleted()
  328. }, error: {[weak self] (error) in
  329. self?.pswPayRequest = nil
  330. disposable.onError(error)
  331. })
  332. return Disposables.create()
  333. }
  334. }
  335. }