You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

142 lines
4.9 KiB

//
// FamilyContact.m
// tongxin
//
// Created by ecell on 2021/7/15.
// Copyright © 2021 xTT. All rights reserved.
//
#import "FamilyContact.h"
#import "Device.h"
#import "User.h"
@implementation FamilyContact
-(void)save:(FamilyContact *)familyContact success:(void (^)(void))success failure:(void (^)(NSError *error))failure{
NSString *urlStr = HTTP_FAMILY__CONTACT;
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
[parameter setValue:familyContact.number forKey:@"number"];
[parameter setValue:familyContact.name forKey:@"name"];
[parameter setValue:familyContact.phone forKey:@"phone"];
[parameter setValue:cUser.cDevice.imei forKey:@"imei"];
[parameter setValue:@"1" forKey:@"type"];
[xMyHttp URL:urlStr
method:@"POST" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"result"] intValue] == 1) {
success();
} else {
if (failure) {
NSString *domain = @"com.ecellsz.lekang.guard";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
-(void)update:(FamilyContact *)familyContact success:(void (^)(void))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = HTTP_FAMILY__CONTACT;
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
[parameter setValue:familyContact.number forKey:@"number"];
[parameter setValue:familyContact.name forKey:@"name"];
[parameter setValue:familyContact.phone forKey:@"phone"];
[parameter setValue:cUser.cDevice.imei forKey:@"imei"];
[parameter setValue:familyContact.id forKey:@"id"];
[parameter setValue:@"1" forKey:@"type"];
[xMyHttp URL:urlStr
method:@"PATCH" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"result"] intValue] == 1) {
success();
} else {
if (failure) {
NSString *domain = @"com.ecellsz.lekang.guard";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
-(void)query:(void (^)(NSMutableArray *arr))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = HTTP_FAMILY__CONTACT;
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
[parameter setValue:cUser.cDevice.imei forKey:@"imei"];
[parameter setValue:@"1" forKey:@"type"];
[xMyHttp URL:urlStr
method:@"GET" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"result"] intValue] == 1) {
NSMutableArray *arr = [FamilyContact mj_objectArrayWithKeyValuesArray:responseObject[@"familyPhones"]];
success(arr);
} else {
if (failure) {
NSString *domain = @"com.ecellsz.lekang.guard";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
-(void)deleteOne:(NSString *)cid imei:(NSString *)imei success:(void (^)(void))success failure:(void (^)(NSError *error))failure {
NSString *urlStr = HTTP_FAMILY__CONTACT;
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
[parameter setValue:cUser.cDevice.imei forKey:@"imei"];
[parameter setValue:cid forKey:@"id"];
[parameter setValue:@"1" forKey:@"type"];
[xMyHttp URL:urlStr
method:@"DELETE" parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"result"] intValue] == 1) {
success();
} else {
if (failure) {
NSString *domain = @"com.ecellsz.lekang.guard";
NSDictionary *userInfo = @{@"msg" : responseObject[@"msg"]};
NSError *err = [NSError errorWithDomain:domain code:-1 userInfo:userInfo];
failure(err);
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
}
@end