OrderViewModel.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // OrderViewModel.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/5.
  6. //
  7. import UIKit
  8. import RxCocoa
  9. import RxSwift
  10. class OrderViewModel: MCBaseViewModel {
  11. var shopType = OrderGeneraType.whiteOrder
  12. var orderType = OrderTypeEnumProtocol.willPay
  13. //MARK: - 获取订单列表
  14. var getOrderListModel : GetOrderListModel = GetOrderListModel.init()
  15. var dataList : [OrderListModel]?
  16. var getOrderListRequset : MCDataRequest?
  17. func signalGetOrderList(_ isFirstPage: Bool) -> Observable<Int>? {
  18. if let _ = getOrderListRequset{
  19. return nil
  20. }
  21. if isFirstPage{
  22. self.getOrderListModel.current = 1
  23. }
  24. if self.shopType == .whiteOrder{
  25. self.getOrderListModel.isGeneral = "2"
  26. }
  27. if self.shopType == .generalOrder{
  28. self.getOrderListModel.isGeneral = "1"
  29. }
  30. if self.orderType == .willPay{
  31. self.getOrderListModel.status = "1"
  32. }
  33. if self.orderType == .takeOrdering{
  34. self.getOrderListModel.status = "2"
  35. }
  36. if self.orderType == .delivery{
  37. self.getOrderListModel.status = "3"
  38. }
  39. if self.orderType == .finish{
  40. self.getOrderListModel.status = "4"
  41. }
  42. if self.orderType == .all{
  43. self.getOrderListModel.status = nil
  44. }
  45. return Observable.create {(disposable) -> Disposable in
  46. self.getOrderListRequset = MCHttpUtil.request(self.getOrderListModel, responseClass: Array<OrderListModel>.self, success: {[unowned self] (data) in
  47. if isFirstPage{
  48. self.dataList = []
  49. }
  50. self.dataList?.append(contentsOf: data.data ?? [])
  51. self.getOrderListModel.current! = self.getOrderListModel.current! + 1
  52. self.getOrderListRequset = nil
  53. disposable.onNext(data.responseData?.count ?? 0)
  54. disposable.onCompleted()
  55. }, error: {[weak self] (error) in
  56. self?.getOrderListRequset = nil
  57. disposable.onError(error)
  58. })
  59. return Disposables.create()
  60. }
  61. }
  62. //MARK: - 获取订单详情
  63. var getOrderDetailModel : GetOrderDetailModel = GetOrderDetailModel.init()
  64. var orderOutDataModel : OrderOutDetailModel?
  65. var getOrderDetailRequset : MCDataRequest?
  66. func signalGetOrderDetail() -> Observable<Int>? {
  67. if let _ = getOrderDetailRequset{
  68. return nil
  69. }
  70. return Observable.create {(disposable) -> Disposable in
  71. self.getOrderDetailRequset = MCHttpUtil.request(self.getOrderDetailModel, responseClass: OrderOutDetailModel.self, success: {[unowned self] (data) in
  72. self.orderOutDataModel = data.data
  73. self.getOrderDetailRequset = nil
  74. disposable.onNext(data.responseData?.count ?? 0)
  75. disposable.onCompleted()
  76. }, error: {[weak self] (error) in
  77. self?.getOrderDetailRequset = nil
  78. disposable.onError(error)
  79. })
  80. return Disposables.create()
  81. }
  82. }
  83. //MARK: - 获取支付方式
  84. var getPayPayMentTypeModel : GetPayPaymentTypeModel = GetPayPaymentTypeModel.init()
  85. /// 结算方式列表
  86. var payMentList : [PayMentTypeModel]?
  87. var getPayMentRequest : MCDataRequest?
  88. /// 获取支付方式
  89. /// - Returns: <#description#>
  90. func signalGetPayMentType() -> Observable<Int>? {
  91. if let _ = getPayMentRequest{
  92. return nil
  93. }
  94. return Observable.create {(disposable) -> Disposable in
  95. self.getPayMentRequest = MCHttpUtil.request(self.getPayPayMentTypeModel, responseClass: Array<PayMentTypeModel>.self, success: {[unowned self] (data) in
  96. self.payMentList = []
  97. self.payMentList?.append(contentsOf: data.data ?? [])
  98. self.getPayMentRequest = nil
  99. disposable.onNext(data.responseData?.count ?? 0)
  100. disposable.onCompleted()
  101. }, error: {[weak self] (error) in
  102. self?.getPayMentRequest = nil
  103. disposable.onError(error)
  104. })
  105. return Disposables.create()
  106. }
  107. }
  108. //MARK: - 获取是否密码支付or StripePay
  109. var getIsStripePayModel : GetIsStripePayModel = GetIsStripePayModel.init()
  110. /// 拉起支付密码支付
  111. var isStripePayModel : IsStripePayModel?
  112. var getIsStripePayRequest : MCDataRequest?
  113. /// 获取是否密码支付or StripePay
  114. /// - Returns: <#description#>
  115. func signalGetIsStripePayRequest() -> Observable<Int>? {
  116. if let _ = getIsStripePayRequest{
  117. return nil
  118. }
  119. return Observable.create {(disposable) -> Disposable in
  120. self.getIsStripePayRequest = MCHttpUtil.request(self.getIsStripePayModel, responseClass: IsStripePayModel.self, success: {[unowned self] (data) in
  121. self.isStripePayModel = data.data
  122. self.getIsStripePayRequest = nil
  123. disposable.onNext(data.responseData?.count ?? 0)
  124. disposable.onCompleted()
  125. }, error: {[weak self] (error) in
  126. self?.getIsStripePayRequest = nil
  127. disposable.onError(error)
  128. })
  129. return Disposables.create()
  130. }
  131. }
  132. //MARK: - 配置支付信息
  133. var getPayConfigurationModel : GetPayConfiguration = GetPayConfiguration.init()
  134. var payConfiguration : PayConfigurationModel?
  135. var getPayConfigurationRequest : MCDataRequest?
  136. /// 配置支付信息
  137. /// - Returns: <#description#>
  138. func signalGetPayConfiguration() -> Observable<Int>? {
  139. if let _ = getPayConfigurationRequest{
  140. return nil
  141. }
  142. return Observable.create {(disposable) -> Disposable in
  143. self.getPayConfigurationRequest = MCHttpUtil.request(self.getPayConfigurationModel, responseClass: PayConfigurationModel.self, success: {[unowned self] (data) in
  144. self.payConfiguration = data.data
  145. self.getPayConfigurationRequest = nil
  146. disposable.onNext(data.responseData?.count ?? 0)
  147. disposable.onCompleted()
  148. }, error: {[weak self] (error) in
  149. self?.getPayConfigurationRequest = nil
  150. disposable.onError(error)
  151. })
  152. return Disposables.create()
  153. }
  154. }
  155. //MARK: - 密码支付
  156. var pswPayModel : PSWPayRequestModel = PSWPayRequestModel.init()
  157. var pswPayRequest : MCDataRequest?
  158. /// 密码支付
  159. /// - Returns: <#description#>
  160. func signalPSWPay() -> Observable<Int>? {
  161. if let _ = pswPayRequest{
  162. return nil
  163. }
  164. return Observable.create {(disposable) -> Disposable in
  165. self.pswPayRequest = MCHttpUtil.request(self.pswPayModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
  166. self.pswPayRequest = nil
  167. disposable.onNext(data.responseData?.count ?? 0)
  168. disposable.onCompleted()
  169. }, error: {[weak self] (error) in
  170. self?.pswPayRequest = nil
  171. disposable.onError(error)
  172. })
  173. return Disposables.create()
  174. }
  175. }
  176. //MARK: - 取消订单
  177. var cancelOrderModel : CancelOrderModel = CancelOrderModel.init()
  178. /// Request
  179. var cancelOrderRequest : MCDataRequest?
  180. /// 取消订单
  181. /// - Returns: <#description#>
  182. func signalCancelOrder() -> Observable<Int>? {
  183. if let _ = cancelOrderRequest{
  184. return nil
  185. }
  186. return Observable.create {(disposable) -> Disposable in
  187. self.cancelOrderRequest = MCHttpUtil.request(self.cancelOrderModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
  188. self.cancelOrderRequest = nil
  189. disposable.onNext(data.responseData?.count ?? 0)
  190. disposable.onCompleted()
  191. }, error: {[weak self] (error) in
  192. self?.cancelOrderRequest = nil
  193. disposable.onError(error)
  194. })
  195. return Disposables.create()
  196. }
  197. }
  198. //MARK: - 修改订单地址
  199. var editOrderAddressModel : EditOrderAddressModel = EditOrderAddressModel.init()
  200. /// 修改订单地址Request
  201. var editOrderAddrRequest : MCDataRequest?
  202. /// 修改订单地址
  203. /// - Returns: <#description#>
  204. func signalEditOrderAddress() -> Observable<Int>? {
  205. if let _ = editOrderAddrRequest{
  206. return nil
  207. }
  208. return Observable.create {(disposable) -> Disposable in
  209. self.editOrderAddrRequest = MCHttpUtil.request(self.editOrderAddressModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
  210. self.editOrderAddrRequest = nil
  211. disposable.onNext(data.responseData?.count ?? 0)
  212. disposable.onCompleted()
  213. }, error: {[weak self] (error) in
  214. self?.editOrderAddrRequest = nil
  215. disposable.onError(error)
  216. })
  217. return Disposables.create()
  218. }
  219. }
  220. //MARK: - 确认收货
  221. /// 确认收货MOdle
  222. var confirmReceiptModel : ConfirmReceiptModel = ConfirmReceiptModel.init()
  223. /// 确认收货Request
  224. var confirmReceiptRequest : MCDataRequest?
  225. /// 确认收货MOdle
  226. /// - Returns: <#description#>
  227. func signalConfirmReceipt() -> Observable<Int>? {
  228. if let _ = confirmReceiptRequest{
  229. return nil
  230. }
  231. return Observable.create {(disposable) -> Disposable in
  232. self.confirmReceiptRequest = MCHttpUtil.request(self.confirmReceiptModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
  233. self.confirmReceiptRequest = nil
  234. disposable.onNext(data.responseData?.count ?? 0)
  235. disposable.onCompleted()
  236. }, error: {[weak self] (error) in
  237. self?.confirmReceiptRequest = nil
  238. disposable.onError(error)
  239. })
  240. return Disposables.create()
  241. }
  242. }
  243. //MARK: - 获取客服电话
  244. /// 获取客服电话MOdle
  245. var getServiceTelModel : GetServiceTelModel = GetServiceTelModel.init()
  246. /// 客服电话MOdle
  247. var serviceTelModel : ServiceTelModel?
  248. /// 获取客服电话Request
  249. var getServiceTelRequest : MCDataRequest?
  250. /// 获取客服电话
  251. /// - Returns: <#description#>
  252. func signalGetServiceTell() -> Observable<Int>? {
  253. if let _ = getServiceTelRequest{
  254. return nil
  255. }
  256. return Observable.create {(disposable) -> Disposable in
  257. self.getServiceTelRequest = MCHttpUtil.request(self.getServiceTelModel, responseClass: ServiceTelModel.self, success: {[unowned self] (data) in
  258. self.serviceTelModel = data.data
  259. self.getServiceTelRequest = nil
  260. disposable.onNext(data.responseData?.count ?? 0)
  261. disposable.onCompleted()
  262. }, error: {[weak self] (error) in
  263. self?.getServiceTelRequest = nil
  264. disposable.onError(error)
  265. })
  266. return Disposables.create()
  267. }
  268. }
  269. }