InMoneyViewController.swift 38 KB

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