OutMoneyViewController.swift 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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 = MTP2BusinessCore.shared.address?.hsbyBankSignZone.components(separatedBy: "-"),
  115. let signTime = configInfo.first,
  116. let outTime = configInfo.last {
  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. let now = Date().getString(formatter: "HH:mm")
  257. guard let configInfo = MTP2BusinessCore.shared.address?.hsbyBankSignZone.components(separatedBy: "-"),
  258. let signTime = configInfo.first,
  259. let outTime = configInfo.last, now>signTime,
  260. now<outTime else {
  261. self.showHintController(title: "提示", message: "请在规定的时间段内进行提现!", handler: nil)
  262. return false
  263. }
  264. /// 出金金额
  265. if let outMoneyAmount = self.outMoneyAmountTextField.text {
  266. if outMoneyAmount.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  267. self.showHintController(title: "提示", message: "请输入出金金额", handler: nil)
  268. return false
  269. }
  270. if let outMoneyAmount = Double(outMoneyAmount), let canUserMoney = Double(canUseMoneyTextField.text!) {
  271. if outMoneyAmount > canUserMoney {
  272. self.showHintController(title: "提示", message: "出金金额不得大于可取资金", handler: nil)
  273. return false
  274. }
  275. } else {
  276. self.showHintController(title: "提示", message: "出金金额格式不正确")
  277. return false
  278. }
  279. }
  280. /// 资金密码
  281. if let moneyPassword = self.moneyPasswordTextField.text {
  282. if moneyPassword.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  283. self.showHintController(title: "提示", message: "请输入资金密码", handler: nil)
  284. return false
  285. }
  286. }
  287. /// 开户省份
  288. if (regiesterProvinceTextField.superview?.isHidden)! == false {
  289. if let regiesterProvince = self.regiesterProvinceTextField.text {
  290. if regiesterProvince.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  291. self.showHintController(title: "提示", message: "请选择开户省份")
  292. return false
  293. }
  294. }
  295. }
  296. /// 开户城市
  297. if (regiesterCityTextField.superview?.isHidden)! == false {
  298. if let regiesterCity = self.regiesterCityTextField.text {
  299. if regiesterCity.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  300. self.showHintController(title: "提示", message: "请选择开户城市")
  301. return false
  302. }
  303. }
  304. }
  305. /// 开户行支行号
  306. if (regiesterBranchBankNumberTextField.superview?.isHidden)! == false {
  307. if let regiesterBranchBankNumber = self.regiesterBranchBankNumberTextField.text {
  308. if regiesterBranchBankNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  309. self.showHintController(title: "提示", message: "请输入开户行支行号")
  310. return false
  311. }
  312. }
  313. }
  314. /// 开户行支行名称
  315. if (regiesterBranchBankNameTextField.superview?.isHidden)! == false {
  316. if let regiesterBranchBankName = self.regiesterBranchBankNameTextField.text {
  317. if regiesterBranchBankName.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  318. self.showHintController(title: "提示", message: "请输入开户行支行名称")
  319. return false
  320. }
  321. }
  322. }
  323. /// 银行密码
  324. if (bankPasswordTextField.superview?.isHidden)! == false {
  325. if let bankPassword = self.bankPasswordTextField.text {
  326. if bankPassword.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  327. self.showHintController(title: "提示", message: "请输入银行密码")
  328. return false
  329. }
  330. }
  331. }
  332. /// 原手机号码
  333. if (oldPhoneNumberTextField.superview?.isHidden)! == false {
  334. if let oldPhoneNumber = self.oldPhoneNumberTextField.text {
  335. if oldPhoneNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  336. self.showHintController(title: "提示", message: "请输入原手机号码")
  337. return false
  338. }
  339. }
  340. }
  341. /// 验证码
  342. if (checkCodeTextField.superview?.superview?.isHidden)! == false {
  343. if let checkCode = self.checkCodeTextField.text {
  344. if checkCode.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  345. self.showHintController(title: "提示", message: "请输入验证码")
  346. return false
  347. }
  348. }
  349. }
  350. /// 男性
  351. if (checkMenButton.superview?.superview?.isHidden)! == false {
  352. if !self.checkMenButton.isSelected && !self.checkWomenButton.isSelected{
  353. self.showHintController(title: "提示", message: "请选择性别")
  354. return false
  355. }
  356. }
  357. /// 法人姓名
  358. if (legalPersonNameTextField.superview?.isHidden)! == false {
  359. if let legalPersonName = self.legalPersonNameTextField.text {
  360. if legalPersonName.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  361. self.showHintController(title: "提示", message: "请输入法人姓名")
  362. return false
  363. }
  364. }
  365. }
  366. /// 法人证件类型
  367. if (legalPersonalIDcardTypeTextField.superview?.isHidden)! == false {
  368. if let legalPersonalIDcardType = self.legalPersonalIDcardTypeTextField.text {
  369. if legalPersonalIDcardType.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  370. self.showHintController(title: "提示", message: "请选择法人证件类型")
  371. return false
  372. }
  373. }
  374. }
  375. /// 法人证件号码
  376. if (legalPersonalIDcardNumberField.superview?.isHidden)! == false {
  377. if let legalPersonalIDcardNumber = self.legalPersonalIDcardNumberField.text {
  378. if legalPersonalIDcardNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  379. self.showHintController(title: "提示", message: "请输入法人证件号码")
  380. return false
  381. }
  382. }
  383. }
  384. /// 经办人姓名
  385. if (agentNameTextField.superview?.isHidden)! == false {
  386. if let agentName = self.agentNameTextField.text {
  387. if agentName.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  388. self.showHintController(title: "提示", message: "请输入经办人姓名")
  389. return false
  390. }
  391. }
  392. }
  393. /// 经办人证件类型
  394. if (agentIDcardTypeTextField.superview?.isHidden)! == false {
  395. if let agentIDcardType = self.agentIDcardTypeTextField.text {
  396. if agentIDcardType.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  397. self.showHintController(title: "提示", message: "请选择经办人证件类型")
  398. return false
  399. }
  400. }
  401. }
  402. /// 经办人证件号码
  403. if (agentIDcardNumberTextField.superview?.isHidden)! == false {
  404. if let agentIDcardNumber = self.agentIDcardNumberTextField.text {
  405. if agentIDcardNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  406. self.showHintController(title: "提示", message: "请输入经办人证件号码")
  407. return false
  408. }
  409. }
  410. }
  411. /// 所属会员代码
  412. if (itsMemberCodeTextField.superview?.isHidden)! == false {
  413. if let itsMemberCode = self.itsMemberCodeTextField.text {
  414. if itsMemberCode.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  415. self.showHintController(title: "提示", message: "请输入所属会员代码")
  416. return false
  417. }
  418. }
  419. }
  420. /// 法人联系号码
  421. if (legalContactNumberTextField.superview?.isHidden)! == false {
  422. if let legalContactNumber = self.legalContactNumberTextField.text {
  423. if legalContactNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  424. self.showHintController(title: "提示", message: "请输入法人联系号码")
  425. return false
  426. }
  427. }
  428. }
  429. /// 经办人联系号码
  430. if (agentContactNumberTextField.superview?.isHidden)! == false {
  431. if let agentContactNumber = self.agentContactNumberTextField.text {
  432. if agentContactNumber.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
  433. self.showHintController(title: "提示", message: "请输入经办人联系号码")
  434. return false
  435. }
  436. }
  437. }
  438. return true
  439. }
  440. }
  441. // MARK: - UITextFieldDelegate
  442. extension OutMoneyViewController: UITextFieldDelegate {
  443. func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  444. textField.resignFirstResponder()
  445. return true
  446. }
  447. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  448. switch textField.tag {
  449. case TAG.moneyAccount:
  450. guard let accountManager = MTP2BusinessCore.shared.accountManager else { return true }
  451. let titleArray = accountManager.getTaAccountInfoList()?.compactMap({ return String($0.accountId) }) ?? []
  452. if titleArray.count > 0 {
  453. self.showPopupsController(title: "选择资金账户", message: nil, titleArray: titleArray) { (value: String, selectedRow: Int, _) in
  454. if self.currentMoneyAccount != value {
  455. self.currentMoneyAccount = value
  456. self.moneyAccountTextField.text = value
  457. self.queryBankSign(accountID: value)
  458. self.queryCanUseMoney(accountID: value)
  459. }
  460. }
  461. } else {
  462. self.showHintController(title: "提示", message: "没有可选的资金账户")
  463. }
  464. return false
  465. case TAG.signingBank:
  466. guard let bankManager = MTP2BusinessCore.shared.bankManager else { return true }
  467. var titleArray = [String]()
  468. if let bankSign = bankManager.moBankSign {
  469. titleArray = bankSign.bankSign.map({ (model) -> String in
  470. return String(model.cusBankName)
  471. })
  472. }
  473. if titleArray.count > 0 {
  474. self.showPopupsController(title: "选择签约银行", message: nil, titleArray: titleArray) { (value: String, selectedRow: Int, _) in
  475. if self.currentBankSign?.cusBankName != value {
  476. self.signingBankTextField.text = value
  477. self.setupSignBank(bankSign: bankManager.moBankSign?.bankSign[selectedRow])
  478. }
  479. }
  480. } else {
  481. self.showHintController(title: "提示", message: "没有可选的签约银行")
  482. }
  483. return false
  484. case TAG.regiesterProvince:
  485. guard let bankManager = MTP2BusinessCore.shared.bankManager else{ return true }
  486. let completeBlock = { (results: [MoBankProvince]?) in
  487. let titleArray = results?.map({ (model) -> String in
  488. return model.bankprovincename
  489. })
  490. self.showPopupsController(title: "选择省份", message: nil, titleArray: titleArray!, clickBlock: { (value, rowNum, _) in
  491. self.regiesterProvinceTextField.text = value
  492. if self.currentProvinceID != results?[rowNum].bankprovinceid {
  493. self.currentProvinceID = results?[rowNum].bankprovinceid
  494. bankManager.queryBankCity(provinceID: self.currentProvinceID!, callback: { (isSuccess, errorInfo, results) in
  495. if isSuccess {
  496. } else {
  497. self.showErrorMessgae(error: errorInfo)
  498. }
  499. })
  500. }
  501. })
  502. }
  503. if let moBankProvice = bankManager.moBankProvice {
  504. completeBlock(moBankProvice)
  505. } else {
  506. _anim?.startAnimating()
  507. bankManager.queryBankProvince { (isSuccess, errorInfo, results) in
  508. DispatchQueue.main.async {
  509. self._anim?.stopAnimating()
  510. if isSuccess {
  511. completeBlock(results)
  512. } else {
  513. self.showErrorMessgae(error: errorInfo)
  514. }
  515. }
  516. }
  517. }
  518. return false
  519. case TAG.regiesterCity:
  520. guard let bankManager = MTP2BusinessCore.shared.bankManager else{ return true }
  521. if let moBankCity = bankManager.moBankCity {
  522. let titleArray = moBankCity.map({ (model) -> String in
  523. return model.bankcityname
  524. })
  525. self.showPopupsController(title: "选择市", message: nil, titleArray: titleArray, clickBlock: { (value, rowNum, _) in
  526. self.regiesterCityTextField.text = value
  527. self.currentCityID = moBankCity[rowNum].bankcityid
  528. })
  529. }
  530. return false
  531. case TAG.legalPersonalIDcardType:
  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.legalPersonalIDcardTypeTextField.text = value
  538. })
  539. return false
  540. case TAG.agentIDcardType:
  541. var titleArray = [String]()
  542. for i in 0...22 {
  543. titleArray.append(ECardTypeStringValue(CardType(rawValue: i)))
  544. }
  545. self.showPopupsController(title: "选择经办人证件类型", message: nil, titleArray: titleArray, clickBlock: { (value, _ , _) in
  546. self.agentIDcardTypeTextField.text = value
  547. })
  548. return false
  549. default:
  550. break
  551. }
  552. return true
  553. }
  554. /// 查询可取资金
  555. func queryCanUseMoney(accountID: String) {
  556. guard let bankManager = MTP2BusinessCore.shared.bankManager, let accountId = UInt64(accountID) else { return }
  557. _anim?.startAnimating()
  558. bankManager.accountFundInfo(accountID: accountId, queryBitMask: 3) { (isSuccess, errorInfo, results) in
  559. DispatchQueue.main.async {
  560. self._anim?.stopAnimating()
  561. if isSuccess {
  562. guard let results = results else{ return }
  563. self.canUseMoneyTextField.text = String(results.availableOutMoney)
  564. }else {
  565. /// 查询失败
  566. }
  567. }
  568. }
  569. }
  570. /// 查询已签约信息
  571. func queryBankSign(accountID: String) {
  572. guard let bankManager = MTP2BusinessCore.shared.bankManager, let accountId = UInt64(accountID) else { return }
  573. _anim?.startAnimating()
  574. bankManager.bankSign(accountId: accountId, cusbankId: "") {(isSuccess, errorInfo, results) in
  575. DispatchQueue.main.async {
  576. self._anim?.stopAnimating()
  577. if isSuccess {
  578. self.setupSignBank(bankSign: results?.bankSign.first)
  579. }else {
  580. /// 查询失败
  581. }
  582. }
  583. }
  584. }
  585. /// 查询扩展信息
  586. func queryExpandInfo(cusBankId: String) {
  587. guard let bankManager = MTP2BusinessCore.shared.bankManager else { return }
  588. _anim?.startAnimating()
  589. bankManager.queryBankExtendInfo(cusBankId: cusBankId, type: 3) { (isSuccess, errorInfo, results) in
  590. DispatchQueue.main.async {
  591. self._anim?.stopAnimating()
  592. if isSuccess {
  593. if let results = results, results.count > 0 {
  594. results.forEach({ (model) in
  595. if let tag = Int(model.fieldid), let view = self.view.viewWithTag(tag) {
  596. view.isHidden = false
  597. }
  598. })
  599. self.splitView.isHidden = false
  600. } else {
  601. self.splitView.isHidden = true
  602. }
  603. } else {
  604. self.showErrorMessgae(error: errorInfo)
  605. }
  606. }
  607. }
  608. }
  609. /// 选择了签约银行要做的事情
  610. func setupSignBank(bankSign: MoBankAccountSign?) {
  611. guard let bankManager = MTP2BusinessCore.shared.bankManager,
  612. let accountManager = MTP2BusinessCore.shared.accountManager,
  613. let accountInfo = accountManager.moAccountBaseInfo?.accountInfo else { return }
  614. if let model = bankSign {
  615. signingBankTextField.text = model.cusBankName
  616. registerBankTextField.text = model.bankName
  617. currentBankSign = model
  618. /// 若是加密字符串需要取分号前面的字符
  619. if model.bankAccountNo.contains(";") {
  620. let index = model.bankAccountNo.firstIndex(of: ";")
  621. let bankAccountNo = model.bankAccountNo.prefix(upTo: index!)
  622. bankAccountTextField.text = bankAccountNo.description
  623. }else {
  624. bankAccountTextField.text = model.bankAccountNo
  625. }
  626. phoneNumberTextField.text = model.mobilePhoneDisp
  627. queryExpandInfo(cusBankId: model.cusBankID)
  628. if let cusbankParam = bankManager.cusbankInfos?.first(where: { $0.cusbankid == model.cusBankID }) {
  629. if cusbankParam.canoutamount != 1 {
  630. submitButton.isHidden = true
  631. }
  632. }
  633. let userType = accountInfo.userInfoType == 1 ? EBank_BankAccountType.BANK_BANKACCOUNTTYPE_PRIVATE.rawValue : EBank_BankAccountType.BANK_BANKACCOUNTTYPE_PUBLIC.rawValue
  634. _anim?.startAnimating()
  635. // 查询
  636. bankManager.queryQueryBank_CusBankCharge(cusBankID: model.cusBankID, outOrIn: 1, userType: userType) { (isSuccess, errorInfo, results) in
  637. DispatchQueue.main.async {
  638. self._anim?.stopAnimating()
  639. if isSuccess {
  640. if let currentCusBankCharge = results?.first {
  641. self.currentCusBankCharge = currentCusBankCharge
  642. self.calCusBankCharge()
  643. }
  644. } else {
  645. self.showErrorMessgae(error: errorInfo)
  646. }
  647. }
  648. }
  649. }
  650. }
  651. /// 计算出金手续费
  652. /**
  653. 统一:
  654. 1.比例:1.手续费=出入金金额*收费值 2.手续费<单笔最小,手续费=单笔最小,3.手续费>单笔最大,手续费=单笔最大
  655. 2.固定:1.手续费=收费值
  656. 区间:
  657. 1.比例:ps:首先判断出入金金额在哪个区间范围内,取区间内收费值计算,若无则不收取服务费。 1.手续费=出入金金额*收费值 2.手续费<单笔最小,手续费=单笔最小,3.手续费>单笔最大,手续费=单笔最大
  658. 2.固定:ps:首先判断出入金金额在哪个区间范围内,取区间内收费值值计算,若无则不收取服务费。 1.手续费=收费值
  659. */
  660. @objc func calCusBankCharge() {
  661. // 没有就不用算了
  662. guard let cusBankCharge = currentCusBankCharge else { return }
  663. // 入金金额
  664. let outMoney = Double(outMoneyAmountTextField.text!) ?? 0.0
  665. var tempCharge = 0.0
  666. if cusBankCharge.ChargeType == 1 { // 手续费收取类型 - 1:统一 2:区间
  667. if cusBankCharge.ChargeAlgorithm == 1 { // 手续费收取方式 - 1:比率 2:固定 [统一 ]
  668. tempCharge = cusBankCharge.ChargeValue * outMoney
  669. if tempCharge > cusBankCharge.SingleMax {
  670. tempCharge = cusBankCharge.SingleMax
  671. } else if tempCharge < cusBankCharge.SingleMin {
  672. tempCharge = cusBankCharge.SingleMin
  673. }
  674. } else if cusBankCharge.ChargeAlgorithm == 2 {
  675. tempCharge = outMoney > 0 ? cusBankCharge.ChargeValue : 0.0
  676. }
  677. } else if cusBankCharge.ChargeType == 2 {
  678. if let moCusBankChargeDetails = cusBankCharge.CusBankChargeDetail.first(where: { $0.RangeMax >= outMoney && $0.RangeMin <= outMoney }) {
  679. if moCusBankChargeDetails.ChargeAlgorithm == 1 { // 手续费收取方式 - 1:比率 2:固定 [统一 ]
  680. tempCharge = moCusBankChargeDetails.ChargeValue * outMoney
  681. if tempCharge > cusBankCharge.SingleMax {
  682. tempCharge = cusBankCharge.SingleMax
  683. } else if tempCharge < cusBankCharge.SingleMin {
  684. tempCharge = cusBankCharge.SingleMin
  685. }
  686. } else if moCusBankChargeDetails.ChargeAlgorithm == 2 {
  687. tempCharge = outMoney > 0 ? cusBankCharge.ChargeValue : 0.0
  688. }
  689. }
  690. }
  691. outMoneyChargeTextField.text = String(format: "%.2f", tempCharge)
  692. }
  693. }
  694. // MARK: - PageChangeDelegate
  695. extension OutMoneyViewController: PageChangeDelegate {
  696. func didShow() {
  697. /// 异常
  698. guard let accountManager = MTP2BusinessCore.shared.accountManager,
  699. let accountId = accountManager.getCurrentTAAccountInfo()?.accountId else { return }
  700. /// queryCanUseMoney
  701. queryCanUseMoney(accountID: String(accountId))
  702. /// moveView
  703. moveView(views: [outMoneyAmountTextField,
  704. moneyPasswordTextField,
  705. phoneNumberTextField,
  706. remarkTextField,
  707. regiesterBranchBankNumberTextField,
  708. regiesterBranchBankNameTextField,
  709. bankPasswordTextField,
  710. oldPhoneNumberTextField,
  711. checkCodeTextField,
  712. legalPersonNameTextField,
  713. legalPersonalIDcardNumberField,
  714. itsMemberCodeTextField,
  715. legalContactNumberTextField,
  716. agentContactNumberTextField])
  717. }
  718. func didHide() {
  719. //do something
  720. }
  721. }