123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- //
- // PersonalBaseViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/11/2.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class PersonalBindCardViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
- @IBOutlet weak var txtFL: UITextField!
- @IBOutlet weak var txtType: UITextField!
- @IBOutlet weak var txtBankPhone: UITextField!
- @IBOutlet weak var txtBankChild: UITextField!
- @IBOutlet weak var txtBandAddress: UITextField!
- @IBOutlet weak var txtBankName: UITextField!
- @IBOutlet weak var txtBankCard: UITextField!
- @IBOutlet weak var txtKHM: UITextField!
- var viewSelectCity: Virgil_SelectCity!
- @IBOutlet weak var view5: UIView!
- @IBOutlet weak var view4: UIView!
- @IBOutlet weak var view3: UIView!
- var shopOpen: ShopOpenEntity!
- var bankCardCityName = ""
- var namem = ""
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "完善资料"
- initNavLeftBackButton()
- }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txtKHM.resignFirstResponder()
- txtType.resignFirstResponder()
- txtBankPhone.resignFirstResponder()
- txtBankChild.resignFirstResponder()
- txtBandAddress.resignFirstResponder()
- txtBankName.resignFirstResponder()
- txtBankCard.resignFirstResponder()
- txtKHM.resignFirstResponder()
- }
- //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 识别银行卡
- uploadImage(type: 0)
- break
- case 1002: // 银行所在地区
- let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
- if viewSelectCity == nil {
- viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
- viewSelectCity.modelType = 2
- viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
- self!.shopOpen.bankAddressId1 = self!.getString(key: "addressId1", dic: dic)
- self!.shopOpen.bankAddressId2 = self!.getString(key: "addressId2", dic: dic)
- self!.shopOpen.bankAddressId3 = self!.getString(key: "addressId3", dic: dic)
- self!.shopOpen.bankAddressName1 = self!.getString(key: "addressName1", dic: dic)
- self!.shopOpen.bankAddressName2 = self!.getString(key: "addressName2", dic: dic)
- self!.shopOpen.bankAddressName3 = self!.getString(key: "addressName3", dic: dic)
- self!.txtBandAddress.text = self!.getString(key: "address", dic: dic)
- self!.bankCardCityName = self!.getString(key: "addressName2", dic: dic)
- }
- self.view.addSubview(viewSelectCity)
- }
- viewSelectCity.showPickerView()
- break
- case 1003: // 所在支行
- let vc = SelectBankViewController()
- vc.shopEntity = shopOpen
- vc.provinceId = ""//addressIds[0]
- vc.cityId = ""//addressIds[1];
- var substr = ""
- if self.bankCardCityName.contains("市") {
- let arr = self.bankCardCityName.components(separatedBy: "市")
- substr = arr[0]
- }else {
- substr = self.bankCardCityName
- }
- namem = self.txtBankName.text! + substr
- vc.bankName = namem //txtBank.text!;
- toViewController(viewController: vc)
- break
- case 1004: // 所属行业
- let vc = ShopIndustryViewController()
- vc.shopOpen = self.shopOpen
- toViewController(viewController: vc)
- break
- case 1005: // 费率
- getFeiLv(isDefault: false)
- break
- case 1006: // 提交
- submitHK()
- break
- default:
- break
- }
- }
- ///费率
- let dicFL = NSMutableDictionary()
- func getFeiLv(isDefault: Bool) {
- if dicFL.count > 0 {
- returnData(tag: 1003)
- return
- }
- let params = NSMutableDictionary()
- let url = RequestURL.rateConfig
- params.setValue(shopOpen.posId, forKey: "machine_type_id")
- params.setValue(shopOpen.shopType, forKey: "merchant_type")
- params.setValue(shopOpen.productTypeId, forKey: "product_type_id")
- if isDefault {
- loadDataInfo(url: url, params: params, tag: 1002, reDic: dicFL)
- } else {
- loadDataInfo(url: url, params: params, tag: 1003, reDic: dicFL)
- }
- }
- func submitHK() {
- if txtKHM.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入开户名")
- return
- }
- if txtBankCard.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入银行卡号")
- return
- }
- if txtBankName.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入所属银行")
- return
- }
- if self.shopOpen.bankAddressId1 == "" || self.shopOpen.bankAddressId2 == "" || self.shopOpen.bankAddressId3 == "" {
- SVProgressHUD.showError(withStatus: "请选择银行所在地区")
- return
- }
- if txtBankChild.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请选择所在支行")
- return
- }
- if txtBankPhone.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入银行卡预留手机号")
- return
- }
- if txtType.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请选择所属行业")
- return
- }
- let url = RequestURL.bindMercBank
- let params = NSMutableDictionary()
- params.setValue(shopOpen.pmmerId, forKey: "pmmerId")
- params.setValue(txtKHM.text!, forKey: "acctName")
- params.setValue(txtBankName.text!, forKey: "acctBnk")
- params.setValue(txtBankCard.text!, forKey: "acctNo")
- params.setValue(shopOpen.bankAffiliatedBank, forKey: "bankCode")
- params.setValue(shopOpen.bankAffiliatedBranchBankCN, forKey: "brnkName")
- params.setValue(shopOpen.bankAffiliatedBranchBank, forKey: "brnkCode")
- params.setValue(shopOpen.bankAddressName1, forKey: "acctProvinceName")
- params.setValue(shopOpen.bankAddressName2, forKey: "acctCityName")
- params.setValue(shopOpen.bankAddressName3, forKey: "acctCountyName")
- params.setValue(txtBankPhone.text!, forKey: "acctPhone")
- params.setValue(self.shopOpen.bankAddressId1, forKey: "acctProvince")
- params.setValue(self.shopOpen.phone, forKey: "regAccno")
- submitData(url: url, params: params, tag: 1001)
- }
- //海科成功后,提交本地
- func submitData() {
- let params = NSMutableDictionary()
- let url = RequestURL.openingMerchantsJian
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- params.setValue(shopOpen.posId, forKey: "machineTypeId")
- params.setValue(shopOpen.posSN, forKey: "machineSnCode")
- params.setValue(shopOpen.shopType, forKey: "busType")
- params.setValue(shopOpen.phone, forKey: "busPhone")
- params.setValue(shopOpen.companyName, forKey: "companyName")
- params.setValue(shopOpen.name, forKey: "applicantName")
- params.setValue(shopOpen.card, forKey: "applicantCard")
- params.setValue(shopOpen.cardFront, forKey: "applicantCardFront")
- params.setValue(shopOpen.cardReverse, forKey: "applicantCardReverse")
- params.setValue(shopOpen.cardHoldFront, forKey: "applicantCardHoldFront")
- params.setValue(shopOpen.otherImage, forKey: "applicantCardHoldReverse")
- params.setValue(shopOpen.addressDetail, forKey: "shopAddress")
- params.setValue(shopOpen.addressId1, forKey: "shopProvinceId")
- params.setValue(shopOpen.addressId2, forKey: "shopCityId")
- params.setValue(shopOpen.addressId3, forKey: "shopAreaId")
- params.setValue(shopOpen.addressName1, forKey: "provinceCN")
- params.setValue(shopOpen.addressName2, forKey: "cityCN")
- params.setValue(shopOpen.addressName3, forKey: "areaCN")
- params.setValue(shopOpen.typeId2, forKey: "categoryTwoId")
- params.setValue(shopOpen.typeId1, forKey: "categoryOneId")
- params.setValue(shopOpen.bankCardNo, forKey: "bankCardNumber")
- params.setValue(shopOpen.bankAddressId1, forKey: "bankProvinceId")
- params.setValue(shopOpen.bankAddressId2, forKey: "bankCityId")
- params.setValue(shopOpen.bankAddressId3, forKey: "bankAreaId")
- params.setValue(shopOpen.bankAddressName1, forKey: "bankProvinceCN")
- params.setValue(shopOpen.bankAddressName2, forKey: "bankCityCN")
- params.setValue(shopOpen.bankAddressName3, forKey: "bankAreaCN")
- //params.setValue(shopOpen.bankAddressName3, forKey: "bankAreaCN")
- params.setValue(shopOpen.bankAffiliatedBranchBank, forKey: "bankAffiliatedBranchBank")
- params.setValue(shopOpen.bankOpenName, forKey: "bankOpenName")
- params.setValue(shopOpen.bankCardImage, forKey: "bankCardImg")
- params.setValue(shopOpen.typeName1, forKey: "categoryONECN")
- params.setValue(shopOpen.typeName2, forKey: "categoryTWOCN")
- params.setValue(shopOpen.licenseImage, forKey: "licenseImage")
- params.setValue(shopOpen.licenseNum, forKey: "licenseNum")
- params.setValue(shopOpen.bankAccountType, forKey: "bankAccountType")
- params.setValue(shopOpen.openingPermitImage, forKey: "openingPermitImage")
- params.setValue(shopOpen.reservePhone, forKey: "reservePhone")
- params.setValue(shopOpen.bankName, forKey: "bankAffiliatedBankCN")
- params.setValue(shopOpen.bankAffiliatedBank, forKey: "bankAffiliatedBank")
- params.setValue(shopOpen.applicantCardFrontLocal, forKey: "applicantCardFrontLocal")
- params.setValue(shopOpen.applicantCardReverseLocal, forKey: "applicantCardReverseLocal")
- params.setValue(shopOpen.applicantCardHoldFrontLocal, forKey: "applicantCardHoldFrontLocal")
- params.setValue(shopOpen.bankCardImgLocal, forKey: "bankCardImgLocal")
- params.setValue(shopOpen.bankAffiliatedBranchBankCN, forKey: "bankAffiliatedBranchBankCN")
- params.setValue(shopOpen.dpImages, forKey: "shopPhoto")
- params.setValue(shopOpen.shhyzImages, forKey: "shopUserPhoto")
- params.setValue(shopOpen.productTypeId, forKey: "productTypeId")
- params.setValue(shopOpen.rate, forKey: "rate")
- params.setValue(shopOpen.debitCardCostRate, forKey: "debitCardCostRate")
- params.setValue(shopOpen.debitCardCapping, forKey: "debitCardCapping")
- params.setValue(shopOpen.unionpayRate, forKey: "unionpayRate")
- params.setValue(shopOpen.loanCardCapping, forKey: "loanCardCapping")
- params.setValue(shopOpen.pmmerId, forKey: "pmmerId")
- submitData(url: url, params: params, tag: 1004)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- let dichaike = dicBackData["haike"] as? NSDictionary
- if dichaike != nil {
- let dicMessage = dichaike!["message"] as? NSDictionary
- if dicMessage != nil {
- if dicMessage!.getString(key: "code") == "success" {
- let dicResult = dichaike!["result"] as? NSDictionary
- if dicResult != nil {
- self.shopOpen.pmmerId = dicResult!.getString(key: "pmmerId")
- }
- self.shopOpen.bankOpenName = txtKHM.text!
- self.shopOpen.bankName = txtBankName.text!
- self.shopOpen.bankCardNo = txtBankCard.text!
- self.shopOpen.reservePhone = txtBankPhone.text!
- self.shopOpen.bankAccountType = "0"
- submitData()
- } else {
- SVProgressHUD.showError(withStatus: dicMessage!.getString(key: "content"))
- }
- } else {
- SVProgressHUD.showError(withStatus: "提交海科失败,请稍后重试!")
- }
- } else {
- SVProgressHUD.showError(withStatus: "提交海科失败,请稍后重试!")
- }
- } else if(tag == 1002) //初始化加载默认费率
- {
- shopOpen.rate = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default"))
- shopOpen.debitCardCostRate = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_cost_rate"))
- shopOpen.debitCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_capping"))
- shopOpen.unionpayRate = String.init(format: "%.2f", dicFL.getDouble(key: "unionpay_rate"))
- shopOpen.loanCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_capping"))
- txtFL.text = "\(String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default")))%"
- } else if(tag == 1003) //加载费率选择框
- {
- shopOpen.rate = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default"))
- shopOpen.debitCardCostRate = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_cost_rate"))
- shopOpen.debitCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_capping"))
- shopOpen.unionpayRate = String.init(format: "%.2f", dicFL.getDouble(key: "unionpay_rate"))
- shopOpen.loanCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_capping"))
- var rateMin = dicFL.getDouble(key: "loan_card_rate_min") * 100
- let rateMax = dicFL.getDouble(key: "loan_card_rate_max") * 100
- arrRateContent.removeAll()
- var arrTitle = [String]()
- while Int(rateMin) <= Int(rateMax) {
- arrTitle.append("\(String.init(format: "%.2f", rateMin / 100))%")
- arrRateContent.append(String.init(format: "%.2f", rateMin / 100))
- rateMin += 1
- }
- CommonUntils.AlertView(controller: self, title: nil, message: "请选择费率", buttons: arrTitle, style: .actionSheet) {[weak self] (index, _) in
- self!.txtFL.text = "\(self!.arrRateContent[index])%"
- self!.shopOpen.rate = self!.arrRateContent[index]
- }
- } else if tag == 1004 {
- SVProgressHUD.showSuccess(withStatus: "提交成功!")
- if !CommonUntils.reBackView(controller: self, aclass: ShopManagerViewController.classForCoder()) {
- self.navigationController?.popToRootViewController(animated: true)
- }
- }
- }
- var arrRateContent = [String]()
- override func returnError(tag: Int, type: String) {
- }
- // MARK: ============选择头像============
- var uploadImageType = 0
- func uploadImage(type: Int) {
- uploadImageType = type
- CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
- let ipc = UIImagePickerController()
- if index == 0 {
- ipc.sourceType = .camera
- } else {
- ipc.sourceType = .photoLibrary
- }
- ipc.delegate = self!
- ipc.allowsEditing = false
- self!.present(ipc, animated: true, completion: nil)
- }
- }
- var imgTemp: UIImage!
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
- self.dismiss(animated: true) {[weak self] in
- var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
- if picker.allowsEditing {
- imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
- }
- if imgTemp != nil {
- self!.UploadFile(img: imgTemp!)
- } else {
- SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
- }
- }
- }
- func UploadFile(img: UIImage) {
- MBProgressHUD.showAdded(to: self.view, animated: true)
- let uploadFile = QiNiuUploadFile()
- uploadFile.uploadFile(img: img) {[weak self] (type, _) in
- if type == 1 {
- self!.uploadWeb(img: img)
- } else {
- MBProgressHUD.hide(for: self!.view, animated: true)
- SVProgressHUD.showError(withStatus: "上传失败")
- }
- }
- }
- var imgLocalPath = ""
- func uploadWeb(img: UIImage) {
- let manage = AFHTTPSessionManager()
- let param = NSMutableDictionary()
- param.setValue(8, forKey: "type")
- manage.requestSerializer.timeoutInterval = 60.0
- manage.post(RequestURL.uploadMerchantFile, parameters: param, constructingBodyWith: { (formDate) in
- formDate.appendPart(withFileData: img.jpegData(compressionQuality: 0.4)!, name: "fileInput", fileName: "fileInput", mimeType: "multipart/form-data")
- }, progress: nil, success: {[weak self] (op, json1) in
- let json = json1 as! NSDictionary
- print(json)
- let succeed = json.object(forKey: "succeed") as! String
- if succeed == "000" {
- let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
- if status == 200 {
- self!.imgLocalPath = (json["dataInfo"] as! NSDictionary).getString(key: "url")
- let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
- let hkResult = haike["result"] as! NSDictionary
- let hkResultData = hkResult["data"] as! NSDictionary
- self!.txtBankName.text = hkResultData.getString(key: "bankName")
- self!.txtBankCard.text = hkResultData.getString(key: "cardNumber")
- } else {
- SVProgressHUD.showError(withStatus: "银行卡识别失败,请重新上传或手动输入银行卡号!")
- }
- } else {
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- }
- MBProgressHUD.hide(for: self!.view, animated: true)
- }) { (_, _) in
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- MBProgressHUD.hide(for: self.view, animated: true)
- }
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- if shopOpen.rate == "" {
- getFeiLv(isDefault: true)
- } else {
- txtFL.text = "\(shopOpen.rate)%"
- }
- txtType.text = shopOpen.typeName1
- if mainViewControllerIsGo {
- if mainViewControllerIsGoType == 0 {
- shopOpen.bankAffiliatedBranchBankCN = mainViewControllerIsGoValue
- shopOpen.bankAffiliatedBranchBank = mainViewControllerIsGoValue1
- shopOpen.bankAffiliatedBank = mainViewControllerIsGoValue2
- txtBankChild.text = mainViewControllerIsGoValue
- }
- }
- mainViewControllerIsGo = false
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "PersonalBindCardViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|