RebateViewController.m 14 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9
//
//  RebateViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/8/26.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "RebateViewController.h"
曹云霄's avatar
曹云霄 committed
10 11
#import "RebateDetailsViewController.h"
#import "WithdrawalTableViewController.h"
12 13
#import "CardViewController.h"
#import "CardDetailsViewController.h"
14 15
#import "LuckyDrawViewController.h"
#import "LuckyDrawDetailsViewController.h"
16 17
#import "PaymentWithdrawalMainViewController.h"
#import "BindingBankCARDViewController.h"
曹云霄's avatar
曹云霄 committed
18 19
#import "ReadPacketViewController.h"
#import "ReadPacketStateViewController.h"
20 21
#import "LuckyDrawMainViewController.h"
#import "ReadPacketMainViewController.h"
曹云霄's avatar
曹云霄 committed
22 23 24 25 26 27 28 29 30

@interface RebateViewController ()

/**
 *  头像
 */
@property (weak, nonatomic) IBOutlet UIImageView *headerImageView;

/**
31
 *  总资产
曹云霄's avatar
曹云霄 committed
32 33
 */
@property (weak, nonatomic) IBOutlet UILabel *currentAmountLabel;
34 35 36 37 38
/*******************************/
/**
 *  产品返利
 */
@property (weak, nonatomic) IBOutlet UILabel *productRebateAmountLabel;
曹云霄's avatar
曹云霄 committed
39 40 41 42

/**
 *  昨日收益
 */
43
@property (weak, nonatomic) IBOutlet UILabel *productRebateYesterdayAmountLabel;
曹云霄's avatar
曹云霄 committed
44 45 46 47

/**
 *  历史收益
 */
48
@property (weak, nonatomic) IBOutlet UILabel *productRebateHistoryAmountLabel;
曹云霄's avatar
曹云霄 committed
49

曹云霄's avatar
曹云霄 committed
50 51 52
/**
 *  冻结金额
 */
53
@property (weak, nonatomic) IBOutlet UILabel *productRebateFreezeAmountLabel;
曹云霄's avatar
曹云霄 committed
54

曹云霄's avatar
曹云霄 committed
55
/**
56
 提现
曹云霄's avatar
曹云霄 committed
57
 */
58
@property (weak, nonatomic) IBOutlet UIButton *productRebateButton;
曹云霄's avatar
曹云霄 committed
59

60
/*******************************/
曹云霄's avatar
曹云霄 committed
61
/**
62
 *  欧普奖励
曹云霄's avatar
曹云霄 committed
63
 */
64
@property (weak, nonatomic) IBOutlet UILabel *oppleRewardAmountLabel;
曹云霄's avatar
曹云霄 committed
65 66

/**
67
 *  昨日收益
曹云霄's avatar
曹云霄 committed
68
 */
69
@property (weak, nonatomic) IBOutlet UILabel *oppleRewardYesterdayAmountLabel;
曹云霄's avatar
曹云霄 committed
70 71

/**
72
 *  历史收益
曹云霄's avatar
曹云霄 committed
73
 */
74
@property (weak, nonatomic) IBOutlet UILabel *oppleRewardHistoryAmountLabel;
曹云霄's avatar
曹云霄 committed
75 76

/**
77
 *  冻结金额
曹云霄's avatar
曹云霄 committed
78
 */
79
@property (weak, nonatomic) IBOutlet UILabel *oppleRewardFreezeAmountLabel;
曹云霄's avatar
曹云霄 committed
80 81

/**
82
 提现
曹云霄's avatar
曹云霄 committed
83
 */
84 85 86
@property (weak, nonatomic) IBOutlet UIButton *oppleRewardButton;

/*******************************/
曹云霄's avatar
曹云霄 committed
87

88 89 90 91 92
/**
 *  我的卡劵包
 */
@property (weak, nonatomic) IBOutlet UIView *cardBackgroundView;

93 94 95 96 97
/**
 *  我的抽奖
 */
@property (weak, nonatomic) IBOutlet UIView *drawBackgroundView;

曹云霄's avatar
曹云霄 committed
98 99 100 101 102
/**
    我的红包
 */
@property (weak, nonatomic) IBOutlet UIView *readPacketBackgroundView;

103
/**
104
 返利数据
105
 */
106 107
@property (nonatomic,strong) EarningsResponse *resultEntity;

108

109
@end
110

曹云霄's avatar
曹云霄 committed
111 112 113 114


@implementation RebateViewController

曹云霄's avatar
曹云霄 committed
115
- (void)viewDidAppear:(BOOL)animated
116
{
曹云霄's avatar
曹云霄 committed
117
    [super viewDidAppear:animated];
118 119 120
    [self getRebateDatasFromUser];
}

曹云霄's avatar
曹云霄 committed
121 122 123 124 125 126 127 128 129 130
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupChildViewController];
    [self uiConfigAction];
}

#pragma mark - UI
- (void)uiConfigAction
{
131
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:[Shoppersmanager manager].shoppers.employee.picture] placeholderImage:GuideReplaceImage];
曹云霄's avatar
曹云霄 committed
132 133
}

曹云霄's avatar
曹云霄 committed
134
#pragma mark - 添加卡劵、抽奖控制器、红包
曹云霄's avatar
曹云霄 committed
135 136
- (void)setupChildViewController
{
137
    // 我的卡劵
曹云霄's avatar
曹云霄 committed
138
    CardViewController *cardVc = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"CardViewController"];
139 140
    [self addChildViewController:cardVc];
    [self.cardBackgroundView addSubview:cardVc.view];
曹云霄's avatar
曹云霄 committed
141 142 143 144 145 146
    [cardVc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardBackgroundView.mas_left).offset(10);
        make.right.equalTo(self.cardBackgroundView.mas_right).offset(-10);
        make.top.equalTo(self.cardBackgroundView.mas_top).offset(40);
        make.bottom.equalTo(self.cardBackgroundView.mas_bottom).offset(-10);
    }];
147 148
    
    // 我的抽奖
149
    LuckyDrawMainViewController *draw = [[[self class] getMainStoryboardClass]instantiateViewControllerWithIdentifier:@"LuckyDrawMainViewController"];
150 151
    [self addChildViewController:draw];
    [self.drawBackgroundView addSubview:draw.view];
曹云霄's avatar
曹云霄 committed
152 153 154 155 156 157 158 159
    [draw.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.drawBackgroundView.mas_left).offset(10);
        make.right.equalTo(self.drawBackgroundView.mas_right).offset(-10);
        make.top.equalTo(self.drawBackgroundView.mas_top).offset(40);
        make.bottom.equalTo(self.drawBackgroundView.mas_bottom).offset(-10);
    }];
    
    // 红包
160
    ReadPacketMainViewController *readPacket = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"ReadPacketMainViewController"];
曹云霄's avatar
曹云霄 committed
161 162 163 164 165 166 167 168
    [self addChildViewController:readPacket];
    [self.readPacketBackgroundView addSubview:readPacket.view];
    [readPacket.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.readPacketBackgroundView.mas_left).offset(10);
        make.right.equalTo(self.readPacketBackgroundView.mas_right).offset(-10);
        make.top.equalTo(self.readPacketBackgroundView.mas_top).offset(40);
        make.bottom.equalTo(self.readPacketBackgroundView.mas_bottom).offset(-10);
    }];
169 170
}

曹云霄's avatar
曹云霄 committed
171 172 173 174
#pragma mark - 查询返利信息
- (void)getRebateDatasFromUser
{
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
175
    [XBLoadingView showHUDViewWithDefault];
176
    NSString *url = [NSString stringWithFormat:@"%@/%@",REBATE,[Shoppersmanager manager].shoppers.employee.fid];
曹云霄's avatar
曹云霄 committed
177
    [HTTP networkWithDictionaryRequestWithURL:SERVERREQUESTURL(url) withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
178
        
曹云霄's avatar
曹云霄 committed
179
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
180
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
181
            weakSelf.resultEntity = [[EarningsResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
182
            [weakSelf setUpRichTextString:weakSelf.resultEntity];
曹云霄's avatar
曹云霄 committed
183 184
        }else
        {
185
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
曹云霄's avatar
曹云霄 committed
186 187
        }
        
188
    } withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
189
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
190 191 192
    }];
}

