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

#import "SettlementViewController.h"
10
#import "PayViewController.h"
11 12
#import "PromotionalDeductionModel.h"
#import "PromotionalGoodsModel.h"
13 14 15
#import "PromotionLuckyDrawModel.h"
#import "PromotionWeChatCardModel.h"
#import "PromotionJDECardModel.h"
曹云霄's avatar
曹云霄 committed
16
#import "PromotionalReadPacketModel.h"
勾芒's avatar
勾芒 committed
17

勾芒's avatar
勾芒 committed
18
@interface SettlementViewController ()<ReturnTableviewcellIndexpathdelegate,UITextFieldDelegate>
19

勾芒's avatar
勾芒 committed
20 21 22 23 24 25 26 27 28 29
/**
 *  支付宝二维码
 */
@property (nonatomic,copy) NSString *zhiFubaoLabe;

/**
 *  微信二维码
 */
@property (nonatomic,copy) NSString *weiXinLabe;

30 31 32 33 34
/**
 *  二维码界面
 */
@property (nonatomic,strong) PayViewController *payController;

35 36 37 38 39
/**
 总金额来源
 */
@property (nonatomic,copy) NSString *totalAmountSource;

勾芒's avatar
勾芒 committed
40

41 42 43 44
@end

@implementation SettlementViewController

45 46 47 48 49 50 51 52 53 54

#pragma mark -初始化二维码显示
- (PayViewController *)payController
{
    if (!_payController) {
        _payController = [[PayViewController alloc]init];
    }
    return _payController;
}

55 56
- (void)viewDidLoad {
    [super viewDidLoad];
勾芒's avatar
勾芒 committed
57 58
    
    [self uiConfigAction];
59
    [self calculateGoodsTotalAmountAndTotalNumber];
勾芒's avatar
勾芒 committed
60
    [self getPayQrCode];
61 62 63
}


勾芒's avatar
勾芒 committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#pragma mark -布局
- (void)uiConfigAction
{
    self.goodsAllNumberBackvie.layer.masksToBounds = YES;
    self.goodsAllNumberBackvie.layer.cornerRadius = kCornerRadius;
    self.goodsAllpriceBackView.layer.masksToBounds = YES;
    self.goodsAllpriceBackView.layer.cornerRadius = kCornerRadius;
    self.payTypeButton.layer.masksToBounds = YES;
    self.payTypeButton.layer.cornerRadius = kCornerRadius;
    self.WeixiPayButton.layer.masksToBounds = YES;
    self.WeixiPayButton.layer.cornerRadius = kCornerRadius;
    self.payTreasureButton.layer.masksToBounds = YES;
    self.payTreasureButton.layer.cornerRadius = kCornerRadius;
    self.ISinvoiceButton.layer.masksToBounds = YES;
    self.ISinvoiceButton.layer.cornerRadius = kCornerRadius;
    self.invoiceType.layer.masksToBounds = YES;
    self.invoiceType.layer.cornerRadius = kCornerRadius;
    self.invoiceBackView.layer.masksToBounds = YES;
    self.invoiceBackView.layer.cornerRadius = kCornerRadius;
勾芒's avatar
勾芒 committed
83 84 85 86
    self.cancelButton.layer.masksToBounds = YES;
    self.cancelButton.layer.cornerRadius = kCornerRadius;
    self.sureButton.layer.masksToBounds = YES;
    self.sureButton.layer.cornerRadius = kCornerRadius;
勾芒's avatar
勾芒 committed
87 88
    self.myScrollView.contentSize = CGSizeMake(0, self.view.frame.size.height);
    self.invoiceHeader.delegate = self;
勾芒's avatar
勾芒 committed
89 90 91 92
}


