Kaynağa Gözat

修复offline_itemsearch:中overtype为空时 where的赋值,以及category多选情况下sql语句category条件的动态生成

Pen Li 9 yıl önce
ebeveyn
işleme
32785282b3

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


+ 45 - 17
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -3637,8 +3637,7 @@
    
     
     sqlite3 *db = [iSalesDB get_db];
-    
-    int count = [iSalesDB get_recordcount:db table:@"model" where:where];
+
     
     
     NSString *sqlQuery = nil;
@@ -3697,31 +3696,52 @@
             qty = [NSString stringWithFormat:@"= 'Sold in quantities of %@'",qty];
         }
         
+#warning category 多选情况(已经处理)
         // category
         NSString *category_id = params[@"ctgId"];
+        NSMutableArray *cate_id_array = nil;
+        NSMutableString *cateWhere = [NSMutableString string];
         
         if ([category_id isEqualToString:@""] || !category_id) {
-            category_id = @"%";
+            [cateWhere appendString:@"m.category like'%%#%#%%'"];
         } else {
+            
+            if ([category_id containsString:@","]) {
+                cate_id_array = [[category_id componentsSeparatedByString:@","] mutableCopy];
+            } else {
+                cate_id_array = [@[category_id] mutableCopy];
+            }
+            /*-----------*/
             NSMutableDictionary *cateDic = [[filter objectForKey:@"category"] mutableCopy];
-            for (NSString *key0 in cateDic.allKeys) {
+            
+            
+            for (int i = 0; i < cate_id_array.count; i++) {
                 
-                if ([key0 containsString:@"category_"]) {
+                for (NSString *key0 in cateDic.allKeys) {
                     
-                    NSMutableDictionary *category0 = [[cateDic objectForKey:key0] mutableCopy];
-                    for (NSString *key1 in category0.allKeys) {
+                    if ([key0 containsString:@"category_"]) {
                         
-                        if ([key1 containsString:@"category_"]) {
+                        NSMutableDictionary *category0 = [[cateDic objectForKey:key0] mutableCopy];
+                        for (NSString *key1 in category0.allKeys) {
                             
-                            NSMutableDictionary *category1 = [[category0 objectForKey:key1] mutableCopy];
-                            [category1 setValue:[NSNumber numberWithInteger:0] forKey:@"check"];
-                            if ([[category1 objectForKey:@"cid"] isEqualToString:category_id]) {
+                            if ([key1 containsString:@"category_"]) {
+                                
+                                NSMutableDictionary *category1 = [[category0 objectForKey:key1] mutableCopy];
+                                [category1 setValue:[NSNumber numberWithInteger:0] forKey:@"check"];
+                                if ([[category1 objectForKey:@"cid"] isEqualToString:cate_id_array[i]]) {
+                                    
+                                    cate_id_array[i] = [category1 objectForKey:@"id"];
+                                    if (i == 0) {
+                                        [cateWhere appendFormat:@"m.category like'%%#%@#%%'",cate_id_array[i]];
+                                    } else {
+                                        [cateWhere appendFormat:@"or m.category like'%%#%@#%%'",cate_id_array[i]];
+                                    }
+                                    [category1 setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
+                                    [category0 setValue:category1 forKey:key1];
+                                    [cateDic setValue:category0 forKey:key0];
+                                    
+                                }
                                 
-                                category_id = [category1 objectForKey:@"id"];
-                                [category1 setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
-                                [category0 setValue:category1 forKey:key1];
-                                [cateDic setValue:category0 forKey:key0];
-                                [filter setValue:cateDic forKey:@"category"];
                             }
                             
                         }
@@ -3731,14 +3751,22 @@
                 }
                 
             }
+            [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 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];
+        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];
+        
+        where = cateWhere;
     }
     
+#warning where == nil 在filter选择时
+    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"];