KWMPaySuccessVC.m 6.55 KB
Newer Older
houweibin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
//  KWMPaySuccess.m
//  iCemarose
//
//  Created by HouWeiBin on 16/9/5.
//  Copyright © 2016年 kollway. All rights reserved.
//

#import "KWMPaySuccessVC.h"
#import "UIColor+SAMAdditions.h"
#import "KWMInformationVC.h"
#import "KWMShopCartData.h"
#import "UIViewController+BackButtonHandler.h"
#import "KWMOrderVC.h"

16
@interface KWMPaySuccessVC ()<KWMRecommendDelegate>
houweibin committed
17 18 19 20 21 22 23 24

@end

@implementation KWMPaySuccessVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"支付成功";
lee committed
25
   
houweibin committed
26
    [self initButton];
27 28 29
    [self requestProductWithHandle:@"products-list-app-homepage" tags:nil valueKeyPath:@"productArray"];
    self.hotRecommendView.title = @"热卖单品";
    self.hotRecommendView.delegate = self;
houweibin committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
}

+(NSString *)kwmTag{
    return @"KWMPaySuccessVC";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)initButton{
    self.btnGetTime.layer.masksToBounds = YES;
    //btn.layer.cornerRadius = 20/2; //圆角(圆形)
    self.btnGetTime.layer.borderColor  = [UIColor sam_colorWithHex:@"979797"].CGColor; //要设置的颜色
    self.btnGetTime.layer.borderWidth = 1; //要设置的描边宽
    self.btnStartTime.layer.masksToBounds = YES;
    self.btnStartTime.layer.borderColor  = [UIColor sam_colorWithHex:@"979797"].CGColor; //要设置的颜色
    self.btnStartTime.layer.borderWidth = 1; //要设置的描边宽
    self.btnMyOrder.layer.masksToBounds = YES;
    self.btnMyOrder.layer.borderColor  = [UIColor sam_colorWithHex:@"979797"].CGColor; //要设置的颜色
    self.btnMyOrder.layer.borderWidth = 1; //要设置的描边宽
51 52 53
    self.btnBackHome.layer.masksToBounds = YES;
    self.btnBackHome.layer.borderColor  = [UIColor sam_colorWithHex:@"979797"].CGColor; //要设置的颜色
    self.btnBackHome.layer.borderWidth = 1; //要设置的描边宽
houweibin committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
}


-(void)onClickStartTime:(id)sender{
    KWMInformationVC *informationVC = (KWMInformationVC *)[KWMBaseVC findControllerBy:[KWMInformationVC kwmTag] fromStoryboard:@"Main"];
    informationVC.inforStr = NSLocalizedString(@"WhenPutGoods",@"WhenPutGoods");
    informationVC.inforTitleStr = NSLocalizedString(@"WhenPutGoodsTitle",@"WhenPutGoodsTitle");
    informationVC.titleStr = @"何时发货";
    [self.navigationController pushViewController:informationVC animated:YES];
}

-(void)onClickGetTime:(id)sender{
    KWMInformationVC *informationVC = (KWMInformationVC *)[KWMBaseVC findControllerBy:[KWMInformationVC kwmTag] fromStoryboard:@"Main"];
    informationVC.inforStr = NSLocalizedString(@"WhenPutGoods",@"WhenPutGoods");
    informationVC.inforTitleStr = NSLocalizedString(@"WhenPutGoodsTitle",@"WhenPutGoodsTitle");
    informationVC.titleStr = @"多久到货";
    [self.navigationController pushViewController:informationVC animated:YES];
}

-(void)onClickMyOrder:(id)sender{
    KWMOrderVC *orderVC = (KWMOrderVC *)[KWMBaseVC findControllerBy:[KWMOrderVC kwmTag] fromStoryboard:@"Mine"];
75
    orderVC.paidCheckout = self.paidCheckout;
houweibin committed
76 77 78
    [self.navigationController pushViewController:orderVC animated:YES];
}

79 80 81 82
-(void)onClickBackHome:(id)sender{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

houweibin committed
83 84 85 86 87 88
-(BOOL) navigationShouldPopOnBackButton {
    [self.navigationController popToRootViewControllerAnimated:YES];

     return NO; // Ignore 'Back' button this time
}

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
#pragma mark KWMRecommendDelegate
-(void)kwm_gotoRecommendPage:(KWMRecommendView *)recommendView{
    [self openURLWithString:@"https://cemarose.myshopify.com/collections/products-list-app-homepage?title=热卖单品"];
}

-(void)kwm_onClickProduct:(BUYProduct *)product{
    [self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/products/%@",product.handle]];
}

#pragma makr - api
- (void) requestProductWithHandle:(NSString *) handle tags:(NSArray *) tags valueKeyPath:(nonnull NSString *) valueKeyPath {
    NSDictionary *parameters = [KWMPPCacheUtil getProductCacheKeyDictionary:1 tags:tags handle:handle];
    BOOL useProductDataCache = [self useProductDataCache:parameters valueKeyPath:valueKeyPath page:1];
    __weak KWMPaySuccessVC *weakSelf = self;
    [self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
        if (!error) {
            [weakSelf.client getProductsPage:1 inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
                if (!error) {
                    [KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage products:products];
                    if(products){
                        NSArray *productIds;
                            @try {
                                if(self.paidCheckout && self.paidCheckout.lineItemsArray){
                                    productIds = [[self.paidCheckout.lineItems array] rx_mapWithBlock:^id(BUYLineItem* each) {
                                        NSNumber *a = each.productId ?: @(0);
                                        return a;
                                    }];
                                }
                            }
                            @catch (NSException *exception) {
                                // 捕获到的异常exception
                            }
                        self.hotRecommendView.productArray = products;
                        self.hotRecommendView.boughtProductIdArray = productIds;
                    }
                }
            }];
        }
    }];
}

-(BOOL)useProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page{
    if(!kIsNetwork || page == 1){
        NSArray *productIds;
        NSArray *products = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage];
        if(products && products.count > 0){
            @try {
                if(self.paidCheckout && self.paidCheckout.lineItemsArray){
                    productIds = [[self.paidCheckout.lineItems array] rx_mapWithBlock:^id(BUYLineItem* each) {
                        NSNumber *a = each.productId ?: @(0);
                        return a;
                    }];
                }
            }
            @catch (NSException *exception) {
                // 捕获到的异常exception
            }
            self.hotRecommendView.productArray = products;
            self.hotRecommendView.boughtProductIdArray = productIds;
        }else{
            return false;
        }
    }
    return !kIsNetwork;
}
houweibin committed
154 155

@end