#pragma mark -支付总金额,商品总数量
93
- (void)calculateGoodsTotalAmountAndTotalNumber
勾芒's avatar
勾芒 committed
94 95 96 97 98
{
    NSInteger goodsAllNumber = 0;//总数量
    for (TOOrderdetailEntity *model in _goodsArray) {
        goodsAllNumber += [model.goodsNum integerValue];
    }
99 100 101 102 103 104
    CGFloat allPrice = 0;//实际支付金额
    NSDictionary *deductionPrice = nil;//抵扣金额
    NSDictionary *weChatPrice = nil;//微信卡劵
    NSDictionary *drawPrice = nil;//转盘抽奖
    for (TOOrderdetailEntity *model in _goodsArray) {
        allPrice += [model.goodsPrice floatValue]*[model.goodsNum floatValue];
曹云霄's avatar
曹云霄 committed
105
    }
106
    //促销列表
107 108
    for (JSONModel *model in self.consumerPromotionalArray) {
            //微信卡劵
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        if ([model isMemberOfClass:[PromotionWeChatCardModel class]]) {
            PromotionWeChatCardModel *weChatModel = (PromotionWeChatCardModel *)model;
            weChatPrice = @{@"price":[NSString stringWithFormat:@"%ld",self.weChatModel.wxcardDenomation],@"priority":@(weChatModel.priority)};
            
        }else if ([model isMemberOfClass:[PromotionalDeductionModel class]]) {
            //抵扣
            PromotionalDeductionModel *deductionModel = (PromotionalDeductionModel *)model;
            deductionPrice = @{@"price":[NSString stringWithFormat:@"%ld",deductionModel.total],@"priority":@(deductionModel.priority)};
            
        }else if ([model isMemberOfClass:[PromotionLuckyDrawModel class]]) {
            //抽奖
            PromotionLuckyDrawModel *drawModel = (PromotionLuckyDrawModel *)model;
            drawPrice = @{@"price":[NSString stringWithFormat:@"%@",self.resultModel.number],@"priority":@(drawModel.priority)};
            
        }else if ([model isMemberOfClass:[PromotionalGoodsModel class]]) {
            //送商品
曹云霄's avatar
曹云霄 committed
125
            //PromotionalGoodsModel *goodsModel = (PromotionalGoodsModel *)model;
126 127
        }
    }
128
    CGFloat goodsAllPrice = [self promotionSorting:deductionPrice andWeChatPrice:weChatPrice andDrawPrice:drawPrice andAllPrice:allPrice];
勾芒's avatar
勾芒 committed
129
    self.goodsAllNumber.text = [NSString stringWithFormat:@"%ld",goodsAllNumber];
130
    self.goodsAllPrice.text = [NSString stringWithFormat:@"¥%.2f",goodsAllPrice];
勾芒's avatar
勾芒 committed
131 132
}

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
#pragma mark - 通过优先级排列促销项
- (CGFloat)promotionSorting:(NSDictionary *)deductionPrice andWeChatPrice:(NSDictionary *)weChatPrice andDrawPrice:(NSDictionary *)drawPrice andAllPrice:(CGFloat)allPrice
{
    NSMutableArray *array = [NSMutableArray array];
    if (deductionPrice) {
        [array addObject:deductionPrice];
    }
    if (weChatPrice) {
        [array addObject:weChatPrice];
    }
    if (drawPrice) {
        [array addObject:drawPrice];
    }
    //安装权限降序排列
    NSArray *chooseArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *obj1, NSDictionary *obj2) {
        if (obj1[@"priority"] < obj2[@"priority"]) {
149
            return NSOrderedDescending;
150 151
        }
        if (obj1[@"priority"] < obj2[@"priority"]) {
152
            return NSOrderedAscending;
153 154 155 156 157
        }
        return NSOrderedSame;
    }];
    //计算促销后的价格
    CGFloat newPrice = allPrice;
158
    NSMutableString *priceString = [NSMutableString stringWithFormat:@"原价 %.2f元",allPrice];
