ソースを参照

增加方法offline_movewish2cart,并实现之。

Pen Li 9 年 前
コミット
21a18629be

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


+ 6 - 6
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -20,11 +20,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/data_provider/iSalesNetwork.m"
-            timestampString = "495944149.948286"
+            timestampString = "496639431.204805"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "788"
-            endingLineNumber = "788"
+            startingLineNumber = "791"
+            endingLineNumber = "791"
             landmarkName = "+commit_Order:"
             landmarkType = "5">
          </BreakpointContent>
@@ -36,11 +36,11 @@
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "common/data_provider/iSalesNetwork.m"
-            timestampString = "495944248.440445"
+            timestampString = "496639431.204805"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "768"
-            endingLineNumber = "768"
+            startingLineNumber = "771"
+            endingLineNumber = "771"
             landmarkName = "+commit_Order:"
             landmarkType = "5">
          </BreakpointContent>

+ 1 - 1
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.h

@@ -61,7 +61,7 @@
 +(NSData*) offline_copyorder :(NSMutableDictionary *) params;
 +(NSData*) offline_submitorder :(NSMutableDictionary *) params;
 
-
++ (NSData*)offline_movewish2cart:(NSMutableDictionary *)params;
 +(NSData*) offline_add2cart :(NSMutableDictionary *) params;
 +(NSData*) offline_add2cartbyname :(NSMutableDictionary *) params;
 +(NSData*) offline_requestcart :(NSMutableDictionary *) params;

+ 79 - 44
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -2147,15 +2147,19 @@
     
     NSString* product_id=params[@"product_id"];
     NSString* orderCode=params[@"orderCode"];
-    
+    NSString *qty = params[@"qty"];
     
     NSArray* arr_id=[RAUtils string2arr:product_id separator:@","];
+    NSArray *qty_arr = [RAUtils string2arr:qty separator:@","];
     
     for(int i=0;i<arr_id.count;i++)
     {
         
         int _id=[iSalesDB get_recordid:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@' and product_id=%@",orderCode,arr_id[i]]];
         int item_qty= count;
+        if (qty) {
+            item_qty = [qty_arr[i] integerValue];
+        }
         if(item_qty==0)
             item_qty=[self model_stockUom:[arr_id[i] intValue] db:db];
         
@@ -2165,10 +2169,9 @@
 
         if(_id<0)
         {
-            //             NSString* bundle_serialno= [self model_bundle:[arr_id[i] intValue] db:db];
+
             int item_id=[self product_itemid:[arr_id[i] intValue] db:db];
             
-//            sql=[NSString stringWithFormat:@"insert into offline_cart(product_id,so_no,item_count,item_id,create_time) values(%@,'%@',%d,%d,datetime('now', 'localtime'))",arr_id[i],orderCode,item_qty,item_id];
             
             sql=[NSString stringWithFormat:@"insert into offline_cart(product_id,so_no,item_count,item_id,create_time) values(?,?,?,?,datetime('now', 'localtime'))"];
             
@@ -2181,15 +2184,24 @@
         }
         else
         {
-//            sql=[NSString stringWithFormat:@"update offline_cart set item_count=item_count+%d,create_time = datetime('now', 'localtime') where _id=%d",item_qty,_id];
+            if (qty) {
+                 sql=[NSString stringWithFormat:@"update offline_cart set item_count=1,modify_time = datetime('now', 'localtime') where _id=?"];
+                
+                sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
+                sqlite3_bind_int(stmt, 1, _id);
+                
+            } else {
+                sql=[NSString stringWithFormat:@"update offline_cart set item_count=item_count+?,create_time = datetime('now', 'localtime') where _id=?"];
+                
+                sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
+                sqlite3_bind_text(stmt,1,[[NSString stringWithFormat:@"%d",item_qty] UTF8String],[[NSString stringWithFormat:@"%d",item_qty] length],NULL);
+                sqlite3_bind_text(stmt,2,[[NSString stringWithFormat:@"%d",_id] UTF8String],[[NSString stringWithFormat:@"%d",_id] length],NULL);
+            }
+
             
-            sql=[NSString stringWithFormat:@"update offline_cart set item_count=item_count+?,create_time = datetime('now', 'localtime') where _id=?"];
             
-            sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
-            sqlite3_bind_text(stmt,1,[[NSString stringWithFormat:@"%d",item_qty] UTF8String],[[NSString stringWithFormat:@"%d",item_qty] length],NULL);
-            sqlite3_bind_text(stmt,2,[[NSString stringWithFormat:@"%d",_id] UTF8String],[[NSString stringWithFormat:@"%d",_id] length],NULL);
         }
-//        [iSalesDB execSql:sql db:db];
+        
         if (sqlite3_step(stmt) == SQLITE_ERROR) {
             [iSalesDB execSql:@"ROLLBACK" db:db];
             ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR ];
@@ -3665,6 +3677,7 @@
         if(count==0)
         {
 
+            sqlQuery = [NSString stringWithFormat:@"insert into wishlist(product_id,qty) values(?,?);"];
             __block int cart_count = 0;
             if (!item_count_str) {
                 NSString *product_sold_qty_sql = [NSString stringWithFormat:@"select model_set from product where product_id = %@",arr[i]];
@@ -3694,6 +3707,18 @@
                 DebugLog(@"add to wishlist error");
                 return ret;
             }
+        } else {
+            sqlQuery = [NSString stringWithFormat:@"update wishlist set qty = 1 where product_id = %@;",arr[i]];
+            
+            if ([iSalesDB execSql:sqlQuery db:db] == RESULT_FALSE) {
+                [iSalesDB execSql:@"ROLLBACK" db:db];
+                ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR];
+                
+                [iSalesDB close_db:db];
+                DebugLog(@"add to wishlist error");
+                return ret;
+
+            }
         }
 
     }
