123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- //
- // ShoppingCarViewModel.swift
- // ADHTuanCan
- //
- // Created by 敖德亨 on 2023/10/30.
- //
- import UIKit
- import RxCocoa
- import RxSwift
- class ShoppingCarViewModel: MCBaseViewModel {
- //MARK: - 获取时间范围
- var HomeTimeGetModel : HomeGetTimeRangRequestModel = HomeGetTimeRangRequestModel.init()
- var TimeRangDetail : HomeTimeRangModel?
- var HomeTimeRequset : MCDataRequest?
-
- func signalGetHomeTime() -> Observable<Int>? {
-
- if let _ = HomeTimeRequset{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.HomeTimeRequset = MCHttpUtil.request(self.HomeTimeGetModel, responseClass: HomeTimeRangModel.self, success: {[unowned self] (data) in
- self.TimeRangDetail = data.data
- self.HomeTimeRequset = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.HomeTimeRequset = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
- //MARK: - 获取购物车详情
- var getShoppingCarMsgResultMeal : GetShoppingCarMsgResultMeal = GetShoppingCarMsgResultMeal.init()
- var ShopCarAllModelList : [ShopMealMsgModel]?
- var getShopCarResult : MCDataRequest?
-
- func signalgetShoppingCarMsg() -> Observable<Int>? {
-
- if let _ = getShopCarResult{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getShopCarResult = MCHttpUtil.request(self.getShoppingCarMsgResultMeal, responseClass: Array<ShopMealMsgModel>.self, success: {[unowned self] (data) in
- self.ShopCarAllModelList = []
- self.ShopCarAllModelList?.append(contentsOf: data.data ?? [])
- self.getShopCarResult = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getShopCarResult = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
- //MARK: - 获取购物车价格
- var getShopCarPriceRModel : GetShoppingCarPriceRequestModel = GetShoppingCarPriceRequestModel.init()
- var shopCarPriceDetail : ShopCarPriceDetailModel?
- var getShopCarRequset : MCDataRequest?
-
- func signalGetShopCarPrice() -> Observable<Int>? {
- if let _ = getShopCarRequset{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getShopCarRequset = MCHttpUtil.request(self.getShopCarPriceRModel, responseClass: ShopCarPriceDetailModel.self, success: {[unowned self] (data) in
- self.shopCarPriceDetail = data.data
- self.getShopCarRequset = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getShopCarRequset = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
-
- //MARK: - 获取配送时段
- var getTimeRequestModel : GetDeliveryTimeRequestModel = GetDeliveryTimeRequestModel.init()
- var deliveryTimeList : [DeliveryTimeModel]?//详情数据
- var getDeliveryTimeRequest : MCDataRequest?
- /// 获取配送时段
- /// - Returns: <#description#>
- func signalGetDeliveryTime() -> Observable<Int>? {
-
- if let _ = getDeliveryTimeRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getDeliveryTimeRequest = MCHttpUtil.request(self.getTimeRequestModel, responseClass: Array<DeliveryTimeModel>.self, success: {[unowned self] (data) in
- self.deliveryTimeList = []
- self.deliveryTimeList?.append(contentsOf: data.data ?? [])
- self.getDeliveryTimeRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getDeliveryTimeRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
-
- //MARK: - 修改套餐
- var editShoppingCarRequestModel : EditorShoppingCarRequestModel = EditorShoppingCarRequestModel.init()
- var editShoppingCarRequest : MCDataRequest?
-
- /// 修改套餐
- /// - Returns: <#description#>
- func signalEditShopCar() -> Observable<Int>? {
-
- if let _ = editShoppingCarRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.editShoppingCarRequest = MCHttpUtil.request(self.editShoppingCarRequestModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
-
- self.editShoppingCarRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.editShoppingCarRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
- //MARK: - 清空购物车
- /// 清空购物车Model
- var cleanShopcarModel : CleanShopcarModel = CleanShopcarModel.init()
- var cleanShopcarRequest : MCDataRequest?
-
- /// 清空购物车Model
- /// - Returns: <#description#>
- func signalCleanShopCar() -> Observable<Int>? {
-
- if let _ = cleanShopcarRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.cleanShopcarRequest = MCHttpUtil.request(self.cleanShopcarModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
-
- self.cleanShopcarRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.cleanShopcarRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
-
- //MARK: - 获取默认地址
- var getDefualAddressModel : GetDefAddressRequestModel = GetDefAddressRequestModel.init()
- var defualAddressModel : AddressModel?
- var getDefualAddRequest : MCDataRequest?
- /// 获取默认地址
- /// - Returns: <#description#>
- func signalGetDefualAdd() -> Observable<Int>? {
-
- if let _ = getDefualAddRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.editShoppingCarRequest = MCHttpUtil.request(self.getDefualAddressModel, responseClass: AddressModel.self, success: {[unowned self] (data) in
- self.defualAddressModel = data.data
- self.getDefualAddRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getDefualAddRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
- /// 结算方式
- var paySetModel : PaySettleTypeModel?
-
- /// 支付方式Model
- var payMentModel : PayMentTypeModel?
-
- //MARK: - 生成订单
- var addOrderModel : AddOrderModel = AddOrderModel.init()
- var orderIdModel : OrderIDmModel?
- var addOrderRequest : MCDataRequest?
- /// 生成订单
- /// - Returns: <#description#>
- func signalAddOrderRequest() -> Observable<Int>? {
-
- if let _ = addOrderRequest{
- return nil
- }
-
- self.addOrderModel.settleId = self.paySetModel?.id
-
- self.addOrderModel.payTypeId = self.payMentModel?.id
-
- return Observable.create {(disposable) -> Disposable in
- self.addOrderRequest = MCHttpUtil.request(self.addOrderModel, responseClass: OrderIDmModel.self, success: {[unowned self] (data) in
- self.orderIdModel = data.data
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.addOrderRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
-
- //MARK: - 配置支付信息
- var getPayConfigurationModel : GetPayConfiguration = GetPayConfiguration.init()
- var payConfiguration : PayConfigurationModel?
- var getPayConfigurationRequest : MCDataRequest?
- /// 配置支付信息
- /// - Returns: <#description#>
- func signalGetPayConfiguration() -> Observable<Int>? {
-
-
- if let _ = getPayConfigurationRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getPayConfigurationRequest = MCHttpUtil.request(self.getPayConfigurationModel, responseClass: PayConfigurationModel.self, success: {[unowned self] (data) in
- self.payConfiguration = data.data
- self.getPayConfigurationRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getPayConfigurationRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
- //MARK: - 根据支付方式获取价格
- var getPriceWithTypeModel : GetPriceWithTypeModel = GetPriceWithTypeModel.init()
- var priceWithTypeModel : PriceWithTypeModel?
- var getPriceWithTypeRequest : MCDataRequest?
- /// 根据支付方式获取价格
- /// - Returns: <#description#>
- func signalGetPriceWithTypeRequest() -> Observable<Int>? {
-
- self.getPriceWithTypeModel.settleId = self.paySetModel?.id
-
- if let _ = getPriceWithTypeRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getPriceWithTypeRequest = MCHttpUtil.request(self.getPriceWithTypeModel, responseClass: PriceWithTypeModel.self, success: {[unowned self] (data) in
- self.priceWithTypeModel = data.data
- self.getPriceWithTypeRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getPriceWithTypeRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
-
- //MARK: - 获取结算方式
- var getPaySettleTypeModel : GetPaySettleTypeModel = GetPaySettleTypeModel.init()
- /// 结算方式列表
- var paySettleList : [PaySettleTypeModel]?
-
- var getPaySettleRequest : MCDataRequest?
- /// 获取结算方式
- /// - Returns: <#description#>
- func signalGetPaySettleType() -> Observable<Int>? {
-
- if let _ = getPaySettleRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getPaySettleRequest = MCHttpUtil.request(self.getPaySettleTypeModel, responseClass: Array<PaySettleTypeModel>.self, success: {[unowned self] (data) in
- self.paySettleList = []
- self.paySettleList?.append(contentsOf: data.data ?? [])
- self.getPaySettleRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getPaySettleRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
- //MARK: - 获取支付方式
- var getPayPayMentTypeModel : GetPayPaymentTypeModel = GetPayPaymentTypeModel.init()
- /// 结算方式列表
- var payMentList : [PayMentTypeModel]?
- var getPayMentRequest : MCDataRequest?
- /// 获取支付方式
- /// - Returns: <#description#>
- func signalGetPayMentType() -> Observable<Int>? {
-
- if let _ = getPayMentRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getPayMentRequest = MCHttpUtil.request(self.getPayPayMentTypeModel, responseClass: Array<PayMentTypeModel>.self, success: {[unowned self] (data) in
- self.payMentList = []
- self.payMentList?.append(contentsOf: data.data ?? [])
- self.getPayMentRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getPayMentRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
- //MARK: - 获取是否密码支付or StripePay
- var getIsStripePayModel : GetIsStripePayModel = GetIsStripePayModel.init()
- /// 拉起支付密码支付
- var isStripePayModel : IsStripePayModel?
- var getIsStripePayRequest : MCDataRequest?
- /// 获取是否密码支付or StripePay
- /// - Returns: <#description#>
- func signalGetIsStripePayRequest() -> Observable<Int>? {
-
- if let _ = getIsStripePayRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getIsStripePayRequest = MCHttpUtil.request(self.getIsStripePayModel, responseClass: IsStripePayModel.self, success: {[unowned self] (data) in
- self.isStripePayModel = data.data
- self.getIsStripePayRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getIsStripePayRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
- //MARK: - 密码支付
- var pswPayModel : PSWPayRequestModel = PSWPayRequestModel.init()
- var pswPayRequest : MCDataRequest?
- /// 密码支付
- /// - Returns: <#description#>
- func signalPSWPay() -> Observable<Int>? {
-
- if let _ = pswPayRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.pswPayRequest = MCHttpUtil.request(self.pswPayModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
-
- self.pswPayRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.pswPayRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
- }
|