PersonalBindCardViewController.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. //
  2. // PersonalBaseViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/11/2.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class PersonalBindCardViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
  10. @IBOutlet weak var txtFL: UITextField!
  11. @IBOutlet weak var txtType: UITextField!
  12. @IBOutlet weak var txtBankPhone: UITextField!
  13. @IBOutlet weak var txtBankChild: UITextField!
  14. @IBOutlet weak var txtBandAddress: UITextField!
  15. @IBOutlet weak var txtBankName: UITextField!
  16. @IBOutlet weak var txtBankCard: UITextField!
  17. @IBOutlet weak var txtKHM: UITextField!
  18. var viewSelectCity: Virgil_SelectCity!
  19. @IBOutlet weak var view5: UIView!
  20. @IBOutlet weak var view4: UIView!
  21. @IBOutlet weak var view3: UIView!
  22. var shopOpen: ShopOpenEntity!
  23. var bankCardCityName = ""
  24. var namem = ""
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. self.title = "完善资料"
  28. initNavLeftBackButton()
  29. }
  30. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  31. txtKHM.resignFirstResponder()
  32. txtType.resignFirstResponder()
  33. txtBankPhone.resignFirstResponder()
  34. txtBankChild.resignFirstResponder()
  35. txtBandAddress.resignFirstResponder()
  36. txtBankName.resignFirstResponder()
  37. txtBankCard.resignFirstResponder()
  38. txtKHM.resignFirstResponder()
  39. }
  40. //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
  41. @IBAction func btnMenuClick(_ sender: AnyObject) {
  42. switch (sender as! UIButton).tag {
  43. case 1001: // 识别银行卡
  44. uploadImage(type: 0)
  45. break
  46. case 1002: // 银行所在地区
  47. let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
  48. if viewSelectCity == nil {
  49. viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
  50. viewSelectCity.modelType = 2
  51. viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
  52. self!.shopOpen.bankAddressId1 = self!.getString(key: "addressId1", dic: dic)
  53. self!.shopOpen.bankAddressId2 = self!.getString(key: "addressId2", dic: dic)
  54. self!.shopOpen.bankAddressId3 = self!.getString(key: "addressId3", dic: dic)
  55. self!.shopOpen.bankAddressName1 = self!.getString(key: "addressName1", dic: dic)
  56. self!.shopOpen.bankAddressName2 = self!.getString(key: "addressName2", dic: dic)
  57. self!.shopOpen.bankAddressName3 = self!.getString(key: "addressName3", dic: dic)
  58. self!.txtBandAddress.text = self!.getString(key: "address", dic: dic)
  59. self!.bankCardCityName = self!.getString(key: "addressName2", dic: dic)
  60. }
  61. self.view.addSubview(viewSelectCity)
  62. }
  63. viewSelectCity.showPickerView()
  64. break
  65. case 1003: // 所在支行
  66. let vc = SelectBankViewController()
  67. vc.shopEntity = shopOpen
  68. vc.provinceId = ""//addressIds[0]
  69. vc.cityId = ""//addressIds[1];
  70. var substr = ""
  71. if self.bankCardCityName.contains("市") {
  72. let arr = self.bankCardCityName.components(separatedBy: "市")
  73. substr = arr[0]
  74. }else {
  75. substr = self.bankCardCityName
  76. }
  77. namem = self.txtBankName.text! + substr
  78. vc.bankName = namem //txtBank.text!;
  79. toViewController(viewController: vc)
  80. break
  81. case 1004: // 所属行业
  82. let vc = ShopIndustryViewController()
  83. vc.shopOpen = self.shopOpen
  84. toViewController(viewController: vc)
  85. break
  86. case 1005: // 费率
  87. getFeiLv(isDefault: false)
  88. break
  89. case 1006: // 提交
  90. submitHK()
  91. break
  92. default:
  93. break
  94. }
  95. }
  96. ///费率
  97. let dicFL = NSMutableDictionary()
  98. func getFeiLv(isDefault: Bool) {
  99. if dicFL.count > 0 {
  100. returnData(tag: 1003)
  101. return
  102. }
  103. let params = NSMutableDictionary()
  104. let url = RequestURL.rateConfig
  105. params.setValue(shopOpen.posId, forKey: "machine_type_id")
  106. params.setValue(shopOpen.shopType, forKey: "merchant_type")
  107. params.setValue(shopOpen.productTypeId, forKey: "product_type_id")
  108. if isDefault {
  109. loadDataInfo(url: url, params: params, tag: 1002, reDic: dicFL)
  110. } else {
  111. loadDataInfo(url: url, params: params, tag: 1003, reDic: dicFL)
  112. }
  113. }
  114. func submitHK() {
  115. if txtKHM.text!.length() < 1 {
  116. SVProgressHUD.showError(withStatus: "请输入开户名")
  117. return
  118. }
  119. if txtBankCard.text!.length() < 1 {
  120. SVProgressHUD.showError(withStatus: "请输入银行卡号")
  121. return
  122. }
  123. if txtBankName.text!.length() < 1 {
  124. SVProgressHUD.showError(withStatus: "请输入所属银行")
  125. return
  126. }
  127. if self.shopOpen.bankAddressId1 == "" || self.shopOpen.bankAddressId2 == "" || self.shopOpen.bankAddressId3 == "" {
  128. SVProgressHUD.showError(withStatus: "请选择银行所在地区")
  129. return
  130. }
  131. if txtBankChild.text!.length() < 1 {
  132. SVProgressHUD.showError(withStatus: "请选择所在支行")
  133. return
  134. }
  135. if txtBankPhone.text!.length() < 1 {
  136. SVProgressHUD.showError(withStatus: "请输入银行卡预留手机号")
  137. return
  138. }
  139. if txtType.text!.length() < 1 {
  140. SVProgressHUD.showError(withStatus: "请选择所属行业")
  141. return
  142. }
  143. let url = RequestURL.bindMercBank
  144. let params = NSMutableDictionary()
  145. params.setValue(shopOpen.pmmerId, forKey: "pmmerId")
  146. params.setValue(txtKHM.text!, forKey: "acctName")
  147. params.setValue(txtBankName.text!, forKey: "acctBnk")
  148. params.setValue(txtBankCard.text!, forKey: "acctNo")
  149. params.setValue(shopOpen.bankAffiliatedBank, forKey: "bankCode")
  150. params.setValue(shopOpen.bankAffiliatedBranchBankCN, forKey: "brnkName")
  151. params.setValue(shopOpen.bankAffiliatedBranchBank, forKey: "brnkCode")
  152. params.setValue(shopOpen.bankAddressName1, forKey: "acctProvinceName")
  153. params.setValue(shopOpen.bankAddressName2, forKey: "acctCityName")
  154. params.setValue(shopOpen.bankAddressName3, forKey: "acctCountyName")
  155. params.setValue(txtBankPhone.text!, forKey: "acctPhone")
  156. params.setValue(self.shopOpen.bankAddressId1, forKey: "acctProvince")
  157. params.setValue(self.shopOpen.phone, forKey: "regAccno")
  158. submitData(url: url, params: params, tag: 1001)
  159. }
  160. //海科成功后,提交本地
  161. func submitData() {
  162. let params = NSMutableDictionary()
  163. let url = RequestURL.openingMerchantsJian
  164. params.setValue(CommonValue.getUserId(), forKey: "userId")
  165. params.setValue(shopOpen.posId, forKey: "machineTypeId")
  166. params.setValue(shopOpen.posSN, forKey: "machineSnCode")
  167. params.setValue(shopOpen.shopType, forKey: "busType")
  168. params.setValue(shopOpen.phone, forKey: "busPhone")
  169. params.setValue(shopOpen.companyName, forKey: "companyName")
  170. params.setValue(shopOpen.name, forKey: "applicantName")
  171. params.setValue(shopOpen.card, forKey: "applicantCard")
  172. params.setValue(shopOpen.cardFront, forKey: "applicantCardFront")
  173. params.setValue(shopOpen.cardReverse, forKey: "applicantCardReverse")
  174. params.setValue(shopOpen.cardHoldFront, forKey: "applicantCardHoldFront")
  175. params.setValue(shopOpen.otherImage, forKey: "applicantCardHoldReverse")
  176. params.setValue(shopOpen.addressDetail, forKey: "shopAddress")
  177. params.setValue(shopOpen.addressId1, forKey: "shopProvinceId")
  178. params.setValue(shopOpen.addressId2, forKey: "shopCityId")
  179. params.setValue(shopOpen.addressId3, forKey: "shopAreaId")
  180. params.setValue(shopOpen.addressName1, forKey: "provinceCN")
  181. params.setValue(shopOpen.addressName2, forKey: "cityCN")
  182. params.setValue(shopOpen.addressName3, forKey: "areaCN")
  183. params.setValue(shopOpen.typeId2, forKey: "categoryTwoId")
  184. params.setValue(shopOpen.typeId1, forKey: "categoryOneId")
  185. params.setValue(shopOpen.bankCardNo, forKey: "bankCardNumber")
  186. params.setValue(shopOpen.bankAddressId1, forKey: "bankProvinceId")
  187. params.setValue(shopOpen.bankAddressId2, forKey: "bankCityId")
  188. params.setValue(shopOpen.bankAddressId3, forKey: "bankAreaId")
  189. params.setValue(shopOpen.bankAddressName1, forKey: "bankProvinceCN")
  190. params.setValue(shopOpen.bankAddressName2, forKey: "bankCityCN")
  191. params.setValue(shopOpen.bankAddressName3, forKey: "bankAreaCN")
  192. //params.setValue(shopOpen.bankAddressName3, forKey: "bankAreaCN")
  193. params.setValue(shopOpen.bankAffiliatedBranchBank, forKey: "bankAffiliatedBranchBank")
  194. params.setValue(shopOpen.bankOpenName, forKey: "bankOpenName")
  195. params.setValue(shopOpen.bankCardImage, forKey: "bankCardImg")
  196. params.setValue(shopOpen.typeName1, forKey: "categoryONECN")
  197. params.setValue(shopOpen.typeName2, forKey: "categoryTWOCN")
  198. params.setValue(shopOpen.licenseImage, forKey: "licenseImage")
  199. params.setValue(shopOpen.licenseNum, forKey: "licenseNum")
  200. params.setValue(shopOpen.bankAccountType, forKey: "bankAccountType")
  201. params.setValue(shopOpen.openingPermitImage, forKey: "openingPermitImage")
  202. params.setValue(shopOpen.reservePhone, forKey: "reservePhone")
  203. params.setValue(shopOpen.bankName, forKey: "bankAffiliatedBankCN")
  204. params.setValue(shopOpen.bankAffiliatedBank, forKey: "bankAffiliatedBank")
  205. params.setValue(shopOpen.applicantCardFrontLocal, forKey: "applicantCardFrontLocal")
  206. params.setValue(shopOpen.applicantCardReverseLocal, forKey: "applicantCardReverseLocal")
  207. params.setValue(shopOpen.applicantCardHoldFrontLocal, forKey: "applicantCardHoldFrontLocal")
  208. params.setValue(shopOpen.bankCardImgLocal, forKey: "bankCardImgLocal")
  209. params.setValue(shopOpen.bankAffiliatedBranchBankCN, forKey: "bankAffiliatedBranchBankCN")
  210. params.setValue(shopOpen.dpImages, forKey: "shopPhoto")
  211. params.setValue(shopOpen.shhyzImages, forKey: "shopUserPhoto")
  212. params.setValue(shopOpen.productTypeId, forKey: "productTypeId")
  213. params.setValue(shopOpen.rate, forKey: "rate")
  214. params.setValue(shopOpen.debitCardCostRate, forKey: "debitCardCostRate")
  215. params.setValue(shopOpen.debitCardCapping, forKey: "debitCardCapping")
  216. params.setValue(shopOpen.unionpayRate, forKey: "unionpayRate")
  217. params.setValue(shopOpen.loanCardCapping, forKey: "loanCardCapping")
  218. params.setValue(shopOpen.pmmerId, forKey: "pmmerId")
  219. submitData(url: url, params: params, tag: 1004)
  220. }
  221. override func returnData(tag: Int) {
  222. if tag == 1001 {
  223. let dichaike = dicBackData["haike"] as? NSDictionary
  224. if dichaike != nil {
  225. let dicMessage = dichaike!["message"] as? NSDictionary
  226. if dicMessage != nil {
  227. if dicMessage!.getString(key: "code") == "success" {
  228. let dicResult = dichaike!["result"] as? NSDictionary
  229. if dicResult != nil {
  230. self.shopOpen.pmmerId = dicResult!.getString(key: "pmmerId")
  231. }
  232. self.shopOpen.bankOpenName = txtKHM.text!
  233. self.shopOpen.bankName = txtBankName.text!
  234. self.shopOpen.bankCardNo = txtBankCard.text!
  235. self.shopOpen.reservePhone = txtBankPhone.text!
  236. self.shopOpen.bankAccountType = "0"
  237. submitData()
  238. } else {
  239. SVProgressHUD.showError(withStatus: dicMessage!.getString(key: "content"))
  240. }
  241. } else {
  242. SVProgressHUD.showError(withStatus: "提交海科失败,请稍后重试!")
  243. }
  244. } else {
  245. SVProgressHUD.showError(withStatus: "提交海科失败,请稍后重试!")
  246. }
  247. } else if(tag == 1002) //初始化加载默认费率
  248. {
  249. shopOpen.rate = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default"))
  250. shopOpen.debitCardCostRate = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_cost_rate"))
  251. shopOpen.debitCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_capping"))
  252. shopOpen.unionpayRate = String.init(format: "%.2f", dicFL.getDouble(key: "unionpay_rate"))
  253. shopOpen.loanCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_capping"))
  254. txtFL.text = "\(String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default")))%"
  255. } else if(tag == 1003) //加载费率选择框
  256. {
  257. shopOpen.rate = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default"))
  258. shopOpen.debitCardCostRate = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_cost_rate"))
  259. shopOpen.debitCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_capping"))
  260. shopOpen.unionpayRate = String.init(format: "%.2f", dicFL.getDouble(key: "unionpay_rate"))
  261. shopOpen.loanCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_capping"))
  262. var rateMin = dicFL.getDouble(key: "loan_card_rate_min") * 100
  263. let rateMax = dicFL.getDouble(key: "loan_card_rate_max") * 100
  264. arrRateContent.removeAll()
  265. var arrTitle = [String]()
  266. while Int(rateMin) <= Int(rateMax) {
  267. arrTitle.append("\(String.init(format: "%.2f", rateMin / 100))%")
  268. arrRateContent.append(String.init(format: "%.2f", rateMin / 100))
  269. rateMin += 1
  270. }
  271. CommonUntils.AlertView(controller: self, title: nil, message: "请选择费率", buttons: arrTitle, style: .actionSheet) {[weak self] (index, _) in
  272. self!.txtFL.text = "\(self!.arrRateContent[index])%"
  273. self!.shopOpen.rate = self!.arrRateContent[index]
  274. }
  275. } else if tag == 1004 {
  276. SVProgressHUD.showSuccess(withStatus: "提交成功!")
  277. if !CommonUntils.reBackView(controller: self, aclass: ShopManagerViewController.classForCoder()) {
  278. self.navigationController?.popToRootViewController(animated: true)
  279. }
  280. }
  281. }
  282. var arrRateContent = [String]()
  283. override func returnError(tag: Int, type: String) {
  284. }
  285. // MARK: ============选择头像============
  286. var uploadImageType = 0
  287. func uploadImage(type: Int) {
  288. uploadImageType = type
  289. CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
  290. let ipc = UIImagePickerController()
  291. if index == 0 {
  292. ipc.sourceType = .camera
  293. } else {
  294. ipc.sourceType = .photoLibrary
  295. }
  296. ipc.delegate = self!
  297. ipc.allowsEditing = false
  298. self!.present(ipc, animated: true, completion: nil)
  299. }
  300. }
  301. var imgTemp: UIImage!
  302. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
  303. self.dismiss(animated: true) {[weak self] in
  304. var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
  305. if picker.allowsEditing {
  306. imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
  307. }
  308. if imgTemp != nil {
  309. self!.UploadFile(img: imgTemp!)
  310. } else {
  311. SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
  312. }
  313. }
  314. }
  315. func UploadFile(img: UIImage) {
  316. MBProgressHUD.showAdded(to: self.view, animated: true)
  317. let uploadFile = QiNiuUploadFile()
  318. uploadFile.uploadFile(img: img) {[weak self] (type, _) in
  319. if type == 1 {
  320. self!.uploadWeb(img: img)
  321. } else {
  322. MBProgressHUD.hide(for: self!.view, animated: true)
  323. SVProgressHUD.showError(withStatus: "上传失败")
  324. }
  325. }
  326. }
  327. var imgLocalPath = ""
  328. func uploadWeb(img: UIImage) {
  329. let manage = AFHTTPSessionManager()
  330. let param = NSMutableDictionary()
  331. param.setValue(8, forKey: "type")
  332. manage.requestSerializer.timeoutInterval = 60.0
  333. manage.post(RequestURL.uploadMerchantFile, parameters: param, constructingBodyWith: { (formDate) in
  334. formDate.appendPart(withFileData: img.jpegData(compressionQuality: 0.4)!, name: "fileInput", fileName: "fileInput", mimeType: "multipart/form-data")
  335. }, progress: nil, success: {[weak self] (op, json1) in
  336. let json = json1 as! NSDictionary
  337. print(json)
  338. let succeed = json.object(forKey: "succeed") as! String
  339. if succeed == "000" {
  340. let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
  341. if status == 200 {
  342. self!.imgLocalPath = (json["dataInfo"] as! NSDictionary).getString(key: "url")
  343. let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
  344. let hkResult = haike["result"] as! NSDictionary
  345. let hkResultData = hkResult["data"] as! NSDictionary
  346. self!.txtBankName.text = hkResultData.getString(key: "bankName")
  347. self!.txtBankCard.text = hkResultData.getString(key: "cardNumber")
  348. } else {
  349. SVProgressHUD.showError(withStatus: "银行卡识别失败,请重新上传或手动输入银行卡号!")
  350. }
  351. } else {
  352. SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
  353. }
  354. MBProgressHUD.hide(for: self!.view, animated: true)
  355. }) { (_, _) in
  356. SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
  357. MBProgressHUD.hide(for: self.view, animated: true)
  358. }
  359. }
  360. override func viewWillAppear(_ animated: Bool) {
  361. super.viewWillAppear(animated)
  362. if shopOpen.rate == "" {
  363. getFeiLv(isDefault: true)
  364. } else {
  365. txtFL.text = "\(shopOpen.rate)%"
  366. }
  367. txtType.text = shopOpen.typeName1
  368. if mainViewControllerIsGo {
  369. if mainViewControllerIsGoType == 0 {
  370. shopOpen.bankAffiliatedBranchBankCN = mainViewControllerIsGoValue
  371. shopOpen.bankAffiliatedBranchBank = mainViewControllerIsGoValue1
  372. shopOpen.bankAffiliatedBank = mainViewControllerIsGoValue2
  373. txtBankChild.text = mainViewControllerIsGoValue
  374. }
  375. }
  376. mainViewControllerIsGo = false
  377. }
  378. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  379. super.init(nibName: "PersonalBindCardViewController", bundle: nil)
  380. }
  381. required init?(coder aDecoder: NSCoder) {
  382. fatalError("init(coder:) has not been implemented")
  383. }
  384. }