159 160 161 162
    for (NSDictionary *dict in chooseArray) {
        if ([dict isEqual:deductionPrice]) {
            CGFloat deduction = [dict[@"price"] floatValue];
            newPrice = newPrice - deduction;
163
            [priceString appendString:[NSString stringWithFormat:@" - 抵扣促销 %.2f元",deduction]];
164 165 166 167
            
        }else if ([dict isEqual:weChatPrice]){
            CGFloat weChat = [dict[@"price"] floatValue];
            newPrice = newPrice - weChat;
168
            [priceString appendString:[NSString stringWithFormat:@" - 微信卡劵 %.2f元",weChat]];
169
            
曹云霄's avatar
曹云霄 committed
170
        }else if ([dict isEqual:drawPrice] && self.resultModel){
171 172
            CGFloat draw = [self.resultModel.number floatValue]/100.0;
            newPrice = newPrice * draw;
173
            [priceString appendString:[NSString stringWithFormat:@" X 转盘抽奖 %@",self.resultModel.descriptionString]];
174 175 176 177 178 179 180
        }
    }
    //判断促销是否为空
    if (chooseArray.count) {
        if (newPrice < 0) {
            newPrice = 0;
        }
181
        [priceString appendString:[NSString stringWithFormat:@" = %.2f元",newPrice]];
182
    }
183
    self.totalAmountSource = priceString;
184 185
    return newPrice;
}
勾芒's avatar
勾芒 committed
186

勾芒's avatar
勾芒 committed
187 188 189
#pragma mark -获取经营者支付二维码
- (void)getPayQrCode
{
190
    WS(weakSelf);
191
    [[NetworkRequestClassManager manager ] networkWithDictionaryRequestWithURL:SERVERREQUESTURL(QRCODE)  withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
192
        
曹云霄's avatar
曹云霄 committed
193
        if (RESULT(returnValue)) {
勾芒's avatar
勾芒 committed
194 195
            
            NSLog(@"获取二维码成功");
曹云霄's avatar
曹云霄 committed
196 197
            weakSelf.zhiFubaoLabe = RESPONSE(returnValue)[@"zhifubao"];
            weakSelf.weiXinLabe = RESPONSE(returnValue)[@"weixin"];
勾芒's avatar
勾芒 committed
198 199 200 201
            
        }else
        {
            NSLog(@"获取二维码失败");
202
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
203
        }
勾芒's avatar
勾芒 committed
204
        
205
    } withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
206
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
207 208
    }];
}
勾芒's avatar
勾芒 committed
209 210


211 212
- (void)viewWillAppear:(BOOL)animated
{
曹云霄's avatar
曹云霄 committed
213
    [super viewWillAppear:animated];
214 215 216 217
    self.view.superview.layer.cornerRadius = 0;
}


勾芒's avatar
勾芒 committed
218 219 220 221 222 223 224 225 226 227
#pragma mark -取消支付
- (IBAction)CancelButtonClick:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark -确认支付
- (IBAction)SureButtonClick:(UIButton *)sender {
    
勾芒's avatar
勾芒 committed
228
    if ([self.payTypeButton.currentTitle isEqualToString:@"现金、支票、转账、刷卡"] && !self.payTreasureButton.selected && !self.WeixiPayButton.selected) {
曹云霄's avatar
曹云霄 committed
229
        [XBLoadingView showHUDViewWithText:@"请选择一种支付方式"];
勾芒's avatar
勾芒 committed
230
        
231
    }else if ([self.invoiceType.currentTitle isEqualToString:@"公司发票"] && [[self class] isBlankString:self.invoiceHeader.text])
勾芒's avatar
勾芒 committed
232
    {
曹云霄's avatar
曹云霄 committed
233
        [XBLoadingView showHUDViewWithText:@"请输入发票抬头"];
勾芒's avatar
勾芒 committed
234 235
    }else
    {
236
      [self surePayRequest];
勾芒's avatar
勾芒 committed
237
    }
勾芒's avatar
勾芒 committed
238 239 240 241 242
}

#pragma amrk -支付方式选择
- (IBAction)payTypeButtonClick:(UIButton *)sender {
    
勾芒's avatar
勾芒 committed
243
    NSArray *arr = @[@"现金",@"支票",@"转账",@"刷卡"];
244
    [self showPopoverViewController:CGSizeMake(100, 200) withdatas:arr showButton:sender selectedIndex:0 getTitle:YES];
勾芒's avatar
勾芒 committed
245 246
}

勾芒's avatar
勾芒 committed
247 248 249
#pragma mark -微信支付
- (IBAction)WechatButtonClick:(UIButton *)sender {
    
250
    [self.payController dismissViewControllerAnimated:NO completion:nil];
251
    if ([self.weiXinLabe isKindOfClass:[NSNull class]]) {
曹云霄's avatar
曹云霄 committed
252
        [XBLoadingView showHUDViewWithText:@"微信支付二维码为空,暂停使用!"];return;
253
    }
勾芒's avatar
勾芒 committed
254
    self.showPayQrCodeImageView.hidden = NO;
255 256 257 258 259
    sender.selected = NO;
    [self.showPayQrCodeImageView sd_setImageWithURL:[NSURL URLWithString:self.weiXinLabe] placeholderImage:REPLACEIMAGE];
    self.payTreasureButton.selected = NO;
    [self.payTypeButton setTitle:@"现金、支票、转账、刷卡" forState:UIControlStateNormal];
    [self BringPayController:YES withButton:sender];
勾芒's avatar
勾芒 committed
260 261 262 263 264 265
}


#pragma mark -支付宝支付
- (IBAction)ZhifubaoPayButtonClick:(UIButton *)sender {
    
266
    [self.payController dismissViewControllerAnimated:NO completion:nil];
267
    if ([self.zhiFubaoLabe isKindOfClass:[NSNull class]]) {
曹云霄's avatar
曹云霄 committed
268
        [XBLoadingView showHUDViewWithText:@"支付宝支付二维码为空,暂停使用!"];return;
269
    }
勾芒's avatar
勾芒 committed
270
    self.showPayQrCodeImageView.hidden = NO;
271 272 273 274 275
    sender.selected = NO;
    [self.showPayQrCodeImageView sd_setImageWithURL:[NSURL URLWithString:self.zhiFubaoLabe] placeholderImage:REPLACEIMAGE];
    self.WeixiPayButton.selected = NO;
    [self.payTypeButton setTitle:@"现金、支票、转账、刷卡" forState:UIControlStateNormal];
    [self BringPayController:NO withButton:sender];
勾芒's avatar
勾芒 committed
276 277 278
}


279 280 281 282 283 284 285 286 287 288 289 290
#pragma mark -调出二维码支付框
- (void)BringPayController:(BOOL)weichat withButton:(UIButton *)sender
{
    
    self.payController.preferredContentSize = CGSizeMake(281, 387);
    self.payController.modalPresentationStyle = UIModalPresentationPopover;
    sender.selected = YES;
    UIPopoverPresentationController *pop = self.payController.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionLeft;
    pop.sourceView = self.payController.view;
    pop.sourceRect = [self.view convertRect:CGRectMake(sender.mj_x, sender.mj_y-30, sender.mj_w, sender.mj_h) toView:self.view.window];
    self.payController.dealersName.text = weichat?@"微信支付":@"支付宝支付";
曹云霄's avatar
曹云霄 committed
291
    self.payController.dealersName.textColor = weichat?RGB(30, 198, 34,1):RGB(88, 172, 220,1);
292 293 294 295 296 297
    [self.payController.dealersImageView sd_setImageWithURL:[NSURL URLWithString:weichat?self.weiXinLabe:self.zhiFubaoLabe] placeholderImage:REPLACEIMAGE];
    self.payController.payTypeBackimageView.image = weichat?TCImage(@"weixinpay"):TCImage(@"zhifubaopay");
    [self presentViewController:self.payController animated:NO completion:nil];
}


勾芒's avatar
勾芒 committed
298 299
#pragma mark -是否开票
- (IBAction)isinvoiceButtonClick:(UIButton *)sender {
勾芒's avatar
勾芒 committed
300 301
    
    NSArray *arr = @[@"是",@"否"];
302
    [self showPopoverViewController:CGSizeMake(50, 150) withdatas:arr showButton:sender selectedIndex:1 getTitle:YES];
勾芒's avatar
勾芒 committed
303 304 305 306 307
}


