|
|
@@ -48,6 +48,31 @@ class QSLVipController: QSLBaseController {
|
|
|
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()
|
|
|
@@ -103,6 +128,18 @@ class QSLVipController: QSLBaseController {
|
|
|
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 goodsCollectionView: UICollectionView = {
|
|
|
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
|
@@ -278,6 +315,8 @@ class QSLVipController: QSLBaseController {
|
|
|
|
|
|
requestItemList()
|
|
|
|
|
|
+ calculateBuyCount()
|
|
|
+
|
|
|
if let type = self.type {
|
|
|
switch type {
|
|
|
case .homeRoad:
|
|
|
@@ -318,6 +357,53 @@ extension QSLVipController {
|
|
|
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() {
|
|
|
|
|
|
switch self.selectGood?.level {
|
|
|
@@ -348,6 +434,13 @@ extension QSLVipController {
|
|
|
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.show()
|
|
|
QSLVipManager.shared.startPay(goods: selectGood) { status, outTradeNo in
|
|
|
@@ -431,9 +524,10 @@ extension QSLVipController {
|
|
|
|
|
|
extension QSLVipController {
|
|
|
|
|
|
+ // 请求商品列表
|
|
|
func requestItemList() {
|
|
|
|
|
|
- QSLNetwork().request(.vipItemList(dict: [:])) { response in
|
|
|
+ QSLNetwork().request(.vipItemList(dict: ["itemListType": 1])) { response in
|
|
|
let list = response.mapArray(QSLGoodModel.self, modelKey: "data>list")
|
|
|
self.goodList = list
|
|
|
if self.goodList.count > 0 {
|
|
|
@@ -445,6 +539,20 @@ extension QSLVipController {
|
|
|
self.view.toast(text: "加载商品列表失败")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 计算购买人数
|
|
|
+ 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
|
|
|
@@ -561,6 +669,26 @@ extension QSLVipController {
|
|
|
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)
|
|
|
@@ -600,6 +728,7 @@ extension QSLVipController {
|
|
|
mainView.addSubview(goodsBgView)
|
|
|
goodsBgView.snp.makeConstraints { make in
|
|
|
make.top.left.right.equalTo(0)
|
|
|
+ make.width.equalTo(QSLConst.qsl_kScreenW)
|
|
|
make.height.equalTo(255.rpx)
|
|
|
}
|
|
|
|
|
|
@@ -610,6 +739,13 @@ extension QSLVipController {
|
|
|
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(goodsCollectionView)
|
|
|
goodsCollectionView.snp.makeConstraints { make in
|
|
|
make.left.equalTo(18.rpx)
|