OutMoneyViewController.swift 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. //
  2. // OutMoneyViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by zhongyuan on 2018/3/20.
  6. // Copyright © 2018年 zhongyuan.All rights reserved.
  7. //
  8. import UIKit
  9. import NVActivityIndicatorView
  10. class OutMoneyViewController: BaseViewController {
  11. /// 出金金额
  12. @IBOutlet weak var outMoneyAmountTextField: IBTextField!
  13. /// 可取资金
  14. @IBOutlet weak var canUseMoneyTextField: IBTextField!
  15. /// 资金账户
  16. @IBOutlet weak var moneyAccountTextField: IBTextField!
  17. /// 资金密码
  18. @IBOutlet weak var moneyPasswordTextField: IBTextField!
  19. /// 出金手续费
  20. @IBOutlet weak var outMoneyChargeTextField: IBTextField!
  21. /// 账户名称
  22. @IBOutlet weak var accountNameTextField: IBTextField!
  23. /// 签约银行
  24. @IBOutlet weak var signingBankTextField: IBTextField!
  25. /// 开户银行
  26. @IBOutlet weak var registerBankTextField: IBTextField!
  27. /// 银行账户
  28. @IBOutlet weak var bankAccountTextField: IBTextField!
  29. /// 手机号码
  30. @IBOutlet weak var phoneNumberTextField: IBTextField!
  31. /// 备注
  32. @IBOutlet weak var remarkTextField: IBTextField!
  33. /// 银行出金提示
  34. @IBOutlet weak var bankOutMoneyTipMessage: UILabel!
  35. /// 提交按钮
  36. @IBOutlet weak var submitButton: UIButton!
  37. //MARK: 扩展信息
  38. @IBOutlet weak var splitView: UIView!
  39. /// 开户省份
  40. @IBOutlet weak var regiesterProvinceTextField: IBTextField!
  41. /// 开户城市
  42. @IBOutlet weak var regiesterCityTextField: IBTextField!
  43. /// 开户行支行号
  44. @IBOutlet weak var regiesterBranchBankNumberTextField: IBTextField!
  45. /// 开户行支行名称
  46. @IBOutlet weak var regiesterBranchBankNameTextField: IBTextField!
  47. /// 银行密码
  48. @IBOutlet weak var bankPasswordTextField: IBTextField!
  49. /// 原手机号码
  50. @IBOutlet weak var oldPhoneNumberTextField: IBTextField!
  51. /// 验证码
  52. @IBOutlet weak var checkCodeTextField: IBTextField!
  53. /// 男性
  54. @IBOutlet weak var checkMenButton: UIButton!
  55. /// 女性
  56. @IBOutlet weak var checkWomenButton: UIButton!
  57. /// 法人姓名
  58. @IBOutlet weak var legalPersonNameTextField: IBTextField!
  59. /// 法人证件类型
  60. @IBOutlet weak var legalPersonalIDcardTypeTextField: IBTextField!
  61. /// 法人证件号码
  62. @IBOutlet weak var legalPersonalIDcardNumberField: IBTextField!
  63. /// 经办人姓名
  64. @IBOutlet weak var agentNameTextField: IBTextField!
  65. /// 经办人证件类型
  66. @IBOutlet weak var agentIDcardTypeTextField: IBTextField!
  67. /// 经办人证件号码
  68. @IBOutlet weak var agentIDcardNumberTextField: IBTextField!
  69. /// 所属会员代码
  70. @IBOutlet weak var itsMemberCodeTextField: IBTextField!
  71. /// 法人联系号码
  72. @IBOutlet weak var legalContactNumberTextField: IBTextField!
  73. /// 经办人联系号码
  74. @IBOutlet weak var agentContactNumberTextField: IBTextField!
  75. /// 临时变量,当前资金账号
  76. private var currentMoneyAccount: String?
  77. /// 临时变量,当前签约银行
  78. private var currentBankSign: MoBankAccountSign?
  79. /// 托管银行手续费配置表
  80. private var currentCusBankCharge: MoCusBankCharge?
  81. var currentProvinceID: String?
  82. var currentCityID: String?
  83. /// 当前页面索引
  84. var pageIndex: Int?
  85. struct TAG {
  86. static let moneyAccount = 100
  87. static let regiesterProvince = 200
  88. static let regiesterCity = 300
  89. static let legalPersonalIDcardType = 400
  90. static let agentIDcardType = 500
  91. static let men = 600
  92. static let women = 700
  93. static let signingBank = 800
  94. }
  95. override func viewDidLoad() {
  96. super.viewDidLoad()
  97. addLoadingView()
  98. initData()
  99. }
  100. // MARK: - 初始化相关
  101. func initData() {
  102. /// 数据异常
  103. guard let accountManager = MTP2BusinessCore.shared.accountManager else {
  104. return
  105. }
  106. if let accountId = accountManager.getTaAccountInfoList()?.first?.accountId {
  107. moneyAccountTextField.text = String(accountId)
  108. currentMoneyAccount = String(accountId)
  109. queryBankSign(accountID: String(accountId))
  110. queryCanUseMoney(accountID: String(accountId))
  111. }
  112. accountNameTextField.text = accountManager.moAccountBaseInfo?.accountInfo.customerName
  113. outMoneyAmountTextField.addTarget(self, action: #selector(calCusBankCharge), for: .editingChanged)
  114. if let configInfo = accountManager.configInfo,
  115. let signTime = configInfo["012"]?.paramValue,
  116. let outTime = configInfo["013"]?.paramValue {
  117. bankOutMoneyTipMessage.text = "银行出金时间段:\(signTime) - \(outTime)"
  118. } else {
  119. bankOutMoneyTipMessage.isHidden = true
  120. }
  121. }
  122. // MARK: - 交互相关
  123. @IBAction func selectSex(_ sender: UIButton) {
  124. if sender.currentTitle == "男" && !sender.isSelected{
  125. sender.isSelected = true
  126. checkWomenButton.isSelected = false
  127. }
  128. if sender.currentTitle == "女" && !sender.isSelected{
  129. sender.isSelected = true
  130. checkMenButton.isSelected = false
  131. }
  132. }
  133. /// 忘记密码
  134. @IBAction func forgetPassword(_ sender: UIButton) {
  135. /// 资金密码修改
  136. let fund = UIStoryboard(name: "Settings", bundle: nil).instantiateViewController(withIdentifier: "FundPasswordUpdate")
  137. self.view.superController()?.navigationController?.pushViewController(fund, animated: true)
  138. }
  139. /// 出金提交
  140. @IBAction func onclickSubmitButton(_ sender: UIButton) {
  141. if !TradeControlUtils.checkAuthState(navigationController: self.navigationController) {
  142. return
  143. }
  144. if !checkValue() { return }
  145. guard let bankManager = MTP2BusinessCore.shared.bankManager,
  146. let accountManager = MTP2BusinessCore.shared.accountManager,
  147. let currentBankSign = currentBankSign else { return }
  148. let outMoneyParam = MoOutMoneyParam()
  149. outMoneyParam.extOperatorID = Int(Date().timeIntervalSince1970)
  150. outMoneyParam.accountCode = currentMoneyAccount!
  151. outMoneyParam.cusBankID = currentBankSign.cusBankID
  152. outMoneyParam.currency = currentBankSign.currency
  153. if let userType = accountManager.moAccountBaseInfo?.accountInfo.userType {
  154. outMoneyParam.accountType = userType
  155. }
  156. outMoneyParam.bankAccoutName = currentBankSign.bankAccountName
  157. outMoneyParam.remark = remarkTextField.text!
  158. if (currentBankSign.bankAccountNo.contains(";")) {
  159. let array = currentBankSign.bankAccountNo.components(separatedBy: ";")
  160. outMoneyParam.bankAccoutNum = array[1]
  161. } else {
  162. outMoneyParam.bankAccoutNum = currentBankSign.bankAccountNo
  163. }
  164. outMoneyParam.appDateTime = currentBankSign.cusBankTradeDate
  165. outMoneyParam.amount = Double(outMoneyAmountTextField.text!)!
  166. outMoneyParam.oldTaPWD = (moneyPasswordTextField.text?.bytes.sha256().toHexString().lowercased())!
  167. outMoneyParam.identifyCode = checkCodeTextField.text!
  168. outMoneyParam.extend_info = getJSONExtendInfo()
  169. // 开启Loading
  170. NVActivityIndicatorPresenter.sharedInstance.startAnimating(ActivityData(message: "正在出金...", color: UIColor.loding()), NVActivityIndicatorView.DEFAULT_FADE_IN_ANIMATION)
  171. bankManager.outMoney(param: outMoneyParam) { (isSuccess, errorInfo, results) in
  172. DispatchQueue.main.async {
  173. NVActivityIndicatorPresenter.sharedInstance.stopAnimating(NVActivityIndicatorView.DEFAULT_FADE_OUT_ANIMATION)
  174. if isSuccess {
  175. self.showHintController(title: "提示", message: "出金成功",handler: { (_) in
  176. /// 重新请求可出资金
  177. MTP2BusinessCore.shared.broadcastManager?.post(action: .FundationInfoReloadData, object: nil)
  178. /// 更新可出资金
  179. self.queryCanUseMoney(accountID: self.currentMoneyAccount!)
  180. /// 清空数据
  181. self.clearData()
  182. })
  183. } else {
  184. if let results = results {
  185. if results.netAddr == "" {
  186. /// 不需要跳转网页
  187. let decp = results.centerErrMsg
  188. var error = ErrorUtils.getDesc(errorCode: results.status) ?? "未知错误类型"
  189. if decp != "" {
  190. error = "银行信息返回" + ":" + decp
  191. self.showHintController(title: "提示", message: error)
  192. } else {
  193. self.showHintController(title: "提示", message: error)
  194. }
  195. } else {
  196. /// 需要跳转网页
  197. if let url = URL(string: results.netAddr) {
  198. /// 根据iOS系统版本,分别处理
  199. UIApplication.shared.open(url)
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. /// 组装扩展信息
  208. ///
  209. /// - Returns: json串
  210. func getJSONExtendInfo() -> String {
  211. var dict: [String: Any] = [:]
  212. dict["verify_code"] = checkCodeTextField.text
  213. dict["bank_password"] = bankPasswordTextField.text
  214. dict["sex"] = getSex()
  215. dict["legal_name"] = legalPersonNameTextField.text
  216. dict["legal_cert_type"] = legalPersonalIDcardTypeTextField.text
  217. dict["legal_cert_code"] = legalPersonalIDcardNumberField.text
  218. dict["agent_name"] = agentNameTextField.text
  219. dict["agent_cert_type"] = agentIDcardTypeTextField.text
  220. dict["agent_cert_code"] = agentIDcardNumberTextField.text
  221. dict["org_mobile"] = oldPhoneNumberTextField.text
  222. dict["member_code"] = itsMemberCodeTextField.text
  223. dict["legal_contact"] = legalContactNumberTextField.text
  224. dict["agent_contact"] = agentContactNumberTextField.text
  225. dict["bank_branch_name"] = regiesterBranchBankNameTextField.text
  226. //json 的可用性判断
  227. if !JSONSerialization.isValidJSONObject(dict) {
  228. dPrint("不能转化")
  229. return ""
  230. }
  231. //json 字符串转换为data
  232. guard let data = try? JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted) else { return "" }
  233. //data 转为字符串
  234. let jsonstr = String(data: data, encoding: .utf8)
  235. return jsonstr!
  236. }
  237. /// 获取选择的性别
  238. ///
  239. /// - Returns: 男女
  240. func getSex() -> Int {
  241. if checkMenButton.isSelected {
  242. return ESex.SEX_MALE.rawValue
  243. }
  244. return ESex.SEX_FEMALE.rawValue
  245. }
  246. /// 清空列表数据
  247. func clearData() {
  248. outMoneyAmountTextField.text = ""
  249. moneyPasswordTextField.text = ""
  250. bankPasswordTextField.text = ""
  251. checkCodeTextField.text = ""
  252. remarkTextField.text = ""
  253. }
  254. /// 校验数据
  255. func checkValue() -> Bool {
  256. /// 出金金额
  257. if let outMoneyAmount = self.outMoneyAmountTextField.text {
  258. if outMoneyAmount.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  259. self.showHintController(title: "提示", message: "请输入出金金额", handler: nil)
  260. return false
  261. }
  262. if let outMoneyAmount = Double(outMoneyAmount), let canUserMoney = Double(canUseMoneyTextField.text!) {
  263. if outMoneyAmount > canUserMoney {
  264. self.showHintController(title: "提示", message: "出金金额不得大于可取资金", handler: nil)
  265. return false
  266. }
  267. } else {
  268. self.showHintController(title: "提示", message: "出金金额格式不正确")
  269. return false
  270. }
  271. }
  272. /// 资金密码
  273. if let moneyPassword = self.moneyPasswordTextField.text {
  274. if moneyPassword.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  275. self.showHintController(title: "提示", message: "请输入资金密码", handler: nil)
  276. return false
  277. }
  278. }
  279. /// 开户省份
  280. if (regiesterProvinceTextField.superview?.isHidden)! == false {
  281. if let regiesterProvince = self.regiesterProvinceTextField.text {
  282. if regiesterProvince.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  283. self.showHintController(title: "提示", message: "请选择开户省份")
  284. return false
  285. }
  286. }
  287. }
  288. /// 开户城市
  289. if (regiesterCityTextField.superview?.isHidden)! == false {
  290. if let regiesterCity = self.regiesterCityTextField.text {
  291. if regiesterCity.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  292. self.showHintController(title: "提示", message: "请选择开户城市")
  293. return false
  294. }
  295. }
  296. }
  297. /// 开户行支行号
  298. if (regiesterBranchBankNumberTextField.superview?.isHidden)! == false {
  299. if let regiesterBranchBankNumber = self.regiesterBranchBankNumberTextField.text {
  300. if regiesterBranchBankNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  301. self.showHintController(title: "提示", message: "请输入开户行支行号")
  302. return false
  303. }
  304. }
  305. }
  306. /// 开户行支行名称
  307. if (regiesterBranchBankNameTextField.superview?.isHidden)! == false {
  308. if let regiesterBranchBankName = self.regiesterBranchBankNameTextField.text {
  309. if regiesterBranchBankName.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  310. self.showHintController(title: "提示", message: "请输入开户行支行名称")
  311. return false
  312. }
  313. }
  314. }
  315. /// 银行密码
  316. if (bankPasswordTextField.superview?.isHidden)! == false {
  317. if let bankPassword = self.bankPasswordTextField.text {
  318. if bankPassword.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  319. self.showHintController(title: "提示", message: "请输入银行密码")
  320. return false
  321. }
  322. }
  323. }
  324. /// 原手机号码
  325. if (oldPhoneNumberTextField.superview?.isHidden)! == false {
  326. if let oldPhoneNumber = self.oldPhoneNumberTextField.text {
  327. if oldPhoneNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  328. self.showHintController(title: "提示", message: "请输入原手机号码")
  329. return false
  330. }
  331. }
  332. }
  333. /// 验证码
  334. if (checkCodeTextField.superview?.superview?.isHidden)! == false {
  335. if let checkCode = self.checkCodeTextField.text {
  336. if checkCode.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  337. self.showHintController(title: "提示", message: "请输入验证码")
  338. return false
  339. }
  340. }
  341. }
  342. /// 男性
  343. if (checkMenButton.superview?.superview?.isHidden)! == false {
  344. if !self.checkMenButton.isSelected && !self.checkWomenButton.isSelected{
  345. self.showHintController(title: "提示", message: "请选择性别")
  346. return false
  347. }
  348. }
  349. /// 法人姓名
  350. if (legalPersonNameTextField.superview?.isHidden)! == false {
  351. if let legalPersonName = self.legalPersonNameTextField.text {
  352. if legalPersonName.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  353. self.showHintController(title: "提示", message: "请输入法人姓名")
  354. return false
  355. }
  356. }
  357. }
  358. /// 法人证件类型
  359. if (legalPersonalIDcardTypeTextField.superview?.isHidden)! == false {
  360. if let legalPersonalIDcardType = self.legalPersonalIDcardTypeTextField.text {
  361. if legalPersonalIDcardType.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  362. self.showHintController(title: "提示", message: "请选择法人证件类型")
  363. return false
  364. }
  365. }
  366. }
  367. /// 法人证件号码
  368. if (legalPersonalIDcardNumberField.superview?.isHidden)! == false {
  369. if let legalPersonalIDcardNumber = self.legalPersonalIDcardNumberField.text {
  370. if legalPersonalIDcardNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  371. self.showHintController(title: "提示", message: "请输入法人证件号码")
  372. return false
  373. }
  374. }
  375. }
  376. /// 经办人姓名
  377. if (agentNameTextField.superview?.isHidden)! == false {
  378. if let agentName = self.agentNameTextField.text {
  379. if agentName.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  380. self.showHintController(title: "提示", message: "请输入经办人姓名")
  381. return false
  382. }
  383. }
  384. }
  385. /// 经办人证件类型
  386. if (agentIDcardTypeTextField.superview?.isHidden)! == false {
  387. if let agentIDcardType = self.agentIDcardTypeTextField.text {
  388. if agentIDcardType.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  389. self.showHintController(title: "提示", message: "请选择经办人证件类型")
  390. return false
  391. }
  392. }
  393. }
  394. /// 经办人证件号码
  395. if (agentIDcardNumberTextField.superview?.isHidden)! == false {
  396. if let agentIDcardNumber = self.agentIDcardNumberTextField.text {
  397. if agentIDcardNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  398. self.showHintController(title: "提示", message: "请输入经办人证件号码")
  399. return false
  400. }
  401. }
  402. }
  403. /// 所属会员代码
  404. if (itsMemberCodeTextField.superview?.isHidden)! == false {
  405. if let itsMemberCode = self.itsMemberCodeTextField.text {
  406. if itsMemberCode.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  407. self.showHintController(title: "提示", message: "请输入所属会员代码")
  408. return false
  409. }
  410. }
  411. }
  412. /// 法人联系号码
  413. if (legalContactNumberTextField.superview?.isHidden)! == false {
  414. if let legalContactNumber = self.legalContactNumberTextField.text {
  415. if legalContactNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  416. self.showHintController(title: "提示", message: "请输入法人联系号码")
  417. return false
  418. }
  419. }
  420. }
  421. /// 经办人联系号码
  422. if (agentContactNumberTextField.superview?.isHidden)! == false {
  423. if let agentContactNumber = self.agentContactNumberTextField.text {
  424. if agentContactNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  425. self.showHintController(title: "提示", message: "请输入经办人联系号码")
  426. return false
  427. }
  428. }
  429. }
  430. return true
  431. }
  432. }
  433. // MARK: - UITextFieldDelegate
  434. extension OutMoneyViewController: UITextFieldDelegate {
  435. func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  436. textField.resignFirstResponder()
  437. return true
  438. }
  439. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  440. switch textField.tag {
  441. case TAG.moneyAccount:
  442. guard let accountManager = MTP2BusinessCore.shared.accountManager else { return true }
  443. let titleArray = accountManager.getTaAccountInfoList()?.compactMap({ return String($0.accountId) }) ?? []
  444. if titleArray.count > 0 {
  445. self.showPopupsController(title: "选择资金账户", message: nil, titleArray: titleArray) { (value: String, selectedRow: Int, _) in
  446. if self.currentMoneyAccount != value {
  447. self.currentMoneyAccount = value
  448. self.moneyAccountTextField.text = value
  449. self.queryBankSign(accountID: value)
  450. self.queryCanUseMoney(accountID: value)
  451. }
  452. }
  453. } else {
  454. self.showHintController(title: "提示", message: "没有可选的资金账户")
  455. }
  456. return false
  457. case TAG.signingBank:
  458. guard let bankManager = MTP2BusinessCore.shared.bankManager else { return true }
  459. var titleArray = [String]()
  460. if let bankSign = bankManager.moBankSign {
  461. titleArray = bankSign.bankSign.map({ (model) -> String in
  462. return String(model.cusBankName)
  463. })
  464. }
  465. if titleArray.count > 0 {
  466. self.showPopupsController(title: "选择签约银行", message: nil, titleArray: titleArray) { (value: String, selectedRow: Int, _) in
  467. if self.currentBankSign?.cusBankName != value {
  468. self.signingBankTextField.text = value
  469. self.setupSignBank(bankSign: bankManager.moBankSign?.bankSign[selectedRow])
  470. }
  471. }
  472. } else {
  473. self.showHintController(title: "提示", message: "没有可选的签约银行")
  474. }
  475. return false
  476. case TAG.regiesterProvince:
  477. guard let bankManager = MTP2BusinessCore.shared.bankManager else{ return true }
  478. let completeBlock = { (results: [MoBankProvince]?) in
  479. let titleArray = results?.map({ (model) -> String in
  480. return model.bankprovincename
  481. })
  482. self.showPopupsController(title: "选择省份", message: nil, titleArray: titleArray!, clickBlock: { (value, rowNum, _) in
  483. self.regiesterProvinceTextField.text = value
  484. if self.currentProvinceID != results?[rowNum].bankprovinceid {
  485. self.currentProvinceID = results?[rowNum].bankprovinceid
  486. bankManager.queryBankCity(provinceID: self.currentProvinceID!, callback: { (isSuccess, errorInfo, results) in
  487. if isSuccess {
  488. } else {
  489. self.showErrorMessgae(error: errorInfo)
  490. }
  491. })
  492. }
  493. })
  494. }
  495. if let moBankProvice = bankManager.moBankProvice {
  496. completeBlock(moBankProvice)
  497. } else {
  498. _anim?.startAnimating()
  499. bankManager.queryBankProvince { (isSuccess, errorInfo, results) in
  500. DispatchQueue.main.async {
  501. self._anim?.stopAnimating()
  502. if isSuccess {
  503. completeBlock(results)
  504. } else {
  505. self.showErrorMessgae(error: errorInfo)
  506. }
  507. }
  508. }
  509. }
  510. return false
  511. case TAG.regiesterCity:
  512. guard let bankManager = MTP2BusinessCore.shared.bankManager else{ return true }
  513. if let moBankCity = bankManager.moBankCity {
  514. let titleArray = moBankCity.map({ (model) -> String in
  515. return model.bankcityname
  516. })
  517. self.showPopupsController(title: "选择市", message: nil, titleArray: titleArray, clickBlock: { (value, rowNum, _) in
  518. self.regiesterCityTextField.text = value
  519. self.currentCityID = moBankCity[rowNum].bankcityid
  520. })
  521. }
  522. return false
  523. case TAG.legalPersonalIDcardType:
  524. var titleArray = [String]()
  525. for i in 0...22 {
  526. titleArray.append(ECardTypeStringValue(CardType(rawValue: i)))
  527. }
  528. self.showPopupsController(title: "选择法人证件类型", message: nil, titleArray: titleArray, clickBlock: { (value, _ , _) in
  529. self.legalPersonalIDcardTypeTextField.text = value
  530. })
  531. return false
  532. case TAG.agentIDcardType:
  533. var titleArray = [String]()
  534. for i in 0...22 {
  535. titleArray.append(ECardTypeStringValue(CardType(rawValue: i)))
  536. }
  537. self.showPopupsController(title: "选择经办人证件类型", message: nil, titleArray: titleArray, clickBlock: { (value, _ , _) in
  538. self.agentIDcardTypeTextField.text = value
  539. })
  540. return false
  541. default:
  542. break
  543. }
  544. return true
  545. }
  546. /// 查询可取资金
  547. func queryCanUseMoney(accountID: String) {
  548. guard let bankManager = MTP2BusinessCore.shared.bankManager, let accountId = UInt64(accountID) else { return }
  549. _anim?.startAnimating()
  550. bankManager.accountFundInfo(accountID: accountId, queryBitMask: 3) { (isSuccess, errorInfo, results) in
  551. DispatchQueue.main.async {
  552. self._anim?.stopAnimating()
  553. if isSuccess {
  554. guard let results = results else{ return }
  555. self.canUseMoneyTextField.text = String(results.availableOutMoney)
  556. }else {
  557. /// 查询失败
  558. }
  559. }
  560. }
  561. }
  562. /// 查询已签约信息
  563. func queryBankSign(accountID: String) {
  564. guard let bankManager = MTP2BusinessCore.shared.bankManager, let accountId = UInt64(accountID) else { return }
  565. _anim?.startAnimating()
  566. bankManager.bankSign(accountId: accountId, cusbankId: "") {(isSuccess, errorInfo, results) in
  567. DispatchQueue.main.async {
  568. self._anim?.stopAnimating()
  569. if isSuccess {
  570. self.setupSignBank(bankSign: results?.bankSign.first)
  571. }else {
  572. /// 查询失败
  573. }
  574. }
  575. }
  576. }
  577. /// 查询扩展信息
  578. func queryExpandInfo(cusBankId: String) {
  579. guard let bankManager = MTP2BusinessCore.shared.bankManager else { return }
  580. _anim?.startAnimating()
  581. bankManager.queryBankExtendInfo(cusBankId: cusBankId, type: 2) { (isSuccess, errorInfo, results) in
  582. DispatchQueue.main.async {
  583. self._anim?.stopAnimating()
  584. if isSuccess {
  585. if let results = results, results.count > 0 {
  586. results.forEach({ (model) in
  587. if let tag = Int(model.fieldid), let view = self.view.viewWithTag(tag) {
  588. view.isHidden = false
  589. }
  590. })
  591. self.splitView.isHidden = false
  592. } else {
  593. self.splitView.isHidden = true
  594. }
  595. } else {
  596. self.showErrorMessgae(error: errorInfo)
  597. }
  598. }
  599. }
  600. }
  601. /// 选择了签约银行要做的事情
  602. func setupSignBank(bankSign: MoBankAccountSign?) {
  603. guard let bankManager = MTP2BusinessCore.shared.bankManager,
  604. let accountManager = MTP2BusinessCore.shared.accountManager,
  605. let accountInfo = accountManager.moAccountBaseInfo?.accountInfo else { return }
  606. if let model = bankSign {
  607. signingBankTextField.text = model.cusBankName
  608. registerBankTextField.text = model.bankName
  609. currentBankSign = model
  610. /// 若是加密字符串需要取分号前面的字符
  611. if model.bankAccountNo.contains(";") {
  612. let index = model.bankAccountNo.firstIndex(of: ";")
  613. let bankAccountNo = model.bankAccountNo.prefix(upTo: index!)
  614. bankAccountTextField.text = bankAccountNo.description
  615. }else {
  616. bankAccountTextField.text = model.bankAccountNo
  617. }
  618. phoneNumberTextField.text = model.mobilePhoneDisp
  619. queryExpandInfo(cusBankId: model.cusBankID)
  620. if let cusbankParam = bankManager.cusbankInfos?.first(where: { $0.cusbankid == model.cusBankID }) {
  621. if cusbankParam.canoutamount != 1 {
  622. submitButton.isHidden = true
  623. }
  624. }
  625. let userType = accountInfo.userInfoType == 1 ? EBank_BankAccountType.BANK_BANKACCOUNTTYPE_PRIVATE.rawValue : EBank_BankAccountType.BANK_BANKACCOUNTTYPE_PUBLIC.rawValue
  626. _anim?.startAnimating()
  627. // 查询
  628. bankManager.queryQueryBank_CusBankCharge(cusBankID: model.cusBankID, outOrIn: 1, userType: userType) { (isSuccess, errorInfo, results) in
  629. DispatchQueue.main.async {
  630. self._anim?.stopAnimating()
  631. if isSuccess {
  632. if let currentCusBankCharge = results?.first {
  633. self.currentCusBankCharge = currentCusBankCharge
  634. self.calCusBankCharge()
  635. }
  636. } else {
  637. self.showErrorMessgae(error: errorInfo)
  638. }
  639. }
  640. }
  641. }
  642. }
  643. /// 计算出金手续费
  644. /**
  645. 统一:
  646. 1.比例:1.手续费=出入金金额*收费值 2.手续费<单笔最小,手续费=单笔最小,3.手续费>单笔最大,手续费=单笔最大
  647. 2.固定:1.手续费=收费值
  648. 区间:
  649. 1.比例:ps:首先判断出入金金额在哪个区间范围内,取区间内收费值计算,若无则不收取服务费。 1.手续费=出入金金额*收费值 2.手续费<单笔最小,手续费=单笔最小,3.手续费>单笔最大,手续费=单笔最大
  650. 2.固定:ps:首先判断出入金金额在哪个区间范围内,取区间内收费值值计算,若无则不收取服务费。 1.手续费=收费值
  651. */
  652. @objc func calCusBankCharge() {
  653. // 没有就不用算了
  654. guard let cusBankCharge = currentCusBankCharge else { return }
  655. // 入金金额
  656. let outMoney = Double(outMoneyAmountTextField.text!) ?? 0.0
  657. var tempCharge = 0.0
  658. if cusBankCharge.ChargeType == 1 { // 手续费收取类型 - 1:统一 2:区间
  659. if cusBankCharge.ChargeAlgorithm == 1 { // 手续费收取方式 - 1:比率 2:固定 [统一 ]
  660. tempCharge = cusBankCharge.ChargeValue * outMoney
  661. if tempCharge > cusBankCharge.SingleMax {
  662. tempCharge = cusBankCharge.SingleMax
  663. } else if tempCharge < cusBankCharge.SingleMin {
  664. tempCharge = cusBankCharge.SingleMin
  665. }
  666. } else if cusBankCharge.ChargeAlgorithm == 2 {
  667. tempCharge = outMoney > 0 ? cusBankCharge.ChargeValue : 0.0
  668. }
  669. } else if cusBankCharge.ChargeType == 2 {
  670. if let moCusBankChargeDetails = cusBankCharge.CusBankChargeDetail.first(where: { $0.RangeMax >= outMoney && $0.RangeMin <= outMoney }) {
  671. if moCusBankChargeDetails.ChargeAlgorithm == 1 { // 手续费收取方式 - 1:比率 2:固定 [统一 ]
  672. tempCharge = moCusBankChargeDetails.ChargeValue * outMoney
  673. if tempCharge > cusBankCharge.SingleMax {
  674. tempCharge = cusBankCharge.SingleMax
  675. } else if tempCharge < cusBankCharge.SingleMin {
  676. tempCharge = cusBankCharge.SingleMin
  677. }
  678. } else if moCusBankChargeDetails.ChargeAlgorithm == 2 {
  679. tempCharge = outMoney > 0 ? cusBankCharge.ChargeValue : 0.0
  680. }
  681. }
  682. }
  683. outMoneyChargeTextField.text = String(format: "%.2f", tempCharge)
  684. }
  685. }
  686. // MARK: - PageChangeDelegate
  687. extension OutMoneyViewController: PageChangeDelegate {
  688. func didShow() {
  689. /// 异常
  690. guard let accountManager = MTP2BusinessCore.shared.accountManager,
  691. let accountId = accountManager.getCurrentTAAccountInfo()?.accountId else { return }
  692. /// queryCanUseMoney
  693. queryCanUseMoney(accountID: String(accountId))
  694. /// moveView
  695. moveView(views: [outMoneyAmountTextField,
  696. moneyPasswordTextField,
  697. phoneNumberTextField,
  698. remarkTextField,
  699. regiesterBranchBankNumberTextField,
  700. regiesterBranchBankNameTextField,
  701. bankPasswordTextField,
  702. oldPhoneNumberTextField,
  703. checkCodeTextField,
  704. legalPersonNameTextField,
  705. legalPersonalIDcardNumberField,
  706. itsMemberCodeTextField,
  707. legalContactNumberTextField,
  708. agentContactNumberTextField])
  709. }
  710. func didHide() {
  711. //do something
  712. }
  713. }