You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

167 lines
6.8 KiB

//
// WXYZ_BookReaderMenuPayView.m
// WXReader
//
// Created by Andrew on 2018/7/15.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import "WXYZ_BookReaderMenuPayView.h"
#import "TFRechargeViewController.h"
#import "WXYZ_ChapterBottomPayBar.h"
#import "TFReaderSettingHelper.h"
#import "TFReaderBookManager.h"
@interface WXYZ_BookReaderMenuPayView ()
{
TFReaderSettingHelper *functionalManager;
}
@end
@implementation WXYZ_BookReaderMenuPayView
- (instancetype)init
{
if (self = [super init]) {
[self initialize];
[self createSubViews];
}
return self;
}
- (void)initialize
{
self.frame = CGRectMake(0, SCREEN_HEIGHT / 2 - PUB_TABBAR_OFFSET - 2 * kMargin, SCREEN_WIDTH, SCREEN_HEIGHT / 2);
self.backgroundColor = [UIColor clearColor];
functionalManager = [TFReaderSettingHelper sharedManager];
}
- (void)createSubViews
{
UIButton *buyBulkButton = [UIButton buttonWithType:UIButtonTypeCustom];
buyBulkButton.layer.cornerRadius = 4;
buyBulkButton.layer.borderColor = [functionalManager getReaderTextColor].CGColor;
buyBulkButton.layer.borderWidth = 0.7;
buyBulkButton.clipsToBounds = YES;
[buyBulkButton setTitle:TFLocalizedString(@"批量购买更优惠") forState:UIControlStateNormal];
[buyBulkButton setTitleColor:[functionalManager getReaderTextColor] forState:UIControlStateNormal];
[buyBulkButton.titleLabel setFont:kMainFont];
[buyBulkButton addTarget:self action:@selector(buyBulkButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:buyBulkButton];
[buyBulkButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- 2 * kMargin);
make.left.mas_equalTo(self.mas_left).with.offset(2 * kMargin);
make.right.mas_equalTo(self.mas_right).with.offset(- 2 * kMargin);
make.height.mas_equalTo(40);
}];
UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
buyButton.layer.cornerRadius = 4;
buyButton.layer.borderColor = [functionalManager getReaderTextColor].CGColor;
buyButton.layer.borderWidth = 0.7;
buyButton.clipsToBounds = YES;
[buyButton setTitle:TFLocalizedString(@"确定购买") forState:UIControlStateNormal];
[buyButton setTitleColor:[functionalManager getReaderTextColor] forState:UIControlStateNormal];
[buyButton.titleLabel setFont:kMainFont];
[buyButton addTarget:self action:@selector(buyCurrentChapter) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:buyButton];
[buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(buyBulkButton.mas_top).with.offset(- 15);
make.left.mas_equalTo(buyBulkButton.mas_left);
make.right.mas_equalTo(buyBulkButton.mas_right);
make.height.mas_equalTo(buyBulkButton.mas_height);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = TFLocalizedString(@"支持正版");
titleLabel.textColor = [functionalManager getReaderTextColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = kFont10;
titleLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.mas_centerX);
make.bottom.mas_equalTo(buyButton.mas_top).with.offset( - 2 * kMargin);
make.width.mas_equalTo(100);
make.height.mas_equalTo(20);
}];
UIView *leftLine = [[UIView alloc] init];
leftLine.backgroundColor = [functionalManager getReaderTextColor];
[self addSubview:leftLine];
[leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(titleLabel.mas_centerY);
make.left.mas_equalTo(buyBulkButton.mas_left);
make.right.mas_equalTo(titleLabel.mas_left).with.offset(- kHalfMargin);
make.height.mas_equalTo(kCellLineHeight);
}];
UIView *rightLine = [[UIView alloc] init];
rightLine.backgroundColor = [functionalManager getReaderTextColor];
[self addSubview:rightLine];
[rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(titleLabel.mas_centerY);
make.left.mas_equalTo(titleLabel.mas_right).with.offset(kHalfMargin);
make.right.mas_equalTo(buyBulkButton.mas_right);
make.height.mas_equalTo(kCellLineHeight);
}];
}
- (void)buyBulkButtonClick
{
TFReaderBookManager *bookManager = [TFReaderBookManager sharedManager];
TFProductionChapterModel *t_model = [[TFProductionChapterModel alloc] init];
t_model.production_id = bookManager.book_id;
t_model.chapter_id = bookManager.chapter_id;
WXYZ_ChapterBottomPayBar *payBar = [[WXYZ_ChapterBottomPayBar alloc] initWithChapterModel:t_model barType:WXYZ_BottomPayBarTypeBuyChapter productionType:TFProductionTypeNovel];
[payBar showBottomPayBar];
}
- (void)buyCurrentChapter
{
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
TFReaderBookManager *bookManager = [TFReaderBookManager sharedManager];
TFProductionChapterModel *t_model = [[TFProductionChapterModel alloc] init];
t_model.production_id = bookManager.book_id;
t_model.chapter_id = bookManager.chapter_id;
[TFNetworkTools POST:Book_Buy_Chapter parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:bookManager.book_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:bookManager.chapter_id], @"num":@"1"} model:nil success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
NSArray<NSString *> *t_arr = [requestModel.data objectForKey:@"chapter_ids"];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"购买成功")];
NSInteger index = [TFReaderBookManager sharedManager].currentChapterIndex;
[TFReaderBookManager sharedManager].bookModel.chapter_list[index].is_preview = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Production_Pay_Success object:t_arr];
} else if (requestModel.code == 802) {
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"TFRechargeViewController"];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
@end