|
@@ -3299,6 +3299,21 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
[img_section setValue:nsname forKey:@"model_name"];
|
|
[img_section setValue:nsname forKey:@"model_name"];
|
|
|
[img_section setValue:nsdescription forKey:@"model_descrition"];
|
|
[img_section setValue:nsdescription forKey:@"model_descrition"];
|
|
|
|
|
|
|
|
|
|
+ if (appDelegate.order_code) { // 离线order code即so#
|
|
|
|
|
+
|
|
|
|
|
+ NSString *cartQtySql = [NSString stringWithFormat:@"select c.item_count from offline_cart as c left join offline_order as o on c.so_no = o.so_id where o.so_id = '%@' and c.item_id = %d;",appDelegate.order_code,item_id];
|
|
|
|
|
+ __block int cartQTY = 0;
|
|
|
|
|
+ [iSalesDB jk_query:cartQtySql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
|
|
+
|
|
|
|
|
+ cartQTY = sqlite3_column_int(stmt, 0);
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+ if (cartQTY > 0) {
|
|
|
|
|
+ [img_section setObject:[NSNumber numberWithInt:cartQTY] forKey:@"Model QTY in cart"];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
[ret setObject:img_section forKey:@"img_section"];
|
|
[ret setObject:img_section forKey:@"img_section"];
|
|
|
|
|
|
|
|
NSMutableDictionary* detail0_section = [[NSMutableDictionary alloc] init];
|
|
NSMutableDictionary* detail0_section = [[NSMutableDictionary alloc] init];
|
|
@@ -3831,11 +3846,21 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
|
|
for(int i=0;i<arr_id.count;i++)
|
|
for(int i=0;i<arr_id.count;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];
|
|
|
|
|
+
|
|
|
|
|
+ // 检查新加Model数量是否大于库存
|
|
|
__block BOOL needContinue = NO;
|
|
__block BOOL needContinue = NO;
|
|
|
[iSalesDB jk_query:[NSString stringWithFormat:@"select availability from product where product_id = %@;",arr_id[i]] db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
[iSalesDB jk_query:[NSString stringWithFormat:@"select availability from product where product_id = %@;",arr_id[i]] db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
|
|
|
|
|
int availability = sqlite3_column_int(stmt, 0);
|
|
int availability = sqlite3_column_int(stmt, 0);
|
|
|
- if (availability <= 0) {
|
|
|
|
|
|
|
+ // 库存小于购买量为缺货
|
|
|
|
|
+ if (availability < item_qty || availability <= 0) {
|
|
|
number_of_outOfStock++;
|
|
number_of_outOfStock++;
|
|
|
needContinue = YES;
|
|
needContinue = YES;
|
|
|
}
|
|
}
|
|
@@ -3847,16 +3872,12 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int _id=[iSalesDB get_recordid:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@' and product_id=%@",orderCode,arr_id[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];
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
NSString* sql=nil;
|
|
NSString* sql=nil;
|
|
|
|
|
|
|
|
- sqlite3_stmt *stmt;
|
|
|
|
|
|
|
+ sqlite3_stmt *stmt = nil;
|
|
|
|
|
+ BOOL shouldStep = NO;
|
|
|
|
|
|
|
|
if(_id<0)
|
|
if(_id<0)
|
|
|
{
|
|
{
|
|
@@ -3871,35 +3892,58 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
sqlite3_bind_text(stmt,2,[orderCode UTF8String],[orderCode length],NULL);
|
|
sqlite3_bind_text(stmt,2,[orderCode UTF8String],[orderCode length],NULL);
|
|
|
sqlite3_bind_text(stmt,3,[[NSString stringWithFormat:@"%d",item_qty] UTF8String],[[NSString stringWithFormat:@"%d",item_qty] length],NULL);
|
|
sqlite3_bind_text(stmt,3,[[NSString stringWithFormat:@"%d",item_qty] UTF8String],[[NSString stringWithFormat:@"%d",item_qty] length],NULL);
|
|
|
sqlite3_bind_text(stmt,4,[[NSString stringWithFormat:@"%d",item_id] UTF8String],[[NSString stringWithFormat:@"%d",item_id] length],NULL);
|
|
sqlite3_bind_text(stmt,4,[[NSString stringWithFormat:@"%d",item_id] UTF8String],[[NSString stringWithFormat:@"%d",item_id] length],NULL);
|
|
|
-
|
|
|
|
|
|
|
+ shouldStep = YES;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- if (qty) {
|
|
|
|
|
|
|
+ if (qty) { // wish list move to cart
|
|
|
sql=[NSString stringWithFormat:@"update offline_cart set item_count=1,modify_time = datetime('now', 'localtime') where _id=?"];
|
|
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_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
|
|
|
sqlite3_bind_int(stmt, 1, _id);
|
|
sqlite3_bind_int(stmt, 1, _id);
|
|
|
-
|
|
|
|
|
|
|
+ shouldStep = YES;
|
|
|
} else {
|
|
} 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:@"select c.item_count + %d,p.availability from product as p left join offline_cart as c on c.item_id = p.item_id where c._id = %d;",item_qty,_id];
|
|
|
|
|
+ __block BOOL update = YES;
|
|
|
|
|
+ [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
|
|
+
|
|
|
|
|
+ int newQTY = sqlite3_column_int(stmt, 0);
|
|
|
|
|
+ int availability = sqlite3_column_int(stmt, 1);
|
|
|
|
|
+
|
|
|
|
|
+ if (newQTY > availability) { // 库存不够
|
|
|
|
|
+ update = NO;
|
|
|
|
|
+ number_of_outOfStock++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+ if (update) {
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
|
|
+ shouldStep = YES;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (sqlite3_step(stmt) == SQLITE_ERROR) {
|
|
|
|
|
- [iSalesDB execSql:@"ROLLBACK" db:db];
|
|
|
|
|
- ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR ];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (shouldStep) {
|
|
|
|
|
|
|
|
- [iSalesDB close_db:db];
|
|
|
|
|
- DebugLog(@"add to cart error");
|
|
|
|
|
- return [RAUtils dict2data:ret];
|
|
|
|
|
|
|
+ if (sqlite3_step(stmt) == SQLITE_ERROR) {
|
|
|
|
|
+ [iSalesDB execSql:@"ROLLBACK" db:db];
|
|
|
|
|
+ ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR ];
|
|
|
|
|
+
|
|
|
|
|
+ [iSalesDB close_db:db];
|
|
|
|
|
+ DebugLog(@"add to cart error");
|
|
|
|
|
+ return [RAUtils dict2data:ret];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -4316,7 +4360,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
itemjson[@"description"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
|
|
itemjson[@"description"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
|
|
|
itemjson[@"stockUom"]=[NSNumber numberWithInt:stockUom];
|
|
itemjson[@"stockUom"]=[NSNumber numberWithInt:stockUom];
|
|
|
itemjson[@"note"]=nsline_note;
|
|
itemjson[@"note"]=nsline_note;
|
|
|
- itemjson[@"is_out_of_stock"] = [NSNumber numberWithBool:availability > 0 ? NO : YES];
|
|
|
|
|
|
|
+ itemjson[@"is_out_of_stock"] = [NSNumber numberWithBool:availability >= item_count ? NO : YES];
|
|
|
// NSDate *date2 = [NSDate date];
|
|
// NSDate *date2 = [NSDate date];
|
|
|
itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false contactID:appDelegate.contact_id];
|
|
itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false contactID:appDelegate.contact_id];
|
|
|
// DebugLog(@"model_bundle time interval");
|
|
// DebugLog(@"model_bundle time interval");
|
|
@@ -8725,8 +8769,12 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
}];
|
|
}];
|
|
|
[iSalesDB close_db:db];
|
|
[iSalesDB close_db:db];
|
|
|
// 去除第一个,
|
|
// 去除第一个,
|
|
|
- product_id = [product_id substringFromIndex:1];
|
|
|
|
|
- item_count_str = [item_count_str substringFromIndex:1];
|
|
|
|
|
|
|
+ if (product_id.length > 1) {
|
|
|
|
|
+ product_id = [product_id substringFromIndex:1];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (item_count_str.length > 1) {
|
|
|
|
|
+ item_count_str = [item_count_str substringFromIndex:1];
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
|
|
|
|
@@ -8851,9 +8899,30 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
|
|
+(NSData*) offline_cartsetqty :(NSMutableDictionary *) params
|
|
+(NSData*) offline_cartsetqty :(NSMutableDictionary *) params
|
|
|
{
|
|
{
|
|
|
|
|
+ NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
|
|
+
|
|
|
NSString *_id = [self valueInParams:params key:@"cartitem_id"];
|
|
NSString *_id = [self valueInParams:params key:@"cartitem_id"];
|
|
|
int item_count = [params[@"inputInt"] integerValue];
|
|
int item_count = [params[@"inputInt"] integerValue];
|
|
|
|
|
|
|
|
|
|
+ // 购买检查数量大于库存
|
|
|
|
|
+ NSString *checkSql = [NSString stringWithFormat:@"select p.availability from product as p left join offline_cart as c on c.item_id = p.item_id where c._id = %@;",_id];
|
|
|
|
|
+ __block BOOL out_of_stock = NO;
|
|
|
|
|
+ [iSalesDB jk_query:checkSql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
|
|
+
|
|
|
|
|
+ int availability = sqlite3_column_int(stmt, 0);
|
|
|
|
|
+
|
|
|
|
|
+ if (availability < item_count) {
|
|
|
|
|
+ out_of_stock = YES;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+ if (out_of_stock) { // 缺货
|
|
|
|
|
+ [dic setValue:[NSNumber numberWithInteger:8] forKey:@"result"];
|
|
|
|
|
+ [dic setObject:@"Item is out of stock" forKey:@"err_msg"];
|
|
|
|
|
+ return [RAUtils dict2data:dic];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
NSString *sql = [NSString stringWithFormat:@"update offline_cart set item_count = %d where _id = %@;",item_count,_id];
|
|
NSString *sql = [NSString stringWithFormat:@"update offline_cart set item_count = %d where _id = %@;",item_count,_id];
|
|
|
|
|
|
|
|
int ret = [iSalesDB execSql:sql];
|
|
int ret = [iSalesDB execSql:sql];
|
|
@@ -8870,7 +8939,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
|
|
[iSalesDB close_db:db];
|
|
[iSalesDB close_db:db];
|
|
|
|
|
|
|
|
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
|
|
|
|
|
+
|
|
|
[dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
|
|
[dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
|
|
|
[dic setValue:@"Regular Mode" forKey:@"mode"];
|
|
[dic setValue:@"Regular Mode" forKey:@"mode"];
|
|
|
// [dic setValue:@"160409" forKey:@"min_ver"];
|
|
// [dic setValue:@"160409" forKey:@"min_ver"];
|
|
@@ -10569,7 +10638,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
orderCode = [self translateSingleQuote:orderCode];
|
|
orderCode = [self translateSingleQuote:orderCode];
|
|
|
|
|
|
|
|
// 缺货检查
|
|
// 缺货检查
|
|
|
- NSString *out_of_stock_SQL = [NSString stringWithFormat:@"select p.availability from product as p left join offline_cart as c on p.product_id = c.product_id where c.so_no = '%@';",orderCode];
|
|
|
|
|
|
|
+ NSString *out_of_stock_SQL = [NSString stringWithFormat:@"select p.availability,c.item_count from product as p left join offline_cart as c on p.product_id = c.product_id where c.so_no = '%@';",orderCode];
|
|
|
|
|
|
|
|
__block BOOL outOfStock = NO;
|
|
__block BOOL outOfStock = NO;
|
|
|
sqlite3 *database = db;
|
|
sqlite3 *database = db;
|
|
@@ -10579,7 +10648,9 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
[iSalesDB jk_query:out_of_stock_SQL db:database close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
[iSalesDB jk_query:out_of_stock_SQL db:database close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
|
|
|
|
|
|
|
|
int availability = sqlite3_column_int(stmt, 0);
|
|
int availability = sqlite3_column_int(stmt, 0);
|
|
|
- outOfStock = outOfStock || (availability <= 0 ? YES : NO);
|
|
|
|
|
|
|
+ int item_qty = sqlite3_column_int(stmt, 1);
|
|
|
|
|
+
|
|
|
|
|
+ outOfStock = outOfStock || (availability < item_qty ? YES : NO);
|
|
|
|
|
|
|
|
}];
|
|
}];
|
|
|
|
|
|
|
@@ -11540,6 +11611,7 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
#pragma mark move wish list to cart
|
|
#pragma mark move wish list to cart
|
|
|
|
|
|
|
|
+ (NSData*)offline_movewish2cart:(NSMutableDictionary *)params {
|
|
+ (NSData*)offline_movewish2cart:(NSMutableDictionary *)params {
|
|
|
|
|
+ // cart中存在的Model在wish list move to cart之后,cart中Model数量为1
|
|
|
|
|
|
|
|
NSString *collectId = params[@"collectId"];
|
|
NSString *collectId = params[@"collectId"];
|
|
|
NSString *sql = [NSString stringWithFormat:@"select w.product_id,w.qty,p.availability,w._id from wishlist as w left join product as p on w.product_id = p.product_id where w._id in (%@);",collectId];
|
|
NSString *sql = [NSString stringWithFormat:@"select w.product_id,w.qty,p.availability,w._id from wishlist as w left join product as p on w.product_id = p.product_id where w._id in (%@);",collectId];
|
|
@@ -11558,8 +11630,8 @@ NSString* gprice = [self get_portfolio_price :appDelegate.contact_id item_id:ite
|
|
|
|
|
|
|
|
int _id = sqlite3_column_int(stmt, 3);
|
|
int _id = sqlite3_column_int(stmt, 3);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- if (availability > 0) {
|
|
|
|
|
|
|
+ // 库存小于购买量为缺货
|
|
|
|
|
+ if (availability >= item_qty) {
|
|
|
product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%d",productId]];
|
|
product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%d",productId]];
|
|
|
|
|
|
|
|
qty = [qty stringByAppendingString:[NSString stringWithFormat:@",%d",item_qty]];
|
|
qty = [qty stringByAppendingString:[NSString stringWithFormat:@",%d",item_qty]];
|