#pragma mark -发票类型
- (IBAction)invoiceTypeButtonClick:(UIButton *)sender {
勾芒's avatar
勾芒 committed
308
    
勾芒's avatar
勾芒 committed
309
    if ([self.ISinvoiceButton.currentTitle isEqualToString:@"否"]) {
曹云霄's avatar
曹云霄 committed
310
        [XBLoadingView showHUDViewWithText:@"请选择开票"];
勾芒's avatar
勾芒 committed
311 312
        return;
    }
勾芒's avatar
勾芒 committed
313
    NSArray *arr = @[@"个人发票",@"公司发票"];
314
    [self showPopoverViewController:CGSizeMake(100, 150) withdatas:arr showButton:sender selectedIndex:2 getTitle:YES];
勾芒's avatar
勾芒 committed
315 316 317 318
}


#pragma mark -弹出popover视图控制器
319
- (void)showPopoverViewController:(CGSize)size withdatas:(NSArray *)datasArray showButton:(UIButton *)button selectedIndex:(NSInteger)index getTitle:(BOOL )istitle
勾芒's avatar
勾芒 committed
320 321 322 323
{
    PopoverViewController *popover = [[PopoverViewController alloc]init];
    popover.datasArray = datasArray;
    popover.delegate = self;
324
    popover.selectedindex = index;
勾芒's avatar
勾芒 committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
    popover.isString = YES;
    popover.contentSize = size;
    popover.preferredContentSize = size;
    popover.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *pop = popover.popoverPresentationController;
    pop.permittedArrowDirections = UIPopoverArrowDirectionUp;
    pop.sourceView = popover.view;
    pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    [self presentViewController:popover animated:YES completion:nil];
}


/**
 *  选中筛选条件对象typecode
 *
 *  @param index NSString
 */
