SettlementViewController.m 13 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"
勾芒's avatar
勾芒 committed
11

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

勾芒's avatar
勾芒 committed
14 15 16 17 18 19 20 21 22 23
/**
 *  支付宝二维码
 */
@property (nonatomic,copy) NSString *zhiFubaoLabe;

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

24 25 26 27 28
/**
 *  二维码界面
 */
@property (nonatomic,strong) PayViewController *payController;

勾芒's avatar
勾芒 committed
29 30 31



32 33 34 35
@end

@implementation SettlementViewController

36 37 38 39 40 41 42 43 44 45

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

46 47
- (void)viewDidLoad {
    [super viewDidLoad];
勾芒's avatar
勾芒 committed
48 49
    
    [self uiConfigAction];
勾芒's avatar
勾芒 committed
50 51
    [self setGoodsArray];
    [self getPayQrCode];
52 53 54
}


勾芒's avatar
勾芒 committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75


#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
76 77 78 79
    self.cancelButton.layer.masksToBounds = YES;
    self.cancelButton.layer.cornerRadius = kCornerRadius;
    self.sureButton.layer.masksToBounds = YES;
    self.sureButton.layer.cornerRadius = kCornerRadius;
勾芒's avatar
勾芒 committed
80 81
    self.myScrollView.contentSize = CGSizeMake(0, self.view.frame.size.height);
    self.invoiceHeader.delegate = self;
勾芒's avatar
勾芒 committed
82 83 84 85 86
}



#pragma mark -支付总金额,商品总数量
勾芒's avatar
勾芒 committed
87
- (void)setGoodsArray
勾芒's avatar
勾芒 committed
88 89
{
    NSInteger goodsAllNumber = 0;//总数量
勾芒's avatar
勾芒 committed
90
    CGFloat goodAllprice = 0;//总价格
勾芒's avatar
勾芒 committed
91 92
    for (TOOrderdetailEntity *model in _goodsArray) {
        goodsAllNumber += [model.goodsNum integerValue];
勾芒's avatar
勾芒 committed
93
        goodAllprice += [model.goodsPrice floatValue]*[model.goodsNum integerValue];
勾芒's avatar
勾芒 committed
94 95
    }
    self.goodsAllNumber.text = [NSString stringWithFormat:@"%ld",goodsAllNumber];
勾芒's avatar
勾芒 committed
96
    self.goodsAllPrice.text = [NSString stringWithFormat:@"¥%.2f",goodAllprice];
勾芒's avatar
勾芒 committed
97 98 99
}


勾芒's avatar
勾芒 committed
100 101 102 103 104
#pragma mark -获取经营者支付二维码
- (void)getPayQrCode
{
    [[NetworkRequestClassManager Manager ] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/employee/getReseller"] WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
        
勾芒's avatar
勾芒 committed
105 106 107
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            NSLog(@"获取二维码成功");
勾芒's avatar
勾芒 committed
108 109
            self.zhiFubaoLabe = returnValue[@"data"][@"zhifubao"];
            self.weiXinLabe = returnValue[@"data"][@"weixin"];
勾芒's avatar
勾芒 committed
110 111 112 113 114
            
        }else
        {
            NSLog(@"获取二维码失败");
        }
勾芒's avatar
勾芒 committed
115 116 117 118 119 120 121
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        NSLog(@"%@",error);
    }];
}
勾芒's avatar
勾芒 committed
122 123


124 125 126 127 128 129
- (void)viewWillAppear:(BOOL)animated
{
    self.view.superview.layer.cornerRadius = 0;
}


勾芒's avatar
勾芒 committed
130 131 132 133 134 135 136 137 138 139 140

#pragma mark -取消支付
- (IBAction)CancelButtonClick:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark -确认支付
- (IBAction)SureButtonClick:(UIButton *)sender {
    
勾芒's avatar
勾芒 committed
141 142 143 144 145 146 147 148 149 150
    if ([self.payTypeButton.currentTitle isEqualToString:@"现金、支票、转账、刷卡"] && !self.payTreasureButton.selected && !self.WeixiPayButton.selected) {
        [self ErrorMBProgressView:@"请选择一种支付方式"];
        
    }else if ([self.invoiceType.currentTitle isEqualToString:@"公司发票"] && self.invoiceHeader.text.length == 0)
    {
        [self ErrorMBProgressView:@"请输入发票抬头"];
    }else
    {
      [self SurePayRequest];
    }
勾芒's avatar
勾芒 committed
151 152 153 154 155
}

