123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- //
- // IHAddressService.swift
- // Inhealth
- //
- // Created by weclouds on 2020/1/7.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- class IHAddressService: NSObject {
- static let share = IHAddressService()
- ///国家列表
- lazy var countryList: [DropDownData] = {
- let contrylist = [DropDownData]()
- return contrylist
- }()
- //省份列表
- lazy var provinceList: [DropDownData] = {
- let provinceList = [DropDownData]()
- return provinceList
- }()
- //城市列表
- lazy var cityList: [DropDownData] = {
- let cityList = [DropDownData]()
- return cityList
- }()
-
- //酒店下拉列表
- lazy var hotelList: [DropDownData] = {
- let hotelList = [DropDownData]()
- return hotelList
- }()
-
- ///获取国家列表
- func getContryList(requestSuccess:@escaping ([DropDownData])->Void,requestFail:@escaping (()->Void)){
- let username = AppShare.username
- let client_key = AppShare.client_key
- let os = AppShare.os
- let version = AppShare.version
- let token = AppShare.token
- g_area_country_listHttpRequest(username, client_key: client_key, os: os, version: version, token: token, success: { (json) -> (Void) in
- self.countryList.removeAll()
- let mCountryInfo = DropDown_Info.fromJSON(json)
- let result = mCountryInfo?.result
- guard let list = result?.list else { return}
- for country in list{
- // let mdata =
- self.countryList.append(country)
- }
- requestSuccess(self.countryList)
-
-
- }, fail: requestFail)
- }
-
- ///获取省份列表
- func getProvinceList(_ countryId:String?,requestSuccess:@escaping ([DropDownData]?)->Void,requestFail:@escaping (()->Void)){
- let username = AppShare.username
- let client_key = AppShare.client_key
- let os = AppShare.os
- let version = AppShare.version
- let token = AppShare.token
- g_area_province_listHttpRequest(username, client_key: client_key, os: os, version: version, token: token, countryId: countryId, success: { (json) -> (Void) in
- self.provinceList.removeAll()
- let mProvinceInfo = DropDown_Info.fromJSON(json)
- let result = mProvinceInfo?.result
- guard let list = result?.list else { return}
- for country in list{
- self.provinceList.append(country)
- }
- requestSuccess(self.provinceList)
- }, fail: requestFail)
-
- }
-
- //获取城市列表
- func getCityeList(_ provinceId:String?,requestSuccess:@escaping ([DropDownData]?)->Void,requestFail:@escaping (()->Void)){
- let username = AppShare.username
- let client_key = AppShare.client_key
- let os = AppShare.os
- let version = AppShare.version
- let token = AppShare.token
- g_area_city_listHttpRequest(username, client_key: client_key, os: os, version: version, token: token, provinceId: provinceId, success: { (json) -> (Void) in
- self.cityList.removeAll()
- let mCityInfo = DropDown_Info.fromJSON(json)
- let result = mCityInfo?.result
- guard let list = result?.list else { return}
- for city in list{
- self.cityList.append(city)
- }
- requestSuccess(self.cityList)
- }, fail: requestFail)
- }
-
-
- ///获取酒店下拉列表
- func getHotelList(_ cityId:String?,requestSuccess:@escaping ([DropDownData])->Void,requestFail:@escaping (()->Void)){
- let username = AppShare.username
- let client_key = AppShare.client_key
- let os = AppShare.os
- let version = AppShare.version
- let token = AppShare.token
- g_area_hotel_listHttpRequest(username, client_key: client_key, os: os, version: version, token: token, cityId: cityId, success: { (json) -> (Void) in
- log.debug("hotel json - \(json)")
- self.hotelList.removeAll()
- let mCityInfo = DropDown_Info.fromJSON(json)
- let result = mCityInfo?.result
- if result?.list?.count == 0{
- AppShare.noHotel = true
- }else{
- AppShare.noHotel = false
- }
- guard let list = result?.list else { return}
- for hotel in list{
- self.hotelList.append(hotel)
- }
- requestSuccess(self.hotelList)
- }, fail: requestFail)
- }
-
-
- ///获取酒店下拉列表
- func getHotelWithBuildlist(_ cityId:String?,requestSuccess:@escaping ([Hotel])->Void,requestFail:@escaping (()->Void)){
- let username = AppShare.username
- let client_key = AppShare.client_key
- let os = AppShare.os
- let version = AppShare.version
- let token = AppShare.token
- g_area_hotel_listHttpRequest(username, client_key: client_key, os: os, version: version, token: token, cityId: cityId, success: { (json) -> (Void) in
- log.debug("hotel json - \(json)")
- let mCityInfo = Hotel_List_Info.fromJSON(json)
- let result = mCityInfo?.result
- if result?.list?.count == 0{
- AppShare.noHotel = true
- }else{
- AppShare.noHotel = false
- }
- if result?.code == .Success{
- requestSuccess(result!.list!)
- }else{
- requestFail()
- }
-
- }, fail: requestFail)
- }
-
-
-
-
-
- //获取第一个酒店
- func getFirstHotel(complete:@escaping ((String?,String?)->Void)) {
-
- IHAddressService.share.getContryList(requestSuccess: { (countrys) in
- if countrys.count == 0 {
- return
- }
- let firstCountry = countrys.first
- Intermediate.countryName = (firstCountry?.name)!
- Intermediate.countryId = (firstCountry?.id)!
- //1、有省份
- IHAddressService.share.getProvinceList(firstCountry?.id, requestSuccess: { (provinces) in
- //没有省份
- if provinces == nil || provinces!.count == 0{
- //请求酒店列表
- IHAddressService.share.getHotelList(firstCountry?.id, requestSuccess: { (hotelList) in
- let firstHotel = hotelList.first
- self.getFirstBuild(firstHotel!.id!)
- complete(firstHotel?.id,firstHotel?.name)
- let info = StorageInfo(countryId: Intermediate.countryId, countryName: Intermediate.countryName, provinceId: "", provinceName: "", cityId: "", cityName: "", hotelId: firstHotel?.id, hotelName: firstHotel!.name,buildId:"",buildName:"")
- IHHotelStorage.shareInstance.storageHotelInfo(info)
-
- }) {
- log.debug("失败了")
- }
- }else{//有省份
- let firstProvince = provinces?.first
- //请求城市
- IHAddressService.share.getCityeList(firstProvince?.id, requestSuccess: { (citylist) in
- if citylist == nil || citylist!.count == 0 { //没有城市
- //请求酒店列表 ->省份id
- IHAddressService.share.getHotelList(firstProvince?.id, requestSuccess: { (hotelList) in
- let firstHotel = hotelList.first
- self.getFirstBuild(firstHotel!.id!)
- complete(firstHotel?.id,firstHotel?.name)
- let info = StorageInfo(countryId: Intermediate.countryId, countryName: Intermediate.countryName, provinceId: firstProvince?.id, provinceName: firstProvince?.name, cityId: "", cityName: "", hotelId: firstHotel?.id, hotelName: firstHotel!.name,buildId:"",buildName:"")
- IHHotelStorage.shareInstance.storageHotelInfo(info)
- }) {
- log.debug("失败了")
- }
- }else{
- //请求酒店列表 ->城市id
- let firstCity = citylist?.first
- IHAddressService.share.getHotelList(firstCity?.id, requestSuccess: { (hotelList) in
- let firstHotel = hotelList.first
- complete(firstHotel?.id,firstHotel?.name)
- self.getFirstBuild(firstHotel!.id!)
- let info = StorageInfo(countryId: Intermediate.countryId, countryName: Intermediate.countryName, provinceId: firstProvince?.id, provinceName: firstProvince?.name, cityId: firstCity?.id, cityName: firstCity?.name, hotelId: firstHotel?.id, hotelName: firstHotel!.name,buildId:"",buildName:"")
- IHHotelStorage.shareInstance.storageHotelInfo(info)
- }) {
- log.debug("失败了")
- }
- }
- }) {
- log.debug("失败了")
- }
- }
- }) {
-
- }
- //1.1 有城市
-
- //1.2 无城市
-
- //2、无省份
-
- }) {
-
- }
- }
-
-
- func getFirstBuild(_ hotelId:String) {
- IHAreaService.share.getBuildNavData(hotelId: hotelId, requestSuccess: { (buildList) in
- if buildList.count != 0{
- let build = buildList.first
- Intermediate.buildId = build!.id!
- Intermediate.buildName = build!.name!
- }
-
- }) {
-
- }
- }
- }
|