123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- //
- // YOUPAIHRRechargePayWindow.m
- // VQU
- //
- // Created by xiaohaoran on 2021/10/28.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAIHRRechargePayWindow.h"
- #import "YOUPAILCRechargeModel.h"
- //#import "YOUPAILCIAPHelper.h"
- #import "YOUPAILCBillDetailVC.h"
- //#import <AlibabaSDK/AlibabaSDK.h>
- //#import "IPAManager.h"
- #import "YOUPAIZYRechargeBtn.h"
- #import "UIViewController+TFPresent.h"
- //#import "WXApiObject.h"
- #import "YOUPAIHRBillDetailVC.h"
- #import "IPAManager.h"
- @interface YOUPAIHRRechargePayWindow ()
- @property(nonatomic,strong)UILabel* youpaiprechargeTotalLabel;
- @property(nonatomic,strong)UIView* youpaiprechargeView;
- @property(nonatomic,strong)NSMutableArray* youpaipgoodList;
- @property(nonatomic,strong)YOUPAILCRechargeModel* youpaipcurrentModel;
- @property(nonatomic,strong)NSMutableArray* youpaipbtnArray;
- @property(nonatomic,strong)UIButton* youpaipbuyBtn;
- @property(nonatomic,strong)UIScrollView* youpaipscrollView;
- @end
- @implementation YOUPAIHRRechargePayWindow
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self youpaifinitDataWithType:2];
- }
- -(void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [UMengRecordTool umengEventCountWithId:RechargePopUp];
- self.baseView.hidden = YES;
- self.youpaipbtnArray = [NSMutableArray array];
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifApplePaySuccess:) name:@"yqApplePaySuccess" object:nil];
- [self youpaifsetupUI];
- }
- -(void)youpaifsetupUI{
-
- UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, KScreenHeight*0.4, KScreenWidth,KScreenHeight*0.6)];
- [bgView setBackgroundColor:[UIColor whiteColor]];
- CAShapeLayer *sectionmaskLayer = [CAShapeLayer layer];
- UIBezierPath *sectionpath = [UIBezierPath bezierPathWithRoundedRect:bgView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
- sectionmaskLayer.path = sectionpath.CGPath;
- bgView.layer.mask = sectionmaskLayer;
- [self.view addSubview:bgView];
- //关闭按钮
- UIButton *closeBtn = [UIButton new];
- [bgView addSubview:closeBtn];
- [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(15);
- make.top.mas_equalTo(15);
- make.size.mas_equalTo(CGSizeMake(35, 35));
- }];
- [closeBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_window_close1"] forState:UIControlStateNormal];
- [closeBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
- //title
- UILabel *titleLabel = [UILabel new];
- [bgView addSubview:titleLabel];
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(0);
- make.centerY.mas_equalTo(closeBtn);
- }];
- titleLabel.text = @"充值";
- titleLabel.font = LCBoldFont(17);
- titleLabel.textColor = LZ273145Color;
- [bgView addSubview:self.youpaipscrollView];
- self.youpaipscrollView.frame = CGRectMake(0, 59, KScreenWidth, 400);
- self.youpaiprechargeView = [[UIView alloc] init];
- [self.youpaipscrollView addSubview:self.youpaiprechargeView];
- [self.youpaiprechargeView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(14);
- make.width.mas_equalTo(KScreenWidth - 28.0f);
- make.top.mas_equalTo(0);
- make.height.mas_equalTo(400);
- }];
-
- UIButton* buyBtn = [[UIButton alloc]init];
- [self.view addSubview:buyBtn];
- [buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(-SafeHeight-10);
- make.size.mas_equalTo(CGSizeMake(KScreenWidth-120, 48));
- make.centerX.mas_equalTo(0);
- }];
- buyBtn.userInteractionEnabled = NO;
- buyBtn.backgroundColor = LZD3D1D7Color;
- buyBtn.layer.cornerRadius = 24.0;
- buyBtn.layer.masksToBounds = YES;
- buyBtn.titleLabel.font = LCFont17;
- [buyBtn setTitleColor:LZ273145Color forState:(UIControlStateNormal)];
- [buyBtn setTitle:@"立即充值" forState:(UIControlStateNormal)];
- [buyBtn addTarget:self action:@selector(youpaifbuyBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
- self.youpaipbuyBtn = buyBtn;
- }
- - (void)youpaifupdateView{
-
-
- if (self.youpaipbtnArray.count>0) {
- for (YOUPAIZYRechargeBtn* btn in self.youpaipbtnArray) {
- [btn removeFromSuperview];
- }
- }
- [self.youpaipbtnArray removeAllObjects];
-
- for (UIView *view in self.youpaiprechargeView.subviews) {
- [view removeFromSuperview];
- }
-
- CGFloat space = ScaleSize(6.0f);
- CGFloat width = (KScreenWidth - 24.0f - space) / 2.0f;
- CGFloat height = ScaleSize(74.0f);
-
- CGFloat rechargeViewHeight = 0.0f;
- for (NSInteger i = 0; i<self.youpaipgoodList.count; i++) {
- YOUPAILCRechargeModel* model = self.youpaipgoodList[i];
- model.youpaipreward = model.youpaipreward.length == 0 ? @"0" : model.youpaipreward;
-
- NSInteger col = i % 2;
- NSInteger row = i / 2;
-
- YOUPAIZYRechargeBtn* btn = [[YOUPAIZYRechargeBtn alloc]initWithFrame:CGRectMake(col * width + col * space, row * height + row * space,width,height) model:model];
- // btn.backgroundColor = HexColorFromRGB(0x4F4B5B);
- btn.layer.cornerRadius = ScaleSize(5.0f);
- btn.layer.borderWidth = ScaleSize(1.0f);
- btn.layer.borderColor = LZF5F4F7Color.CGColor;
-
- btn.youpaippriceLabel.text = [NSString stringWithFormat:@"¥%@",model.youpaipprice];
-
- NSString *amountText = [NSString stringWithFormat:@"%@钻石",model.youpaipamount];
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:amountText];
- NSRange range = NSMakeRange(model.youpaipamount.length, 2);
- [attrStr addAttribute:NSFontAttributeName value:LCFont(ScaleSize(14.0f)) range:range];
- [attrStr addAttribute:NSForegroundColorAttributeName value:LZ273145Color range:range];
- btn.youpaipgoodLabel.attributedText = attrStr.copy;
-
- if (model.youpaipbtn_text.count != 0) {
- btn.youpaipgiveLabel.text = model.youpaipbtn_text[0];
- }
-
- [btn addTarget:self action:@selector(youpaifrechargeBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
- [self.youpaiprechargeView addSubview:btn];
- [self.youpaipbtnArray addObject:btn];
-
- if (i==1) {
- [self youpaifrechargeBtnClick:btn];
- }
- rechargeViewHeight = CGRectGetMaxY(btn.frame);
- }
-
- // CGRect rechargeRect = self.rechargeView.frame;
- // rechargeRect.size.height = rechargeViewHeight;
- // self.rechargeView.frame = rechargeRect;
- [self.youpaiprechargeView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(rechargeViewHeight);
- }];
-
- // [self.buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.mas_equalTo(self.rechargeView.mas_bottom).offset(35);
- // make.size.mas_equalTo(CGSizeMake(KScreenWidth-120, 48));
- // make.centerX.mas_equalTo(0);
- // }];
- self.youpaipscrollView.contentSize = CGSizeMake(0,CGRectGetMaxY(_youpaiprechargeView.frame) + SafeHeight+130);
- }
- - (void)youpaifrechargeBtnClick:(YOUPAIZYRechargeBtn*)reBtn{
- self.youpaipcurrentModel = reBtn.youpaipreModel;
- [self.youpaipbuyBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-120, 48) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
- [self.youpaipbuyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- self.youpaipbuyBtn.userInteractionEnabled = YES;
-
- for (YOUPAIZYRechargeBtn* btn in self.youpaipbtnArray) {
- btn.layer.cornerRadius = ScaleSize(5.0f);
- btn.layer.borderWidth = ScaleSize(1.0f);
- btn.layer.borderColor = LZF5F4F7Color.CGColor;
- btn.selected = NO;
- btn.backgroundColor = [UIColor clearColor];
- btn.youpaipgoodLabel.textColor = LZ273145Color;
- btn.youpaipgiveLabel.textColor = LZA3AABEColor;
- }
-
- reBtn.layer.cornerRadius = ScaleSize(5.0f);
- reBtn.layer.borderWidth = ScaleSize(2.0f);
- reBtn.layer.borderColor = LZ7C69FEColor.CGColor;
- reBtn.selected = YES;
- reBtn.backgroundColor = [LZ7C69FEColor colorWithAlphaComponent:0.05f];
- reBtn.youpaipgoodLabel.textColor = LZ7C69FEColor;
- reBtn.youpaipgiveLabel.textColor = LZ7C69FEColor;
-
- }
- - (void)youpaifinitDataWithType:(NSInteger)type{
- [LCHttpHelper requestWithURLString:WalletGoodList parameters:@{@"type":@(type)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- self.youpaiprechargeTotalLabel.text = [NSString stringWithFormat:@"%.0f",[[[dict objectForKey:@"data"]objectForKey:@"coin"]floatValue]+[[[dict objectForKey:@"data"]objectForKey:@"income_coin"]floatValue]];
-
- self.youpaipgoodList = [YOUPAILCRechargeModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"list"]];
- [self youpaifupdateView];
-
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)youpaifApplePaySuccess:(NSNotification*)noti{
- if ([noti.name isEqualToString:@"yqApplePaySuccess"]) {
- [self youpaifinitDataWithType:2];
- }
- }
- //支付
- -(void)youpaifbuyBtnClick{
- [self applePay];
- }
- - (void)applePay{
- self.youpaipbuyBtn.userInteractionEnabled = NO;
- /// 内购
- [ZCHUDHelper showWithStatus:@"支付中..."];
- NSLog(@"%@",self.youpaipcurrentModel.youpaipios_product_id);
- [[IPAManager shareIAPManager] startPurchWithID:self.youpaipcurrentModel.youpaipios_product_id completeHandle:^(IAPPurchType type, NSString *data) {
-
- NSLog(@"type = %ld",type);
- if (type == IAPPurchSuccess) {
- [LCSaveData saveReceiptData:data];
- [self requestApplePayBack:data];
- }else{
- dispatch_async(dispatch_get_main_queue(), ^{
- self.youpaipbuyBtn.userInteractionEnabled = YES;
- });
- NSString *title = @"";
- switch (type) {
- case IAPPurchFailed:
- title = @"购买失败";
- break;
- case IAPPurchCancle:
- title = @"已取消购买";
- break;
- case IAPPurchVerFailed:
- title = @"订单校验失败";
- break;
- // case IAPPurchVerSuccess:
- // NSLog(@"订单校验成功");
- // break;
- case IAPPurchNotArrow:
- title = @"不允许程序内付费";
- break;
- default:
- break;
- }
- if (title.length == 0) {
- [ZCHUDHelper dismiss];
- }else{
- [ZCHUDHelper showTitle:title];
- }
- }
- }];
- }
- - (void)requestApplePayBack:(NSString *)receipt_data{
-
- [LCHttpHelper requestWithURLString:ApplePayBack parameters:@{@"receipt_data":receipt_data} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- dispatch_async(dispatch_get_main_queue(), ^{
- self.youpaipbuyBtn.userInteractionEnabled = YES;
- });
- if (code == 0) {
- [LCSaveData removeReceiptData:receipt_data];
- NSInteger type = 4;
- // if (![LCSaveData getOnlineVersion]) {
- // type = 4;
- // }
- [self youpaifinitDataWithType:type];
- // if (self.paySuccessBlock != nil) {
- // self.paySuccessBlock();
- // }
- }
- [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- } failure:^(NSError *error) {
- dispatch_async(dispatch_get_main_queue(), ^{
- self.youpaipbuyBtn.userInteractionEnabled = YES;
- });
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- -(void)youpaifcloseBtnClick{
- [self dismissViewControllerAnimated:YES completion:^{
-
- }];
-
- }
- - (UIScrollView *)youpaipscrollView{
- if (!_youpaipscrollView) {
- _youpaipscrollView = [[UIScrollView alloc]initWithFrame:CGRectZero];
- _youpaipscrollView.scrollEnabled = YES;
- _youpaipscrollView.pagingEnabled = NO;
- _youpaipscrollView.bounces = YES;
- _youpaipscrollView.showsVerticalScrollIndicator = NO;
- _youpaipscrollView.showsHorizontalScrollIndicator = NO;
- _youpaipscrollView.backgroundColor = [UIColor clearColor];
- }
- return _youpaipscrollView;
- }
- @end
|