342
- (void)returnCellindexpathwithrow:(NSString *)type withCellTitle:(NSString *)title withSelected:(NSInteger)selected
勾芒's avatar
勾芒 committed
343
{
344
    switch (selected) {
勾芒's avatar
勾芒 committed
345 346 347
        case 0://支付方式
        {
            [self.payTypeButton setTitle:title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
348 349
            self.payTreasureButton.selected = NO;
            self.WeixiPayButton.selected = NO;
勾芒's avatar
勾芒 committed
350
            self.showPayQrCodeImageView.hidden = YES;
勾芒's avatar
勾芒 committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
        }
            break;
        case 1://是否开票
        {
            [self.ISinvoiceButton setTitle:title forState:UIControlStateNormal];
        }
            break;
        case 2://发票类型
        {
            [self.invoiceType setTitle:title forState:UIControlStateNormal];
        }
            break;
            
        default:
            break;
    }
}

勾芒's avatar
勾芒 committed
369 370

#pragma mark -确认支付请求
371
- (void)surePayRequest
勾芒's avatar
勾芒 committed
372
{
勾芒's avatar
勾芒 committed
373
    OrderPayRequest *order = [[OrderPayRequest alloc]init];
374 375 376
    order.orderNumber =  self.orderCode;
    order.fnewstate =  PAYSUCCESS;
    order.oldstate =  NOTPAY;
377
    order.realAmount = [NSNumber numberWithFloat:[[self.goodsAllPrice.text substringFromIndex:1] floatValue]];
378
    // 查询是否有京东E卡促销、是否有导购抽奖
379
    NSInteger totalNumber = 0;
曹云霄's avatar
曹云霄 committed
380
    NSMutableArray *readPacketArray = [NSMutableArray array];
381
    for (id object in self.guidePromotionArray) {
382 383
        if ([object isKindOfClass:[PromotionJDECardModel class]]) {
            PromotionJDECardModel *model = (PromotionJDECardModel *)object;
384
            if ([model.type isEqualToString:JDECardAction] && [model.body isEqualToString:GUIDE]) {
385 386 387
                totalNumber += model.total;
            }
        }
388 389
        if ([object isKindOfClass:[PromotionLuckyDrawModel class]]) {
            PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object;
390 391
            if ([model.body isEqualToString:GUIDE]) {
                order.lotteryId = model.lottery.uuid;
392
            }
393
        }
曹云霄's avatar
曹云霄 committed
394 395 396 397 398 399 400 401 402 403
        if ([object isKindOfClass:[PromotionalReadPacketModel class]]) {
            PromotionalReadPacketModel *model = (PromotionalReadPacketModel *)object;
            if ([model.body isEqualToString:GUIDE]) {
                RedPackageDetail *entity = [[RedPackageDetail alloc] init];
                entity.money = [NSNumber numberWithInteger:model.total];
                entity.promotionBillNumber = model.promotionBillNumber;
                entity.redPrority = [NSString stringWithFormat:@"%ld",model.priority];
                [readPacketArray addObject:entity];
            }
        }        
404
    }
曹云霄's avatar
曹云霄 committed
405
    order.redPackageDetails = (NSArray<RedPackageDetail> *)readPacketArray;
406
    order.jdCardDenomation = totalNumber;
407 408 409 410 411
    // 查询是否有消费者抽奖促销、微信卡劵促销、抵扣金额、商品促销
    CGFloat promotionMoney = 0;
    NSInteger deductionPrority = 0;//抵扣优先级
    NSInteger goodsPrority = 0;//商品促销优先级
    NSMutableArray *goodsArray = [NSMutableArray array];
曹云霄's avatar
曹云霄 committed
412
    for (id object in self.consumerPromotionalArray) {
413 414
        if ([object isKindOfClass:[PromotionLuckyDrawModel class]]) {
            PromotionLuckyDrawModel *model = (PromotionLuckyDrawModel *)object;
415 416
            if ([model.body isEqualToString:CONSUMER]) {
                order.drawId = self.resultModel.drawId;
417
                order.drawPrority = model.priority;
418
            }
419
        }
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
        if ([object isKindOfClass:[PromotionWeChatCardModel class]]) {
            PromotionWeChatCardModel *model = (PromotionWeChatCardModel *)object;
            if ([model.body isEqualToString:CONSUMER]) {
                if (![[self class] isBlankString:self.weChatModel.wxcardNumber]) {
                    order.wxcardNumber = self.weChatModel.wxcardNumber;
                    order.wxcardDenomation = [NSNumber numberWithInteger:self.weChatModel.wxcardDenomation];
                    order.wxCardPrority = model.priority;
                }
            }
        }
        if ([object isKindOfClass:[PromotionalDeductionModel class]]) {
            PromotionalDeductionModel *model = (PromotionalDeductionModel *)object;
            if (model.isSelected) {
                promotionMoney += model.total;
                deductionPrority = model.priority;
            }
        }
        if ([object isKindOfClass:[PromotionalGoodsModel class]]) {
            PromotionalGoodsModel *model = (PromotionalGoodsModel *)object;
            if (model.isSelected) {
                PromotionGoods *goods = [[PromotionGoods alloc]init];
                UCN *goodDetails = [[UCN alloc]init];
                goodDetails.code = model.goods.code;
                goodDetails.uuid = model.goods.uuid;
                goodDetails.name = model.goods.name;
                goods.goods = goodDetails;
                goods.promotionNumber = [NSNumber numberWithInteger:model.count];
                [goodsArray addObject:goods];
            }
            goodsPrority = model.priority;
        }
451
    }
452 453 454 455
    order.promotionMoney = @(promotionMoney);
    order.deductionPrority = deductionPrority;
    order.promotionGoods = (NSArray<PromotionGoods> *)goodsArray;
    order.goodsPrority = goodsPrority;
勾芒's avatar
勾芒 committed
456 457 458
    //支付类型
    if (self.payTreasureButton.selected) {
       order.payType =  @"005";
459
    }else if (self.WeixiPayButton.selected){
勾芒's avatar
勾芒 committed
460
        order.payType = @"006";
461
    }else{
勾芒's avatar
勾芒 committed
462 463 464 465
        order.payType =  [self PayTypeSelected:self.payTypeButton.currentTitle];
    }
    //是否开票
    if ([self.ISinvoiceButton.currentTitle isEqualToString:@"是"]) {
勾芒's avatar
勾芒 committed
466
        order.isbill = @"Y";
勾芒's avatar
勾芒 committed
467 468
    }
    else if ([self.ISinvoiceButton.currentTitle isEqualToString:@"否"]){
勾芒's avatar
勾芒 committed
469
       order.isbill =  @"N";
勾芒's avatar
勾芒 committed
470 471
    }
    //发票类型
472
    if ([self.invoiceType.currentTitle isEqualToString:@"公司发票"] && [order.isbill isEqualToString:@"Y"]) {
473
        order.billType =  @"002";
勾芒's avatar
勾芒 committed
474
        if (self.invoiceHeader.text.length == 0 || !self.invoiceHeader.text) {
曹云霄's avatar
曹云霄 committed
475
            [XBLoadingView showHUDViewWithText:@"发票抬头不能为空"];
勾芒's avatar
勾芒 committed
476 477
            return;
        }
勾芒's avatar
勾芒 committed
478
        order.billTitle = self.invoiceHeader.text;
479
    }else if ([self.invoiceType.currentTitle isEqualToString:@"个人发票"] && [order.isbill isEqualToString:@"Y"])
勾芒's avatar
勾芒 committed
480
    {
481
        order.billType =  @"001";
482
    }
曹云霄's avatar
曹云霄 committed
483
    [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
484
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
485
    [HTTP networkRequestWithURL:SERVERREQUESTURL(CONFIRMPAY)  withRequestType:ZERO withParameter:order withReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
486
        
曹云霄's avatar
曹云霄 committed
487
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
488
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
489 490 491 492 493
            [weakSelf dismissViewControllerAnimated:YES completion:^{
                if (weakSelf.PaySuccessReturnBlock) {
                    weakSelf.PaySuccessReturnBlock();
                }
            }];
494
        }else{
495
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
勾芒's avatar
勾芒 committed
496
        }
497
    }withFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
498
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
勾芒's avatar
勾芒 committed
499 500 501
    }];
}

