|
@@ -15,6 +15,10 @@
|
|
|
#import "CartVM.h"
|
|
|
#import "ASUserModel.h"
|
|
|
|
|
|
+#import "ASGoodsDetailsVM.h"
|
|
|
+
|
|
|
+#import "ASAddGiftGoodsView.h"
|
|
|
+
|
|
|
@interface Cart_CheckoutC ()<RY_baseVMprotocol>
|
|
|
|
|
|
@property (nonatomic, strong) CartVM *VM;
|
|
@@ -38,6 +42,15 @@
|
|
|
@property (nonatomic, strong) ASCheckoutPaymentModel *paymentModel;
|
|
|
|
|
|
|
|
|
+//手动添加赠品至购物车
|
|
|
+@property (nonatomic, strong) ASGoodsDetailsVM *goodsDetailsVM;
|
|
|
+
|
|
|
+@property (nonatomic, strong) ASAddGiftGoodsView *addGiftView;
|
|
|
+@property (nonatomic, strong) NSMutableArray *addGiftParamArr;
|
|
|
+@property (nonatomic, assign) int index;
|
|
|
+@property (nonatomic, assign) int giftShowCount;
|
|
|
+
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation Cart_CheckoutC
|
|
@@ -57,6 +70,10 @@
|
|
|
- (void)initSubviews {
|
|
|
[super initSubviews];
|
|
|
|
|
|
+ self.addGiftParamArr = [[NSMutableArray alloc] initWithCapacity:1];
|
|
|
+ self.index = 0;
|
|
|
+ self.giftShowCount = 0;
|
|
|
+
|
|
|
IPhoneXHeigh
|
|
|
[self setupTableV:[CartCheckTableV class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, KScreenHeight - securitytop_Y)];
|
|
|
self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
|
|
@@ -211,16 +228,43 @@
|
|
|
[self updateData];
|
|
|
|
|
|
} else if ([mark isEqualToString:Cart_cartsMineItems_Post]
|
|
|
- || [mark isEqualToString:DEL_cartsMineItems]
|
|
|
- || [mark isEqualToString:PUT_cartsMineCoupons]
|
|
|
- || [mark isEqualToString:Chectout_PUT_usePoints]
|
|
|
- || [mark isEqualToString:Chectout_DEL_cancelusePoints]
|
|
|
- || [mark isEqualToString:Chectout_setShipMethod]){
|
|
|
+ || [mark isEqualToString:DEL_cartsMineItems]
|
|
|
+ || [mark isEqualToString:PUT_cartsMineCoupons]
|
|
|
+ || [mark isEqualToString:Chectout_PUT_usePoints]
|
|
|
+ || [mark isEqualToString:Chectout_DEL_cancelusePoints]
|
|
|
+ || [mark isEqualToString:Chectout_setShipMethod]
|
|
|
+ || [mark isEqualToString:Chectout_giftAddCart]){
|
|
|
if(sucessOrFail){
|
|
|
- [self reqNet_Cart_cartsMineTotals];
|
|
|
+ if ([mark isEqualToString:Chectout_giftAddCart]) {
|
|
|
+ self.index --;
|
|
|
+ if (self.index == 0) {
|
|
|
+ [self reqNet_Cart_cartsMineTotals];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ [self reqNet_Cart_cartsMineTotals];
|
|
|
+ }
|
|
|
}else{
|
|
|
[self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
|
|
|
}
|
|
|
+ } else if ([mark isEqualToString:Goods_productGetProductsById]) {
|
|
|
+ //请求赠品详情
|
|
|
+ GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
|
|
|
+
|
|
|
+ NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{@"product_id":model.Id, @"isPromoItems":@"yes"}];
|
|
|
+ if (model.options.count > 0) {
|
|
|
+ NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
|
|
|
+ for (OptionsModel *optionM in model.options) {
|
|
|
+ OptionsValuesM *valuesM = optionM.values[0];
|
|
|
+ NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
|
|
|
+ optionDic[tempStr] =valuesM.option_type_id;
|
|
|
+ }
|
|
|
+ [param addEntriesFromDictionary:optionDic];
|
|
|
+ }
|
|
|
+ [self.addGiftParamArr addObject:param];
|
|
|
+ if (self.giftShowCount < 2 && self.addGiftParamArr.count == 1 && self.addGiftView.hidden) {
|
|
|
+ self.addGiftView.hidden = NO;
|
|
|
+ [self.addGiftView setGiftData:model.add_gooodsImgUrl];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -269,8 +313,21 @@
|
|
|
//支付方式数据
|
|
|
[self.TableV.infodata addObjectsFromArray:self.paymentArray];
|
|
|
|
|
|
+ //手动添加赠品功能
|
|
|
+ [self.addGiftParamArr removeAllObjects];
|
|
|
|
|
|
-
|
|
|
+ NSDictionary *freeData = (NSDictionary *)[[self.totalsM.extension_attributes objectForKey:@"free_data"] mj_JSONObject];
|
|
|
+ BOOL is_show = [[freeData objectForKey:@"is_show"] boolValue];
|
|
|
+ if (is_show && self.giftShowCount< 2) {//显示存在赠品
|
|
|
+ NSArray *productArr = [freeData objectForKey:@"products"];
|
|
|
+ if (productArr.count > 0) { //存在赠品
|
|
|
+ for (int i = 0; i < productArr.count; i++) {
|
|
|
+ NSDictionary *productDic = productArr[i];
|
|
|
+ NSString *entity_id = productDic[@"entity_id"];
|
|
|
+ [self reqNet_GoodsDetails_productGetProduct:entity_id];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
[self.TableV reloadData];
|
|
|
}
|
|
@@ -348,6 +405,11 @@
|
|
|
|
|
|
[param removeObjectForKey:@"extension_attributes"];//移除格式不正确的无用参数
|
|
|
|
|
|
+ if (NIL(self.shipmethodCellM.shipMethodModel.method_code) || NIL(self.shipmethodCellM.shipMethodModel.carrier_code)) {
|
|
|
+ [self.view makeToast:@"运输方式获取失败"];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
NSDictionary *params = @{@"shipping_address":param,
|
|
|
@"shipping_method_code":self.shipmethodCellM.shipMethodModel.method_code,
|
|
|
@"shipping_carrier_code":self.shipmethodCellM.shipMethodModel.carrier_code};
|
|
@@ -385,7 +447,7 @@
|
|
|
}
|
|
|
-(void)reqNet_PUT_cartsMineCoupons:(NSString *)coupon{
|
|
|
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
-
|
|
|
+ self.giftShowCount = 0;
|
|
|
[self.VM ry_requestPutApi:PUT_cartsMineCoupons param:coupon];
|
|
|
}
|
|
|
-(void)reqNet_DEL_cartsMineCoupons{
|
|
@@ -418,9 +480,34 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+//请求赠品商品详情
|
|
|
+-(void)reqNet_GoodsDetails_productGetProduct:(NSString *)enterId{
|
|
|
+ NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
|
|
|
+// [params setObject:@"55475" forKey:@"productId"];
|
|
|
+ [params setObject:enterId forKey:@"productId"];
|
|
|
+ [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
|
|
|
+// [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
+ [self.goodsDetailsVM ry_requestGetApi:Goods_productGetProductsById param:params];
|
|
|
+}
|
|
|
+
|
|
|
+//赠品加车
|
|
|
+- (void)requestGiftAddCart {
|
|
|
+ [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
+
|
|
|
+ for (int i = 0; i < self.addGiftParamArr.count; i++) {
|
|
|
+ NSDictionary *param = self.addGiftParamArr[i];
|
|
|
+ self.index ++;
|
|
|
+ self.giftShowCount = 2;
|
|
|
+ [self.VM ry_formDataRequestPostApi:Chectout_giftAddCart param:param];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark --- 懒加载 ---
|
|
|
- (void)ucm_bindvmmodel{
|
|
|
self.VM = [[CartVM alloc] initDelegate:self];
|
|
|
+ self.goodsDetailsVM = [[ASGoodsDetailsVM alloc] initDelegate:self];
|
|
|
}
|
|
|
|
|
|
- (MyCartCouponCellData *)couponCellM {
|
|
@@ -491,6 +578,25 @@
|
|
|
return _bottomView;
|
|
|
}
|
|
|
|
|
|
+- (ASAddGiftGoodsView *)addGiftView {
|
|
|
+ if (!_addGiftView) {
|
|
|
+ _addGiftView = [[ASAddGiftGoodsView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
|
|
|
+ @weakify(self)
|
|
|
+ _addGiftView.addBlock = ^(int type) {
|
|
|
+ @strongify(self)
|
|
|
+ self.addGiftView.hidden = YES;
|
|
|
+ if (type == 1) {
|
|
|
+ [self requestGiftAddCart];
|
|
|
+ } else {
|
|
|
+ self.giftShowCount ++;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ _addGiftView.hidden = YES;
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:_addGiftView];
|
|
|
+ }
|
|
|
+ return _addGiftView;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - **************** reqNet ****************
|
|
|
|
|
|
|