diff --git a/MoviaBox/Base/Networking/API/SPWalletAPI.swift b/MoviaBox/Base/Networking/API/SPWalletAPI.swift index 022bbdd..90871d0 100644 --- a/MoviaBox/Base/Networking/API/SPWalletAPI.swift +++ b/MoviaBox/Base/Networking/API/SPWalletAPI.swift @@ -24,7 +24,7 @@ class SPWalletAPI: NSObject { } ///创建内购订单 - static func requestCreateOrder(payId: String, shortPlayId: String = "0", videoId: String = "0", completer: ((_ orderModel: SPIAPOrderModel?) -> Void)?) { + static func requestCreateOrder(payId: String, shortPlayId: String, videoId: String, completer: ((_ orderModel: SPIAPOrderModel?) -> Void)?) { var param = SPNetworkParameters(path: "/createOrder") param.parameters = [ "payment_channel" : "apple", diff --git a/MoviaBox/Class/Player/Controller/SPPlayerDetailViewController.swift b/MoviaBox/Class/Player/Controller/SPPlayerDetailViewController.swift index df91136..0b7fef4 100644 --- a/MoviaBox/Class/Player/Controller/SPPlayerDetailViewController.swift +++ b/MoviaBox/Class/Player/Controller/SPPlayerDetailViewController.swift @@ -78,11 +78,17 @@ class SPPlayerDetailViewController: SPPlayerListViewController { override func play() { guard let videoInfo = self.viewModel.currentPlayer?.videoInfo else { return } + //视频需要付费 if videoInfo.is_lock == true { self.pause() + //我的金币 + let myCoin = SPLoginManager.manager.userInfo?.coin_left_total ?? 0 + //解锁视频需要的金币 + let videoCoin = videoInfo.coins ?? 0 - self.onPlayBuy() - + if myCoin < videoCoin { + self.onPlayBuy() + } return } @@ -149,7 +155,11 @@ extension SPPlayerDetailViewController { ///打开支付页面 private func onPlayBuy() { + guard let videoInfo = self.viewModel.currentPlayer?.videoInfo else { return } + let view = SPPlayBuyView() + view.shortPlayId = videoInfo.short_play_id + view.videoId = videoInfo.short_play_video_id view.present(in: nil) } diff --git a/MoviaBox/Class/Player/View/SPPlayBuyView.swift b/MoviaBox/Class/Player/View/SPPlayBuyView.swift index f746314..041b7cf 100644 --- a/MoviaBox/Class/Player/View/SPPlayBuyView.swift +++ b/MoviaBox/Class/Player/View/SPPlayBuyView.swift @@ -9,6 +9,18 @@ import UIKit class SPPlayBuyView: HWPanModalContentView { + var shortPlayId: String? { + didSet { + rechargeView.shortPlayId = shortPlayId + memberView.shortPlayId = shortPlayId + } + } + var videoId: String? { + didSet { + rechargeView.videoId = videoId + memberView.videoId = videoId + } + } //MARK: UI属性 private lazy var bgView: UIImageView = { @@ -54,11 +66,18 @@ class SPPlayBuyView: HWPanModalContentView { private lazy var rechargeView: SPCoinRechargeView = { let view = SPCoinRechargeView() + view.userInfo = SPLoginManager.manager.userInfo + view.rechargeFinishHandle = { [weak self] in + self?.handleBuyFinish() + } return view }() private lazy var memberView: SPMemberRechargeView = { let view = SPMemberRechargeView() + view.buyFinishHandle = { [weak self] in + self?.handleBuyFinish() + } return view }() @@ -95,6 +114,17 @@ class SPPlayBuyView: HWPanModalContentView { } } +extension SPPlayBuyView { + ///购买成功 + private func handleBuyFinish() { + SPLoginManager.manager.updateUserInfo { [weak self] in + guard let self = self else { return } + self.rechargeView.userInfo = SPLoginManager.manager.userInfo + } + + } +} + extension SPPlayBuyView { private func _setupUI() { diff --git a/MoviaBox/Class/Wallet/Model/SPBuyRecordsModel.swift b/MoviaBox/Class/Wallet/Model/SPBuyRecordsModel.swift index fa83784..8b0f538 100644 --- a/MoviaBox/Class/Wallet/Model/SPBuyRecordsModel.swift +++ b/MoviaBox/Class/Wallet/Model/SPBuyRecordsModel.swift @@ -10,6 +10,14 @@ import SmartCodable class SPBuyRecordsModel: SPModel, SmartCodable { + var short_play_id: String? + var coins: Int? + var short_play_video_id: String? + var coin_type: Int? + var created_at: String? + var episode: String? + var image_url: String? + var name: String? } diff --git a/MoviaBox/Class/Wallet/View/SPCoinRechargeView.swift b/MoviaBox/Class/Wallet/View/SPCoinRechargeView.swift index a618305..5c46d1a 100644 --- a/MoviaBox/Class/Wallet/View/SPCoinRechargeView.swift +++ b/MoviaBox/Class/Wallet/View/SPCoinRechargeView.swift @@ -30,6 +30,9 @@ class SPCoinRechargeView: UIView { } } + var shortPlayId: String? + var videoId: String? + //MARK: UI属性 private lazy var coinNameLabel: UILabel = { let label = UILabel() @@ -136,8 +139,9 @@ extension SPCoinRechargeView: UICollectionViewDelegate, UICollectionViewDataSour guard let model = self.dataArr?[indexPath.row] else { return } - SPIAPManager.manager.startRecharge(model: model) { [weak self] finish in + SPIAPManager.manager.startRecharge(model: model, shortPlayId: shortPlayId, videoId: videoId) { [weak self] finish in if finish { + SPToast.show(text: "success".localized) self?.rechargeFinishHandle?() } } diff --git a/MoviaBox/Class/Wallet/View/SPConsumptionRecordsCell.swift b/MoviaBox/Class/Wallet/View/SPConsumptionRecordsCell.swift index 203b8ae..1bcd53a 100644 --- a/MoviaBox/Class/Wallet/View/SPConsumptionRecordsCell.swift +++ b/MoviaBox/Class/Wallet/View/SPConsumptionRecordsCell.swift @@ -11,7 +11,10 @@ class SPConsumptionRecordsCell: SPTableViewCell { var model: SPBuyRecordsModel? { didSet { - + titleLabel.text = "Purchase Single Episode".localized + timeLabel.text = model?.created_at + desLabel.text = "Ep.\(model?.episode ?? "") \(model?.name ?? "")" + coinLabel.text = "-\(model?.coins ?? 0) Coins" } } @@ -46,10 +49,6 @@ class SPConsumptionRecordsCell: SPTableViewCell { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - titleLabel.text = "Purchase Single Episode" - timeLabel.text = "2024-6-10 23:41:18" - desLabel.text = "Ep.8 Romantic Flash Marriage In Progress" - coinLabel.text = "-500 Coins" _setupUI() } diff --git a/MoviaBox/Class/Wallet/View/SPMemberRechargeView.swift b/MoviaBox/Class/Wallet/View/SPMemberRechargeView.swift index 0f33daa..b993528 100644 --- a/MoviaBox/Class/Wallet/View/SPMemberRechargeView.swift +++ b/MoviaBox/Class/Wallet/View/SPMemberRechargeView.swift @@ -27,6 +27,9 @@ class SPMemberRechargeView: UIView { } } + var shortPlayId: String? + var videoId: String? + //MARK: UI属性 private lazy var titleLabel: UILabel = { let label = UILabel() @@ -101,8 +104,9 @@ extension SPMemberRechargeView: UICollectionViewDelegate, UICollectionViewDataSo func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let model = dataArr?[indexPath.row] else { return } - SPIAPManager.manager.startRecharge(model: model) { [weak self] finish in + SPIAPManager.manager.startRecharge(model: model, shortPlayId: shortPlayId, videoId: videoId) { [weak self] finish in if finish { + SPToast.show(text: "success".localized) self?.buyFinishHandle?() } } diff --git a/MoviaBox/Libs/SPIAPManager/SPIAPManager.swift b/MoviaBox/Libs/SPIAPManager/SPIAPManager.swift index 5103cb7..623e4c0 100644 --- a/MoviaBox/Libs/SPIAPManager/SPIAPManager.swift +++ b/MoviaBox/Libs/SPIAPManager/SPIAPManager.swift @@ -28,7 +28,7 @@ class SPIAPManager: NSObject { private var payId: String? ///开始内购 - func startRecharge(model: SPPayTemplateItem, handler: CompletionHandler? = nil) { + func startRecharge(model: SPPayTemplateItem, shortPlayId: String? = nil, videoId: String? = nil, handler: CompletionHandler? = nil) { guard let payId = model.id else { handler?(false) return @@ -39,7 +39,7 @@ class SPIAPManager: NSObject { SPHUD.show() - SPWalletAPI.requestCreateOrder(payId: payId) { orderModel in + SPWalletAPI.requestCreateOrder(payId: payId, shortPlayId: shortPlayId ?? "0", videoId: videoId ?? "0") { orderModel in guard let orderModel = orderModel else { SPHUD.dismiss() self.completionHandler?(false) diff --git a/MoviaBox/Source/en.lproj/Localizable.strings b/MoviaBox/Source/en.lproj/Localizable.strings index d4319e8..ed68531 100644 --- a/MoviaBox/Source/en.lproj/Localizable.strings +++ b/MoviaBox/Source/en.lproj/Localizable.strings @@ -7,6 +7,7 @@ */ "Home" = "Home"; +"success" = "success"; "For You" = "For You"; "Error" = "Error"; "Profile" = "Profile"; @@ -88,6 +89,7 @@ "This episode is locked" = "This episode is locked"; "Unlock now for" = "Unlock now for"; "Unlock the previous episode" = "Unlock the previous episode"; +"Purchase Single Episode" = "Purchase Single Episode"; ///请购买上一集提示 "kAlertMessage_01" = "The previous episode of this series has not been unlocked yet. Please unlock the previous episode first.";