勾芒's avatar
勾芒 committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
#pragma mark -支付方式选择
- (NSString *)PayTypeSelected:(NSString *)selecte
{
    NSString *payCode = nil;
    if ([selecte isEqualToString:@"现金"]) {
        return payCode = @"001";
    }
    if ([selecte isEqualToString:@"刷卡"]) {
        return payCode = @"002";
    }
    if ([selecte isEqualToString:@"转账"]) {
        return payCode = @"003";
    }
    if ([selecte isEqualToString:@"支票"]) {
        return payCode = @"004";
    }
    return nil;
}

勾芒's avatar
勾芒 committed
521

勾芒's avatar
勾芒 committed
522 523 524 525
#pragma mark -开始编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if ([self.ISinvoiceButton.currentTitle isEqualToString:@"否"]) {
曹云霄's avatar
曹云霄 committed
526
        [XBLoadingView showHUDViewWithText:@"请选择开票"];
勾芒's avatar
勾芒 committed
527 528 529 530 531 532 533 534 535 536 537
        return NO;
    }
    return YES;
}

#pragma mark -结束编辑
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    self.myScrollView.contentOffset = CGPointMake(0, 0);
}

538 539
#pragma mark - 价格疑问
- (IBAction)priceQuestionButtonClickAction:(UIButton *)sender {
曹云霄's avatar
曹云霄 committed
540 541 542 543
        
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:self.totalAmountSource preferredStyle:UIAlertControllerStyleAlert];
    [alertVc addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alertVc animated:YES completion:nil];
544 545 546
}


547 548


549
@end