|
@@ -23,7 +23,8 @@ NSString *const RQUserDataConfigureCompleteUserInfoKey = @"RQUserDataConfigureCo
|
|
|
@property (nonatomic, readwrite, strong) RQUserModel *currentUser;
|
|
|
@property (nonatomic, readwrite, assign) BOOL isObserve;
|
|
|
@property (nonatomic, readwrite, strong) RQLoginViewModel *loginViewModel;
|
|
|
-
|
|
|
+@property (nonatomic, strong) NSArray *cityData;
|
|
|
+@property (nonatomic, strong) NSArray *cityCodeData;
|
|
|
@end
|
|
|
|
|
|
@implementation RQUserManager
|
|
@@ -162,6 +163,7 @@ static id rq_userManager = nil;
|
|
|
}
|
|
|
|
|
|
- (void)loginUser:(RQUserModel *)user{
|
|
|
+ _city_dbId = nil;
|
|
|
/// 保存用户
|
|
|
[self saveUser:user];
|
|
|
|
|
@@ -191,7 +193,7 @@ static id rq_userManager = nil;
|
|
|
RQ_VIP_Module.isSubject4Vip = NO;
|
|
|
RQ_VIP_Module.isSubjectAllVip = NO;
|
|
|
RQ_VIP_Module.videoVipModel = nil;
|
|
|
-
|
|
|
+ _city_dbId = nil;
|
|
|
NSInteger localVersion = [[RQ_APP_VERSION stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
|
|
|
[[RQ_HTTP_Service getJsjpSet] subscribeNext:^(NSArray *setArr) {
|
|
|
[setArr.rac_sequence.signal subscribeNext:^(RQDictInfoModel *dictInfoModel) {
|
|
@@ -276,7 +278,130 @@ static id rq_userManager = nil;
|
|
|
return value;
|
|
|
}
|
|
|
|
|
|
+/// 获取了 db cityid
|
|
|
+- (id)getCityidByCode:(NSString *)code
|
|
|
+{
|
|
|
+ NSString *cityid = @"0";
|
|
|
+ NSString *city = @"";
|
|
|
+ NSArray *cityCodeArray = self.cityCodeData;
|
|
|
+ if(cityCodeArray){
|
|
|
+ for (int i=0; i<cityCodeArray.count; i++) {
|
|
|
+ NSString *ccode = cityCodeArray[i][@"code"];
|
|
|
+ NSString *cname = cityCodeArray[i][@"name"];
|
|
|
+ if ([ccode isEqualToString:code]){
|
|
|
+ city = cname;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (city.length>0){
|
|
|
+ cityid = [self getCityidByName:city];
|
|
|
+ }
|
|
|
+ return cityid;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (id)getCityidByName:(NSString *)name
|
|
|
+{
|
|
|
+ NSString *cityid = @"0";
|
|
|
+ NSArray *cityArray = self.cityData;
|
|
|
+ if(cityArray){
|
|
|
+ NSDictionary *item = [self getRecursive:cityArray name:name];
|
|
|
+ if ([item isKindOfClass:[NSDictionary class]]) {
|
|
|
+ NSString *cid = item[@"id"];
|
|
|
+ NSString *cname = item[@"name"];
|
|
|
+ cityid = cid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cityid;
|
|
|
+}
|
|
|
+
|
|
|
+- (id)getRecursive:(NSArray *)cityArray name:(NSString *)name{
|
|
|
+ if(cityArray){
|
|
|
+ for (int i=0; i<cityArray.count; i++) {
|
|
|
+ NSString *cid = cityArray[i][@"id"];
|
|
|
+ NSString *cname = cityArray[i][@"name"];
|
|
|
+ NSArray *citys = cityArray[i][@"cities"];
|
|
|
+ NSLog(@"cityid = %@ and cityname = %@",cid,cname);
|
|
|
+ if ([cname containsString:@"市"]){
|
|
|
+ if ([cname isEqualToString:name]){
|
|
|
+ return cityArray[i];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if (citys!=nil&&citys.count>0){
|
|
|
+ id list = [self getRecursive:citys name:name];
|
|
|
+ if(list){
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - LazyLoad
|
|
|
+
|
|
|
+- (NSString *)city_dbId{
|
|
|
+ if(!_city_dbId){
|
|
|
+ _city_dbId = [self getCityidByName:RQ_USER_MANAGER.currentUser.cityName];
|
|
|
+ }
|
|
|
+ return _city_dbId;
|
|
|
+}
|
|
|
+- (NSArray *)cityCodeData{
|
|
|
+ if(!_cityCodeData){
|
|
|
+ @autoreleasepool {
|
|
|
+ NSString *filePath = [[NSBundle mainBundle] pathForResource:@"cities" ofType:@"json"];
|
|
|
+ if (filePath) {
|
|
|
+ NSError *error = nil;
|
|
|
+ NSData *jsonData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
|
|
|
+ if (!error) {
|
|
|
+ NSError *jsonError = nil;
|
|
|
+ NSArray *jsonDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&jsonError];
|
|
|
+
|
|
|
+ if (!jsonError && [jsonDictionary isKindOfClass:[NSArray class]]) {
|
|
|
+ _cityCodeData = jsonDictionary;
|
|
|
+ } else {
|
|
|
+ NSLog(@"Error parsing JSON: %@", jsonError);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ NSLog(@"Error reading file: %@", error);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ NSLog(@"JSON file not found.");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return _cityCodeData;
|
|
|
+}
|
|
|
+- (NSArray *)cityData{
|
|
|
+ if(!_cityData){
|
|
|
+ @autoreleasepool {
|
|
|
+ NSString *filePath = [[NSBundle mainBundle] pathForResource:@"DrCityInfoThree" ofType:@"json"];
|
|
|
+ if (filePath) {
|
|
|
+ NSError *error = nil;
|
|
|
+ NSData *jsonData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
|
|
|
+ if (!error) {
|
|
|
+ NSError *jsonError = nil;
|
|
|
+ NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&jsonError];
|
|
|
+
|
|
|
+ if (!jsonError && [jsonDictionary isKindOfClass:[NSDictionary class]]) {
|
|
|
+ _cityData = jsonDictionary[@"provinces"];
|
|
|
+ } else {
|
|
|
+ NSLog(@"Error parsing JSON: %@", jsonError);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ NSLog(@"Error reading file: %@", error);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ NSLog(@"JSON file not found.");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return _cityData;
|
|
|
+}
|
|
|
- (RQLoginViewModel *)loginViewModel {
|
|
|
if (!_loginViewModel) {
|
|
|
_loginViewModel = [[RQLoginViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
|