| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069 |
- //
- // 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
- +(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];
- }
- +(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 @"";
- }
- #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];
- [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];
- }
- +(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) {
- DebugLog(@"导出失败");
- }else {
- DebugLog(@"导出成功");
- }
- }
- +(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
- {
-
- // 当前日期小于设定日期,返回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:@"2023-4-18"];
-
- // bool review=[cdate earlierDate:ddate];
- NSTimeInterval secondsInterval= [cdate timeIntervalSinceDate:ddate];
- int sec =secondsInterval;
-
- //#ifdef DEBUG
- // return false;
- //#endif
- return sec<0;
- }
- +(NSString*) queryStockUpdateTime
- {
-
- NSString* serverpath = [OLDataProvider getServerPath];
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- NSString* path = [serverpath stringByAppendingPathComponent:@"stock.json"];
-
-
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
-
- NSError* error;
- NSDictionary *fileAttributes =[fileManager attributesOfItemAtPath:path error:&error];
-
- if (fileAttributes != nil) {
-
- NSDate *creationDate;
-
- //NSString *NSFileCreationDate
- //文件创建日期
- creationDate = [fileAttributes objectForKey:NSFileCreationDate];
-
-
- NSDateFormatter * df = [[NSDateFormatter alloc] init ];
- [df setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
- NSString * na = [df stringFromDate:creationDate];
- return na;
- }
- else {
- return @"Last Update Unknown";
- }
-
-
- }
- +(NSString*) queryStock:(NSString*)modelname
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* user =appDelegate.user;
- if(user.length==0||[user.lowercaseString isEqualToString:@"guest"])
- return @"Stock:0";
-
- NSString* serverpath = [OLDataProvider getServerPath];
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- NSString* path = [serverpath stringByAppendingPathComponent:@"stock.json"];
-
- NSDictionary* map=[RAUtils dictfromfile:path];
-
- int stock = [map[modelname] intValue];
- if(stock<0)
- stock=0;
-
- return [NSString stringWithFormat:@"Stock: %d",stock];
-
-
-
- }
- +(void) updateStock:(UIViewController*) vc
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- NSString* user =appDelegate.user;
-
- if(user.length==0||[user.lowercaseString isEqualToString:@"guest"])
- {
-
- [RAUtils message_box:@"Warrning" message:@"Can not update inventory, you must login first." completion:nil];
- return;
- }
-
- bool haserp = [self getSiteHasERP];
- if(!haserp)
- {
- [RAUtils message_box:@"Warrning" message:@"Can not update inventory, current site dosen't have ERP." completion:nil];
- return;
- }
-
- NSString* serverpath = [OLDataProvider getServerPath];
- [RAUtils deletefiles:[serverpath stringByAppendingPathComponent:@"stock.json"]];
-
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Inventory update" message:@"Inventory update will take 60s or longer" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Yes, proceed" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
-
-
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:vc title:@"Update stock" completion:^{
-
-
- PopWaitAlert * pop = [RAUtils waiting_pop:@"Update stock" completion:nil];
-
- [RADataProvider request_scan_stock:^(NSMutableDictionary *result) {
-
- NSMutableDictionary* return_json = result;
-
- // [waitalert dismissViewControllerAnimated:false completion:^{
-
- [pop hide];
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- // NSString* file_name=[appDelegate.downloadurl lastPathComponent];
- NSString* path = [serverpath stringByAppendingPathComponent:@"stock.json"];
-
- [RAUtils dicttofile:path dict:result];
-
-
- // NSMutableDictionary *templateDic = [NSMutableDictionary dictionary];
- // NSString* datetime= [RAUtils current_date_time];
- // templateDic[@"updatetime"]= datetime;
- //
- //
- // NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- // [userDefaults setValue:templateDic forKey:@"ScanStock"];
- // [userDefaults synchronize];
-
-
- if([vc respondsToSelector:@selector(refreshStock)])
- {
- [vc performSelector:@selector(refreshStock) withObject:nil afterDelay:0];
- }
-
- }
- else
- [RAUtils message_box:@"Warrning" message:@"Can not update inventory, you can try again later." completion:nil];
-
- [ActiveViewController Notify:@"ScanSearchViewController" Message:@"Clear"];
- [ActiveViewController Notify:@"ServerSettingViewController" Message:RA_NOTIFICATION_REFRESH_UI];
-
-
- // }];
-
-
- }];
-
-
-
-
- // }];
-
- }];
- UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- //create new;
-
- }];
-
- [alertController addAction:action_1];
- [alertController addAction:action_2];
- [vc presentViewController:alertController animated:YES completion:nil];
-
-
-
-
-
- ;
- }
- +(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:^{
-
-
- PopWaitAlert * pop = [RAUtils waiting_pop:@"Update local data" completion:nil];
- 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:^{
-
- [pop hide];
-
- 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_box:@"Warrning" message:@"Can not unzip template file, please try download again." completion:nil];
-
-
- }
- else
- {
- [zip UnzipCloseFile];
-
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- [fileManager removeItemAtPath:path error:nil];
-
- [RAUtils message_box:@"Message" message:@"Update template file successful." completion:nil];
-
- // [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_box:@"Warrning" message:@"Can not unzip template file, please contact the Administrator." completion:nil];
-
- // 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_box:@"Warrning" message:@"Can not update template file, you can update manually in the setting." completion:nil];
- // 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];
-
- NSArray* keysort=[self sortedDictionary:of];
-
- AppDelegate *appDelegate = nil;
-
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- appDelegate.scan_model = of;
- appDelegate.scan_model_key=keysort;
-
- }
- +(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;
- // DebugLog(@"afterSortKeyArray:%@",afterSortKeyArray);
-
- // //通过排列的key值获取value
- // NSMutableArray *valueArray = [NSMutableArray array];
- // for (NSString *sortsing in afterSortKeyArray) {
- // NSString *valueString = [dict objectForKey:sortsing];
- // [valueArray addObject:valueString];
- // }
- // DebugLog(@"valueArray:%@",valueArray);
- }
- +(void) request_scan_stock:(resultHandler)result
- {
-
- NSMutableDictionary* param = [NSMutableDictionary new];
- param[@"_method"]=@"offlineModelCheckStock";
- 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_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_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];
- }
- +(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(), ^{
- DebugLog(@"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);
- DebugLog(@"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
|