| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934 |
- //
- // RADataProvider.m
- // iSales-USAI
- //
- // Created by Rui Zhang on 11/11/21.
- // Copyright © 2021 United Software Applications, Inc. All rights reserved.
- //
- #import "RADataProvider.h"
- #import "ZipArchive.h"
- #import "ActiveViewController.h"
- @implementation RADataProvider
- #ifdef SCANNER_ORDER
- +(NSMutableDictionary*)scan_search:(NSString*)keyword
- {
- // NSMutableArray* arr = [NSMutableArray new];
-
-
- if(keyword.length==0)
- keyword=@"";
- int count = 0;
- NSMutableDictionary * ret = [NSMutableDictionary new];
- ret[@"result"]=@2;
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- // NSArray* keys=[dict allKeys];
-
- for(int i=0;i<appDelegate.scan_model_key.count;i++)
- {
- NSString* key = appDelegate.scan_model_key[i];
- if([key.lowercaseString containsString:keyword.lowercaseString]||keyword.length==0)
- {
- ret[[NSString stringWithFormat:@"item_%d",count]]=appDelegate.scan_model[key];
- // [arr addObject:dict[key]];
- count ++;
- }
-
-
- }
- ret[@"count"]=@(count);
- return ret;
- // int a=0;
-
- }
- +(void)request_scansearch:(long ) offset limit :(long)limit keywords :(NSString*) keywords completionHandler:(resultHandler)result
- {
- result([self scan_search:keywords]);
-
- return;
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(appDelegate.user!=nil)
- // [params setValue:appDelegate.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- // if(appDelegate.password!=nil)
- // [params setValue:appDelegate.password forKey:@"password"];
- // if(appDelegate.order_code!=nil)
- // [params setValue:appDelegate.order_code forKey:@"orderCode"];
- // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
- // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
- // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
- // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
- // [params setValue:filter forKey:@"filter"];
- [params setValue:keywords forKey:@"keyword"];
- [params setValue:@"search" forKey:@"_method"];
- params[@"site_name"]=[self getSiteName];
- [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
- [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
-
- [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
- // if(appDelegate.offline_mode)
- // {
- // return [OLDataProvider offline_search:params];
- // }
- // if(![self IsNetworkAvailable])
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- //
- // NSData* json=[self get_json:URL_SEARCH parameters:params];
- // if(json==nil)
- // return nil;
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // return jsobj;
- }
- +(void)encrypt_scan_models
- {
- return;
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- NSString* templatefile = [unZipTo stringByAppendingPathComponent:@"offline_models.json"];
- NSString* str = [NSString stringWithContentsOfFile:templatefile encoding:NSUTF8StringEncoding error:nil];
- NSString * stre = [AESCrypt encrypt:str password:@"usai2010"];
- // NSString *writePath = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp/haha.txt"];
- NSError *error;
- [stre writeToFile:templatefile atomically:YES encoding:NSUTF8StringEncoding error:&error];
- if (error) {
- NSLog(@"导出失败");
- }else {
- NSLog(@"导出成功");
- }
- }
- +(NSArray*)request_scan_model_by_names:(NSString*)names
- {
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSMutableArray* models=[NSMutableArray new];
-
- NSArray* arrname=[RAConvertor string2dict:names];
- for(int i=0;i<arrname.count;i++)
- {
- NSString* key = arrname[i];
- NSDictionary* m=appDelegate.scan_model[key];
- if(m!=nil)
- [models addObject:m];
-
-
- }
- return models;
-
- }
- +(bool) scanRtime:(NSString* )rtime
- {
-
- // 当前日期小于设定日期,返回true
- NSDate *cdate= [NSDate date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd"];
- // 2022-07-14。1.17
- // 2022-07-14。1.19
-
- NSDate * ddate =[dateFormatter dateFromString:@"2022-10-14"];
-
- // bool review=[cdate earlierDate:ddate];
- NSTimeInterval secondsInterval= [cdate timeIntervalSinceDate:ddate];
- int sec =secondsInterval;
-
- //#ifdef DEBUG
- // return false;
- //#endif
- return sec<0;
- }
- +(void) updateTemplate:(UIViewController*) vc
- {
-
- // if(self.internalTextField.text.length>0)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
-
- [RAUtils deletefiles:[documents stringByAppendingPathComponent:@"download"]];
- RASingleton.sharedInstance.scan_list = nil;
- [RADataProvider load_scan_models];
- __block UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Update local data" completion:^{
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- NSData* download_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [waitalert dismissViewControllerAnimated:false completion:^{
-
- if(download_data!=nil)
- {
- NSString* file_name=[appDelegate.downloadurl lastPathComponent];
- NSString* path = [documents stringByAppendingPathComponent:file_name];
- [RAUtils saveData:download_data toPath:path];
-
- ZipArchive* zip = [[ZipArchive alloc] init];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- // NSFileManager* fileManager=[NSFileManager defaultManager];
- // [fileManager removeItemAtPath:unZipTo error:nil];
- // NSString *unZipTo = [temp stringByAppendingPathComponent:unziplocation];
- //
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
- //NSString* zipFile = [documentPath stringByAppendingString:@"/images.zip"] ;
- // NSString* unZipTo = img_cache;//[documentPath stringByAppendingString:@"/images"] ;
-
- DebugLog(@"path: %@",unZipTo);
- if( [zip UnzipOpenFile:path Password:nil] ){
- BOOL result = [zip UnzipFileTo:unZipTo overWrite:YES];
- if( NO==result )
- {
- // int aaa=0;
- //解压失败
-
- [zip UnzipCloseFile];
- //文件损坏,删除文件重试
-
-
- NSFileManager* fileManager=[NSFileManager defaultManager];
- //debug
- // BOOL blDele= [fileManager removeItemAtPath:zipFile error:nil];
- [fileManager removeItemAtPath:path error:nil];
- [fileManager removeItemAtPath:unZipTo error:nil];
-
- [RAUtils message_alert:@"Can not unzip template file, please try download again." title:@"Warrning" controller:vc];
-
-
-
-
- }
- else
- {
- [zip UnzipCloseFile];
-
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- [fileManager removeItemAtPath:path error:nil];
- [RAUtils message_alert:@"Update template file successful." title:@"Message" controller:vc];
-
- // [RADataProvider encrypt_scan_models];
- NSMutableDictionary *templateDic = [NSMutableDictionary dictionary];
- NSString* datetime= [RAUtils current_date_time];
- templateDic[@"updatetime"]= datetime;
-
-
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- [userDefaults setValue:templateDic forKey:@"ScanTemplate"];
- [userDefaults synchronize];
-
-
- [RADataProvider load_scan_models];
-
-
- if([self get_price_group:appDelegate.price_group]==nil )
- [RADataProvider default_price_group];
-
- // [self loadTemplate];
-
-
- }
- //[zip UnzipCloseFile];
- }
- else
- {
- //打开文件失败,通常是文件路径有问题或密码错误。
- [RAUtils message_alert:@"Can not unzip template file, please contact the Administrator." title:@"Warrning" controller:vc];
-
- // NSFileManager *fileManager = [NSFileManager defaultManager];
- // [fileManager removeItemAtPath:zipFile error:nil];
- }
-
-
- // [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
- //
- // UIImage * img =[UIImage imageWithData:downloadimg_data];
- // cell.imageView.image=img;
- }
- else
- [RAUtils message_alert:@"Can not update template file, you can update manually in the setting." title:@"Warrning" controller:vc];
- // cell.imageView.image=[UIImage imageNamed:@"notfound_s"];
-
-
- [ActiveViewController Notify:@"ScanSearchViewController" Message:@"Clear"];
- [ActiveViewController Notify:@"ServerSettingViewController" Message:RA_NOTIFICATION_REFRESH_UI];
-
-
- }];
-
-
- });
-
- });
-
-
- }];
-
-
- // NSString* file_name=[appDelegate.downloadurl lastPathComponent];
-
-
-
- // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:appDelegate.downloadurl]];
- // [RADataProvider downloadFileOffset:0 Param:nil from:appDelegate.downloadurl method:@"post" toPath:[documents stringByAppendingPathComponent:file_name] progressHandler:nil completionHandler:^(NSMutableDictionary *result) {
- // int i=0; ;
- // }];
- }
- }
- +(void)load_scan_models
- {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- NSString* templatefile = [unZipTo stringByAppendingPathComponent:@"offline_models.json"];
- NSString* str = [NSString stringWithContentsOfFile:templatefile encoding:NSUTF8StringEncoding error:nil];
- NSString * str3 = [AESCrypt AES128Decrypt:str key:@"usai2010"];
- NSMutableDictionary* of = [[RAConvertor string2dict:str3] mutableCopy];
- // NSData *filedata = [NSData dataWithContentsOfFile:path];
- // if(filedata == nil)
- // return nil;
- // NSError *error = nil;
- // NSDictionary *string2dic = [NSJSONSerialization JSONObjectWithData: filedata
- // options: NSJSONReadingMutableContainers
- // error: &error];
- // DebugLog(@"%@",string2dic);
-
- // NSString* str =@"";
- // NSMutableDictionary* item = [@{
- // @"product_id": @"114",
- // @"model": @"1420K-1EK*",
- // @"description": @"Eastern King Platform Bed with Footboard Storage",
- // @"dimension": @"82 x 91.5 x 59.5H",
- // @"stockUom": @"1",
- // @"unit_cuft": @"34.602",
- // @"port": @"VIET",
- // @"origin": @"VCGS",
- // @"available": @"Apr",
- // @"Fremont_DDP": @"289",
- // @"Fremont_WHSE": @"429"
- // } mutableCopy];
- // NSMutableDictionary* of = [NSMutableDictionary new];
- // for(int i=0;i<4000;i++)
- // {
- // item[@"product_id"]=[NSString stringWithFormat:@"pid_%d",i];
- // of[[NSString stringWithFormat:@"model_%d",i]]=item;
- // }
- //
- // NSString* strof=[RAConvertor dict2string:of];
- //
- //
- // NSString* str2 = [AESCrypt encrypt:strof password:@"usai2010"];
- // NSString * str3 = [AESCrypt decrypt:str2 password:@"usai2010"];
-
-
- NSArray* keysort=[self sortedDictionary:of];
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- appDelegate.scan_model = of;
- appDelegate.scan_model_key=keysort;
-
- // NSString* templatefile1 = [unZipTo stringByAppendingPathComponent:@"price_name.json"];
- //
- // NSString* str1 = [NSString stringWithContentsOfFile:templatefile1 encoding:NSUTF8StringEncoding error:nil];
- //
- // NSMutableDictionary* pn = [[RAConvertor string2dict:str1] mutableCopy];
- //
- // appDelegate.price0_name=pn[@"price_0"];
- // appDelegate.price1_name=pn[@"price_1"];
- // appDelegate.price2_name=pn[@"price_2"];
- // appDelegate.price3_name=pn[@"price_3"];
-
-
- }
- +(NSMutableDictionary*)all_price_group
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- NSString* templatefile1 = [unZipTo stringByAppendingPathComponent:@"offline_price_group.json"];
-
- NSString* str1 = [NSString stringWithContentsOfFile:templatefile1 encoding:NSUTF8StringEncoding error:nil];
-
- NSMutableDictionary* pg = [[RAConvertor string2dict:str1] mutableCopy];
- return pg;
- }
- +(NSDictionary*)get_price_group:(NSString*) groupname
- {
- NSMutableDictionary* pg = [self all_price_group];
-
- return pg[groupname];
- }
- +(void)default_price_group
- {
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- // 如果用户有设置价格组,则默认为第一个,如果没有设置,则用服务器设置的默认价格组。
- if(appDelegate.available_price_group.count!=0)
- {
- appDelegate.price_group=nil;
-
-
- // 账号price group 要检查合法性
- for(int i=0;i<appDelegate.available_price_group.count;i++)
- {
- if([self all_price_group][appDelegate.available_price_group[i]]!=nil)
- {
- appDelegate.price_group= appDelegate.available_price_group[i];
- return;
- }
- }
-
- //如果账号的price group 全部非法,则用默认价格组。
- // if(appDelegate.price_group==nil)
- {
- NSMutableDictionary* pg = [self all_price_group];
- appDelegate.price_group=pg[@"default"];
- }
-
- }
- else
- {
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- // NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- //
- //
- //
- //
- //
- // NSString* templatefile1 = [unZipTo stringByAppendingPathComponent:@"price_group.json"];
- //
- // NSString* str1 = [NSString stringWithContentsOfFile:templatefile1 encoding:NSUTF8StringEncoding error:nil];
- //
- // NSMutableDictionary* pg = [[RAConvertor string2dict:str1] mutableCopy];
- //
- NSMutableDictionary* pg = [self all_price_group];
- appDelegate.price_group=pg[@"default"];
- if(appDelegate.price_group!=nil)
- appDelegate.available_price_group = @[appDelegate.price_group];
-
- }
-
-
-
-
- }
- + (NSArray*)sortedDictionary:(NSDictionary *)dict{
-
- //将所有的key放进数组
- NSArray *allKeyArray = [dict allKeys];
-
- //序列化器对数组进行排序的block 返回值为排序后的数组
- NSArray *afterSortKeyArray = [allKeyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id
- _Nonnull obj2) {
- /**
- In the compare: methods, the range argument specifies the
- subrange, rather than the whole, of the receiver to use in the
- comparison. The range is not applied to the search string. For
- example, [@"AB" compare:@"ABC" options:0 range:NSMakeRange(0,1)]
- compares "A" to "ABC", not "A" to "A", and will return
- NSOrderedAscending. It is an error to specify a range that is
- outside of the receiver's bounds, and an exception may be raised.
-
- - (NSComparisonResult)compare:(NSString *)string;
-
- compare方法的比较原理为,依次比较当前字符串的第一个字母:
- 如果不同,按照输出排序结果
- 如果相同,依次比较当前字符串的下一个字母(这里是第二个)
- 以此类推
-
- 排序结果
- NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
- NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
-
- 注意:compare方法是区分大小写的,即按照ASCII排序
- */
- //排序操作
- NSComparisonResult resuest = [obj1 compare:obj2];
- return resuest;
- }];
-
- return afterSortKeyArray;
- // NSLog(@"afterSortKeyArray:%@",afterSortKeyArray);
-
- // //通过排列的key值获取value
- // NSMutableArray *valueArray = [NSMutableArray array];
- // for (NSString *sortsing in afterSortKeyArray) {
- // NSString *valueString = [dict objectForKey:sortsing];
- // [valueArray addObject:valueString];
- // }
- // NSLog(@"valueArray:%@",valueArray);
- }
- +(void) request_scan_news:(resultHandler)result
- {
-
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"offlineNews";
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.address==nil)
- return;
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_SCAN_NEWS];
- param[@"site_name"]=[RADataProvider getSiteName];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_autocomplete:(NSMutableDictionary*)param completionHandler:(resultHandler)result
- {
- param[@"site_name"]=[self getSiteName];
- // param[@"_method"]=@"customerID";
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* full_url ;
- if([param[@"full_url"] boolValue])
- full_url =param[@"url"];
- else
- {
- if(appDelegate.address==nil||[param[@"url"] stringValue].length==0)
- {
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- ret[@"result"]=@"8";
- ret[@"err_msg"]=@"Missing query url, please contact administrator.";
- }
- full_url = [appDelegate.address stringByAppendingPathComponent:[param[@"url"] stringValue]];
- }
-
-
-
- [self request_interface:full_url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- //+(void)request_scan_cid:(NSMutableDictionary*)param url:(NSString*) url completionHandler:(resultHandler)result
- //{
- // param[@"site_name"]=[self getSiteName];
- // param[@"_method"]=@"customerID";
- // AppDelegate *appDelegate = nil;
- //
- // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- // NSString* full_url = [appDelegate.address stringByAppendingPathComponent:url];
- // [self request_interface:full_url parameters:param err_record_url:nil completionHandler:result retry:0];
- //}
- //+(void)request_scan_shipto_company:(NSMutableDictionary*)param url:(NSString*) url completionHandler:(resultHandler)result
- //{
- // param[@"site_name"]=[self getSiteName];
- // param[@"_method"]=@"shiptoCompany";
- // AppDelegate *appDelegate = nil;
- //
- // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- // NSString* full_url = [appDelegate.address stringByAppendingPathComponent:url];
- // [self request_interface:full_url parameters:param err_record_url:nil completionHandler:result retry:0];
- //}
- +(void)request_scan_stock:(NSMutableDictionary*)param completionHandler:(resultHandler)result
- {
- param[@"site_name"]=[self getSiteName];
- param[@"_method"]=@"orderItemCheckStock";
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_CHECK_STOCK];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void) request_scan_server :(resultHandler)result
- {
-
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"hostList";
- [self request_interface:URL_SERVER_LIST parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_validate_scan_server:(NSString*)url name:(NSString*)name password:(NSString*)password completionHandler:(resultHandler)result
- {
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"hostCheck";
- param[@"password"]=password;
- param[@"site_name"]=name;
- // param[@"url"]=url;
-
- NSString* check_url = [NSString stringWithFormat:@"%@%@",url,URL_SERVER_CHECK];
- [self request_interface:check_url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(NSString*)getSiteName
- {
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];;
- if (addressDic) {
- NSString* ia=addressDic[@"internalAddress"];
- NSString* ea=addressDic[@"externalAddress"];
- NSString* sa=addressDic[@"serverAddress"];
- if(sa.length==0)
- {
- if(ea.length>0)
- sa=ea;
- else if(ia.length>0)
- sa=ia;
- }
-
- return [addressDic objectForKey:@"name"];
- }
- return @"";
- }
- +(bool)getSiteHasERP
- {
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if( [appDelegate.user isEqualToString:@"GUEST"])
- return false;
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];;
- if (addressDic) {
- return [addressDic[@"has_erp_site"] boolValue];
- }
- return false;
- }
- #endif
- +(void)request_change_password:(NSString*) pwd completionHandler:(resultHandler)result
- {
-
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"changePasswordOfflineOrderUser";
- param[@"opsw"]=appDelegate.password;
- param[@"npsw"]=pwd;
- param[@"user"]=appDelegate.user;
- param[@"site_name"]=[self getSiteName];
- // param[@"url"]=url;
-
-
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_CHANGE_PASSWORD];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_sign_up:user email:(NSString*)email password:(NSString*) pwd completionHandler:(resultHandler)result
- {
-
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"registerOfflineOrderUser";
- param[@"password"]=pwd;
- param[@"email"]=email;
- param[@"user"]=user;
- param[@"site_name"]=[self getSiteName];
- // param[@"url"]=url;
-
-
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_SIGN_UP];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_change_password:user oldpassword:(NSString*)opwd newpassword:(NSString*) npwd completionHandler:(resultHandler)result
- {
-
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"changePasswordOfflineOrderUser";
- param[@"opsw"]=opwd;
- param[@"password"]=opwd;
- param[@"npsw"]=npwd;
- param[@"user"]=user;
- param[@"site_name"]=[self getSiteName];
- // param[@"url"]=url;
-
-
- NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_SIGN_UP];
- [self request_interface:url parameters:param err_record_url:nil completionHandler:result retry:0];
- }
- +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
- {
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.user!=nil)
- [params setValue:appDelegate.user forKey:@"user"];
-
-
- // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
- // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
- // else
-
- if(appDelegate.contact_id!=nil)
- [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(appDelegate.password!=nil)
- [params setValue:appDelegate.password forKey:@"password"];
-
- if(appDelegate.order_code!=nil)
- [params setValue:appDelegate.order_code forKey:@"orderCode"];
-
- bool can_create_backorder=appDelegate.can_create_backorder;
- // [params setValue:sourceid forKey:@"sourceid"];
- // [params setValue:editor forKey:@"editor"];
- DebugLog(@"request editor url:%@",request_url);
-
-
- if([request_url isEqualToString:URL_NEW_CUSTOMER])
- {
- [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
- }
- else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
- {
- [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
- }
- else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
- {
- [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
- }
- else if([request_url isEqualToString:URL_CARTDELIVERY])
- {
- [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
- }
- else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
- {
- [params setObject:ScreenCodeNewAddress forKey:kScreenName];
- }
- else if ([request_url isEqualToString:URL_DM_PARAMS]){
- [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
- }
-
-
- if(appDelegate.offline_mode)
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* json = nil;
- if([request_url isEqualToString:URL_NEW_CUSTOMER])
- {
- json= [OLDataProvider offline_createContact:params];
- }
- else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
- {
- json= [OLDataProvider offline_editContact:params];
- }
- else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
- {
- json= [OLDataProvider offline_contactAdvancedSearch:params];
- }
- else if([request_url isEqualToString:URL_CARTDELIVERY])
- {
-
- params[@"contact_id"]=params[@"contactId"];
- params[@"can_create_backorder"]=@(can_create_backorder);
-
- json= [OLDataProvider offline_placeorder:params];
- }
- else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
- {
- json= [OLDataProvider offline_addreditor:params];
- }
- else if ([request_url isEqualToString:URL_DM_PARAMS]){
- json = [OLDataProvider offline_createTearSheet:params];
- }
-
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if(json==nil)
- result( [[OLDataProvider offline_notimpl] mutableCopy]);
- else
- result([[RAConvertor data2dict:json] mutableCopy]);
- });
- });
-
- return;
-
-
- }
- else
- {
-
-
- if([request_url isEqualToString:URL_CARTDELIVERY])
- {
-
-
- NSString * uuid= [[NSUUID UUID] UUIDString];
- params[@"resultSerial"]=uuid;
- __block bool bbreak = false;
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- for(int i=0;i<150;i++)
- {
- // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
- // result_params[@"resultSerial"]=uuid;
- //json=[self get_json:request_url parameters:params];
- if(bbreak)
- break;
- dispatch_async(dispatch_get_main_queue(), ^{
- NSLog(@"request cart delivery %d",i);
- [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
- if(resulti!=nil)
- {
-
-
- if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
- {
-
-
- if(!bbreak) //此判断保证result只调用一次。
- {
- result(resulti);
- NSLog(@"result called at %d",i);
- }
- bbreak=true;
- }
- }
-
- } retry:3];
- });
-
- // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
-
- sleep(2);
- }
- });
- }
- else
- [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
- }
- // if(json!=nil)
- // {
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // return jsobj;
- // }
- // else
- // return nil;
- }
- +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
- {
- // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- AppDelegate *appDelegate = nil;
-
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.user!=nil)
- [params setValue:appDelegate.user forKey:@"user"];
- if(appDelegate.contact_id!=nil)
- [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(appDelegate.password!=nil)
- [params setValue:appDelegate.password forKey:@"password"];
-
- // if(appDelegate.order_code!=nil)
- // [params setValue:appDelegate.order_code forKey:@"orderCode"];
-
- // NSDictionary* customerinfo= appDelegate.customerInfo;
- //
- // NSArray* keys=[customerinfo allKeys];
- // for(int i=0;i<keys.count;i++)
- // {
- // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
- // }
- //
- // [params setValue:sourceid forKey:@"sourceid"];
- // [params setValue:editor forKey:@"editor"];
-
- [params setObject:ScreenCodeModelInfo forKey:kScreenName];
-
- if(appDelegate.offline_mode)
- {
- params[@"offline_Command"]=url;
- [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
- //
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
- // dispatch_async(dispatch_get_main_queue(), ^{
- // result(json);
- // });
- // });
-
- return;
-
- }
- [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
-
-
- //
- // if(appDelegate.offline_mode)
- // {
- // params[@"offline_Command"]=url;
- // return [OLDataProvider offline_commoneditor_partialrefresh:params];
- // }
- //
- // if(![self IsNetworkAvailable])
- // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
- //
- // NSData* json=[self get_json:url parameters:params];
- // if(json!=nil)
- // {
- // NSError *error=nil;
- // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
- // if([[jsobj valueForKey:@"result"]intValue]==2)
- // [appDelegate SetSo:nil];
- //
- //
- // return jsobj;
- // }
- // else
- // return nil;
- }
- +(void)SaveEditor:(NSMutableDictionary*)params completionHandler:(resultHandler)result
- {
- }
- @end
|