OutMoneyViewController.swift 34 KB

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