Commit a1b63a16 by lee

解决一致性问题version版本

parent 5b9b3e13
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
- (void) loginWebSuccess:(void(^)()) success failure:(void(^)(NSError *error)) failure; - (void) loginWebSuccess:(void(^)()) success failure:(void(^)(NSError *error)) failure;
/** /**
* 添加商品到购物车 * 立即购买使用
* *
* @param variantId <#variantId description#> * @param variantId <#variantId description#>
* @param quantity <#quantity description#> * @param quantity <#quantity description#>
...@@ -81,10 +81,9 @@ ...@@ -81,10 +81,9 @@
* *
* @return <#return value description#> * @return <#return value description#>
*/ */
- (NSURLSessionDataTask *) addProductWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity success:(void(^)(NSURLSessionDataTask *task,KWMRequestResult *result)) success failure:(void(^)(NSURLSessionDataTask *task,NSError *error)) failure; - (NSURLSessionDataTask *) tmpCartWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity success:(void(^)(NSURLSessionDataTask *task,NSString *cartCookie)) success failure:(void(^)(NSURLSessionDataTask *task,NSError *error)) failure;
/** /**
* 立即购买使用 * 添加商品到购物车
* *
* @param variantId <#variantId description#> * @param variantId <#variantId description#>
* @param quantity <#quantity description#> * @param quantity <#quantity description#>
...@@ -93,7 +92,7 @@ ...@@ -93,7 +92,7 @@
* *
* @return <#return value description#> * @return <#return value description#>
*/ */
- (NSURLSessionDataTask *) tmpCartWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity success:(void(^)(NSURLSessionDataTask *task,NSString *cartCookie)) success failure:(void(^)(NSURLSessionDataTask *task,NSError *error)) failure; - (NSURLSessionDataTask *) addProductWithVariantId:(NSNumber *) variantId quantity:(NSInteger) quantity success:(void(^)(NSURLSessionDataTask *task,KWMRequestResult *result)) success failure:(void(^)(NSURLSessionDataTask *task,NSError *error)) failure;
/** /**
* *
* *
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
@interface KWMShoppingCart () @interface KWMShoppingCart ()
@property (nonatomic, strong) KWMCartResult *result; @property (nonatomic, strong) KWMCartResult *result;
@property (nonatomic, assign) CGFloat version;
@end @end
...@@ -54,19 +55,29 @@ ...@@ -54,19 +55,29 @@
} }
- (void)allItemsWithCallback:(ShoppingCartCallBack)callback { - (void)allItemsWithCallback:(ShoppingCartCallBack)callback {
CGFloat version = [[NSDate date] timeIntervalSince1970];
_version = version;
__weak typeof(self) this = self;
[[KWMAPIManager sharedManager] getCartSuccess:^(NSURLSessionDataTask *task, KWMCartResult *result) { [[KWMAPIManager sharedManager] getCartSuccess:^(NSURLSessionDataTask *task, KWMCartResult *result) {
[[KWMShoppingCart sharedInstance] setResult:result]; if (version == this.version) {
callback(nil,result); [[KWMShoppingCart sharedInstance] setResult:result];
callback(nil,result);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) { } failure:^(NSURLSessionDataTask *task, NSError *error) {
callback(error,nil); callback(error,nil);
}]; }];
} }
- (void)increaseProductWithVariantId:(NSNumber *)variantId quantity:(NSInteger)quantity callback:(ShoppingCartCallBack)callback { - (void)increaseProductWithVariantId:(NSNumber *)variantId quantity:(NSInteger)quantity callback:(ShoppingCartCallBack)callback {
CGFloat version = [[NSDate date] timeIntervalSince1970];
_version = version;
__weak typeof(self) this = self;
[[KWMAPIManager sharedManager] addProductWithVariantId:variantId quantity:quantity success:^(NSURLSessionDataTask *task, KWMRequestResult *result) { [[KWMAPIManager sharedManager] addProductWithVariantId:variantId quantity:quantity success:^(NSURLSessionDataTask *task, KWMRequestResult *result) {
[[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) { if (version == this.version) {
// callback(error,cart); [[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) {
}]; // callback(error,cart);
}];
}
} failure:^(NSURLSessionDataTask *task, NSError *error) { } failure:^(NSURLSessionDataTask *task, NSError *error) {
// callback(error,nil); // callback(error,nil);
}]; }];
...@@ -74,9 +85,14 @@ ...@@ -74,9 +85,14 @@
} }
- (void)changeProductWithVariantId:(NSNumber *)variantId quantity:(NSInteger)quantity callback:(ShoppingCartCallBack)callback { - (void)changeProductWithVariantId:(NSNumber *)variantId quantity:(NSInteger)quantity callback:(ShoppingCartCallBack)callback {
CGFloat version = [[NSDate date] timeIntervalSince1970];
_version = version;
__weak typeof(self) this = self;
[[KWMAPIManager sharedManager] changeProductWithVariantId:variantId quantity:quantity success:^(NSURLSessionDataTask *task, KWMCartResult *result) { [[KWMAPIManager sharedManager] changeProductWithVariantId:variantId quantity:quantity success:^(NSURLSessionDataTask *task, KWMCartResult *result) {
[[KWMShoppingCart sharedInstance] setResult:result]; if (version == this.version) {
[[KWMShoppingCart sharedInstance] setResult:result];
// callback(nil,result); // callback(nil,result);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) { } failure:^(NSURLSessionDataTask *task, NSError *error) {
// callback(error,nil); // callback(error,nil);
}]; }];
...@@ -84,9 +100,14 @@ ...@@ -84,9 +100,14 @@
} }
-(void)updateProductWithVariantIds:(NSArray<NSNumber *> *)variantIds quantitties:(NSArray<NSNumber *> *)quantites callback:(ShoppingCartCallBack)callback { -(void)updateProductWithVariantIds:(NSArray<NSNumber *> *)variantIds quantitties:(NSArray<NSNumber *> *)quantites callback:(ShoppingCartCallBack)callback {
CGFloat version = [[NSDate date] timeIntervalSince1970];
_version = version;
__weak typeof(self) this = self;
[[KWMAPIManager sharedManager] updateProductWithVariantIds:variantIds quantities:quantites success:^(NSURLSessionDataTask *task, KWMCartResult *result) { [[KWMAPIManager sharedManager] updateProductWithVariantIds:variantIds quantities:quantites success:^(NSURLSessionDataTask *task, KWMCartResult *result) {
[[KWMShoppingCart sharedInstance] setResult:result]; if (version == this.version) {
[[KWMShoppingCart sharedInstance] setResult:result];
// callback(nil,result); // callback(nil,result);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) { } failure:^(NSURLSessionDataTask *task, NSError *error) {
// callback(error,nil); // callback(error,nil);
}]; }];
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
[[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) { [[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) {
[this refresh]; [this refresh];
}]; }];
} }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment