MainTabBarController.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. //
  2. // MainTabBarController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2020/12/28.
  6. // Copyright © 2020 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import WHToast
  10. import NVActivityIndicatorView
  11. import DeviceKit
  12. /// normal
  13. var normal: [NSAttributedString.Key : Any] {
  14. return [NSAttributedString.Key.font: Device.current.isFaceIDCapable ? UIFont.font_15 : UIFont.font_13, NSAttributedString.Key.foregroundColor: UIColor.fromHex(rgbValue: 0x8F8AA6)]
  15. }
  16. /// selected
  17. var selected: [NSAttributedString.Key : Any] {
  18. return [NSAttributedString.Key.font: Device.current.isFaceIDCapable ? UIFont.font_15 : UIFont.font_13, NSAttributedString.Key.foregroundColor: UIColor.fromHex(rgbValue: 0x2A80B9)]
  19. }
  20. /// 主菜单项控制视图容器类
  21. class MainTabBarController: UITabBarController {
  22. // MARK: - 生命周期
  23. override func viewDidLoad() {
  24. super.viewDidLoad()
  25. // Do any additional setup after loading the view.
  26. /// white
  27. UITabBar.appearance().barTintColor = .white
  28. /// 设置通用样式
  29. UITabBarItem.appearance().setTitleTextAttributes(normal, for: .normal)
  30. UITabBarItem.appearance().setTitleTextAttributes(selected, for: .selected)
  31. /// 视图容器初始化
  32. initControllers()
  33. /// 数据初始化
  34. requestData()
  35. }
  36. /// 视图容器初始化
  37. fileprivate func initControllers() {
  38. /// 视图
  39. var controllers: [UIViewController] = []
  40. /// 企业风管
  41. if MTP2BusinessCore.shared.address?.oem == "qyfg" {
  42. controllers.append(contentsOf: initFxglViewControllers())
  43. }
  44. /// 千海金
  45. if MTP2BusinessCore.shared.address?.oem == "qhj" {
  46. controllers.append(contentsOf: initQhjViewControllers())
  47. }
  48. /// 云融大宗
  49. if MTP2BusinessCore.shared.address?.oem == "yrdz" {
  50. controllers.append(contentsOf: initHnstViewControllers())
  51. }
  52. /// 天津麦顿
  53. if MTP2BusinessCore.shared.address?.oem == "tjmd" {
  54. controllers.append(contentsOf: initTjmdViewControllers())
  55. }
  56. /// 廣陈优品
  57. if MTP2BusinessCore.shared.address?.oem == "xhcp" {
  58. controllers.append(contentsOf: initXhcpViewControllers())
  59. }
  60. /// 设置视图
  61. self.viewControllers = controllers
  62. }
  63. /************************************************企业风管***********************************************/
  64. /// 初始化企业风管视图容器控制类数据
  65. /// - Returns: [UIViewController]
  66. fileprivate func initFxglViewControllers() -> [UIViewController] {
  67. /// 视图
  68. var viewControllers: [UIViewController] = []
  69. /// 首页
  70. let h = viewController("Main", "HomeNav")
  71. h.tabBarItem = getTabBarItem("首页", "tab_home", "tab_home_selected")
  72. viewControllers.append(h)
  73. /// 该账户没权限
  74. guard let commonManager = MTP2BusinessCore.shared.commonManager else { return viewControllers }
  75. /// 现货 判断其是否有现货权限
  76. if commonManager.containMenu(key: "client_spots") {
  77. let s = viewController("Spots", "SpotsNav")
  78. s.tabBarItem = getTabBarItem("现货", "tab_caigou", "tab_caigou_selected")
  79. viewControllers.append(s)
  80. }
  81. /// 期货 判断其是否有期货权限
  82. if commonManager.containMenu(key: "client_futures") {
  83. let f = viewController("Futures", "FuturesNav")
  84. f.tabBarItem = getTabBarItem("期货", "tab_qihuo", "tab_qihuo_selected")
  85. viewControllers.append(f)
  86. }
  87. /// 敞口 判断其是否有敞口权限
  88. if commonManager.containMenu(key: "client_exposure") {
  89. let e = viewController("Exposure", "ExposureNav")
  90. e.tabBarItem = getTabBarItem("敞口", "tab_changkou", "tab_changkou_selected")
  91. viewControllers.append(e)
  92. }
  93. /// 报表 判断其是否有报表权限
  94. if commonManager.containMenu(key: "client_report") {
  95. let r = viewController("Report", "ReportNav")
  96. r.tabBarItem = getTabBarItem("报表", "tab_xiaoshou", "tab_xiaoshou_selected")
  97. viewControllers.append(r)
  98. }
  99. return viewControllers
  100. }
  101. /************************************************天津麦顿***********************************************/
  102. /// 初始化天津麦顿视图容器控制类数据
  103. /// - Returns: [UIViewController]
  104. fileprivate func initTjmdViewControllers() -> [UIViewController] {
  105. /// 视图
  106. var viewControllers: [UIViewController] = []
  107. /// 首页
  108. let h = viewController("TjmdHome", "TjmdHomeNav")
  109. h.tabBarItem = getTabBarItem("首页", "tab_home", "tab_home_selected")
  110. viewControllers.append(h)
  111. /// 该账户没权限
  112. guard let yrdzManager = MTP2BusinessCore.shared.yrdzManager,
  113. let commonManager = MTP2BusinessCore.shared.commonManager else { return viewControllers }
  114. /// 市场属性
  115. var sections: [MoMarketSection] = []
  116. /// 如果多于三个 则取前三个
  117. if yrdzManager.sections.count > 3 {
  118. sections = Array(yrdzManager.sections[0...2])
  119. } else {
  120. sections = yrdzManager.sections
  121. }
  122. /// MD Fuck TMD
  123. for (index, obj) in sections.enumerated() {
  124. /// 参考行情
  125. if let _ = obj.mlist.first(where: {$0.trademode == .TRADEMODE_QHJ_CKHQ}) {
  126. let q = self.viewController("QHJQuote", "BJBQuote") as! BJBQuoteViewController
  127. q.title = "参考行情"
  128. q.isQhj = false
  129. let nav = BaseNavigationController(rootViewController: q)
  130. nav.tabBarItem = getTabBarItem(obj.marketsectionname, "hnst_tab_hyjy", "hnst_tab_hyjy_selected")
  131. viewControllers.append(nav)
  132. } else {
  133. let nav = viewController("YrdzQuote", "TjmdQuoteNav") as! BaseNavigationController
  134. switch index {
  135. case 0:
  136. nav.tabBarItem = getTabBarItem(obj.marketsectionname, "hnst_tab_cdmy", "hnst_tab_cdmy_selected")
  137. default:
  138. nav.tabBarItem = getTabBarItem(obj.marketsectionname, "hnst_tab_cdys", "hnst_tab_cdys_selected")
  139. }
  140. (nav.viewControllers[0] as? TjmdQuoteViewController)?.takeInfo = obj
  141. viewControllers.append(nav)
  142. }
  143. }
  144. /// 云融大宗-我的 判断其是否有云融大宗-我的权限
  145. if commonManager.containMenu(key: "client_mobile_hnstmine") {
  146. let m = viewController("YrdzMine", "YrdzMineNav")
  147. m.tabBarItem = getTabBarItem("我的", "hnst_tab_mine", "hnst_tab_mine_selected")
  148. viewControllers.append(m)
  149. }
  150. return viewControllers
  151. }
  152. /************************************************千海金***********************************************/
  153. /// 初始化千海金视图容器控制类数据
  154. /// - Returns: [UIViewController]
  155. fileprivate func initQhjViewControllers() -> [UIViewController] {
  156. /// 视图
  157. var viewControllers: [UIViewController] = []
  158. /// 首页
  159. let h = viewController("Main", "HomeNav")
  160. h.tabBarItem = getTabBarItem("首页", "tab_home", "tab_home_selected")
  161. viewControllers.append(h)
  162. /// 该账户没权限
  163. guard let commonManager = MTP2BusinessCore.shared.commonManager else { return viewControllers }
  164. /// 千海金-铂金宝 判断其是否有千海金-铂金宝
  165. if commonManager.containMenu(key: "client_qhjbjb") {
  166. let b = viewController("QHJQuote", "BJBNav")
  167. b.tabBarItem = getTabBarItem("铂金宝", "qhj_tab_bjb", "qhj_tab_bjb_selected")
  168. viewControllers.append(b)
  169. }
  170. /// 千海金-饰品回收 判断其是否有千海金-饰品回收
  171. if commonManager.containMenu(key: "client_qhjsphg") {
  172. let s = viewController("QHJQuote", "SPHGNav")
  173. s.tabBarItem = getTabBarItem("饰品回收", "qhj_tab_sphg", "qhj_tab_sphg_selected")
  174. viewControllers.append(s)
  175. }
  176. /// 千海金-我的 判断其是否有千海金-我的权限
  177. if commonManager.containMenu(key: "client_qhjmine") {
  178. let m = viewController("QHJMine", "QhjMine")
  179. m.tabBarItem = getTabBarItem("我的", "qhj_tab_mine", "qhj_tab_mine_selected")
  180. viewControllers.append(m)
  181. }
  182. return viewControllers
  183. }
  184. /************************************************云融大宗***********************************************/
  185. /// 初始化云融大宗视图容器控制类数据
  186. /// - Returns: [UIViewController]
  187. fileprivate func initHnstViewControllers() -> [UIViewController] {
  188. /// 视图
  189. var viewControllers: [UIViewController] = []
  190. /// 首页
  191. let h = viewController("YrdzHome", "YrdzHomeNav")
  192. h.tabBarItem = getTabBarItem("首页", "tab_home", "tab_home_selected")
  193. viewControllers.append(h)
  194. /// 该账户没权限
  195. guard let commonManager = MTP2BusinessCore.shared.commonManager else { return viewControllers }
  196. /// 云融大宗-仓单贸易 判断其是否云融大宗-仓单贸易权限
  197. if commonManager.containMenu(key: "client_mobile_hnstcdmy") {
  198. let c = viewController("YrdzQuote", "WarehouseNav") as! BaseNavigationController
  199. (c.viewControllers[0] as? WarehouseQuoteViewController)?.isCdmy = 1
  200. c.tabBarItem = getTabBarItem("仓单贸易", "hnst_tab_cdmy", "hnst_tab_cdmy_selected")
  201. viewControllers.append(c)
  202. }
  203. /// 云融大宗-仓单预售 判断其是否有顺通-仓单预售权限
  204. if commonManager.containMenu(key: "client_mobile_hnstcdys") {
  205. let c = viewController("YrdzQuote", "WarehouseNav") as! BaseNavigationController
  206. (c.viewControllers[0] as? WarehouseQuoteViewController)?.isCdmy = 0
  207. c.tabBarItem = getTabBarItem("仓单预售", "hnst_tab_cdys", "hnst_tab_cdys_selected")
  208. viewControllers.append(c)
  209. }
  210. /// 云融大宗-合约交易 判断其是否有顺通-订单交易权限
  211. if commonManager.containMenu(key: "client_mobile_hnsthyjy") {
  212. let h = viewController("YrdzQuote", "WarehouseNav") as! BaseNavigationController
  213. (h.viewControllers[0] as? WarehouseQuoteViewController)?.isCdmy = 2
  214. h.tabBarItem = getTabBarItem("订单交易", "hnst_tab_hyjy", "hnst_tab_hyjy_selected")
  215. viewControllers.append(h)
  216. }
  217. /// 云融大宗-我的 判断其是否有云融大宗-我的权限
  218. if commonManager.containMenu(key: "client_mobile_hnstmine") {
  219. let m = viewController("YrdzMine", "YrdzMineNav")
  220. m.tabBarItem = getTabBarItem("我的", "hnst_tab_mine", "hnst_tab_mine_selected")
  221. viewControllers.append(m)
  222. }
  223. return viewControllers
  224. }
  225. /************************************************廣陈优品***********************************************/
  226. /// 初始化廣陈优品视图容器控制类数据
  227. /// - Returns: [UIViewController]
  228. fileprivate func initXhcpViewControllers() -> [UIViewController] {
  229. /// 视图
  230. var viewControllers: [UIViewController] = []
  231. /// 首页
  232. let h = viewController("xhcp", "XHCPHomeNav")
  233. h.tabBarItem = getTabBarItem("首页", "tab_home", "tab_home_selected")
  234. viewControllers.append(h)
  235. /// 该账户没权限
  236. guard let yrdzManager = MTP2BusinessCore.shared.yrdzManager,
  237. let commonManager = MTP2BusinessCore.shared.commonManager else { return viewControllers }
  238. /// 市场属性
  239. var sections: [MoMarketSection] = []
  240. /// 如果多于三个 则取前三个
  241. if yrdzManager.sections.count > 3 {
  242. sections = Array(yrdzManager.sections[0...2])
  243. } else {
  244. sections = yrdzManager.sections
  245. }
  246. /// MD Fuck TMD
  247. for (index, obj) in sections.enumerated() {
  248. /// 参考行情
  249. if let _ = obj.mlist.first(where: {$0.trademode == .TRADEMODE_CDYS}) {
  250. let s = self.viewController("xhcp", "XHCPPreSaleNav") as! BaseNavigationController
  251. s.tabBarItem = getTabBarItem(obj.marketsectionname, "hnst_tab_hyjy", "hnst_tab_hyjy_selected")
  252. viewControllers.append(s)
  253. } else {
  254. /// 系统参数 093 现货商品是否有详
  255. let system = MTP2BusinessCore.shared.accountManager?.loginQuery?.systemParams.first(where: {$0.paramcode == "093"})
  256. if system?.paramvalue == "1" {
  257. let l = viewController("xhcp", "XHCPListingQuoteNav") as! BaseNavigationController
  258. l.tabBarItem = getTabBarItem(obj.marketsectionname, "hnst_tab_cdys", "hnst_tab_cdys_selected")
  259. (l.viewControllers[0] as? XHCPListingQuoteViewController)?.takeInfo = obj
  260. viewControllers.append(l)
  261. } else {
  262. let nav = viewController("YrdzQuote", "TjmdQuoteNav") as! BaseNavigationController
  263. switch index {
  264. case 0:
  265. nav.tabBarItem = getTabBarItem(obj.marketsectionname, "hnst_tab_cdmy", "hnst_tab_cdmy_selected")
  266. default:
  267. nav.tabBarItem = getTabBarItem(obj.marketsectionname, "hnst_tab_cdys", "hnst_tab_cdys_selected")
  268. }
  269. (nav.viewControllers[0] as? TjmdQuoteViewController)?.takeInfo = obj
  270. viewControllers.append(nav)
  271. }
  272. }
  273. }
  274. /// 云融大宗-我的 判断其是否有云融大宗-我的权限
  275. if commonManager.containMenu(key: "client_mobile_hnstmine") {
  276. let m = viewController("YrdzMine", "YrdzMineNav")
  277. m.tabBarItem = getTabBarItem("我的", "hnst_tab_mine", "hnst_tab_mine_selected")
  278. viewControllers.append(m)
  279. }
  280. return viewControllers
  281. }
  282. /// 获取
  283. /// - Parameters:
  284. /// - title: title
  285. /// - image: image
  286. /// - selectedImage: selectedImage
  287. /// - Returns: UITabBarItem
  288. fileprivate func getTabBarItem(_ title: String, _ image: String, _ selectedImage: String) -> UITabBarItem {
  289. return UITabBarItem(title: title, image: UIImage.getImage(name: image), selectedImage: UIImage.getImage(name: selectedImage))
  290. }
  291. // MARK: - 接口请求
  292. /// 数据初始化
  293. private func requestData() {
  294. /// 异常
  295. guard let oem = MTP2BusinessCore.shared.address?.oem,
  296. let quoteManger = MTP2BusinessCore.shared.quoteManager,
  297. let orderManager = MTP2BusinessCore.shared.orderManager,
  298. let spotManager = MTP2BusinessCore.shared.spotManager,
  299. let goodsManager = MTP2BusinessCore.shared.goodsManager,
  300. let qhjManager = MTP2BusinessCore.shared.qhjManager,
  301. let quoteSubscriptManager = MTP2BusinessCore.shared.quoteSubscriptManager,
  302. let commonManager = MTP2BusinessCore.shared.commonManager,
  303. let yrdzManager = MTP2BusinessCore.shared.yrdzManager else { return }
  304. /// 链接行情
  305. let group = DispatchGroup()
  306. /// startAnimating
  307. NVActivityIndicatorPresenter.sharedInstance.startAnimating(self.animData("数据更新中..."))
  308. /// 千海金 需要查询的接口
  309. if oem.lowercased() == "qhj" {
  310. group.enter()
  311. /// 查询千海金定投单据数据信息
  312. qhjManager.queryQhjRStrategy(status: "1,2") { strategy, _, _ in
  313. dPrint("queryQhjContract 查询千海金定投单据数据信息\(strategy ? "成功" : "失败")")
  314. group.leave()
  315. }
  316. group.enter()
  317. /// 查询千海金-融资单据数据信息
  318. qhjManager.queryQhjContract(scfcontractid: nil) { contract, _, _ in
  319. dPrint("queryQhjContract 查询千海金-融资单据数据信息\(contract ? "成功" : "失败")")
  320. group.leave()
  321. }
  322. }
  323. group.enter()
  324. quoteManger.requestQuoteLink(callback: { (isSuccess, _) in
  325. dPrint("[\(#function)] \(isSuccess ? "行情链路链接成功" : "行情链路链接失败")")
  326. group.leave()
  327. })
  328. group.enter()
  329. /// 查询省市区信息
  330. commonManager.requestGetDivisions { (isSuccess, _, _) in
  331. dPrint("requestGetDivisions 查询省市区信息\(isSuccess ? "成功" : "失败")")
  332. group.leave()
  333. }
  334. /// 查询商品交割关系表
  335. group.enter()
  336. yrdzManager.queryDeliveryRelation(goodsid: nil, deliverygoodsid: nil, marketid: nil) { isSuccess, _, _ in
  337. dPrint("[\(#function)] 查询商品交割关系表\(isSuccess ? "成功" : "失败")")
  338. group.leave()
  339. }
  340. /// 查询市场交易参数配置
  341. group.enter()
  342. yrdzManager.queryWrMarketTradeConfig(marketid: nil) { isSuccess, _, _ in
  343. dPrint("[\(#function)] 查询市场交易参数配置\(isSuccess ? "成功" : "失败")")
  344. group.leave()
  345. }
  346. group.enter()
  347. /// 查询商品扩展信息
  348. qhjManager.queryGoodsEx(nil) { isSuccess, _, _ in
  349. dPrint("[\(#function)] 查询商品扩展信息\(isSuccess ? "成功" : "失败")")
  350. group.leave()
  351. }
  352. group.enter()
  353. /// 持仓汇总查询(合约市场)
  354. orderManager.queryTradePosition(tradeMode: nil) { isSuccess, _, objs in
  355. dPrint("[\(#function)] 持仓汇总查询(合约市场)\(isSuccess ? "成功" : "失败")")
  356. group.leave()
  357. }
  358. group.enter()
  359. /// 委托单数据查询(合约市场)
  360. orderManager.queryTradeOrderDetail(tradeMode: nil, orderStatus: nil, orderID: nil) { isSuccess, _, _ in
  361. dPrint("[\(#function)] 委托单数据查询(合约市场)\(isSuccess ? "成功" : "失败")")
  362. group.leave()
  363. }
  364. /// 头寸查询
  365. group.enter()
  366. orderManager.queryErmcpTradePositions(marketID: nil) { (isSuccess, _, _) in
  367. dPrint("[\(#function)] \(isSuccess ? "头寸查询成功" : "头寸查询失败")")
  368. group.leave()
  369. }
  370. group.enter()
  371. orderManager.queryErmcpTradeDetails(goodsid: nil, buyOrSell: nil, orderID: nil) { (isSuccess, _, _) in
  372. dPrint("[\(#function)] \(isSuccess ? "今日成交查询成功" : "今日成交查询失败")")
  373. group.leave()
  374. }
  375. group.enter()
  376. /// 查询现货商品数据信息
  377. spotManager.queryDeliveryGoods(excludecfg: nil) { (isSuccess, _, _) in
  378. dPrint("queryDeliveryGoods 查询现货商品数据信息\(isSuccess ? "成功" : "失败")")
  379. group.leave()
  380. }
  381. /// 查询用户藏品数据
  382. group.enter()
  383. goodsManager.queryUserFavoriteGoodses { (isSuccess, _, _) in
  384. dPrint("queryUserFavoriteGoodses 查询用户藏品数据\(isSuccess ? "成功" : "失败")")
  385. group.leave()
  386. }
  387. /// 获取主力合约数据
  388. group.enter()
  389. goodsManager.getErmcpGoodsSortByPosition(sortIndex: "1") { (isSuccess, _, _) in
  390. dPrint("getErmcpGoodsSortByPosition 获取主力合约数据\(isSuccess ? "成功" : "失败")")
  391. group.leave()
  392. }
  393. /// 掉期商品
  394. let marketid = MTP2BusinessCore.getMarketId(tradeMode: .TRADEMODE_TJMD)
  395. group.enter()
  396. /// 查询商品掉期报价数据
  397. yrdzManager.queryQuoteGoodsList(goodsid: nil, goodsgroupid: nil, marketids: "\(marketid)") { isSuccess, er, objs in
  398. dPrint("getErmcpGoodsSortByPosition查询商品掉期报价数据\(isSuccess ? "成功" : "失败")")
  399. group.leave()
  400. }
  401. /// 查询系统状态
  402. group.enter()
  403. goodsManager.queryMarketRun(marketId: 0, callback: { (isSuccess, _, _) in
  404. dPrint("[\(#function)] 查询系统状态\(isSuccess ? "成功" : "失败")")
  405. group.leave()
  406. })
  407. group.notify(queue: .main) {
  408. /// stopAnimating
  409. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  410. var goodsCodes = Set<String>()
  411. /// 如果头寸 不为空 需要去订阅行情
  412. if let ps = orderManager.positionDetails, ps.count != 0 {
  413. ps.forEach { obj in
  414. goodsCodes.insert(obj.goodscode)
  415. }
  416. }
  417. /// 如果头寸 不为空 需要去订阅行情
  418. if let ps = orderManager.qhjTradePositions, ps.count != 0 {
  419. ps.forEach { obj in
  420. /// 掉期商品
  421. if obj.trademode == .TRADEMODE_TJMD,
  422. let goodsList = yrdzManager.goodsList.first(where: {$0.goodsid == obj.goodsid}) {
  423. goodsCodes.insert(goodsList.refgoodscode)
  424. } else {
  425. goodsCodes.insert(obj.goodscode)
  426. }
  427. }
  428. }
  429. quoteSubscriptManager.updateQuoteSubcriptGoods(uuid: UUID().uuidString, goodsCode: goodsCodes)
  430. }
  431. }
  432. }