@@ -9208,41 +9233,6 @@
 
 +(NSData*) offline_add2cartbyname :(NSMutableDictionary *) params
 {
-//    {
-//        count = 1;
-//        customerInfo =     {
-//            "business_card_0" = "";
-//            "business_card_1" = "";
-//            "business_card_2" = "";
-//            "customer_address1" = "1815 PEARL ST";
-//            "customer_address2" = "";
-//            "customer_address3" = "";
-//            "customer_address4" = "";
-//            "customer_cid" = 3RDVIN0001;
-//            "customer_city" = BOULDER;
-//            "customer_contact" = "CONNIE DRUNNER";
-//            "customer_contact_ext" = "1815 PEARL ST
-//            \n BOULDER, CO, 80302, US United States";
-//            "customer_contact_notes" = "Remark:    Please review your order carefully and make sure EVERYTHING is correct, including the SHIP TO address. Please sign to authorize NPD to ship. Thank you for your business.";
-//            "customer_country" = "US United States";
-//            "customer_email" = "3RDANDVINEDESIGN@GMAIL.COM";
-//            "customer_fax" = "303.442.0672";
-//            "customer_first_name" = CONNIE;
-//            "customer_last_name" = DRUNNER;
-//            "customer_name" = "3rd & Vine Desgin";
-//            "customer_phone" = "303.442.0669";
-//            "customer_price_type" = "West Dealer Price;Special Customer Price;West Wholesale Price;East Wholesale Price;";
-//            "customer_sales_rep" = "";
-//            "customer_state" = CO;
-//            "customer_zipcode" = 80302;
-//        };
-//        mode = RM;
-//        orderCode = MOB1608240002;
-//        password = 123456;
-//        "product_name" = "108239B-23,108239B-01";
-//        result = 2;
-//        user = EvanK;
-//    }
 
     NSString *orderCode = [params objectForKey:@"orderCode"];
     NSString *product_name = [params objectForKey:@"product_name"];
@@ -9380,4 +9370,49 @@
     return [RAUtils dict2data:ret];
 }
 
++ (NSData*)offline_movewish2cart:(NSMutableDictionary *)params {
+    
+    NSString *collectId = params[@"collectId"];
+    NSString *sql = [NSString stringWithFormat:@"select product_id,qty from wishlist where _id in (%@);",collectId];
+    
+    __block NSString *product_id = @"";
+    __block NSString *qty = @"";
+    [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+        
+        int productId = sqlite3_column_int(stmt, 0);
+
+        int item_qty = sqlite3_column_int(stmt, 1);
+        
+        product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%d",productId]];
+        
+        qty = [qty stringByAppendingString:[NSString stringWithFormat:@",%d",item_qty]];
+
+    }];
+    
+    product_id = [product_id substringFromIndex:1];
+    qty = [qty substringFromIndex:1];
+    
+    NSDictionary *newParams = @{
+                                @"product_id" : product_id,
+                                @"orderCode"  : params[@"orderCode"],
+                                @"qty"        : qty
+                                };
+    
+    NSData *data = [self offline_add2cart:newParams.mutableCopy];
+    NSMutableDictionary *retDic = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
+    
+    if ([retDic[@"result"] integerValue] == RESULT_TRUE) {
+        
+        NSString *deleteSQL = [NSString stringWithFormat:@"delete from wishlist where _id in (%@);",collectId];
+        
+        int ret = [iSalesDB execSql:deleteSQL];
+        
+        retDic[@"result"] = [NSNumber numberWithInteger:ret];
+        
+    }
+    
+    return [RAUtils dict2data:retDic];
+    
+}
+
 @end

+ 8 - 5
RedAnt ERP Mobile/common/data_provider/iSalesNetwork.m

@@ -541,14 +541,17 @@ repeat:
         [params setValue:appDelegate.order_code forKey:@"orderCode"];
     [params setValue:item_ids forKey:@"collectId"];
     //    [params setValue:editor forKey:@"editor"];
+    NSData *json = nil;
     if(appDelegate.offline_mode)
     {
-        return [OLDataProvider offline_notimpl];
+        json = [OLDataProvider offline_movewish2cart:params];
+    } else {
+        if(![self IsNetworkAvailable])
+            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+        
+        json=[self get_json:URL_WISH2CART parameters:params];
     }
-    if(![self IsNetworkAvailable])
-        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
-    
-    NSData* json=[self get_json:URL_WISH2CART parameters:params];
+
     if(json!=nil)
     {
         NSError *error=nil;