| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227 |
- //
- // QSLVipController.swift
- // QuickSearchLocation
- //
- // Created by Destiny on 2024/11/27.
- //
- import UIKit
- import YYText
- enum QSLVipJumpType: Int {
-
- case homeRoad // 定位查看轨迹
- case add // 添加好友
- case friendRoad // 好友列表查看轨迹
- case contact // 添加紧急联系人
- case mine //
- case guideComments // 引导评论
- case shortcut // 捷径
- }
- class QSLVipController: QSLBaseController {
-
- // 购买人数
- static let record_non_member_clicks_to_claim = "RECORD_NON_MEMBER_CLIKS_CLAIM"
-
- struct UX {
- static let mostCellHeight = 113.0.rpx
- static let collectionRowHeight = 137.0.rpx
- static let goodsBgHeight = 54.rpx + UX.mostCellHeight + 20.rpx
- }
-
- var type: QSLVipJumpType?
- var isCancel = false
- var yearGood : QSLGoodModel?
- var finishHandler: ((Bool,QSLGoodModel?) -> Void)?
- var goodList: [QSLGoodModel] = [QSLGoodModel]()
-
- ///是否是订阅的产品
- //var is
-
- var selectGood: QSLGoodModel? {
- didSet {
- updateSelectGoodUI()
- }
- }
-
- lazy var vipBg: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "vip_bg")
- return imageView
- }()
-
- lazy var backButton: UIButton = {
-
- let button = UIButton()
- button.image(UIImage(named: "public_back_btn_white"))
- button.title("会员中心")
- button.mediumFont(17)
- button.textColor(.white)
- button.setImageTitleLayout(.imgLeft, spacing: 4.rpx)
- button.addTarget(self, action: #selector(backBtnAction), for: .touchUpInside)
- return button
- }()
-
- lazy var peopleCountView: UIView = {
-
- let view = UIView()
- view.layer.cornerRadius = 12.rpx
- view.layer.borderColor = UIColor.white.withAlphaComponent(0.16).cgColor
- view.layer.borderWidth = 1.rpx
- return view
- }()
-
- lazy var peopleAvatarImageView: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "vip_avatars_icon")
- return imageView
- }()
-
- lazy var peopleCountLabel: UILabel = {
-
- let label = UILabel()
- label.text("1456488人 已开通VIP")
- label.color("#FFE6C0")
- label.font(12)
- return label
- }()
-
- lazy var scrollView: UIScrollView = {
-
- let scrollView = UIScrollView()
- // scrollView.delegate = self
- scrollView.bounces = false
- scrollView.showsVerticalScrollIndicator = false
- scrollView.contentInsetAdjustmentBehavior = .never
- return scrollView
- }()
-
- lazy var cardBannerImageView: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "vip_banner_card")
- return imageView
- }()
-
- lazy var vipTimeLabel: UILabel = {
-
- let label = UILabel()
- label.text("升级VIP会员,解锁全部功能")
- label.font(13)
- label.textColor = .hexStringColor(hexString: "#AF7655")
- return label
- }()
-
- lazy var funcBannerImageView: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "vip_banner_func")
- return imageView
- }()
-
- lazy var mainView: UIView = {
-
- let view = UIView()
- view.backgroundColor = QSLColor.backGroundColor
- view.addRadius(radius: 12.rpx)
- return view
- }()
-
- lazy var goodsBgView: UIView = {
-
- let view = UIView()
- view.gradientBackgroundColor(color1: .hexStringColor(hexString: "#FFF8F2"), color2: .hexStringColor(hexString: "#FFFFFF"), width: QSLConst.qsl_kScreenW, height: UX.goodsBgHeight, direction: .vertical)
- return view
- }()
-
- lazy var vipGoodsTitleIcon: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "vip_title_icon")
- return imageView
- }()
-
- lazy var resumeBtn: UIButton = {
-
- let button = UIButton()
- button.title("恢复购买")
- button.setTitleColor(.hexStringColor(hexString: "#000000").withAlphaComponent(0.5), for: .normal)
- button.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .medium)
- button.image(UIImage(named: "vip_resume_btn"))
- button.setImageTitleLayout(.imgLeft, spacing: 2.rpx)
- button.addTarget(self, action: #selector(resumeBtnAction), for: .touchUpInside)
- return button
- }()
-
- lazy var mostCell: QSLVipMostGoodCell = {
-
- let cell = QSLVipMostGoodCell()
-
- cell.isUserInteractionEnabled = true
- let tap = UITapGestureRecognizer(target: self, action: #selector(firstCellClickAction))
- cell.addGestureRecognizer(tap)
-
- return cell
- }()
-
- lazy var goodsCollectionView: UICollectionView = {
-
- let layout = UICollectionViewFlowLayout()
- layout.minimumLineSpacing = 0
- layout.scrollDirection = .vertical
-
- let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
- collectionView.backgroundColor = .clear
-
- collectionView.dataSource = self
- collectionView.delegate = self
-
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.bounces = false
-
- collectionView.register(cellClass: QSLVipGoodCollectionViewCell.self)
-
- return collectionView
- }()
-
- lazy var selectBtn: UIButton = {
-
- let btn = UIButton()
- btn.image(UIImage(named: "public_select_btn_false"), .normal)
- btn.image(UIImage(named: "public_select_btn_true"), .selected)
- btn.addTarget(self, action: #selector(selectBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var serviceLabel: YYLabel = {
- let label = YYLabel()
- //updateServiceLabelText(showSubscribe: true) // 默认显示所有内容
- return label
- }()
- // 更新服务条款文本内容
- func updateServiceLabelText(showSubscribe: Bool) {
- let attr = NSMutableAttributedString()
-
- // 固定部分:购买即同意
- let firstAttr = NSMutableAttributedString(string: "购买即同意")
- firstAttr.font(10)
- firstAttr.color(.hexStringColor(hexString: "#A7A7A7"))
- attr.append(firstAttr)
-
- let blankAttr = NSMutableAttributedString(string: " ")
- blankAttr.font(10)
- attr.append(blankAttr)
-
- // 《隐私权政策》
- let privacyHL = YYTextHighlight()
- let privacyStr = "《隐私权政策》"
- let privacyText = NSMutableAttributedString(string: privacyStr)
- privacyText.font(10)
- privacyText.color(.hexStringColor(hexString: "#E7B983"))
- privacyText.yy_setTextHighlight(privacyHL, range: NSRange(location: 0, length: privacyStr.count))
- privacyHL.tapAction = { [weak self] containerView, text, range, rect in
- self?.privacyAction()
- }
- attr.append(privacyText)
-
- attr.append(blankAttr)
-
- // 《用户协议》
- let serviceHL = YYTextHighlight()
- let serviceStr = "《用户协议》"
- let serviceText = NSMutableAttributedString(string: serviceStr)
- serviceText.font(10)
- serviceText.color(.hexStringColor(hexString: "#E7B983"))
- serviceText.yy_setTextHighlight(serviceHL, range: NSRange(location: 0, length: serviceStr.count))
- serviceHL.tapAction = { [weak self] containerView, text, range, rect in
- self?.serviceAction()
- }
- attr.append(serviceText)
-
- // 根据条件决定是否添加《续订说明》相关内容
- if showSubscribe {
- attr.append(blankAttr)
-
- let andAttr = NSMutableAttributedString(string: "和")
- andAttr.font(10)
- andAttr.color(.hexStringColor(hexString: "#A7A7A7"))
- attr.append(andAttr)
-
- attr.append(blankAttr)
-
- let subcribeHL = YYTextHighlight()
- let subcribeStr = "《续订说明》"
- let subcribeText = NSMutableAttributedString(string: subcribeStr)
- subcribeText.font(10)
- subcribeText.color(.hexStringColor(hexString: "#E7B983"))
- subcribeText.yy_setTextHighlight(subcribeHL, range: NSRange(location: 0, length: subcribeStr.count))
- subcribeHL.tapAction = { [weak self] containerView, text, range, rect in
- self?.subscibeAction()
- }
- attr.append(subcribeText)
- }
-
- serviceLabel.attributedText = attr
- }
- // 在需要隐藏《续订说明》时调用此方法
- func hideSubscribeDescription() {
- updateServiceLabelText(showSubscribe: false)
- }
- // 在需要显示《续订说明》时调用此方法
- func showSubscribeDescription() {
- updateServiceLabelText(showSubscribe: true)
- }
-
- lazy var commentView: UIView = {
-
- let view = UIView()
- view.backgroundColor = .white
- return view
- }()
-
- lazy var commentTitleIcon: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "vip_comment_title_icon")
- return imageView
- }()
-
- lazy var comment1: QSLVipCommentCellView = {
-
- let view = QSLVipCommentCellView()
- view.config(name: "用户189****7913", comment: "上班没时间,远程遛娃,非常方便很好用。")
- return view
- }()
-
- lazy var comment2: QSLVipCommentCellView = {
-
- let view = QSLVipCommentCellView()
- view.config(name: "用户189****7913", comment: "用了之后,才发现真的可以找到他。")
- return view
- }()
- lazy var comment3: QSLVipCommentCellView = {
-
- let view = QSLVipCommentCellView()
- view.config(name: "用户189****7913", comment: "轨迹很准,一目了然,奶奶出门遇到危险直接一键报警,我就收到信息了")
- return view
- }()
-
- lazy var tipTitleLabel: UILabel = {
-
- let label = UILabel()
- label.text("温馨提示")
- label.font(12)
- label.textColor = .hexStringColor(hexString: "#000000").withAlphaComponent(0.8)
- return label
- }()
-
- lazy var tipContentLabel: UILabel = {
-
- let label = UILabel()
- label.numberOfLines = 0
- label.text("1 订阅后会从您的iTunes账户中扣除相关费用。如需取消续订,请在当前订阅周期结束前,至少24小时内通过手机“账户设置”的订阅管理关闭自动续费功能。\n2 未成年人请在监护者的陪同下进行购买\n3 购买后不支持退款,请仔细审阅《隐私权政策》《用户协议》和《续订说明》")
- label.font(10)
- label.textColor = .hexStringColor(hexString: "#000000").withAlphaComponent(0.6)
- label.changeLineSpace(space: 5)
- return label
- }()
-
- lazy var bottomContentView: UIView = {
- let view = UIView()
- return view
- }()
-
- lazy var bottomTopView: UIView = {
- let view = UIView()
- view.isHidden = true
- view.backgroundColor = .hexStringColor(hexString: "#FFFED8")
- view.addRadius(radius: 30.rpx)
- return view
- }()
-
-
- lazy var bottomTopLabel: UILabel = {
- let label = UILabel()
- label.text = ""
- return label
- }()
-
- func bottomTopLabelInfo(_ goodInfo : QSLGoodModel) {
- let darkGrayAttributes: [NSAttributedString.Key: Any] = [
- .foregroundColor: UIColor.hexStringColor(hexString: "#404040"),
- .font: UIFont.systemFont(ofSize: 11),
- .paragraphStyle: {
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.alignment = .center
- return paragraphStyle
- }(),
- .kern: -1
- ]
- // 创建绿色文本样式
- let greenAttributes: [NSAttributedString.Key: Any] = [
- .foregroundColor: UIColor.hexStringColor(hexString: "#EE6C1C"),
- .font: UIFont.systemFont(ofSize: 15, weight: .black),
- .paragraphStyle: {
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.alignment = .center
- return paragraphStyle
- }(),
- .kern: -1
- ]
-
- let textArray = goodInfo.text.components(separatedBy: goodInfo.keys.key)
- if textArray.count > 0 && goodInfo.text.count > 0{
- bottomTopView.isHidden = false
- let inputtr = NSMutableAttributedString()
- let titleOneAttr = NSAttributedString(string: textArray.first ?? "", attributes: darkGrayAttributes)
- let titleTwoAttr = NSAttributedString(string: " \(goodInfo.keys.value) ", attributes: greenAttributes)
- inputtr.append(titleOneAttr)
- inputtr.append(titleTwoAttr)
- if textArray.count > 1 {
- let titleThreeAttr = NSAttributedString(string: textArray[1], attributes: darkGrayAttributes)
- inputtr.append(titleThreeAttr)
- }
- bottomTopLabel.attributedText = inputtr
- } else {
- bottomTopView.isHidden = true
- }
- }
-
- lazy var bottomView: UIView = {
-
- let view = UIView()
- view.gradientBackgroundColor(color1: .hexStringColor(hexString: "#00434E"), color2: .hexStringColor(hexString: "#0E5E61"), width: QSLConst.qsl_kScreenW - 24.rpx, height: 50.rpx, direction: .horizontal)
- view.addRadius(radius: 25.rpx)
- return view
- }()
-
- lazy var unlockBtn: UIButton = {
-
- let btn = UIButton()
- btn.setBackgroundImage(UIImage(named: "vip_unlock_btn_bg"), for: .normal)
- btn.title("立即解锁")
- btn.textColor(.hexStringColor(hexString: "#9B3800"))
- btn.mediumFont(18)
- btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 30.rpx, bottom: 0, right: 0)
- btn.addTarget(self, action: #selector(unlockBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var priceIconLabel: UILabel = {
-
- let label = UILabel()
- label.text("¥")
- label.textColor = .hexStringColor(hexString: "#FFF8EF")
- label.font(14)
- return label
- }()
-
- lazy var priceLabel: UILabel = {
-
- let label = UILabel()
- label.text("168")
- label.textColor = .hexStringColor(hexString: "#FFF8EF")
- label.font(24)
- return label
- }()
-
- lazy var goodTypeLabel: UILabel = {
-
- let label = UILabel()
- label.text("/")
- label.textColor = .hexStringColor(hexString: "#FFF8EF")
- label.font(12)
- return label
- }()
-
- lazy var goodOriginalPriceLabel: UILabel = {
-
- let label = UILabel()
- label.text("原价228")
- label.textColor = .hexStringColor(hexString: "#FFF8EF")
- label.font(12)
- label.centerLineText(lineValue: 1, underlineColor: .hexStringColor(hexString: "#FFF8EF"))
- return label
- }()
-
- deinit {
- self.finishHandler?(self.isCancel,self.yearGood)
- }
- override func viewDidLoad() {
- super.viewDidLoad()
-
- initializeView()
-
- updateUI()
-
- requestItemList()
-
- calculateBuyCount()
-
- // if(QSLBaseManager.shared.isLogin()){
- // self.resumeBtn.isHidden = false
- // }else{
- // self.resumeBtn.isHidden = true
- // }
-
- if let type = self.type {
- switch type {
- case .homeRoad:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_show, eventProps: ["id": 1001])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_show, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"entry_point":"track"])
- case .add:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_show, eventProps: ["id": 1002])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_show, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"entry_point":"find_friend"])
- case .friendRoad:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_show, eventProps: ["id": 1003])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_show, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"entry_point":"find_track"])
- case .contact:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_show, eventProps: ["id": 1004])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_show, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"entry_point":"contact"])
- case .mine:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_show, eventProps: ["id": 1006])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_show, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"entry_point":"open_now"])
- case .guideComments,.shortcut:
- print("")
- }
- }
- }
- }
- extension QSLVipController {
-
- @objc func privacyAction() {
-
- let vc = QSLWebViewController()
- vc.webUrl = QSLConfig.AppPrivacyAgreementLink
- vc.title = "隐私政策"
- self.navigationController?.pushViewController(vc, animated: true)
- }
-
- @objc func serviceAction() {
-
- let vc = QSLWebViewController()
- vc.webUrl = QSLConfig.AppServiceAgreementLink
- vc.title = "服务协议"
- self.navigationController?.pushViewController(vc, animated: true)
- }
-
- @objc func subscibeAction() {
-
- let vc = QSLWebViewController()
- vc.webUrl = QSLConfig.AppSubscibeAgreementLink
- vc.title = "续订说明"
- self.navigationController?.pushViewController(vc, animated: true)
- }
-
- @objc func selectBtnAction() {
-
- selectBtn.isSelected = !selectBtn.isSelected
- }
-
- // 恢复按钮点击
- @objc func resumeBtnAction() {
-
- let memberModel = QSLBaseManager.shared.userModel.memberModel
- let expired = memberModel.expired
- if !expired {
- QSLLoading.success(text: "您已经在订阅中,无需恢复")
- return
- }
-
- QSLLoading.show()
- QSLVipManager.shared.restoreAction { isSuccess in
- QSLVipManager.shared.isPaying = false
- if isSuccess {
-
- QSLNetwork().request(.userMember(dict: [:])) { response in
-
- let model = response.mapObject(QSLMemberModel.self, modelKey: "data")
- QSLBaseManager.shared.userModel.memberModel = model
-
- if model.expired {
- QSLBaseManager.shared.saveVipExpiredTime(time: 0)
- } else {
- QSLBaseManager.shared.saveVipExpiredTime(time: model.endTimestamp)
- }
-
- QSLBaseManager.shared.saveUserId(id: model.userId)
-
- if model.endTimestamp > memberModel.endTimestamp {
- QSLLoading.success(text: "恢复成功")
- // 支付成功通知
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
- self.navigationController?.popViewController(animated: true)
- }
- } else {
- QSLLoading.error(text: "没有可供恢复的订阅")
- }
-
- } fail: { code, error in
- QSLLoading.error(text: "没有可供恢复的订阅")
- }
- } else {
- QSLLoading.error(text: "没有可供恢复的订阅")
- }
- }
- }
-
- // 支付按钮点击
- @objc func unlockBtnAction() {
- if let curGood = self.selectGood {
- QSLCountdownManager.shared.selectGood = curGood
- }
-
- switch self.selectGood?.level {
- case 100 :
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_buy_click, eventProps: ["id": 1006])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_click, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"package_type": "day"])
- break
- case 700:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_buy_click, eventProps: ["id": 1005])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_click, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"package_type": "weekly"])
- break;
- case 3100:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_buy_click, eventProps: ["id": 1004])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_click, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"package_type": "monthly"])
- break;
- case 9200:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_buy_click, eventProps: ["id": 1003])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_click, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"package_type": "quarterly"])
- break;
- case 36600:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_buy_click, eventProps: ["id": 1002])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_click, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"package_type": "yearly"])
- break;
- case 3660000:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_buy_click, eventProps: ["id": 1001])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_click, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"package_type": "lifetime"])
- break;
- default:
- break;
- }
- // if !selectBtn.isSelected {
- // self.view.toast(text: "请先同意《隐私权政策》和《用户协议》")
- // return
- // }
-
- let memberModel = QSLBaseManager.shared.userModel.memberModel
-
- if let subscriptionExpired = memberModel.subscriptionExpired, !subscriptionExpired {
- self.view.toast(text: "你已经订阅了")
- return
- }
-
- if goodList.count > 0, let selectGood = self.selectGood {
- QSLLoading.showWithCancel()
- QSLVipManager.shared.startPay(goods: selectGood) { [self] status, outTradeNo in
- QSLVipManager.shared.isPaying = false
- if status == .success {
- QSLLoading.success(text: "支付成功")
- self.isCancel = true
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "success","pay_amount":Int32(selectGood.amount)])
- //弹出是否好评的弹窗
- // QSLGuideusersToCommentManager.commentShare.manageWhetherTriggerPopUpWindow(QSLGuideusersToCommentType.member)
-
- // 引力传递支付事件
- if let selectGood = self.selectGood {
- gravityInstance?.trackPayEvent(withAmount: Int32(selectGood.amount), withPayType: "CNY", withOrderId: outTradeNo, withPayReason: selectGood.name, withPayMethod: "apple")
- }
-
- #if DEBUG
- #else
- //苹果广告奇异果传递支付事件
- QSWikiHandle.shared.addEventResultAttribution(eventDict: ["event_name": "pay", "event_val": selectGood.amount])
- #endif
-
- if let type = self.type {
- switch type {
- case .homeRoad:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_page, eventProps: ["id": 1001])
- case .add:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_page, eventProps: ["id": 1002])
- case .friendRoad:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_page, eventProps: ["id": 1003])
- case .contact:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_page, eventProps: ["id": 1004])
- case .mine:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_page, eventProps: ["id": 1006])
- case .guideComments,.shortcut:
- print("")
- }
- }
- switch self.selectGood?.level {
- case 100 :
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_good, eventProps: ["id": 1])
- break
- case 700:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_good, eventProps: ["id": 5])
- break;
- case 3100:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_good, eventProps: ["id": 9])
- break;
- case 9200:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_good, eventProps: ["id": 13])
- break;
- case 36600:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_good, eventProps: ["id": 17])
- break;
- case 3660000:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_success_good, eventProps: ["id": 21])
- break;
- default:
- break;
- }
- DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
- self.navigationController?.popViewController(animated: true)
- NotificationCenter.default.post(name: QSLNotification.QSLRefreshMember, object: nil)
-
- if(!QSLBaseManager.shared.isLogin()){
- QSLJumpManager.shared.pushToLogin(type: .member)
- }
- }
-
- } else if status == .cancel {
- QSLLoading.error(text: "支付取消")
- payFailAlertTip()
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "cancel","pay_amount":Int32(selectGood.amount)])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_retention_show, eventProps: ["trigger_type":"cancel_payment"])
- } else if status == .fail {
- QSLLoading.error(text: "支付失败")
- payFailAlertTip()
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_result, eventProps: ["is_member":QSLBaseManager.shared.isVip(),"purchase_result": "fail","pay_amount":Int32(selectGood.amount)])
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_retention_show, eventProps: ["trigger_type":"fail"])
- }
- }
- }
- }
-
- func payFailAlertTip() {
- if let currentWindow = UIApplication.keyWindow {
- self.isCancel = true
- QSLRetainPopUpAlertView.alert(view: currentWindow, isOneBtn: true, oneBtnText: "继续支付", oneBtnClosure: { [weak self] in
- self?.unlockBtnAction()
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_retention_click, eventProps: ["button":"continue_payment"])
- },closeBtnClosure: {
- QSEventHandle.eventPush(eventName: QSLGravityConst.new_vip_retention_click, eventProps: ["button":"close"])
- })
- }
- }
-
- @objc func firstCellClickAction() {
-
- for i in 0..<self.goodList.count {
- self.goodList[i].isSelect = false
- }
-
- if self.goodList.count > 0 {
- self.goodList[0].isSelect = true
- self.selectGood = self.goodList[0]
- self.mostCell.config(model: self.goodList[0])
- //选中立即支付
- unlockBtnAction()
- }
-
- switch self.selectGood?.level {
- case 100 :
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1006])
- break
- case 700:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1005])
- break;
- case 3100:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1004])
- break;
- case 9200:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1003])
- break;
- case 36600:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1002])
- break;
- case 3660000:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1001])
- break;
- default:
- break;
- }
-
- self.goodsCollectionView.reloadData()
- }
- }
- extension QSLVipController {
-
- // 请求商品列表
- func requestItemList() {
- // 定义并赋值 itemListDict(根据条件变化)
- var itemListDict: [String: Any] = ["itemListType": 2]
- if UserDefaults.standard.string(forKey: QSLVipController.record_non_member_clicks_to_claim) == nil && self.type == .guideComments {
- itemListDict = ["itemListType": 2, "showExtraText": true]
- // 记录非会员点击领取
- UserDefaults.standard.set("YES", forKey: QSLVipController.record_non_member_clicks_to_claim)
- UserDefaults.standard.synchronize()
- }
-
- // 网络请求时使用 itemListDict 作为参数(关键修复)
- QSLNetwork().request(.vipItemList(dict: itemListDict)) { response in
- // 后续逻辑不变...
- let list = response.mapArray(QSLGoodModel.self, modelKey: "data>list")
- self.goodList = list
-
- if self.goodList.count > 0 {
- self.goodList[0].isSelect = true
- self.selectGood = self.goodList[0]
- QSLCountdownManager.shared.selectGood = self.goodList[0]
- self.mostCell.config(model: self.goodList[0])
-
- let row = ceil(Double(self.goodList.count - 1) / 3.0)
- let height = UX.goodsBgHeight + (row * UX.collectionRowHeight)
- self.goodsBgView.gradientBackgroundColor(color1: .hexStringColor(hexString: "#FFF8F2"), color2: .hexStringColor(hexString: "#FFFFFF"), width: QSLConst.qsl_kScreenW, height: height, direction: .vertical)
-
- self.goodsBgView.snp.updateConstraints { make in
- make.height.equalTo(height)
- }
-
- self.scrollView.snp.makeConstraints { make in
- make.bottom.equalTo(self.mainView)
- }
-
- self.checkRenewalOfProducts()
-
- var yearGood = self.selectGood
- for subGood in self.goodList{
- if(subGood.level == 36600){
- yearGood = subGood
- break
- }
- }
- self.yearGood = yearGood
- }
- self.goodsCollectionView.reloadData()
- } fail: { code, error in
- self.view.toast(text: "加载商品列表失败")
- }
- }
-
- ///检查有没有续订的产品
- func checkRenewalOfProducts() {
- let hasSubscribable = self.goodList.contains(where: { model in
- return model.subscribable == 1
- })
-
- if hasSubscribable == false {
- tipContentLabel.isHidden = true
- hideSubscribeDescription()
- serviceLabel.snp.removeConstraints()
- serviceLabel.snp.makeConstraints { make in
- make.left.equalTo(16)
- make.top.equalTo(comment3.snp.bottom).offset(28.rpx)
- }
- } else {
- tipContentLabel.isHidden = false
- showSubscribeDescription()
- }
- }
-
- // 计算购买人数
- func calculateBuyCount() {
-
- var num = 145883
- if let localNum = UserDefaults.standard.value(forKey: QSLConfig.user_default_local_buy_count) as? Int {
- num = localNum
- }
-
- let randomAddCount = Int.random(in: 1...10)
- num = num + randomAddCount
- UserDefaults.standard.setValue(num, forKey: QSLConfig.user_default_local_buy_count)
- self.peopleCountLabel.text("\(num)人 已开通VIP")
- }
- }
- // MARK: - 设置 CollectionView
- extension QSLVipController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return goodList.count - 1
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-
- let cell = collectionView.dequeueReusableCell(cellType: QSLVipGoodCollectionViewCell.self, cellForRowAt: indexPath)
- let model = self.goodList[indexPath.row + 1]
-
- if self.goodList.count - 1 == 2 {
- cell.config(model: model, type: .big)
- } else {
- cell.config(model: model, type: .small)
- }
-
- return cell
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-
- for i in 0..<self.goodList.count {
- self.goodList[i].isSelect = false
- }
-
- if self.goodList.count > 0 {
- self.goodList[indexPath.row + 1].isSelect = true
- self.selectGood = self.goodList[indexPath.row + 1]
- self.mostCell.config(model: self.goodList[0])
- //选中立即支付
- unlockBtnAction()
- }
-
- switch self.selectGood?.level {
- case 100 :
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1006])
- break
- case 700:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1005])
- break;
- case 3100:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1004])
- break;
- case 9200:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1003])
- break;
- case 36600:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1002])
- break;
- case 3660000:
- QSEventHandle.gravityPush(eventName: QSLGravityConst.vip_good_select, eventProps: ["id": 1001])
- break;
- default:
- break;
- }
-
- self.goodsCollectionView.reloadData()
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
-
- var width = (QSLConst.qsl_kScreenW - 42.0.rpx) / 3.0
-
- if self.goodList.count - 1 == 2 {
- width = (QSLConst.qsl_kScreenW - 36.0.rpx) / 2.0
- }
-
- return CGSize(width: width, height: 134.0.rpx)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
- return 6.rpx
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
- return 3.rpx
- }
- }
- extension QSLVipController {
-
- func updateUI() {
-
- if QSLBaseManager.shared.isLogin() && QSLBaseManager.shared.isVip() {
- let model = QSLBaseManager.shared.userModel.memberModel
- if model.permanent {
-
- self.vipTimeLabel.text("您已是尊贵的永久会员")
- self.bottomContentView.isHidden = true
- } else {
-
- let level = model.memberLevelString()
- let endTime = model.endTimestampString()
- self.vipTimeLabel.text("\(level):\(endTime)到期")
- }
- } else {
-
- self.vipTimeLabel.text("升级VIP会员,解锁全部功能")
- }
- }
-
- func updateSelectGoodUI() {
- var priceText = ""
- var originalPriceText = ""
- if let selectGood = self.selectGood {
- if selectGood.amount.truncatingRemainder(dividingBy: 100) == 0 {
- priceText = "\(Int(selectGood.amount / 100))"
- } else {
- priceText = String(format: "%.2lf", selectGood.amount / 100 )
- }
-
- if selectGood.originalAmount.truncatingRemainder(dividingBy: 100) == 0 {
- originalPriceText = "\(Int(selectGood.originalAmount / 100))"
- } else {
- originalPriceText = String(format: "%.2lf", selectGood.originalAmount / 100 )
- }
- }
- self.priceLabel.text(priceText)
- // self.goodTypeLabel.text("/ \(self.selectGood?.name ?? "")")
- self.goodOriginalPriceLabel.text("原价\(originalPriceText)")
-
- ///底部内容
- bottomTopLabelInfo(self.selectGood ?? QSLGoodModel())
- }
-
- func initializeView() {
-
- self.view.addSubview(vipBg)
- vipBg.snp.makeConstraints { make in
- make.left.top.right.equalTo(0)
- }
-
- self.view.addSubview(backButton)
- backButton.snp.makeConstraints { make in
- make.size.equalTo(100.rpx)
- make.height.equalTo(25.rpx)
- make.left.equalTo(12.rpx)
- make.top.equalTo(QSLConst.qsl_kStatusBarFrameH)
- }
-
- self.view.addSubview(peopleCountView)
- peopleCountView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 212.rpx, height: 24.rpx))
- make.right.equalTo(-13.rpx)
- make.centerY.equalTo(backButton.snp.centerY)
- }
-
- peopleCountView.addSubview(peopleAvatarImageView)
- peopleAvatarImageView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 72.rpx, height: 16.6.rpx))
- make.left.equalTo(3.rpx)
- make.centerY.equalTo(peopleCountView.snp.centerY)
- }
-
- peopleCountView.addSubview(peopleCountLabel)
- peopleCountLabel.snp.makeConstraints { make in
- make.left.equalTo(peopleAvatarImageView.snp.right).offset(7.rpx)
- make.centerY.equalTo(peopleCountView.snp.centerY)
- }
-
- self.view.addSubview(scrollView)
- scrollView.snp.makeConstraints { make in
- make.left.right.equalTo(0)
- make.top.equalTo(QSLConst.qsl_kNavFrameH)
- make.bottom.equalTo(0)
- }
-
- scrollView.addSubview(cardBannerImageView)
- cardBannerImageView.snp.makeConstraints { make in
- make.top.equalTo(0)
- make.centerX.equalToSuperview()
- make.width.equalTo(336.rpx)
- make.height.equalTo(108.rpx)
- }
-
- cardBannerImageView.addSubview(vipTimeLabel)
- vipTimeLabel.snp.makeConstraints { make in
- make.left.equalTo(23.rpx)
- make.bottom.equalTo(-19.rpx)
- }
-
- scrollView.addSubview(funcBannerImageView)
- funcBannerImageView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 336.rpx, height: 172.rpx))
- make.centerX.equalToSuperview()
- make.top.equalTo(cardBannerImageView.snp.bottom).offset(14.rpx)
- }
-
- scrollView.addSubview(mainView)
- mainView.snp.makeConstraints { make in
- make.left.right.equalTo(0)
- make.top.equalTo(funcBannerImageView.snp.bottom).offset(-24.rpx)
- make.width.equalTo(QSLConst.qsl_kScreenW)
- // make.height.equalTo(800.rpx)
- }
-
- let goodsBgHeight = 54.rpx + UX.mostCellHeight
- mainView.addSubview(goodsBgView)
- goodsBgView.snp.makeConstraints { make in
- make.top.left.right.equalTo(0)
- make.width.equalTo(QSLConst.qsl_kScreenW)
- make.height.equalTo(goodsBgHeight)
- }
-
- goodsBgView.addSubview(vipGoodsTitleIcon)
- vipGoodsTitleIcon.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 117.rpx, height: 26.rpx))
- make.left.equalTo(20.rpx)
- make.top.equalTo(16.rpx)
- }
-
- goodsBgView.addSubview(resumeBtn)
- resumeBtn.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 75.rpx, height: 16.rpx))
- make.right.equalTo(-18.rpx)
- make.centerY.equalTo(vipGoodsTitleIcon.snp.centerY)
- }
-
- goodsBgView.addSubview(mostCell)
- mostCell.snp.makeConstraints { make in
- make.left.equalTo(12.rpx)
- make.right.equalTo(-16.rpx)
- make.height.equalTo(113.rpx)
- make.top.equalTo(vipGoodsTitleIcon.snp.bottom).offset(10.rpx)
- }
-
- goodsBgView.addSubview(goodsCollectionView)
- goodsCollectionView.snp.makeConstraints { make in
- make.left.equalTo(12.rpx)
- make.right.equalTo(-18.rpx)
- make.bottom.equalTo(-20.rpx)
- make.top.equalTo(mostCell.snp.bottom).offset(3.rpx)
- }
-
- // goodsBgView.addSubview(selectBtn)
- // selectBtn.snp.makeConstraints { make in
- // make.size.equalTo(CGSize(width: 12.rpx, height: 12.rpx))
- // make.left.equalTo(23.rpx)
- // make.top.equalTo(goodsCollectionView.snp.bottom).offset(16.rpx)
- // }
- //
- // goodsBgView.addSubview(serviceLabel)
- // serviceLabel.snp.makeConstraints { make in
- // make.left.equalTo(selectBtn.snp.right).offset(2.rpx)
- // make.centerY.equalTo(selectBtn.snp.centerY)
- // }
-
- mainView.addSubview(commentView)
- commentView.snp.makeConstraints { make in
- make.left.right.equalTo(0)
- make.top.equalTo(goodsBgView.snp.bottom).offset(8.rpx)
- make.height.equalTo(525.rpx + QSLConst.qsl_kTabbarBottom)
- make.bottom.equalTo(0)
- }
-
- commentView.addSubview(commentTitleIcon)
- commentTitleIcon.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 83.rpx, height: 26.rpx))
- make.top.equalTo(16.rpx)
- make.left.equalTo(12.rpx)
- }
-
- let commentHeight1 = "上班没时间,远程遛娃,非常方便很好用。".heightAccording(width: QSLConst.qsl_kScreenW - 52.rpx - 12.rpx, font: .textF(15), lineSpacing: 2) + 35.rpx
- commentView.addSubview(comment1)
- comment1.snp.makeConstraints { make in
- make.left.right.equalTo(0)
- make.top.equalTo(commentTitleIcon.snp.bottom).offset(16.rpx)
- make.height.equalTo(commentHeight1)
- }
-
- let commentHeight2 = "用了之后,才发现真的可以找到他。".heightAccording(width: QSLConst.qsl_kScreenW - 52.rpx - 12.rpx, font: .textF(15), lineSpacing: 2) + 35.rpx
- commentView.addSubview(comment2)
- comment2.snp.makeConstraints { make in
- make.left.right.equalTo(0)
- make.top.equalTo(comment1.snp.bottom).offset(30.rpx)
- make.height.equalTo(commentHeight2)
- }
-
- let commentHeight3 = "轨迹很准,一目了然,奶奶出门遇到危险直接一键报警,我就收到信息了".heightAccording(width: QSLConst.qsl_kScreenW - 52.rpx - 12.rpx, font: .textF(15), lineSpacing: 2) + 35.rpx
- commentView.addSubview(comment3)
- comment3.snp.makeConstraints { make in
- make.left.right.equalTo(0)
- make.top.equalTo(comment2.snp.bottom).offset(30.rpx)
- make.height.equalTo(commentHeight3)
- }
-
- // commentView.addSubview(tipTitleLabel)
- // tipTitleLabel.snp.makeConstraints { make in
- // make.left.equalTo(16)
- // make.top.equalTo(comment3.snp.bottom).offset(28)
- // }
- commentView.addSubview(tipContentLabel)
- tipContentLabel.snp.makeConstraints { make in
- make.left.equalTo(16)
- make.right.equalTo(-16)
- make.top.equalTo(comment3.snp.bottom).offset(11)
- }
-
- commentView.addSubview(serviceLabel)
- serviceLabel.snp.makeConstraints { make in
- make.left.equalTo(16)
- make.top.equalTo(tipContentLabel.snp.bottom).offset(28.rpx)
- }
-
- scrollView.snp.makeConstraints { make in
- make.bottom.equalTo(mainView)
- }
-
- self.view.addSubview(bottomContentView)
- bottomContentView.snp.makeConstraints { make in
- make.left.equalTo(12.rpx)
- make.right.equalTo(-12.rpx)
- make.bottom.equalTo(-QSLConst.qsl_kTabbarBottom)
- make.height.equalTo(72.rpx)
- }
-
- bottomContentView.addSubview(bottomTopView)
- bottomTopView.snp.makeConstraints { make in
- make.left.equalToSuperview()
- make.right.equalToSuperview()
- make.top.equalToSuperview()
- make.height.equalTo(60.rpx)
- }
-
- bottomTopView.addSubview(bottomTopLabel)
- bottomTopLabel.snp.makeConstraints { make in
- make.left.equalToSuperview().offset(22)
- make.top.equalToSuperview()
- make.height.equalTo(21.rpx)
- }
-
- bottomContentView.addSubview(bottomView)
- bottomView.snp.makeConstraints { make in
- make.left.equalToSuperview()
- make.right.equalToSuperview()
- make.bottom.equalToSuperview()
- make.height.equalTo(50.rpx)
- }
-
- bottomView.addSubview(unlockBtn)
- unlockBtn.snp.makeConstraints { make in
- make.right.top.bottom.equalTo(0)
- make.width.equalTo(165.rpx)
- }
-
- bottomView.addSubview(priceIconLabel)
- priceIconLabel.snp.makeConstraints { make in
- make.left.equalTo(20.rpx)
- make.bottom.equalTo(-12.rpx)
- }
-
- bottomView.addSubview(priceLabel)
- priceLabel.snp.makeConstraints { make in
- make.left.equalTo(priceIconLabel.snp.right).offset(2.rpx)
- make.bottom.equalTo(-10.rpx)
- }
-
- bottomView.addSubview(goodTypeLabel)
- goodTypeLabel.snp.makeConstraints { make in
- make.left.equalTo(priceLabel.snp.right).offset(2.rpx)
- make.bottom.equalTo(-14.rpx)
- }
-
- bottomView.addSubview(goodOriginalPriceLabel)
- goodOriginalPriceLabel.snp.makeConstraints { make in
- make.left.equalTo(goodTypeLabel.snp.right).offset(2.rpx)
- make.centerY.equalTo(goodTypeLabel.snp.centerY)
- }
-
- }
- }
|