220 lines
8.5 KiB
Mathematica
220 lines
8.5 KiB
Mathematica
|
|
//
|
||
|
|
// DLJueweiVC.m
|
||
|
|
// SweetParty
|
||
|
|
//
|
||
|
|
// Created by bj_szd on 2023/6/28.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "DLJueweiVC.h"
|
||
|
|
#import "DLJueweiItemCell.h"
|
||
|
|
#import <WXApi.h>
|
||
|
|
#import <AlipaySDK/AlipaySDK.h>
|
||
|
|
#import "NSString+category.h"
|
||
|
|
|
||
|
|
@interface DLJueweiVC () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
|
||
|
|
|
||
|
|
@property (weak, nonatomic) IBOutlet UIImageView *jwImgV;
|
||
|
|
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
|
||
|
|
@property (weak, nonatomic) IBOutlet UILabel *decLab;
|
||
|
|
@property (weak, nonatomic) IBOutlet UILabel *jiesuoLab;
|
||
|
|
@property (weak, nonatomic) IBOutlet UILabel *decNameLabel;
|
||
|
|
|
||
|
|
@property (weak, nonatomic) IBOutlet UILabel *priceLab;
|
||
|
|
@property (weak, nonatomic) IBOutlet UILabel *songLab;
|
||
|
|
@property (weak, nonatomic) IBOutlet UILabel *xufeiLab;
|
||
|
|
@property (weak, nonatomic) IBOutlet UIButton *openBtn;
|
||
|
|
@property (weak, nonatomic) IBOutlet UILabel *expireTimeLab;
|
||
|
|
@property (weak, nonatomic) IBOutlet UILabel *dayNumLabel;
|
||
|
|
@property (nonatomic, strong) NSString *noblity_end_time;
|
||
|
|
@property (nonatomic, strong) DLJueweiInfoModel *infoModel;
|
||
|
|
|
||
|
|
@property (nonatomic, strong) NSArray *dataArray;
|
||
|
|
@property (weak, nonatomic) IBOutlet UIView *bottomView;
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
@implementation DLJueweiVC
|
||
|
|
|
||
|
|
- (void)viewDidLoad {
|
||
|
|
[super viewDidLoad];
|
||
|
|
|
||
|
|
[self createUI];
|
||
|
|
|
||
|
|
[self fetchData];
|
||
|
|
|
||
|
|
self.bottomView.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(ScreenWidth, 600) direction:FXGradientChangeDirectionVertical startColor:HEXCOLOR(0xDFFFF6) endColor:HEXCOLOR(0xFFFFFF)];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)createUI {
|
||
|
|
self.view.backgroundColor = kClearColor;
|
||
|
|
|
||
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||
|
|
CGFloat itemW = (ScreenWidth-32*2-20*2)/3;
|
||
|
|
layout.itemSize = CGSizeMake(itemW, itemW+20);
|
||
|
|
layout.minimumInteritemSpacing = 0;
|
||
|
|
layout.minimumLineSpacing = 10;
|
||
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 18, 28, 18);
|
||
|
|
|
||
|
|
_collectionView.collectionViewLayout = layout;
|
||
|
|
_collectionView.backgroundColor = kClearColor;
|
||
|
|
_collectionView.delegate = self;
|
||
|
|
_collectionView.dataSource = self;
|
||
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"DLJueweiItemCell" bundle:nil] forCellWithReuseIdentifier:@"DLJueweiItemCell"];
|
||
|
|
|
||
|
|
NSString *titleImg = [NSString stringWithFormat:@"juewei_%@",@(_index)];
|
||
|
|
_titleImg.image = ImageNamed(titleImg);
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)fetchData {
|
||
|
|
NSDictionary *params = @{@"lid":C_string(self.lid)};
|
||
|
|
[AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/nobility/get_nobility_info" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
|
||
|
|
NSDictionary *data = responseDic[@"data"];
|
||
|
|
NSArray *arr = [DLJueweiItemModel mj_objectArrayWithKeyValuesArray:[data safeArrayForKey:@"nobility_power_list"]];
|
||
|
|
self.dataArray = arr;
|
||
|
|
[self.collectionView reloadData];
|
||
|
|
|
||
|
|
self.infoModel = [DLJueweiInfoModel mj_objectWithKeyValues:responseDic[@"data"][@"nobility_info"]];
|
||
|
|
self.priceLab.text = self.infoModel.pay_price;
|
||
|
|
[self.jwImgV sd_setImageWithURL:[NSURL URLWithString:self.infoModel.image]];
|
||
|
|
|
||
|
|
self.songLab.text = [NSString stringWithFormat:@"赠送%@金币", self.infoModel.pay_coin];
|
||
|
|
self.xufeiLab.text = [NSString stringWithFormat:@"续费%@元/%@天 赠送%@金币", self.infoModel.renew_price,self.infoModel.day_num,self.infoModel.renew_coin];
|
||
|
|
self.dayNumLabel.text = [NSString stringWithFormat:@"/%@天", self.infoModel.day_num];
|
||
|
|
self.noblity_end_time = [data safeStringForKey:@"user_nobility_end_time"];
|
||
|
|
if ([self.noblity_end_time isEqualToString:@"0"]) {
|
||
|
|
self.openBtn.selected = NO;
|
||
|
|
self.xufeiLab.hidden = YES;
|
||
|
|
self.expireTimeLab.text = @"当前爵位未开通";
|
||
|
|
}else {
|
||
|
|
self.openBtn.selected = YES;
|
||
|
|
self.xufeiLab.hidden = NO;
|
||
|
|
self.expireTimeLab.text = [NSString stringWithFormat:@"到期时间:%@", self.noblity_end_time.formateDateYMD_HM];
|
||
|
|
}
|
||
|
|
|
||
|
|
} Failure:^(id _Nonnull errorData) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (IBAction)openButtonClick:(UIButton *)sender {
|
||
|
|
UIAlertController *sheetAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
||
|
|
|
||
|
|
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"支付宝支付" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||
|
|
[self createrNobilityPayWithType:@"1"];
|
||
|
|
}];
|
||
|
|
[action1 setValue:mainDeepColor forKey:@"_titleTextColor"];
|
||
|
|
[sheetAlert addAction:action1];
|
||
|
|
|
||
|
|
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"微信支付" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||
|
|
[self createrNobilityPayWithType:@"2"];
|
||
|
|
}];
|
||
|
|
[action2 setValue:mainDeepColor forKey:@"_titleTextColor"];
|
||
|
|
[sheetAlert addAction:action2];
|
||
|
|
|
||
|
|
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
|
||
|
|
[action3 setValue:HEXCOLOR(0x333333) forKey:@"_titleTextColor"];
|
||
|
|
[sheetAlert addAction:action3];
|
||
|
|
[self presentViewController:sheetAlert animated:YES completion:nil];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)createrNobilityPayWithType:(NSString *)type
|
||
|
|
{
|
||
|
|
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||
|
|
[dict setValue:type forKey:@"pay_type"];
|
||
|
|
[dict setValue:self.lid forKey:@"lid"];
|
||
|
|
|
||
|
|
[BJHttpTool BJPay_nobilityWithParameters:dict success:^(id response) {
|
||
|
|
if ([type isEqualToString:@"2"]) {
|
||
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(payResultMethod:) name:@"wechatPayResult" object:nil];
|
||
|
|
NSDictionary *dict = response[@"data"];
|
||
|
|
PayReq *req = [[PayReq alloc] init];
|
||
|
|
req.nonceStr = [dict objectForKey:@"noncestr"];
|
||
|
|
req.timeStamp = [[dict objectForKey:@"timestamp"] intValue];
|
||
|
|
req.package = [dict objectForKey:@"package"];
|
||
|
|
req.partnerId = [dict objectForKey:@"partnerid"];
|
||
|
|
req.prepayId = [dict objectForKey:@"prepayid"];
|
||
|
|
req.sign = [dict objectForKey:@"sign"];
|
||
|
|
[WXApi sendReq:req completion:^(BOOL success) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}else if ([type isEqualToString:@"21"]){
|
||
|
|
NSDictionary *data = [response safeDictionaryForKey:@"data"];
|
||
|
|
NSString *rqinfo = [data safeStringForKey:@"pay_info"];
|
||
|
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:rqinfo] options:@{} completionHandler:^(BOOL success) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
else{
|
||
|
|
[self onAliPay:[response safeStringForKey:@"data"]];
|
||
|
|
}
|
||
|
|
} failure:^(NSError *error) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)onAliPay:(NSString *)payStr {
|
||
|
|
[[AlipaySDK defaultService] payOrder:payStr fromScheme:@"redAlipay" callback:^(NSDictionary *resultDic) {
|
||
|
|
NSLog(@"支付宝回调%@", resultDic);
|
||
|
|
if ([resultDic[@"resultStatus"] integerValue] == 9000) {
|
||
|
|
[HelpPageDefine showMessage:@"充值成功"];
|
||
|
|
[self fetchData];
|
||
|
|
}else if ([resultDic[@"resultStatus"] integerValue] == 6001) {
|
||
|
|
[HelpPageDefine showMessage:@"支付取消"];
|
||
|
|
}else {
|
||
|
|
[HelpPageDefine showMessage:@"支付失败"];
|
||
|
|
}
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)payResultMethod:(NSNotification *)note {
|
||
|
|
int code = [note.object intValue];
|
||
|
|
switch (code) {
|
||
|
|
case 1:{
|
||
|
|
//支付成功
|
||
|
|
[HelpPageDefine showMessage:@"充值成功"];
|
||
|
|
[self fetchData];
|
||
|
|
}break;
|
||
|
|
case 2:{
|
||
|
|
//支付取消
|
||
|
|
[HelpPageDefine showMessage:@"支付取消"];
|
||
|
|
}break;
|
||
|
|
case 3:{
|
||
|
|
//支付失败
|
||
|
|
[HelpPageDefine showMessage:@"支付失败"];
|
||
|
|
}break;
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
#pragma mark -------- collectionView代理方法 ------
|
||
|
|
|
||
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||
|
|
return self.dataArray.count;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||
|
|
DLJueweiItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DLJueweiItemCell" forIndexPath:indexPath];
|
||
|
|
DLJueweiItemModel *model = self.dataArray[indexPath.row];
|
||
|
|
cell.model = model;
|
||
|
|
|
||
|
|
return cell;
|
||
|
|
}
|
||
|
|
|
||
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
||
|
|
|
||
|
|
- (UIView *)listView {
|
||
|
|
return self.view;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)setIndex:(NSInteger)index {
|
||
|
|
_index = index;
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|