Pen Li 9 лет назад
Родитель
Сommit
f9a233b5d8

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


+ 21 - 36
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -3637,7 +3637,7 @@
    
     
     sqlite3 *db = [iSalesDB get_db];
-
+    [iSalesDB AddExFunction:db];
     
     
     NSString *sqlQuery = nil;
@@ -3660,16 +3660,19 @@
         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 m.availability > 0";
         } else {
-            available_condition = @"==";
+            available_condition = @"and m.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";
+        }
         
         // price
         [self check:params[@"price"] valueKey:@"price" inDictionary:filter];
@@ -3677,23 +3680,25 @@
         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];
         } 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];
         }
         
         // 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];
         }
         
 #warning category 多选情况(已经处理)
@@ -3703,7 +3708,7 @@
         NSMutableString *cateWhere = [NSMutableString string];
         
         if ([category_id isEqualToString:@""] || !category_id) {
-            [cateWhere appendString:@"m.category like'%%#%#%%'"];
+            [cateWhere appendString:@"1 = 1"];
         } else {
             
             if ([category_id containsString:@","]) {
@@ -3754,17 +3759,18 @@
             [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,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 %@ 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 ;",cateWhere,alert,available_condition,qty,limit, offset];
+        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];
+        
         
         where = cateWhere;
     }
     
-#warning where == nil 在filter选择
+#warning where == nil 在filterSearch
     int count = [iSalesDB get_recordcount:db table:@"model" where:where];
     
     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
@@ -3826,29 +3832,8 @@
             [item setValue:nsname forKey:@"fash_name"];
             [item setValue:nsdescription forKey:@"description"];
             [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
-
-            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];
-                
-                if (price >= price_min && price <= price_max) {
-                    
-                    [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
-                    i++;
-                    
-                }
-            }
-
+            [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
+            i++;
         }
         [items setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
         [ret setObject:items forKey:@"items"];