#pragma amrk -支付方式选择
- (IBAction)payTypeButtonClick:(UIButton *)sender {
    
勾芒's avatar
勾芒 committed
156
    NSArray *arr = @[@"现金",@"支票",@"转账",@"刷卡"];
勾芒's avatar
勾芒 committed
157 158 159
    [self ShowPopoverViewController:CGSizeMake(100, 200) Withdatas:arr ShowButton:sender SelectedIndex:0 GetTitle:YES];
}

勾芒's avatar
勾芒 committed
160 161 162
#pragma mark -微信支付
- (IBAction)WechatButtonClick:(UIButton *)sender {
    
163
    [self.payController dismissViewControllerAnimated:NO completion:nil];
勾芒's avatar
勾芒 committed
164
    self.showPayQrCodeImageView.hidden = NO;
165 166 167 168 169
    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
170 171 172 173 174 175
}


#pragma mark -支付宝支付
- (IBAction)ZhifubaoPayButtonClick:(UIButton *)sender {
    
176
    [self.payController dismissViewControllerAnimated:NO completion:nil];
勾芒's avatar
勾芒 committed
177
    self.showPayQrCodeImageView.hidden = NO;
178 179 180 181 182
    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
183 184 185
}


186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
#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?@"微信支付":@"支付宝支付";
    self.payController.dealersName.textColor = weichat?kTCColor(30, 198, 34):kTCColor(88, 172, 220);
    [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
207 208
#pragma mark -是否开票
- (IBAction)isinvoiceButtonClick:(UIButton *)sender {
勾芒's avatar
勾芒 committed
209 210 211
    
    NSArray *arr = @[@"是",@"否"];
    [self ShowPopoverViewController:CGSizeMake(50, 150) Withdatas:arr ShowButton:sender SelectedIndex:1 GetTitle:YES];
勾芒's avatar
勾芒 committed
212 213 214 215 216
}


#pragma mark -发票类型
- (IBAction)invoiceTypeButtonClick:(UIButton *)sender {
勾芒's avatar
勾芒 committed
217
    
勾芒's avatar
勾芒 committed
218 219 220 221
    if ([self.ISinvoiceButton.currentTitle isEqualToString:@"否"]) {
        [self ErrorMBProgressView:@"请选择开票"];
        return;
    }
勾芒's avatar
勾芒 committed
222 223
    NSArray *arr = @[@"个人发票",@"公司发票"];
    [self ShowPopoverViewController:CGSizeMake(100, 150) Withdatas:arr ShowButton:sender SelectedIndex:2 GetTitle:YES];
勾芒's avatar
勾芒 committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
}



#pragma mark -弹出popover视图控制器
- (void)ShowPopoverViewController:(CGSize)size Withdatas:(NSArray *)datasArray ShowButton:(UIButton *)button SelectedIndex:(NSInteger)index GetTitle:(BOOL )istitle
{
    
    PopoverViewController *popover = [[PopoverViewController alloc]init];
    popover.datasArray = datasArray;
    popover.delegate = self;
    popover.Selectedindex = index;
    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
 */
- (void)returnCellindexpathwithrow:(NSString *)Type WithcellTitle:(NSString *)title Withselected:(NSInteger)Selected
{
勾芒's avatar
勾芒 committed
256
    [self dismissViewControllerAnimated:YES completion:nil];
勾芒's avatar
勾芒 committed
257
    
勾芒's avatar
勾芒 committed
258 259 260 261
    switch (Selected) {
        case 0://支付方式
        {
            [self.payTypeButton setTitle:title forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
262 263
            self.payTreasureButton.selected = NO;
            self.WeixiPayButton.selected = NO;
勾芒's avatar
勾芒 committed
264
            self.showPayQrCodeImageView.hidden = YES;
勾芒's avatar
勾芒 committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
        }
            break;
        case 1://是否开票
        {
            [self.ISinvoiceButton setTitle:title forState:UIControlStateNormal];
        }
            break;
        case 2://发票类型
        {
            [self.invoiceType setTitle:title forState:UIControlStateNormal];
        }
            break;
            
        default:
            break;
    }
}

勾芒's avatar
勾芒 committed
283 284 285 286 287 288


#pragma mark -确认支付请求
- (void)SurePayRequest
{
    
勾芒's avatar
勾芒 committed
289 290 291 292 293 294
    OrderPayRequest *order = [[OrderPayRequest alloc]init];
    order.orderNumber =  _orderCode;
    order.fnewstate =  @"002";
    order.oldstate =  @"001";
    //支付类型
    if (self.payTreasureButton.selected) {
勾芒's avatar
勾芒 committed
295
        
勾芒's avatar
勾芒 committed
296
       order.payType =  @"005";
勾芒's avatar
勾芒 committed
297
        
勾芒's avatar
勾芒 committed
298 299 300 301 302 303 304 305 306
    }else if (self.WeixiPayButton.selected)
    {
        order.payType = @"006";
    }else
    {
        order.payType =  [self PayTypeSelected:self.payTypeButton.currentTitle];
    }
    //是否开票
    if ([self.ISinvoiceButton.currentTitle isEqualToString:@"是"]) {
勾芒's avatar
勾芒 committed
307
        order.isbill = @"Y";
勾芒's avatar
勾芒 committed
308 309
    }
    else if ([self.ISinvoiceButton.currentTitle isEqualToString:@"否"]){
勾芒's avatar
勾芒 committed
310
       order.isbill =  @"N";
勾芒's avatar
勾芒 committed
311 312 313
    }
    //发票类型
    if ([self.invoiceType.currentTitle isEqualToString:@"公司发票"]) {
勾芒's avatar
勾芒 committed
314
        
315
        order.billType =  @"002";
勾芒's avatar
勾芒 committed
316 317 318 319
        if (self.invoiceHeader.text.length == 0 || !self.invoiceHeader.text) {
            [self ErrorMBProgressView:@"发票抬头不能为空"];
            return;
        }
勾芒's avatar
勾芒 committed
320
        order.billTitle = self.invoiceHeader.text;
勾芒's avatar
勾芒 committed
321 322
    }else if ([self.invoiceType.currentTitle isEqualToString:@"个人发票"])
    {
323 324
        order.billType =  @"001";
    }    
勾芒's avatar
勾芒 committed
325 326
    [self CreateMBProgressHUDLoding];
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/order/payOrder"] WithRequestType:0 WithParameter:order WithReturnValueBlock:^(id returnValue) {
勾芒's avatar
勾芒 committed
327
        
勾芒's avatar
勾芒 committed
328 329 330
        [self CreateMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            NSLog(@"支付成功");
勾芒's avatar
勾芒 committed
331
            [self ErrorMBProgressView:@"支付成功"];
勾芒's avatar
勾芒 committed
332 333 334 335 336 337 338 339 340 341
            if (self.PaySuccessReturnBlock) {
                self.PaySuccessReturnBlock();
            }
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        NSLog(@"支付失败");
        [self CreateMBProgressHUDLoding];
勾芒's avatar
勾芒 committed
342 343 344 345
    }];
}


勾芒's avatar
勾芒 committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
#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;
}



//@synthesize orderNumber;
//@synthesize oldstate;
//@synthesize fnewstate;
//@synthesize payType;
//@synthesize isbill;
//@synthesize billType;
//@synthesize billTitle;

勾芒's avatar
勾芒 committed
375 376 377 378 379 380 381 382
#pragma mark -汉字转码
- (NSString *)ReturnUrlString:(NSString *)ChineseString
{
    NSString* encodedString = [ChineseString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    return encodedString;
}


勾芒's avatar
勾芒 committed
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
#pragma mark -开始编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if ([self.ISinvoiceButton.currentTitle isEqualToString:@"否"]) {
        [self ErrorMBProgressView:@"请选择开票"];
        return NO;
    }
    return YES;
}


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

勾芒's avatar
勾芒 committed
400

401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end