Bläddra i källkod

完成分类查询

Pen Li 9 år sedan
förälder
incheckning
9d3c8089c3

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 53 - 14
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -3442,41 +3442,63 @@
 //        "sort_by" = 0;
 //        user = EvanK;
 //    }
+    double price_min = 0;
+    double price_max = 0;
     if ([params.allKeys containsObject:@"alert"]) {
         // 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"];
-        int available_count;
+        NSString *available_condition;
         if ([available isEqualToString:@"Display All"]) {
-            available_count = -1;
+            available_condition = @">=";
         } else if ([available isEqualToString:@"Available Now"]) {
-            available_count = 1;
+            available_condition = @">";
         } else {
-            available_count = 0;
+            available_condition = @"==";
         }
         
         // best seller
         [self check:params[@"bestseller"] valueKey:@"best_seller" inDictionary:filter];
-        NSString *bestSeller = params[@"bestseller"];
-        int best_intValue = bestSeller ? 1 : 0;
+        
         
         // 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];
+        }
+        NSLog(@"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 = @"";
+            qty = @"like 'Sold in quantities of _'";
+        } else {
+            qty = [NSString stringWithFormat:@"= 'Sold in quantities of %@'",qty];
         }
-#warning 分类查询未完待续。。
+        
+        // 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 where m.category like'%%#%@#%%' alert = '%@' order by m.name limit %d offset %d ;",category,alert,limit, offset];
+        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];
     }
     
     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
@@ -3546,21 +3568,38 @@
             [item setValue:nsname forKey:@"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++;
+            
+             NSLog(@"2、min~max:%lf ~ %lf",price_min,price_max);
+            if (price_min == 0 && price_max == 0) {
+                NSLog(@"min && max == 0");
+                [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
+                i++;
+            } else {
+               
+                NSString *enscrypt_price = [NSString stringWithFormat:@"%s",(char *)sqlite3_column_text(statement, 5)];
+                double price = [[AESCrypt fastdecrypt:enscrypt_price] doubleValue];
+                NSLog(@"product price:%lf",price);
+
+                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);
+    } else {
+        NSLog(@"nothing...");
     }
     NSLog(@"count:%d",count);
     
     
     [iSalesDB close_db:db];
-    
-    
-    
+
+//    NSLog(@"descrypt:%@",[AESCrypt fastdecrypt:@"QLhEWeD8ddE4cCEWBOWPhg=="]);
     
     DebugLog(@"data string: %@",[RAUtils dict2string:ret] );