QSLJumpManager.swift 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // QSLJumpManager.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/12/24.
  6. //
  7. import Foundation
  8. import UIKit
  9. enum JumpType: Int {
  10. case createInspration = 0 // 灵感创作
  11. case createDiy // 自定义创作
  12. case mine // 我的
  13. case vip // 会员
  14. case login // 登录
  15. case accompaniment // 伴奏
  16. }
  17. class QSLJumpManager: NSObject {
  18. static let shared = QSLJumpManager()
  19. private override init() {}
  20. }
  21. extension QSLJumpManager {
  22. // 跳转到Vip页面
  23. func pushToVip(type: QSLVipJumpType) {
  24. let vc = QSLVipController()
  25. vc.type = type
  26. self.rootViewController()?.pushVC(vc: vc)
  27. vc.finishHandler = {[weak self] isCancel, yearGood in
  28. if isCancel {
  29. return
  30. }
  31. if QSLBaseManager.shared.isVip() {
  32. return
  33. }
  34. if let currentWindow = UIApplication.keyWindow {
  35. QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_retention_show, eventProps: ["trigger_type":"close_vip_center"])
  36. QSLRetainPopUpAlertView.alert(view: currentWindow, isOneBtn: true, oneBtnText: "继续支付", oneBtnClosure: { [weak self] in
  37. QSLCountdownManager.shared.selectGood = yearGood
  38. self?.unlockBtnAction()
  39. QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_retention_click, eventProps: ["button":"continue_payment"])
  40. },closeBtnClosure: {
  41. QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_retention_click, eventProps: ["button":"close"])
  42. })
  43. }
  44. }
  45. }
  46. func unlockBtnAction(){
  47. if(!QSLBaseManager.shared.isLogin()){
  48. if(QSLBaseManager.shared.isVip()){
  49. QSLJumpManager.shared.pushToLogin(type: .member)
  50. return
  51. }
  52. if(QSLConfig.loginPayEnable){
  53. QSLJumpManager.shared.pushToLogin(type: .member)
  54. return
  55. }
  56. }
  57. if let selectGood = QSLCountdownManager.shared.selectGood{
  58. let memberModel = QSLBaseManager.shared.userModel.memberModel
  59. if let subscriptionExpired = memberModel.subscriptionExpired, !subscriptionExpired {
  60. UIApplication.keyWindow?.toast(text: "你已经订阅了")
  61. return
  62. }
  63. QSLLoading.show()
  64. QSLVipManager.shared.startPay(goods: selectGood) { status, outTradeNo in
  65. QSLVipManager.shared.isPaying = false
  66. if status == .success {
  67. QSLLoading.hide()
  68. QSLLoading.success(text: "支付成功")
  69. //弹出是否好评的弹窗
  70. //QSLGuideusersToCommentManager.commentShare.manageWhetherTriggerPopUpWindow(QSLGuideusersToCommentType.member)
  71. // 引力传递支付事件
  72. gravityInstance?.trackPayEvent(withAmount: Int32(selectGood.amount), withPayType: "CNY", withOrderId: outTradeNo, withPayReason: selectGood.name, withPayMethod: "apple")
  73. QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "success","pay_amount":Int32(selectGood.amount)])
  74. QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_submit_success, eventProps: ["id": 01001])
  75. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  76. NotificationCenter.default.post(name: QSLNotification.QSLRefreshMember, object: nil)
  77. if(!QSLBaseManager.shared.isLogin()){
  78. QSLJumpManager.shared.pushToLogin(type: .member)
  79. }
  80. }
  81. } else if status == .cancel {
  82. QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "cancel","pay_amount":Int32(selectGood.amount)])
  83. QSLLoading.error(text: "支付取消")
  84. } else if status == .fail {
  85. QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "fail","pay_amount":Int32(selectGood.amount)])
  86. QSLLoading.error(text: "支付失败")
  87. }
  88. }
  89. }
  90. }
  91. func unlockTrialBtnAction(){
  92. if(!QSLBaseManager.shared.isLogin()){
  93. if(QSLBaseManager.shared.isVip()){
  94. QSLJumpManager.shared.pushToLogin(type: .member)
  95. return
  96. }
  97. if(QSLConfig.loginPayEnable){
  98. QSLJumpManager.shared.pushToLogin(type: .member)
  99. return
  100. }
  101. }
  102. if let selectGood = QSLCountdownManager.shared.trialGood{
  103. let memberModel = QSLBaseManager.shared.userModel.memberModel
  104. if let subscriptionExpired = memberModel.subscriptionExpired, !subscriptionExpired {
  105. UIApplication.keyWindow?.toast(text: "你已经订阅了")
  106. return
  107. }
  108. QSLLoading.show()
  109. QSLVipManager.shared.startPay(goods: selectGood) { status, outTradeNo in
  110. QSLVipManager.shared.isPaying = false
  111. if status == .success {
  112. QSLLoading.success(text: "支付成功")
  113. //弹出是否好评的弹窗
  114. //QSLGuideusersToCommentManager.commentShare.manageWhetherTriggerPopUpWindow(QSLGuideusersToCommentType.member)
  115. // 引力传递支付事件
  116. gravityInstance?.trackPayEvent(withAmount: Int32(selectGood.amount), withPayType: "CNY", withOrderId: outTradeNo, withPayReason: selectGood.name, withPayMethod: "apple")
  117. QSEventHandle.eventPush(eventName: QSLGravityConst.activity_purchase_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "success","pay_amount":Int32(selectGood.amount),"page_type":"coupon_popup"])
  118. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  119. NotificationCenter.default.post(name: QSLNotification.QSLRefreshMember, object: nil)
  120. if(!QSLBaseManager.shared.isLogin()){
  121. QSLJumpManager.shared.pushToLogin(type: .member)
  122. }
  123. }
  124. } else if status == .cancel {
  125. QSEventHandle.eventPush(eventName: QSLGravityConst.activity_purchase_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "cancel","pay_amount":Int32(selectGood.amount),"page_type":"coupon_popup"])
  126. QSLLoading.error(text: "支付取消")
  127. } else if status == .fail {
  128. QSEventHandle.eventPush(eventName: QSLGravityConst.activity_purchase_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "fail","pay_amount":Int32(selectGood.amount),"page_type":"coupon_popup"])
  129. QSLLoading.error(text: "支付失败")
  130. }
  131. }
  132. }
  133. }
  134. // 跳转到登录页面
  135. func pushToLogin(type: QSLLoginJumpType) {
  136. let vc = QSLLoginViewController()
  137. vc.type = type
  138. self.rootViewController()?.pushVC(vc: vc)
  139. }
  140. // 跳转到紧急联系人页面
  141. func pushToContact(type: QSLContactJumpPage) {
  142. let vc = QSLContactController()
  143. vc.type = type
  144. self.rootViewController()?.pushVC(vc: vc)
  145. }
  146. // 跳转到轨迹页面
  147. func pushToRoad(type: QSLRoadJumpType, model: QSLUserModel) {
  148. let vc = QSLRoadController(userModel: model)
  149. vc.type = type
  150. self.rootViewController()?.pushVC(vc: vc)
  151. }
  152. // 跳转到添加好友页面
  153. func pushToAdd(type: QSLAddJumpType) {
  154. let vc = QSLAddController()
  155. vc.type = type
  156. self.rootViewController()?.pushVC(vc: vc)
  157. }
  158. // 跳转到会员试用页面
  159. func pushToVipTrail(type: QSLTrialVipJumpType) {
  160. let vc = QSLVipTrialVC()
  161. vc.type = type
  162. self.rootViewController()?.pushVC(vc: vc)
  163. }
  164. }