193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
#pragma mark - 设置富文本字符串<赋值>
- (void)setUpRichTextString:(EarningsResponse *)response
{
    //总资产
    NSMutableAttributedString *totalAssets = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%2f",[response.accountTotal floatValue]+[response.redPackageAccountTotal floatValue]]];
    [totalAssets addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(totalAssets.length-3, 3)];
    self.currentAmountLabel.attributedText = totalAssets;
    //产品返利
    NSMutableAttributedString *productRebate = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%.2f",[response.accountTotal floatValue]]];
    [productRebate addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(productRebate.length-3, 3)];
    self.productRebateAmountLabel.attributedText = productRebate;
    //欧普奖励
    NSMutableAttributedString *oppleReward = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%.2f",[response.redPackageAccountTotal floatValue]]];
    [oppleReward addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(oppleReward.length-3, 3)];
    self.oppleRewardAmountLabel.attributedText = oppleReward;
    self.currentAmountLabel.text = [NSString stringWithFormat:@"%.2f",[response.redPackageAccountTotal floatValue] + [response.accountTotal floatValue]];
    self.productRebateAmountLabel.text = [NSString stringWithFormat:@"%.2f",[response.accountTotal floatValue]];
210
     self.productRebateYesterdayAmountLabel.text = [NSString stringWithFormat:@"昨日收益:%.2f",[response.yesterdayEarnings floatValue]];
211
     self.productRebateHistoryAmountLabel.text = [NSString stringWithFormat:@"历史收益:%.2f",[response.historyEarning floatValue]];
212
    self.productRebateFreezeAmountLabel.text = [NSString stringWithFormat:@"提现中:%.2f",[response.applytotal floatValue]];
213 214
    self.oppleRewardYesterdayAmountLabel.text = [NSString stringWithFormat:@"昨日收益:%.2f",[response.redPackageYesterdayEarnings floatValue]];
    self.oppleRewardHistoryAmountLabel.text = [NSString stringWithFormat:@"历史收益:%.2f",[response.redPackageHistoryEarning floatValue]];
215
    self.oppleRewardFreezeAmountLabel.text = [NSString stringWithFormat:@"提现中:%.2f",[response.redPackageApplytotal floatValue]];
216 217 218
    self.oppleRewardAmountLabel.text = [NSString stringWithFormat:@"%.2f",[response.redPackageAccountTotal floatValue]];
}

曹云霄's avatar
曹云霄 committed
219

220
#pragma mark - 提现<tag == 100 产品返利><tag == 101 欧普奖励>
曹云霄's avatar
曹云霄 committed
221
- (IBAction)withdrawalButtonClickAction:(UIButton *)sender {
222

曹云霄's avatar
曹云霄 committed
223
    if (!self.resultEntity.isUsable && sender.tag == 101) {
224
        ShowAlertView(@"提示", self.resultEntity.showApplyMessage, @[@"我知道了"], UIAlertControllerStyleAlert, nil);
225 226
        return;
    }
227 228 229
    if (!self.resultEntity.bankCards.count && sender.tag == 101) {
        [self showUnboundedAlertView];
    }
曹云霄's avatar
曹云霄 committed
230
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
231
    RebateDetailsViewController *rebateDetails = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"RebateDetailsViewController"];
232
    rebateDetails.rebateAmount = (sender.tag == 100)?[self.resultEntity.accountTotal floatValue]:[self.resultEntity.redPackageAccountTotal floatValue];
233
    rebateDetails.billType = (sender.tag == 100)?COMMISSION:REDPACKAGE;
234
    rebateDetails.bankCardNumber = [[self.resultEntity.bankCards firstObject] bankAccount];
曹云霄's avatar
曹云霄 committed
235
    [rebateDetails setShowApplyDetails:^(TOApplyBillEntity *entity) {
236
        WithdrawalTableViewController *detailVC = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"WithdrawalTableViewController"];
曹云霄's avatar
曹云霄 committed
237
        detailVC.model = entity;
曹云霄's avatar
曹云霄 committed
238 239 240 241 242
        [weakSelf.navigationController pushViewController:detailVC animated:YES];
    }];
    [self.navigationController pushViewController:rebateDetails animated:YES];
}

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
#pragma mark - 收支明细
- (IBAction)paymentDetailsClickAction:(UIButton *)sender {
    
    PaymentWithdrawalMainViewController *controller = [[[self class] getMainStoryboardClass]instantiateViewControllerWithIdentifier:@"PaymentWithdrawalMainViewController"];
    [self.navigationController pushViewController:controller animated:YES];
}

