cdts/xdts-ios 3/TreeHole/Code/Features/VIP/VIPViewController.m

440 lines
18 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// VIPViewController.m
// TreeHole
//
// Created by on 2022/5/1.
//
#import "VIPViewController.h"
#import "CWCarousel.h"
#import "VIPSpecialInfoCell.h"
#import "VIPGoodsInfo.h"
#import "MTGridSelectView.h"
#import "VIPConfig.h"
#import <WechatOpenSDK/WXApi.h>
#import "BottleViewController.h"
#import "ApplePayService.h"
#import "FeedbackViewController.h"
#import "RichTextLabel.h"
@interface VIPGoodsView: UIView
@property (nonatomic, strong) VIPGoodsInfo *goods;
- (instancetype)initWithGoods:(VIPGoodsInfo *)goods size:(CGSize)size;
@property (nonatomic, strong) UILabel *typeLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *originPriceLabel;
@property (nonatomic, strong) UIButton *tipsButton;
@property (nonatomic, assign) BOOL isSelected;
@property (nonatomic, strong) UIView *maskView;
@property (nonatomic,assign) int seletedVips;
@end
@implementation VIPGoodsView
- (instancetype)initWithGoods:(VIPGoodsInfo *)goods size:(CGSize)size{
if (self = [super init]) {
self.size = size;
_goods = goods;
[self setupUI];
}
return self;
}
- (void)setupUI {
UILabel *typeLabel = [[UILabel alloc] init];
typeLabel.height = FIX_SIZE(22);
typeLabel.width = self.width;
typeLabel.textAlignment = NSTextAlignmentCenter;
typeLabel.y = FIX_SIZE(18);
typeLabel.text = _goods.good.good_title;
typeLabel.font = MT_FONT_REGULAR_SIZE(15);
[self addSubview:typeLabel];
self.typeLabel = typeLabel;
UILabel *priceLabel = [[UILabel alloc] init];
priceLabel.height = FIX_SIZE(45);
priceLabel.width = self.width;
priceLabel.textAlignment = NSTextAlignmentCenter;
priceLabel.y = typeLabel.bottom + FIX_SIZE(2);
[self addSubview:priceLabel];
self.priceLabel = priceLabel;
UILabel *originPriceLabel = [[UILabel alloc] init];
originPriceLabel.height = FIX_SIZE(25);
originPriceLabel.width = self.width;
originPriceLabel.textAlignment = NSTextAlignmentCenter;
originPriceLabel.y = priceLabel.bottom + FIX_SIZE(10);
originPriceLabel.font = MT_FONT_REGULAR_SIZE(15);
[self addSubview:originPriceLabel];
self.originPriceLabel = originPriceLabel;
self.layer.cornerRadius = FIX_SIZE(8);
self.clipsToBounds = YES;
if (_goods.good.sell_promotion_title.length > 0) {
UIButton *tipsButton = [[UIButton alloc] init];
[tipsButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
tipsButton.titleLabel.font = MT_FONT_MEDIUM_SIZE(13);
[tipsButton setTitle:_goods.good.sell_promotion_title forState:UIControlStateNormal];
[tipsButton sizeToFit];
tipsButton.width += FIX_SIZE(15);
tipsButton.height = FIX_SIZE(21);
UIImage *image = ImageNamed(@"TH_vip_tag_bg");
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(tipsButton.height * 0.5 - 1, tipsButton.width * 0.5 - 1, tipsButton.height * 0.5 - 1, tipsButton.width * 0.5 - 1) resizingMode:UIImageResizingModeStretch];
[tipsButton setBackgroundImage:image forState:UIControlStateNormal];
self.tipsButton = tipsButton;
dispatch_async(dispatch_get_main_queue(), ^{
tipsButton.left = self.left;
tipsButton.centerY = self.y;
[self.superview addSubview:tipsButton];
});
}
}
- (void)setIsSelected:(BOOL)isSelected {
_isSelected = isSelected;
self.typeLabel.textColor = COLOR_WITH_RGB(0xFFE8A1);
NSMutableAttributedString *attrStrM = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@", _goods.good.sell_price] attributes:@{
NSFontAttributeName : MT_FONT_REGULAR_SIZE(31),
NSForegroundColorAttributeName: self.typeLabel.textColor
}];
[attrStrM setAttributes:@{
NSFontAttributeName : MT_FONT_REGULAR_SIZE(16),
NSForegroundColorAttributeName: self.typeLabel.textColor
} range:NSMakeRange(0, 1)];
self.priceLabel.attributedText = attrStrM;
//1.4.8 线
// NSMutableAttributedString *originPriceAttrStrM = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@", _goods.good.original_price] attributes:@{
// NSFontAttributeName : MT_FONT_REGULAR_SIZE(15),
// NSForegroundColorAttributeName : COLOR_WITH_RGB(0xB3B3B3),
// NSStrikethroughStyleAttributeName :[NSNumber numberWithInteger:NSUnderlineStyleSingle],
// NSBaselineOffsetAttributeName: @(0)
// }];
NSMutableAttributedString *originPriceAttrStrM = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", _goods.good.price_desc] attributes:@{
NSFontAttributeName : MT_FONT_REGULAR_SIZE(15),
NSForegroundColorAttributeName : COLOR_WITH_RGB(0xB3B3B3),
NSBaselineOffsetAttributeName: @(0)
}];
self.originPriceLabel.attributedText = originPriceAttrStrM;
self.originPriceLabel.hidden = _goods.good.original_price.length <= 0;
self.layer.borderWidth = 2;
self.layer.borderColor = isSelected ? THEME_COLOR.CGColor : [UIColor clearColor].CGColor;
[self.maskView removeFromSuperview];
self.maskView = [[UIView alloc] init];
self.maskView.frame = self.bounds;
[self.maskView setBackgroundGradientColorWithBeginColorHex:0x2D2943 endColorHex:0x272940 gradientType:GradientColorTypeFromLeftTopToRightBottom];
[self insertSubview:self.maskView atIndex:0];
}
@end
@interface VIPViewController () <CWCarouselDelegate, CWCarouselDatasource>
@property (nonatomic, strong) CWCarousel *carousel;
@property (nonatomic, strong) VIPConfig *config;
@property (nonatomic, strong) VIPGoodsInfo *selectedGoodsInfo;
@property (nonatomic, weak) id observe;
@end
@implementation VIPViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self startLoading];
[self refresh];
_observe = [[NSNotificationCenter defaultCenter] addObserverForName:@"vipViewClosenotifi" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
NSLog(@"VipView收到了通知");
[self close];
}];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"receivedVipMsgnotifi" object:nil];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:ImageNamed(@"TH_down_btn") style:UIBarButtonItemStyleDone target:self action:@selector(close)];
// self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"恢复购买" style:UIBarButtonItemStylePlain target:self action:@selector(restore)];
2023-07-27 09:20:00 +08:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refresh) name:BuyVIPSuccessNotification object:nil];
}
- (void)refresh {
[PYHTTPManager getWithPath:self.userID.length > 0 ? @"vipconfig" : @"vipconfig/experience" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
2023-07-27 09:20:00 +08:00
NSLog(@"会员页面 : %@",rsp);
[self endLoading:error];
if (!error) {
self.config = [VIPConfig mj_objectWithKeyValues:rsp];
[self setupUI];
}else{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
}
}];
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"vipViewClosenotifi" object:nil];
}
- (void)close {
if (self.didCloseAction) {
self.didCloseAction();
}
[self.navigationController dismissViewControllerAnimated:YES completion:^{
//wx pay
// if ([PYAppService selectedTabItemIndex] == 1 && !self.config.is_vip) { //
// [MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
// config.title = @"10天尊享VIP";
// //@"¥6.6已有828人开通"
// config.message = self.config.hidden_vip_des;
// config.cancelTitle = @"放弃优惠";
// config.otherTitle = @"开通";
// config.otherHandler = ^(MTAlertButton *button) {
// [PYAppService buyTryVIP];
// };
// }];
// }
}];
}
- (void)restore {
///
[ApplePayService payProductWithId:nil orderId:nil restoreProduct:YES isFastBuy:NO];
}
- (void)setupUI {
[self.view removeSubviews];
UIView *titleView = [[UIView alloc] init];
titleView.width = self.view.width * 0.7;
titleView.height = 44;
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.font = MT_FONT_MEDIUM_SIZE(15);
titleLabel.textColor = [UIColor whiteColor];
titleLabel.text = @"VIP会员";
[titleLabel sizeToFit];
[titleView addSubview:titleLabel];
titleLabel.centerX = titleView.width * 0.5;
UILabel *subtitleLabel = [[UILabel alloc] init];
subtitleLabel.width = titleView.width;
subtitleLabel.height = titleLabel.height;
subtitleLabel.y = titleLabel.bottom + 2;
subtitleLabel.textColor = COLOR_WITH_RGB(0xC0C6C9);
subtitleLabel.font = MT_FONT_REGULAR_SIZE(11);
subtitleLabel.text = self.config.vip_sub_title;
subtitleLabel.textAlignment = NSTextAlignmentCenter;
[titleView addSubview:subtitleLabel];
self.navigationItem.titleView = titleView;
UIView *bottomView = [[UIView alloc] init];
bottomView.width = SCREEN_WIDTH;
bottomView.backgroundColor = SUB_BG_COLOR;
UILabel *tipsLabel = [[UILabel alloc] init];
tipsLabel.width = SCREEN_WIDTH;
tipsLabel.height = FIX_SIZE(20);
tipsLabel.font = MT_FONT_REGULAR_SIZE(11);
tipsLabel.textColor = COLOR_WITH_RGB(0xB3B3B3);
tipsLabel.textAlignment = NSTextAlignmentCenter;
[bottomView addSubview:tipsLabel];
WeakSelf(self);
UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
buyButton.x = FIX_SIZE(15);
buyButton.height = FIX_SIZE(48);
buyButton.width = SCREEN_WIDTH - buyButton.x * 2;
buyButton.y = tipsLabel.bottom + FIX_SIZE(8);
buyButton.titleLabel.font = MT_FONT_MEDIUM_SIZE(16);
buyButton.layer.cornerRadius = FIX_SIZE(20);
buyButton.clipsToBounds = YES;
[buyButton setTitleColor:COLOR_WITH_RGB(0x040000) forState:UIControlStateNormal];
[buyButton setBackgroundGradientColorWithBeginColorHex:0xFFBE00 endColorHex:0xFFECB4 gradientType:GradientColorTypeFromLeftToRight];
[buyButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
NSString *goodsID = weakself.selectedGoodsInfo.good.apple_good_id ?: @"";
if (self.userID.length>1) {
// NSLog(@"点击的是否==%d",self.seletedVip);
// NSLog(@"%d",self.seletedVip);
// NSString *userID =
if ([self.userID containsString:@"hole_"]) {
NSString *userID = [self.userID stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"hole_"]];
NSLog(@"userID%@",userID);
[ApplePayService sendStartVipPay:[NSString stringWithFormat:@"%@",@(weakself.selectedGoodsInfo.good.vip_good_id)] isFastBuy:NO source:self.vipSource UserID:userID];
2023-07-27 09:20:00 +08:00
}
} else {
[ApplePayService startVipPay:[NSString stringWithFormat:@"%@",@(weakself.selectedGoodsInfo.good.vip_good_id)] isFastBuy:NO source:self.vipSource];
2023-07-27 09:20:00 +08:00
}
}];
[bottomView addSubview:buyButton];
RichTextLabel *richLabel = [RichTextLabel richTextFullString:[NSString stringWithFormat:@"查阅服务协议·隐私协议·会员服务协议"] items:@[
2023-07-27 09:20:00 +08:00
[RichLabelItem itemWithText:@"服务协议" action:^{
[PYAppService openWebVCWithTitle:@"服务协议" url:@"http://iquanpai.com/app-h5/4_131.html"];
}],
[RichLabelItem itemWithText:@"隐私协议" action:^{
[PYAppService openWebVCWithTitle:@"隐私协议" url:@"http://iquanpai.com/app-h5/4_132.html"];
}],
[RichLabelItem itemWithText:@"会员服务协议" action:^{
//
[PYAppService openWebVCWithTitle:@"会员服务协议" url:@"http://iquanpai.com/app-h5/4_133.html"];
}],
// [RichLabelItem itemWithText:@"订阅服务协议" action:^{
//
// [PYAppService openWebVCWithTitle:@"订阅服务协议" url:@"http://iquanpai.com/app-h5/4_134.html"];
// }],
] maxWidth:SCREEN_WIDTH - FIX_SIZE(15) * 2];
richLabel.centerX = bottomView.width * 0.5;
richLabel.y = buyButton.bottom + FIX_SIZE(10);
MTGridSelectView *selectView = [MTGridSelectView gridSelectViewWithItemModels:self.config.vip_goods setupConfig:^(MTGridSelectConfig * _Nonnull config) {
config.contentWidth = SCREEN_WIDTH;
config.contentInset = UIEdgeInsetsMake(FIX_SIZE(15), FIX_SIZE(15), FIX_SIZE(0), FIX_SIZE(15));
config.itemSize = CGSizeMake(FIX_SIZE(105), FIX_SIZE(131));
config.rowSpacing = 0;
config.multiple = NO;
} didSetupItemContentView:^UIView *(UIView * _Nonnull itemContentView, id _Nonnull itemModel) {
VIPGoodsView *item = [[VIPGoodsView alloc] initWithGoods:itemModel size:itemContentView.size];
item.isSelected = NO;
return item;
} itemStateChanged:^(UIView * _Nonnull itemView, id _Nonnull itemModel, MTGridItemState state, BOOL changeByInner) {
VIPGoodsView *item = (VIPGoodsView *)itemView;
item.isSelected = state == MTGridItemStateSelected;
} selectValueChanged:^(NSArray * _Nonnull selectedModels) {
weakself.selectedGoodsInfo = [selectedModels firstObject];
[weakself.carousel freshCarousel];
[weakself.carousel scrollToIndex:weakself.selectedGoodsInfo.vip_selected_index];
if(self.userID.length>1){
[buyButton setTitle:@"赠送会员" forState:UIControlStateNormal];
}else {
[buyButton setTitle:weakself.selectedGoodsInfo.good.buy_button_title forState:UIControlStateNormal];
}
tipsLabel.text = weakself.selectedGoodsInfo.good.buy_des;
}];
selectView.height = FIX_SIZE(181);
[bottomView addSubview:selectView];
[bottomView addSubview:tipsLabel];
[bottomView addSubview:buyButton];
[bottomView addSubview:richLabel];
tipsLabel.y = selectView.bottom + FIX_SIZE(-24);
buyButton.y = tipsLabel.bottom + FIX_SIZE(8);
richLabel.y = buyButton.bottom + FIX_SIZE(8);
bottomView.height = richLabel.bottom + FIX_SIZE(6) + homeIndicatorHeight();
[self.view addSubview:bottomView];
[bottomView setCorners:UIRectCornerTopLeft | UIRectCornerTopRight radius:FIX_SIZE(20)];
bottomView.clipsToBounds = YES;
bottomView.bottom = self.view.height;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[selectView selectItemAtIndex:self.config.vip_selected_good];
});
CGFloat maxHeight = bottomView.y - FIX_SIZE(15) - NAVIGATION_BAR_HEIGHT;
CGFloat itemWith = SCREEN_WIDTH;
CGFloat itemHeight = itemWith * SpecialInfoCellAspectRatio;
if (itemHeight > maxHeight) {
itemHeight = maxHeight;
itemWith = maxHeight / SpecialInfoCellAspectRatio;
}
CWFlowLayout *flowLayout = [[CWFlowLayout alloc] initWithStyle:CWCarouselStyle_Normal];
flowLayout.itemSpace_H = 0.0;
flowLayout.itemWidth = itemWith;
CWCarousel *carousel = [[CWCarousel alloc] initWithFrame:CGRectMake((self.view.width - itemWith) * 0.5, NAVIGATION_BAR_HEIGHT, itemWith, itemHeight)
delegate:self
datasource:self
flowLayout:flowLayout];
carousel.backgroundColor = [UIColor clearColor];
self.carousel = carousel;
carousel.pageControl.currentPageIndicatorTintColor = [UIColor colorWithWhite:1.0 alpha:0.6];
carousel.pageControl.pageIndicatorTintColor = COLOR_WITH_RGB_A(0xFFFFFF, 0.2);
[carousel registerViewClass:[VIPSpecialInfoCell class] identifier:VIPSpecialInfoCellReuseID];
[carousel freshCarousel];
carousel.autoTimInterval = 3.0;
carousel.isAuto = YES;
[self.view addSubview:carousel];
if (_config.is_forever_vip) {
UILabel *tipsLabel = [[UILabel alloc] init];
tipsLabel.backgroundColor = COLOR_WITH_RGB(0x2C2228);
tipsLabel.width = FIX_SIZE(260);
tipsLabel.height = FIX_SIZE(48);
tipsLabel.layer.cornerRadius = FIX_SIZE(20);
tipsLabel.font = MT_FONT_MEDIUM_SIZE(16);
titleLabel.textColor = COLOR_WITH_RGB(0xFFBE00);
tipsLabel.textAlignment = NSTextAlignmentCenter;
tipsLabel.y = self.carousel.bottom + FIX_SIZE(40);
tipsLabel.clipsToBounds = YES;
tipsLabel.text = @"您已成为小酒馆永久创始会员";
tipsLabel.textColor = COLOR_WITH_RGB(0xFFBE00);
tipsLabel.centerX = self.view.width * 0.5;
[self.view addSubview:tipsLabel];
bottomView.hidden = YES;
}
}
#pragma mark - CWCarouselDatasource
// cell
- (UICollectionViewCell *)viewForCarousel:(CWCarousel *)carousel indexPath:(NSIndexPath *)indexPath index:(NSInteger)index{
VIPSpecialInfoCell *cell = [carousel.carouselView dequeueReusableCellWithReuseIdentifier:VIPSpecialInfoCellReuseID forIndexPath:indexPath];
cell.item = self.selectedGoodsInfo.vip_items[index];
return cell;
}
//
- (void)CWCarousel:(CWCarousel *)carousel didSelectedAtIndex:(NSInteger)index {
}
//
- (NSInteger)numbersForCarousel {
// NSLog(@" selectedGoodsInfo : %@",self.selectedGoodsInfo.vip_items);
return self.selectedGoodsInfo.vip_items.count;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.carousel controllerWillAppear];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.carousel controllerWillDisAppear];
}
@end