|
|
@@ -11,21 +11,220 @@
|
|
|
#import "RAUtils.h"
|
|
|
#import "AESCrypt.h"
|
|
|
#import "AppDelegate.h"
|
|
|
-
|
|
|
+#import "ZipArchive.h"
|
|
|
+#import "UIProgressView+AFNetworking.h"
|
|
|
+#import "AFHTTPSessionManager.h"
|
|
|
|
|
|
@interface OLDataProvider ()
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation OLDataProvider
|
|
|
-+(void) prepareUpdata:(NSArray*) arr_order
|
|
|
++(NSArray*) enumOfflineOrder
|
|
|
+{
|
|
|
+
|
|
|
+ NSMutableArray* ret = [[NSMutableArray alloc] init];
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
+
|
|
|
+ NSString *sqlQuery =@"select so_id from offline_order where order_id is null";
|
|
|
+ sqlite3_stmt * statement;
|
|
|
+
|
|
|
+ int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
|
|
|
+ if ( dbresult== SQLITE_OK)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ while (sqlite3_step(statement) == SQLITE_ROW)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ char *so_id = (char*)sqlite3_column_text(statement, 0);
|
|
|
+ NSString* nsso_id=nil;
|
|
|
+ if(so_id!=nil)
|
|
|
+ {
|
|
|
+ nsso_id= [[NSString alloc]initWithUTF8String:so_id];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ [ret addObject:nsso_id];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sqlite3_finalize(statement);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [iSalesDB close_db:db];
|
|
|
+
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
++(void) uploadFile:(NSString*) file
|
|
|
+{
|
|
|
+ NSData* data = [NSData dataWithContentsOfFile: file];
|
|
|
+ UIApplication * app = [UIApplication sharedApplication];
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[app delegate];
|
|
|
+
|
|
|
+
|
|
|
+ AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
|
|
|
+
|
|
|
+ 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"];
|
|
|
+
|
|
|
+
|
|
|
+ NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_OFFLINE parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
|
|
+ [formData appendPartWithFileData:data name:@"upfile" fileName:[file lastPathComponent] mimeType:@"application/zip"];
|
|
|
+ } error:nil];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
|
|
|
+
|
|
|
+ NSProgress *progress = nil;
|
|
|
+
|
|
|
+ NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (error) {
|
|
|
+
|
|
|
+ NSString* err_msg = [error localizedDescription];
|
|
|
+ NSLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
|
|
|
+
|
|
|
+
|
|
|
+ NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
|
|
|
+
|
|
|
+ NSLog(@"data string: %@",str);
|
|
|
+ [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ NSLog(@"response ");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
|
|
|
+
|
|
|
+ // 再将NSData转为字符串
|
|
|
+ NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
|
+
|
|
|
+ // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
|
|
|
+
|
|
|
+ NSLog(@"data string: %@",jsonStr);
|
|
|
+
|
|
|
+ NSDictionary* json = responseObject;
|
|
|
+
|
|
|
+
|
|
|
+ if([[json valueForKey:@"result"] intValue]==2)
|
|
|
+ {
|
|
|
+// NSString* img_url_down = json[@"img_url_aname"];
|
|
|
+// NSString* img_url_up = json[@"img_url"];
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload file" controller:nil] ;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
|
|
|
+ }];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // [self.uploadProgress setProgressWithUploadProgressOfTask:uploadTask animated:true];
|
|
|
+ //
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [uploadTask resume];
|
|
|
+
|
|
|
+}
|
|
|
++(NSString*) prepareUpload:(NSArray*) arr_order
|
|
|
{
|
|
|
NSString* serial= [[NSUUID UUID] UUIDString];
|
|
|
+
|
|
|
+
|
|
|
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
+ NSString *cachefolder = [paths objectAtIndex:0];
|
|
|
+
|
|
|
+ NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
|
|
|
+ upfolder = [upfolder stringByAppendingPathComponent:serial];
|
|
|
+
|
|
|
+ NSFileManager* fileManager = [NSFileManager defaultManager];
|
|
|
+ BOOL bdir=YES;
|
|
|
+ if(! [fileManager fileExistsAtPath:upfolder isDirectory:&bdir])
|
|
|
+ {
|
|
|
+
|
|
|
+ NSError *error = nil;
|
|
|
+ bool bsuccess=[fileManager createDirectoryAtPath:upfolder withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
+
|
|
|
+ if(!bsuccess)
|
|
|
+ DebugLog(@"Create UPLOAD folder failed");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
|
|
|
ret[@"contact"]=[self prepareContact:serial];
|
|
|
ret[@"wishlist"]=[self prepareWishlist:serial];
|
|
|
ret[@"order"]=[self prepareOrder:serial soid:arr_order];
|
|
|
|
|
|
+ NSString* str= [RAUtils dict2string:ret];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ NSString * jsonpath= [upfolder stringByAppendingPathComponent:@"json.json"];
|
|
|
+
|
|
|
+ NSString * zippath= [upfolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",serial]];
|
|
|
+
|
|
|
+
|
|
|
+ NSError *error=nil;
|
|
|
+
|
|
|
+ [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
|
|
|
+
|
|
|
+ NSArray* arr_files=[RAUtils allFilesAtPath:upfolder];
|
|
|
+
|
|
|
+ ZipArchive* zip = [[ZipArchive alloc] init];
|
|
|
+
|
|
|
+
|
|
|
+ BOOL result = [zip CreateZipFile2:zippath Password:@"usai2010"];
|
|
|
+
|
|
|
+ for(int i=0;i<arr_files.count;i++)
|
|
|
+ {
|
|
|
+ NSString* file=arr_files[i];
|
|
|
+
|
|
|
+ result = [zip addFileToZip:file newname:[file lastPathComponent]];
|
|
|
+ }
|
|
|
+
|
|
|
+ if( ![zip CloseZipFile2] )
|
|
|
+ {
|
|
|
+ zippath = @"";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return zippath;
|
|
|
}
|
|
|
+ (bool) copy_upImg:(NSString* ) serial file:(NSString*) filename
|
|
|
{
|
|
|
@@ -66,7 +265,7 @@
|
|
|
NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
|
|
|
- NSString *sqlQuery =@"select _id,product_id,item_id,qty,create_time";
|
|
|
+ NSString *sqlQuery =@"select _id,product_id,item_id,qty,create_time from wishlist";
|
|
|
sqlite3_stmt * statement;
|
|
|
|
|
|
|