|
|
@@ -3586,6 +3586,7 @@
|
|
|
# pragma mark item search
|
|
|
+(NSDictionary*) offline_itemsearch:(NSMutableDictionary *) params
|
|
|
{
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
|
|
|
BOOL filterSearch = ![params.allKeys containsObject:@"covertype"];
|
|
|
|
|
|
@@ -3652,7 +3653,7 @@
|
|
|
if ([alert isEqualToString:@"Display All"]) {
|
|
|
alert = [NSString stringWithFormat:@""];
|
|
|
} else {
|
|
|
- alert = [NSString stringWithFormat:@"and m.alert = '%@'",alert];
|
|
|
+ alert = [NSString stringWithFormat:@"and alert = '%@'",alert];
|
|
|
}
|
|
|
|
|
|
// available
|
|
|
@@ -3662,16 +3663,16 @@
|
|
|
if ([available isEqualToString:@"Display All"]) {
|
|
|
available_condition = @"";
|
|
|
} else if ([available isEqualToString:@"Available Now"]) {
|
|
|
- available_condition = @"and m.availability > 0";
|
|
|
+ available_condition = @"and availability > 0";
|
|
|
} else {
|
|
|
- available_condition = @"and m.availability == 0";
|
|
|
+ available_condition = @"and availability == 0";
|
|
|
}
|
|
|
|
|
|
// best seller
|
|
|
[self check:params[@"bestseller"] valueKey:@"best_seller" inDictionary:filter];
|
|
|
NSString *best_seller = @"";
|
|
|
if ([params[@"bestseller"] isEqualToString:@"Yes"]) {
|
|
|
- best_seller = @"and m.best_seller > 0";
|
|
|
+ best_seller = @"and best_seller > 0";
|
|
|
}
|
|
|
|
|
|
// price
|
|
|
@@ -3679,17 +3680,31 @@
|
|
|
NSString *price = params[@"price"];
|
|
|
price_min = 0;
|
|
|
price_max = MAXFLOAT;
|
|
|
- if ([price isEqualToString:@"Display All"]) {
|
|
|
- price = @"";
|
|
|
- } else if([price containsString:@"+"]){
|
|
|
- price = [price stringByReplacingOccurrencesOfString:@"+" withString:@""];
|
|
|
- price_min = [price doubleValue];
|
|
|
- price = [NSString stringWithFormat:@"and Convert(double,decryptfield(p.price)) >= %.2lf and Convert(double,decryptfield(p.price)) <= %.2lf",price_min,price_max];
|
|
|
+ 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]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ([price isEqualToString:@"Display All"]) {
|
|
|
+ price = [NSString stringWithFormat:@"and product_id in (select DISTINCT product_id from model_price where price_name in (%@))",priceName];
|
|
|
+ } 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 = [NSString stringWithFormat:@"and Convert(double,decryptfield(p.price)) >= %.2lf and Convert(double,decryptfield(p.price)) <= %.2lf",price_min,price_max];
|
|
|
+ price = @"";
|
|
|
}
|
|
|
|
|
|
// sold_by_qty : Sold in quantities of %@
|
|
|
@@ -3737,9 +3752,9 @@
|
|
|
|
|
|
cate_id_array[i] = [category1 objectForKey:@"id"];
|
|
|
if (i == 0) {
|
|
|
- [cateWhere appendFormat:@"m.category like'%%#%@#%%'",cate_id_array[i]];
|
|
|
+ [cateWhere appendFormat:@"category like'%%#%@#%%'",cate_id_array[i]];
|
|
|
} else {
|
|
|
- [cateWhere appendFormat:@"or m.category like'%%#%@#%%'",cate_id_array[i]];
|
|
|
+ [cateWhere appendFormat:@"or category like'%%#%@#%%'",cate_id_array[i]];
|
|
|
}
|
|
|
[category1 setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
|
|
|
[category0 setValue:category1 forKey:key1];
|
|
|
@@ -3757,14 +3772,13 @@
|
|
|
|
|
|
}
|
|
|
[filter setValue: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 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。。。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 %@ %@ %@ %@ and product_id in (select product_id from model_price where price_name='West Dealer Price' %@) ) m left join wishlist w on m.product_id=w.product_id ",cateWhere,best_seller,available_condition,qty,price];
|
|
|
+// 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];
|
|
|
|
|
|
|
|
|
where = cateWhere;
|
|
|
@@ -3773,7 +3787,7 @@
|
|
|
#warning where == nil 在filterSearch时
|
|
|
int count = [iSalesDB get_recordcount:db table:@"model" where:where];
|
|
|
|
|
|
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+
|
|
|
if (!appDelegate.user) {
|
|
|
[filter setValue:@{@"count" : @(0)} forKey:@"price"];
|
|
|
}
|
|
|
@@ -3844,6 +3858,7 @@
|
|
|
|
|
|
DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
|
|
|
|
|
|
+
|
|
|
return ret;
|
|
|
}
|
|
|
|