|
|
@@ -1070,150 +1070,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
- DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
|
|
|
-
|
|
|
- return ret;
|
|
|
-}
|
|
|
-+(NSDictionary*) offline_itemsearch:(NSMutableDictionary *) params
|
|
|
-{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // [params setValue:covertype forKey:@"covertype"];
|
|
|
- // [params setValue:ctgid forKey:@"ctgId"];
|
|
|
- // [params setValue:modelname forKey:@"modelName"];
|
|
|
- // [params setValue:modeldescrip forKey:@"modelDescription"];
|
|
|
- // [params setValue:alert forKey:@"alert"];
|
|
|
- // [params setValue:qty forKey:@"sold_by_qty"];
|
|
|
- // [params setValue:available forKey:@"available"];
|
|
|
- // [params setValue:price forKey:@"price"];
|
|
|
- // [params setValue:bestseller forKey:@"bestseller"];
|
|
|
-
|
|
|
- NSString* orderCode = [params valueForKey:@"orderCode"];
|
|
|
- int covertype = [[params valueForKey:@"covertype"] intValue];
|
|
|
-
|
|
|
- NSString* where= nil;
|
|
|
- NSString* orderby= @"m.name";
|
|
|
- switch (covertype) {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- where=@"m.category like'%%#005#%%'";
|
|
|
- break;
|
|
|
- }
|
|
|
- case 1:
|
|
|
- {
|
|
|
- where=@"m.alert like '%QS%'";
|
|
|
- break;
|
|
|
- }
|
|
|
- case 2:
|
|
|
- {
|
|
|
- where=@"m.availability>0";
|
|
|
- break;
|
|
|
- }
|
|
|
- case 3:
|
|
|
- {
|
|
|
- where=@"m.best_seller>0";
|
|
|
- orderby=@"m.best_seller desc";
|
|
|
- break;
|
|
|
- }
|
|
|
- default:
|
|
|
- where=@"1=1";
|
|
|
- break;
|
|
|
- }
|
|
|
- // NSString* keyword = [params valueForKey:@"keyword"];
|
|
|
-
|
|
|
- // bool exactMatch = [[params valueForKey:@"exactMatch"] boolValue];
|
|
|
-
|
|
|
-
|
|
|
- int limit = [[params valueForKey:@"limit"] intValue];
|
|
|
- int offset = [[params valueForKey:@"offset"] intValue];
|
|
|
-
|
|
|
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- sqlite3 *db = [iSalesDB get_db];
|
|
|
-
|
|
|
- int count = [iSalesDB get_recordcount:db table:@"model" where:where];
|
|
|
-
|
|
|
-
|
|
|
- NSString *sqlQuery = nil;
|
|
|
- sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where %@ order by %@ limit %d offset %d ;",where,orderby,limit, offset];
|
|
|
-
|
|
|
- DebugLog(@"offline_itemsearch sql:%@",sqlQuery);
|
|
|
- sqlite3_stmt * statement;
|
|
|
- [ret setValue:@"2" forKey:@"result"];
|
|
|
- [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"item_total_count"];
|
|
|
- NSMutableDictionary* items = [[NSMutableDictionary alloc] init];
|
|
|
- // int count=0;
|
|
|
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
|
|
|
- {
|
|
|
-
|
|
|
- int i=0;
|
|
|
- while (sqlite3_step(statement) == SQLITE_ROW)
|
|
|
- {
|
|
|
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
|
|
|
-
|
|
|
- // char *name = (char*)sqlite3_column_text(statement, 1);
|
|
|
- // NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
|
|
|
-
|
|
|
- char *name = (char*)sqlite3_column_text(statement, 0);
|
|
|
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
|
|
|
-
|
|
|
- char *description = (char*)sqlite3_column_text(statement, 1);
|
|
|
- NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- int product_id = sqlite3_column_int(statement, 2);
|
|
|
-
|
|
|
-
|
|
|
- // char *url = (char*)sqlite3_column_text(statement, 3);
|
|
|
- // if(url==nil)
|
|
|
- // url="";
|
|
|
- // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
|
|
|
-
|
|
|
- int wid = sqlite3_column_int(statement, 3);
|
|
|
- int closeout = sqlite3_column_int(statement, 4);
|
|
|
-
|
|
|
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
|
|
|
-
|
|
|
- if(wid==0)
|
|
|
- [item setValue:@"false" forKey:@"wish_exists"];
|
|
|
- else
|
|
|
- [item setValue:@"true" forKey:@"wish_exists"];
|
|
|
-
|
|
|
- if(closeout==0)
|
|
|
- [item setValue:@"false" forKey:@"is_closeout"];
|
|
|
- else
|
|
|
- [item setValue:@"true" forKey:@"is_closeout"];
|
|
|
-
|
|
|
- [item addEntriesFromDictionary:imgjson];
|
|
|
-
|
|
|
-
|
|
|
- // [item setValue:nsurl forKey:@"img"];
|
|
|
- [item setValue:nsname forKey:@"fash_name"];
|
|
|
- [item setValue:nsdescription forKey:@"description"];
|
|
|
- [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
|
|
|
- [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
|
|
|
- i++;
|
|
|
-
|
|
|
- }
|
|
|
- [items setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
|
|
|
- [ret setObject:items forKey:@"items"];
|
|
|
- sqlite3_finalize(statement);
|
|
|
- }
|
|
|
- NSLog(@"count:%d",count);
|
|
|
-
|
|
|
-
|
|
|
- [iSalesDB close_db:db];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
|
|
|
|
|
|
return ret;
|
|
|
@@ -3689,7 +3545,11 @@
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- NSString *enscrypt_price = [NSString stringWithFormat:@"%s",(char *)sqlite3_column_text(statement, 5)];
|
|
|
+ char *price_ch = (char *)sqlite3_column_text(statement, 5);
|
|
|
+ if (price_ch == NULL) {
|
|
|
+ price_ch = "";
|
|
|
+ }
|
|
|
+ NSString *enscrypt_price = [NSString stringWithFormat:@"%s",price_ch];
|
|
|
double price = [[AESCrypt fastdecrypt:enscrypt_price] doubleValue];
|
|
|
DebugLog(@"product price:%lf",price);
|
|
|
|
|
|
@@ -3720,6 +3580,261 @@
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+# pragma mark item search
|
|
|
++(NSDictionary*) offline_itemsearch:(NSMutableDictionary *) params
|
|
|
+{
|
|
|
+
|
|
|
+ BOOL filterSearch = ![params.allKeys containsObject:@"covertype"];
|
|
|
+
|
|
|
+ NSMutableDictionary *ret = [self dictionaryFileName:@"category.json"];
|
|
|
+ NSMutableDictionary *filter = [[ret objectForKey:@"filter"] mutableCopy];
|
|
|
+
|
|
|
+ // category
|
|
|
+ NSDictionary *category_menu = [self offline_category_menu];
|
|
|
+ [filter setValue:category_menu forKey:@"category"];
|
|
|
+
|
|
|
+ NSString* where= nil;
|
|
|
+ NSString* orderby= @"m.name";
|
|
|
+ if (!filterSearch) {
|
|
|
+ int covertype = [[params valueForKey:@"covertype"] intValue];
|
|
|
+
|
|
|
+ switch (covertype) {
|
|
|
+ case 0:
|
|
|
+ {
|
|
|
+ where=@"m.category like'%%#005#%%'";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ where=@"m.alert like '%QS%'";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 2:
|
|
|
+ {
|
|
|
+ where=@"m.availability>0";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 3:
|
|
|
+ {
|
|
|
+ where=@"m.best_seller>0";
|
|
|
+ orderby=@"m.best_seller desc";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ where=@"1=1";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int limit = [[params valueForKey:@"limit"] intValue];
|
|
|
+ int offset = [[params valueForKey:@"offset"] intValue];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sqlite3 *db = [iSalesDB get_db];
|
|
|
+
|
|
|
+ int count = [iSalesDB get_recordcount:db table:@"model" where:where];
|
|
|
+
|
|
|
+
|
|
|
+ NSString *sqlQuery = nil;
|
|
|
+ sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where %@ order by %@ limit %d offset %d ;",where,orderby,limit, offset];
|
|
|
+
|
|
|
+ double price_min = 0;
|
|
|
+ double price_max = 0;
|
|
|
+ if (filterSearch) {
|
|
|
+ // alert
|
|
|
+ [self check:params[@"alert"] valueKey:@"alert" inDictionary:filter];
|
|
|
+ NSString *alert = params[@"alert"];
|
|
|
+ if ([alert isEqualToString:@"Display All"]) {
|
|
|
+ alert = [NSString stringWithFormat:@""];
|
|
|
+ } else {
|
|
|
+ alert = [NSString stringWithFormat:@"and m.alert = '%@'",alert];
|
|
|
+ }
|
|
|
+
|
|
|
+ // available
|
|
|
+ [self check:params[@"available"] valueKey:@"availability" inDictionary:filter];
|
|
|
+ NSString *available = params[@"available"];
|
|
|
+ NSString *available_condition;
|
|
|
+ if ([available isEqualToString:@"Display All"]) {
|
|
|
+ available_condition = @">=";
|
|
|
+ } else if ([available isEqualToString:@"Available Now"]) {
|
|
|
+ available_condition = @">";
|
|
|
+ } else {
|
|
|
+ available_condition = @"==";
|
|
|
+ }
|
|
|
+
|
|
|
+ // best seller
|
|
|
+ [self check:params[@"bestseller"] valueKey:@"best_seller" inDictionary:filter];
|
|
|
+
|
|
|
+
|
|
|
+ // price
|
|
|
+ [self check:params[@"price"] valueKey:@"price" inDictionary:filter];
|
|
|
+ NSString *price = params[@"price"];
|
|
|
+ price_min = 0;
|
|
|
+ price_max = MAXFLOAT;
|
|
|
+ if ([price isEqualToString:@"Display All"]) {
|
|
|
+
|
|
|
+ } else if([price containsString:@"+"]){
|
|
|
+ price = [price stringByReplacingOccurrencesOfString:@"+" withString:@""];
|
|
|
+ price_min = [price doubleValue];
|
|
|
+ } else {
|
|
|
+ NSArray *priceArray = [price componentsSeparatedByString:@"-"];
|
|
|
+ price_min = [[priceArray objectAtIndex:0] doubleValue];
|
|
|
+ price_max = [[priceArray objectAtIndex:1] doubleValue];
|
|
|
+ }
|
|
|
+ DebugLog(@"1、min~max:%lf ~ %lf",price_min,price_max);
|
|
|
+
|
|
|
+ // sold_by_qty : Sold in quantities of %@
|
|
|
+ [self check:params[@"sold_by_qty"] valueKey:@"qty" inDictionary:filter];
|
|
|
+ NSString *qty = params[@"sold_by_qty"];
|
|
|
+ if ([qty isEqualToString:@"Display All"]) {
|
|
|
+ qty = @"like 'Sold in quantities of %'";
|
|
|
+ } else {
|
|
|
+ qty = [NSString stringWithFormat:@"= 'Sold in quantities of %@'",qty];
|
|
|
+ }
|
|
|
+
|
|
|
+ // category
|
|
|
+ NSString *category_id = params[@"ctgId"];
|
|
|
+ NSMutableDictionary *cateDic = [[filter objectForKey:@"category"] mutableCopy];
|
|
|
+ for (NSString *key0 in cateDic.allKeys) {
|
|
|
+
|
|
|
+ if ([key0 containsString:@"category_"]) {
|
|
|
+
|
|
|
+ NSMutableDictionary *category0 = [[cateDic objectForKey:key0] mutableCopy];
|
|
|
+ for (NSString *key1 in category0.allKeys) {
|
|
|
+
|
|
|
+ if ([key1 containsString:@"category_"]) {
|
|
|
+
|
|
|
+ NSMutableDictionary *category1 = [[category0 objectForKey:key1] mutableCopy];
|
|
|
+ [category1 setObject:[NSNumber numberWithInteger:0] forKey:@"check"];
|
|
|
+ if ([[category1 objectForKey:@"cid"] isEqualToString:category_id]) {
|
|
|
+
|
|
|
+ category_id = [category1 objectForKey:@"id"];
|
|
|
+ [category1 setObject:[NSNumber numberWithInteger:1] forKey:@"check"];
|
|
|
+ [category0 setObject:category1 forKey:key1];
|
|
|
+ [cateDic setObject:category0 forKey:key0];
|
|
|
+ [filter setObject:cateDic forKey:@"category"];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // where bestseller > 0 order by bestseller desc
|
|
|
+ // sql query: alert availability(int) best_seller(int) price qty
|
|
|
+ sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout,p.price from model m left join wishlist w on m.product_id=w.product_id left JOIN model_price p on m.product_id = p.product_id where m.category like'%%#%@#%%' and m.best_seller > 0 %@ and m.availability %@ 0 and m.model_set %@ order by m.name asc,m.best_seller DESC limit %d offset %d ;",category_id,alert,available_condition,qty,limit, offset];
|
|
|
+ }
|
|
|
+
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+ if (!appDelegate.user) {
|
|
|
+ [filter setValue:@{@"count" : @(0)} forKey:@"price"];
|
|
|
+ }
|
|
|
+
|
|
|
+ [ret setValue:filter forKey:@"filter"];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ DebugLog(@"offline_itemsearch sql:%@",sqlQuery);
|
|
|
+
|
|
|
+ sqlite3_stmt * statement;
|
|
|
+ [ret setValue:@"2" forKey:@"result"];
|
|
|
+ [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"item_total_count"];
|
|
|
+
|
|
|
+ NSMutableDictionary* items = [[NSMutableDictionary alloc] init];
|
|
|
+ // int count=0;
|
|
|
+ if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
|
|
|
+ {
|
|
|
+
|
|
|
+ int i=0;
|
|
|
+ while (sqlite3_step(statement) == SQLITE_ROW)
|
|
|
+ {
|
|
|
+ NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
|
|
|
+
|
|
|
+
|
|
|
+ char *name = (char*)sqlite3_column_text(statement, 0);
|
|
|
+ NSString *nsname = [[NSString alloc]initWithUTF8String:name];
|
|
|
+
|
|
|
+ char *description = (char*)sqlite3_column_text(statement, 1);
|
|
|
+ NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ int product_id = sqlite3_column_int(statement, 2);
|
|
|
+
|
|
|
+
|
|
|
+ int wid = sqlite3_column_int(statement, 3);
|
|
|
+ int closeout = sqlite3_column_int(statement, 4);
|
|
|
+
|
|
|
+ NSMutableDictionary* imgjson=[self category_img:product_id db:db];
|
|
|
+
|
|
|
+ if(wid==0)
|
|
|
+ [item setValue:@"false" forKey:@"wish_exists"];
|
|
|
+ else
|
|
|
+ [item setValue:@"true" forKey:@"wish_exists"];
|
|
|
+
|
|
|
+ if(closeout==0)
|
|
|
+ [item setValue:@"false" forKey:@"is_closeout"];
|
|
|
+ else
|
|
|
+ [item setValue:@"true" forKey:@"is_closeout"];
|
|
|
+
|
|
|
+ [item addEntriesFromDictionary:imgjson];
|
|
|
+
|
|
|
+
|
|
|
+ // [item setValue:nsurl forKey:@"img"];
|
|
|
+ [item setValue:nsname forKey:@"fash_name"];
|
|
|
+ [item setValue:nsdescription forKey:@"description"];
|
|
|
+ [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
|
|
|
+// [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
|
|
|
+// i++;
|
|
|
+ if (price_min == 0 && price_max == 0) {
|
|
|
+
|
|
|
+ [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
|
|
|
+ i++;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ char *price_ch = (char *)sqlite3_column_text(statement, 5);
|
|
|
+ if (price_ch == NULL) {
|
|
|
+ price_ch = "";
|
|
|
+ }
|
|
|
+ NSString *enscrypt_price = [NSString stringWithFormat:@"%s",price_ch];
|
|
|
+ double price = [[AESCrypt fastdecrypt:enscrypt_price] doubleValue];
|
|
|
+ DebugLog(@"product price:%lf",price);
|
|
|
+ DebugLog(@"min & max :%lf ~ %lf",price_min,price_max);
|
|
|
+
|
|
|
+ if (price >= price_min && price <= price_max) {
|
|
|
+
|
|
|
+ [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
|
|
|
+ i++;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ [items setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
|
|
|
+ [ret setObject:items forKey:@"items"];
|
|
|
+ sqlite3_finalize(statement);
|
|
|
+ }
|
|
|
+ NSLog(@"count:%d",count);
|
|
|
+
|
|
|
+
|
|
|
+ [iSalesDB close_db:db];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
@end
|