|
|
@@ -3375,6 +3375,8 @@
|
|
|
{
|
|
|
// NSString* orderCode = [params valueForKey:@"orderCode"];
|
|
|
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+
|
|
|
NSString* category = [params valueForKey:@"category"];
|
|
|
if (!category || [category isEqualToString:@""]) {
|
|
|
category = @"%";
|
|
|
@@ -3391,6 +3393,7 @@
|
|
|
|
|
|
|
|
|
sqlite3 *db = [iSalesDB get_db];
|
|
|
+ [iSalesDB AddExFunction:db];
|
|
|
|
|
|
int count = [iSalesDB get_recordcount:db table:@"model" where:[NSString stringWithFormat:@"category like'%%#%@#%%'",category]];
|
|
|
|
|
|
@@ -3421,7 +3424,7 @@
|
|
|
if ([alert isEqualToString:@"Display All"]) {
|
|
|
alert = [NSString stringWithFormat:@""];
|
|
|
} else {
|
|
|
- alert = [NSString stringWithFormat:@"and m.alert = '%@'",alert];
|
|
|
+ alert = [NSString stringWithFormat:@"and alert = '%@'",alert];
|
|
|
}
|
|
|
|
|
|
// available
|
|
|
@@ -3429,49 +3432,72 @@
|
|
|
NSString *available = params[@"available"];
|
|
|
NSString *available_condition;
|
|
|
if ([available isEqualToString:@"Display All"]) {
|
|
|
- available_condition = @">=";
|
|
|
+ available_condition = @"";
|
|
|
} else if ([available isEqualToString:@"Available Now"]) {
|
|
|
- available_condition = @">";
|
|
|
+ available_condition = @"and availability > 0";
|
|
|
} else {
|
|
|
- available_condition = @"==";
|
|
|
+ available_condition = @"and availability == 0";
|
|
|
}
|
|
|
|
|
|
// best seller
|
|
|
[self check:params[@"bestseller"] valueKey:@"best_seller" inDictionary:filter];
|
|
|
-
|
|
|
+ NSString *best_seller = @"m.name asc";
|
|
|
+ NSString *order_best_seller = @"";
|
|
|
+ if ([params[@"bestseller"] isEqualToString:@"Yes"]) {
|
|
|
+ best_seller = @"and best_seller > 0";
|
|
|
+ order_best_seller = @"m.best_seller desc";
|
|
|
+ }
|
|
|
|
|
|
// price
|
|
|
[self check:params[@"price"] valueKey:@"price" inDictionary:filter];
|
|
|
NSString *price = params[@"price"];
|
|
|
price_min = 0;
|
|
|
price_max = MAXFLOAT;
|
|
|
- if ([price isEqualToString:@"Display All"]) {
|
|
|
+ if (appDelegate.user) {
|
|
|
+ NSArray *priceTypeArray = [self get_contact_default_price_type:nil db:db];
|
|
|
+ NSMutableString *priceName = [NSMutableString string];
|
|
|
+ for (int i = 0; i < priceTypeArray.count; i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ [priceName appendFormat:@"'%@'",priceTypeArray[i]];
|
|
|
+ } else {
|
|
|
+ [priceName appendFormat:@",'%@'",priceTypeArray[i]];
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- } else if([price containsString:@"+"]){
|
|
|
- price = [price stringByReplacingOccurrencesOfString:@"+" withString:@""];
|
|
|
- price_min = [price doubleValue];
|
|
|
+ if ([price isEqualToString:@"Display All"]) {
|
|
|
+ price = [NSString stringWithFormat:@""];
|
|
|
+ } else if([price containsString:@"+"]){
|
|
|
+ price = [price stringByReplacingOccurrencesOfString:@"+" withString:@""];
|
|
|
+ price_min = [price doubleValue];
|
|
|
+ price = [NSString stringWithFormat:@"and product_id in (select DISTINCT product_id from model_price where price_name in (%@) and cast(decrypt(price) as double) >= %.2lf and cast(decrypt(price) as double) <= %.2lf)",priceName,price_min,price_max];
|
|
|
+ } else {
|
|
|
+ NSArray *priceArray = [price componentsSeparatedByString:@"-"];
|
|
|
+ price_min = [[priceArray objectAtIndex:0] doubleValue];
|
|
|
+ price_max = [[priceArray objectAtIndex:1] doubleValue];
|
|
|
+ price = [NSString stringWithFormat:@"and product_id in (select DISTINCT product_id from model_price where price_name in (%@) and cast(decrypt(price) as double) >= %.2lf and cast(decrypt(price) as double) <= %.2lf)",priceName,price_min,price_max];
|
|
|
+ }
|
|
|
} else {
|
|
|
- NSArray *priceArray = [price componentsSeparatedByString:@"-"];
|
|
|
- price_min = [[priceArray objectAtIndex:0] doubleValue];
|
|
|
- price_max = [[priceArray objectAtIndex:1] doubleValue];
|
|
|
+ price = @"";
|
|
|
}
|
|
|
- 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 %'";
|
|
|
+ qty = @"";
|
|
|
} else {
|
|
|
- qty = [NSString stringWithFormat:@"= 'Sold in quantities of %@'",qty];
|
|
|
+ qty = [NSString stringWithFormat:@"and model_set = 'Sold in quantities of %@'",qty];
|
|
|
}
|
|
|
|
|
|
+ // cate
|
|
|
+ NSString *cateWhere = [NSString stringWithFormat:@"category like'%%#%@#%%'",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,alert,available_condition,qty,limit, offset];
|
|
|
+ sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from (select name,description,product_id,closeout,best_seller from model where %@ %@ %@ %@ %@ %@) m left join wishlist w on m.product_id=w.product_id order by %@ limit %d offset %d;",cateWhere,best_seller,alert,available_condition,qty,price,order_best_seller,limit,offset];
|
|
|
}
|
|
|
|
|
|
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+
|
|
|
if (!appDelegate.user) {
|
|
|
[filter setValue:@{@"count" : @(0)} forKey:@"price"];
|
|
|
}
|
|
|
@@ -3493,9 +3519,6 @@
|
|
|
{
|
|
|
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);
|
|
|
if(name==nil)
|
|
|
name="";
|
|
|
@@ -3510,12 +3533,6 @@
|
|
|
|
|
|
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);
|
|
|
|
|
|
@@ -3538,31 +3555,9 @@
|
|
|
[item setValue:nsname forKey:@"name"];
|
|
|
[item setValue:nsdescription forKey:@"description"];
|
|
|
[item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
|
|
|
-
|
|
|
- DebugLog(@"2、min~max:%lf ~ %lf",price_min,price_max);
|
|
|
- if (price_min == 0 && price_max == 0) {
|
|
|
-
|
|
|
- DebugLog(@"min && 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);
|
|
|
+ [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
|
|
|
+ i++;
|
|
|
|
|
|
- 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"];
|
|
|
@@ -3575,8 +3570,6 @@
|
|
|
|
|
|
|
|
|
[iSalesDB close_db:db];
|
|
|
-
|
|
|
-// NSLog(@"descrypt:%@",[AESCrypt fastdecrypt:@"QLhEWeD8ddE4cCEWBOWPhg=="]);
|
|
|
|
|
|
DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
|
|
|
|
|
|
@@ -3671,8 +3664,11 @@
|
|
|
// best seller
|
|
|
[self check:params[@"bestseller"] valueKey:@"best_seller" inDictionary:filter];
|
|
|
NSString *best_seller = @"";
|
|
|
+ NSString *order_best_seller = @"m.name asc";
|
|
|
+
|
|
|
if ([params[@"bestseller"] isEqualToString:@"Yes"]) {
|
|
|
best_seller = @"and best_seller > 0";
|
|
|
+ order_best_seller = @"m.best_seller desc";
|
|
|
}
|
|
|
|
|
|
// price
|
|
|
@@ -3692,7 +3688,7 @@
|
|
|
}
|
|
|
|
|
|
if ([price isEqualToString:@"Display All"]) {
|
|
|
- price = [NSString stringWithFormat:@"and product_id in (select DISTINCT product_id from model_price where price_name in (%@))",priceName];
|
|
|
+ price = [NSString stringWithFormat:@""];
|
|
|
} else if([price containsString:@"+"]){
|
|
|
price = [price stringByReplacingOccurrencesOfString:@"+" withString:@""];
|
|
|
price_min = [price doubleValue];
|
|
|
@@ -3716,7 +3712,6 @@
|
|
|
qty = [NSString stringWithFormat:@"and model_set = 'Sold in quantities of %@'",qty];
|
|
|
}
|
|
|
|
|
|
-#warning category 多选情况(已经处理)
|
|
|
// category
|
|
|
NSString *category_id = params[@"ctgId"];
|
|
|
NSMutableArray *cate_id_array = nil;
|
|
|
@@ -3776,15 +3771,13 @@
|
|
|
|
|
|
// 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 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 %@ %@ %@ %@ %@ %@ order by m.name,m.best_seller DESC limit %d offset %d ;",cateWhere,best_seller,alert,available_condition,qty,price,limit,offset];
|
|
|
-#warning sql还没完,价格部分还没搞定、order by 、limit。。。offline_category部分也需要修改。
|
|
|
- sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from (select name,description,product_id,closeout from model where %@ %@ %@ %@ %@ %@) m left join wishlist w on m.product_id=w.product_id order by m.name asc limit %d offset %d;",cateWhere,best_seller,alert,available_condition,qty,price,limit,offset];
|
|
|
+ sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from (select name,description,product_id,closeout,best_seller from model where %@ %@ %@ %@ %@ %@) m left join wishlist w on m.product_id=w.product_id order by %@ limit %d offset %d;",cateWhere,best_seller,alert,available_condition,qty,price,order_best_seller,limit,offset];
|
|
|
|
|
|
|
|
|
where = cateWhere;
|
|
|
}
|
|
|
|
|
|
-#warning where == nil 在filterSearch时
|
|
|
+ // where == nil 在filterSearch时
|
|
|
int count = [iSalesDB get_recordcount:db table:@"model" where:where];
|
|
|
|
|
|
|
|
|
@@ -3858,7 +3851,6 @@
|
|
|
|
|
|
DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
|
|
|
|
|
|
-
|
|
|
return ret;
|
|
|
}
|
|
|
|