#pragma mark - 提现账户
- (IBAction)withdrawalAccountClickAction:(UIButton *)sender {
    
    if (self.resultEntity.bankCards.count) {
        [self haveBindingBankCARDS];
    }else {
        [self showUnboundedAlertView];
    }
}

#pragma mark - 未绑定银行卡
- (void)showUnboundedAlertView
{
    UIAlertController *alertView = [UIAlertController alertControllerWithTitle:nil message:@"您还没有绑定提现账户" preferredStyle:UIAlertControllerStyleAlert];
    [alertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [alertView addAction:[UIAlertAction actionWithTitle:@"去绑定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        BindingBankCARDViewController *bindingVC = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"BindingBankCARDViewController"];
        [self.navigationController pushViewController:bindingVC animated:YES];
    }]];
    [self presentViewController:alertView animated:YES completion:nil];
}

#pragma mark - 已绑定银行卡
- (void)haveBindingBankCARDS
{
    TOBankCardEntity *entity = self.resultEntity.bankCards[0];
276
    NSString *bankCard = [NSString stringWithFormat:@"您已绑定提现账户\n%@\n%@****%@",entity.bankCardType,[entity.bankAccount substringWithRange:NSMakeRange(0, 4)],[entity.bankAccount substringWithRange:NSMakeRange(entity.bankAccount.length-4, 4)]];
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
    UIAlertController *alertView = [UIAlertController alertControllerWithTitle:nil message:bankCard preferredStyle:UIAlertControllerStyleAlert];
    [alertView addAction:[UIAlertAction actionWithTitle:@"解除绑定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self removeBindingBankCARDS];
    }]];
    [alertView addAction:[UIAlertAction actionWithTitle:@"重新绑定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        BindingBankCARDViewController *bindingVC = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"BindingBankCARDViewController"];
        [self.navigationController pushViewController:bindingVC animated:YES];
    }]];
    [alertView addAction:[UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alertView animated:YES completion:nil];
}

#pragma mark - 解除绑定银行卡
- (void)removeBindingBankCARDS
{
    [XBLoadingView showHUDViewWithDefault];
    WS(weakSelf);
     TOBankCardEntity *entity = self.resultEntity.bankCards[0];
曹云霄's avatar
曹云霄 committed
295
    [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(UNBINDING),entity.bankAccount] withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
296 297
        
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
298
        if (RESULT(returnValue)) {
299 300 301 302
            [XBLoadingView showHUDViewWithSuccessText:@"解除绑定成功" completeBlock:^{
                [weakSelf getRebateDatasFromUser];
            }];
        }else {
303
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
304 305
        }
        
306
    } withFailureBlock:^(NSError *error) {
307 308 309 310 311
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
    }];
}


312 313 314
#pragma mark - 更多卡劵
- (IBAction)moreCardButtonClickAction:(UIButton *)sender {
    
315
    CardDetailsViewController *cardDetails = [[[self class] getMainStoryboardClass]instantiateViewControllerWithIdentifier:@"CardDetailsViewController"];
316 317
    [self.navigationController pushViewController:cardDetails animated:YES];
}
曹云霄's avatar
曹云霄 committed
318

319 320 321
#pragma mark - 更多抽奖信息
- (IBAction)moreDrawButtonClickAction:(UIButton *)sender {
    
322
    LuckyDrawViewController *luckDrawDetails = [[[self class]  getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"LuckyDrawViewController"];
323 324 325
    [self.navigationController pushViewController:luckDrawDetails animated:YES];
}

曹云霄's avatar
曹云霄 committed
326 327 328 329 330 331 332 333 334
#pragma mark - 更多红包信息
- (IBAction)moreReadPacketButtonClickAction:(UIButton *)sender {
    
    ReadPacketStateViewController *luckDrawDetails = [[[self class]  getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"ReadPacketStateViewController"];
    [self.navigationController pushViewController:luckDrawDetails animated:YES];
}



曹云霄's avatar
曹云霄 committed
335 336


曹云霄's avatar
曹云霄 committed
337
@end