Browse Source

视频包购买次数自测完毕,还差翻译

100Years 1 week ago
parent
commit
f90fad74e1

+ 1 - 1
AIEmoji/Business/Data/TSDBTimesManager.swift

@@ -41,7 +41,7 @@ class TSDBTimesManager: Object {
     
     
     func reduceTimes(num:Int = 1){
     func reduceTimes(num:Int = 1){
         TSRMShared.writeThread {
         TSRMShared.writeThread {
-            times = times - num
+            times = max(0, times - num)
             dePrint("视频可用次数TSDBTimesManager.times=\(times)")
             dePrint("视频可用次数TSDBTimesManager.times=\(times)")
         }
         }
     }
     }

+ 48 - 35
AIEmoji/Business/TSPurchaseMembershipVC/TSPurchaseVideoTimesVC/TSPurchaseVideoTimesVC.swift

@@ -15,6 +15,9 @@ class TSPurchaseVideoTimesVM : ObservableObject{
     
     
     /// 订阅publisher
     /// 订阅publisher
     let buyPublisher  = PassthroughSubject<Bool,Never>()
     let buyPublisher  = PassthroughSubject<Bool,Never>()
+    
+    /// 订阅publisher
+    let closePagePublisher  = PassthroughSubject<Bool,Never>()
 }
 }
 
 
 
 
@@ -51,8 +54,6 @@ class TSPurchaseVideoTimesVC: TSBaseVC {
     
     
     
     
     override func createView() {
     override func createView() {
-        addNormalNavBarView()
-        setPageTitle("")
         if isShowAlertModel {
         if isShowAlertModel {
             setUpAlerView()
             setUpAlerView()
         }else{
         }else{
@@ -71,14 +72,56 @@ class TSPurchaseVideoTimesVC: TSBaseVC {
     
     
     func addNotifaction() {
     func addNotifaction() {
         viewModel.buyPublisher.receive(on: DispatchQueue.main).sink { [weak self] _ in
         viewModel.buyPublisher.receive(on: DispatchQueue.main).sink { [weak self] _ in
-            guard let self = self else {
-                return
-            }
+            guard let self = self else { return }
             isHandlePurchaseStateChanged = true
             isHandlePurchaseStateChanged = true
             PurchaseManager.default.pay(for: self.viewModel.selectedType)
             PurchaseManager.default.pay(for: self.viewModel.selectedType)
         }.store(in: &cancellabel)
         }.store(in: &cancellabel)
+        
+        viewModel.closePagePublisher.receive(on: DispatchQueue.main).sink { [weak self] _ in
+            guard let self = self else { return }
+            closePage()
+        }.store(in: &cancellabel)
     }
     }
     
     
+}
+
+extension TSPurchaseVideoTimesVC {
+    
+    func setUpFullView(){
+        addNormalNavBarView()
+        setPageTitle("")
+        
+        contentView.snp.updateConstraints { make in
+            make.top.equalTo(0)
+        }
+      
+        let bgColorView = UIView(frame: UIScreen.main.bounds)
+        bgColorView.addGradientBg(colors: ["#13052C".uiCGColor,"#160B2C".uiCGColor],startPoint: CGPoint(x: 0.5, y: 0),endPoint: CGPoint(x: 0.5, y: 1.0))
+        contentView.addSubview(bgColorView)
+        
+        
+        contentView.addSubview(fullVC.view)
+        fullVC.view.snp.makeConstraints { make in
+            make.leading.trailing.bottom.top.equalToSuperview()
+        }
+    }
+    
+}
+extension TSPurchaseVideoTimesVC {
+    
+    func setUpAlerView(){
+        setNavBarViewHidden(true)
+        self.view.backgroundColor = .black.withAlphaComponent(0.5)
+        
+        contentView.addSubview(alertVC.view)
+        alertVC.view.snp.makeConstraints { make in
+            make.leading.trailing.bottom.top.equalToSuperview()
+        }
+    }
+}
+
+
+extension TSPurchaseVideoTimesVC {
     func onPurchaseStateChanged(){
     func onPurchaseStateChanged(){
         PurchaseManager.default.onPurchaseStateChanged = { [weak self] manager,state,object in
         PurchaseManager.default.onPurchaseStateChanged = { [weak self] manager,state,object in
             guard let self = self else { return }
             guard let self = self else { return }
@@ -162,34 +205,4 @@ class TSPurchaseVideoTimesVC: TSBaseVC {
     }
     }
 }
 }
 
 
-extension TSPurchaseVideoTimesVC {
-    
-    func setUpFullView(){
-        contentView.snp.updateConstraints { make in
-            make.top.equalTo(0)
-        }
-      
-        let bgColorView = UIView(frame: UIScreen.main.bounds)
-        bgColorView.addGradientBg(colors: ["#13052C".uiCGColor,"#160B2C".uiCGColor],startPoint: CGPoint(x: 0.5, y: 0),endPoint: CGPoint(x: 0.5, y: 1.0))
-        contentView.addSubview(bgColorView)
-        
-        
-        contentView.addSubview(fullVC.view)
-        fullVC.view.snp.makeConstraints { make in
-            make.leading.trailing.bottom.top.equalToSuperview()
-        }
-    }
-    
-}
-extension TSPurchaseVideoTimesVC {
-    
-    func setUpAlerView(){
 
 
-        self.view.backgroundColor = .black.withAlphaComponent(0.5)
-        
-        contentView.addSubview(alertVC.view)
-        alertVC.view.snp.makeConstraints { make in
-            make.leading.trailing.bottom.top.equalToSuperview()
-        }
-    }
-}

+ 83 - 76
AIEmoji/Business/TSPurchaseMembershipVC/TSPurchaseVideoTimesVC/View/TSPurchaseVideoTimesAlertView.swift

@@ -13,95 +13,102 @@ struct TSPurchaseVideoTimesAlertView :View {
     @State var isExpand: Bool = false
     @State var isExpand: Bool = false
     var body: some View {
     var body: some View {
         VStack {
         VStack {
+            let limit = "You've hit your limit. Get more effect credits below.".localized
             
             
             Spacer()
             Spacer()
-            
-            VStack {
-                Spacer().frame(height: 24)
-                Text("Limit Reached".localized)
-                    .font(.font(size: 22,weight: .medium))
-                    .foregroundColor(.white)
-                    .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
-                
-                Spacer().frame(height: 16)
-                Text("You've hit your weekly limit. Get more effect credits below.".localized)
-                    .foregroundColor(.white.opacity(0.7))
-                    .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
-                
-                Spacer().frame(height: 15)
-                VStack(alignment: .leading, spacing: 20, content: {
-                    TSPurchaseVideoTimesCellView(type: .purchase(.videoNum1), selectedType: $viewModel.selectedType)
-                        .onTapGesture {
-                            viewModel.selectedType = .purchase(.videoNum1)
-                        }
-                    ZStack(alignment: .topTrailing) {
-                        TSPurchaseVideoTimesCellView(type: .purchase(.videoNum2), selectedType: $viewModel.selectedType)
+            ZStack(alignment: .topTrailing) {
+                VStack {
+                    Spacer().frame(height: 24)
+                    Text("Limit Reached".localized)
+                        .font(.font(size: 22,weight: .medium))
+                        .foregroundColor(.white)
+                        .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
+                    
+                    Spacer().frame(height: 16)
+                    Text(limit)
+                        .foregroundColor(.white.opacity(0.7))
+                        .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
+                    
+                    Spacer().frame(height: 15)
+                    VStack(alignment: .leading, spacing: 20, content: {
+                        TSPurchaseVideoTimesCellView(type: .purchase(.videoNum1), selectedType: $viewModel.selectedType)
                             .onTapGesture {
                             .onTapGesture {
-                                viewModel.selectedType = .purchase(.videoNum2)
+                                viewModel.selectedType = .purchase(.videoNum1)
                             }
                             }
-                        TSPurchaseVideoTimesRecView()
-                            .offset(x:-30,y:-14)
-                    }
-                    TSPurchaseVideoTimesCellView(type: .purchase(.videoNum3), selectedType: $viewModel.selectedType)
-                        .onTapGesture {
-                            viewModel.selectedType = .purchase(.videoNum3)
+                        ZStack(alignment: .topTrailing) {
+                            TSPurchaseVideoTimesCellView(type: .purchase(.videoNum2), selectedType: $viewModel.selectedType)
+                                .onTapGesture {
+                                    viewModel.selectedType = .purchase(.videoNum2)
+                                }
+                            TSPurchaseVideoTimesRecView()
+                                .offset(x:-30,y:-14)
                         }
                         }
-                }).multilineTextAlignment(.center).font(.font(size: 16,weight:.regular)).foregroundColor(.white)
-                
-                Spacer().frame(height: 44)
-                
-                
-                Button {
-                    viewModel.buyPublisher.send(true)
-                } label: {
-                    ZStack {
-                        Image(.purchaseVideoTimesBtnbg)
-                        Text("Purchase".localized)
-                            .font(.font(size: 16,weight: .medium))
-                            .foregroundColor(.white)
-                    }.frame(maxWidth: .infinity ,minHeight: 48.0,maxHeight: 48.0)
-                }
-                
-                
-                VStack{
-                    Spacer().frame(height: 15)
+                        TSPurchaseVideoTimesCellView(type: .purchase(.videoNum3), selectedType: $viewModel.selectedType)
+                            .onTapGesture {
+                                viewModel.selectedType = .purchase(.videoNum3)
+                            }
+                    }).multilineTextAlignment(.center).font(.font(size: 16,weight:.regular)).foregroundColor(.white)
+                    
+                    Spacer().frame(height: 44)
+                    
+                    
                     Button {
                     Button {
-                        withAnimation(.easeInOut(duration: 0.3)) {
-                            isExpand.toggle()
-                        }
+                        viewModel.buyPublisher.send(true)
                     } label: {
                     } label: {
-                        HStack(spacing: 4) {
-                            Text("View Credit Rules".localized)
-                                .font(.font(size: 12,weight: .regular))
-                                .foregroundColor(.white.opacity(0.7))
-                            Image(isExpand ? .chatUpArrow : .chatDownArrow)
-                        }
+                        ZStack {
+                            Image(.purchaseVideoTimesBtnbg)
+                            Text("Purchase".localized)
+                                .font(.font(size: 16,weight: .medium))
+                                .foregroundColor(.white)
+                        }.frame(maxWidth: .infinity ,minHeight: 48.0,maxHeight: 48.0)
                     }
                     }
-                }
-                
-                if isExpand {
                     
                     
-                    Spacer().frame(height: 10)
                     
                     
-                    VStack(alignment: .leading, spacing: 8, content: {
-                        TSPurchaseVideoTextLineView(image: .purchaseVideoTimesCheck, text: "Only VIP can purchase video effect credits".localized)
-                        TSPurchaseVideoTextLineView(image: .purchaseVideoTimesCheck, text: "Credits can be applied to all video generations".localized)
-                        TSPurchaseVideoTextLineView(image: .purchaseVideoTimesCheck, text: "Credits never expire and can be purchased repeatedly".localized)
-                        TSPurchaseVideoTextLineView(image: .purchaseVideoTimesCheck, text: "All unused credits will be lost if the app is uninstalled".localized)
-                    })
-                    .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
+                    VStack{
+                        Spacer().frame(height: 15)
+                        Button {
+                            withAnimation(.easeInOut(duration: 0.3)) {
+                                isExpand.toggle()
+                            }
+                        } label: {
+                            HStack(spacing: 4) {
+                                Text("View Credit Rules".localized)
+                                    .font(.font(size: 12,weight: .regular))
+                                    .foregroundColor(.white.opacity(0.7))
+                                Image(isExpand ? .chatUpArrow : .chatDownArrow)
+                            }
+                        }
+                    }
                     
                     
-                    Spacer().frame(height: 24 + k_Height_safeAreaInsetsBottom())
-                }else{
-                    Spacer().frame(height: k_Height_safeAreaInsetsBottom())
-                }
+                    if isExpand {
+                        
+                        Spacer().frame(height: 10)
+                        
+                        VStack(alignment: .leading, spacing: 8, content: {
+                            TSPurchaseVideoTextLineView(image: .purchaseVideoTimesCheck, text: "Only VIP can purchase video effect credits".localized)
+                            TSPurchaseVideoTextLineView(image: .purchaseVideoTimesCheck, text: "Credits can be applied to all video generations".localized)
+                            TSPurchaseVideoTextLineView(image: .purchaseVideoTimesCheck, text: "Credits never expire and can be purchased repeatedly".localized)
+                            TSPurchaseVideoTextLineView(image: .purchaseVideoTimesCheck, text: "All unused credits will be lost if the app is uninstalled".localized)
+                        })
+                        .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
+                        
+                        Spacer().frame(height: 24 + k_Height_safeAreaInsetsBottom())
+                    }else{
+                        Spacer().frame(height: k_Height_safeAreaInsetsBottom())
+                    }
 
 
+                }
+                .padding(.horizontal,16)
+                .background(
+                    Color.hex("#261840").cornerRadius([.topLeading,.topTrailing], 20)
+                )
+                
+                Button {
+                    viewModel.closePagePublisher.send(true)
+                } label: {
+                    Image(.closeClear).resizable().frame(width: 24, height: 24)
+                }.offset(x:-8,y:8)
             }
             }
-            .padding(.horizontal,16)
-            .background(
-                Color.hex("#261840").cornerRadius([.topLeading,.topTrailing], 20)
-            )
-
         }
         }
         .ignoresSafeArea()
         .ignoresSafeArea()
     }
     }

+ 1 - 1
AIEmoji/Business/TSPurchaseMembershipVC/TSPurchaseVideoTimesVC/View/TSPurchaseVideoTimesView.swift

@@ -133,7 +133,7 @@ struct TSPurchaseVideoTimesCellView: View {
             
             
             HStack(spacing:8) {
             HStack(spacing:8) {
                 Image(.stopWatch).resizable().frame(width: 28, height: 28)
                 Image(.stopWatch).resizable().frame(width: 28, height: 28)
-                Text("\(type.purchaseNum ?? 0) " + "Times".localized)
+                Text(String(format: "%d% Times".localized, type.purchaseNum ?? 0))
                 Spacer()
                 Spacer()
                 Text(PurchaseManager.default.price(for: type) ?? "--")
                 Text(PurchaseManager.default.price(for: type) ?? "--")
             }
             }

+ 1 - 2
AIEmoji/Business/TSSetingVC/SetingVC/TSSetingViewModel.swift

@@ -97,8 +97,7 @@ class TSSetingViewModel: ObservableObject {
     }
     }
     
     
     func purchaseVideoTimesVC(parent: UIViewController) {
     func purchaseVideoTimesVC(parent: UIViewController) {
-        kPresentModalVC(target: parent, modelVC: TSPurchaseVideoTimesVC(isShowAlertModel: true))
-//        kPresentModalVC(target: parent, modelVC: TSPurchaseVideoTimesVC(isShowAlertModel: false))
+        kPresentModalVC(target: parent, modelVC: TSPurchaseVideoTimesVC(isShowAlertModel: false))
     }
     }
     
     
     
     

+ 3 - 3
AIEmoji/Business/TSSetingVC/SetingVC/View/SettingPurchaseTopView.swift

@@ -19,13 +19,13 @@ struct SettingPurchaseTopView: View {
             Image(.settingVipBj).resizable().cornerRadius(16.0)
             Image(.settingVipBj).resizable().cornerRadius(16.0)
             if vipType == .year {
             if vipType == .year {
                 VStack(alignment: .center) {
                 VStack(alignment: .center) {
-                    customGradientText(text: "\(kAppName) pro", font: .font(name: .PoppinsBoldItalic,size: 36))
-                    Spacer().frame(height: 15)
+                    customGradientText(text: "\(kAppName) pro", font: .font(name: .PoppinsBoldItalic,size: 32))
+                    Spacer().frame(height: 10)
                     Text(String(format: "Remaining Times: %d".localized, kPurchaseDefault.videoAvailableNum))
                     Text(String(format: "Remaining Times: %d".localized, kPurchaseDefault.videoAvailableNum))
                         .foregroundColor(UIColor.themeColor.color)
                         .foregroundColor(UIColor.themeColor.color)
                         .font(.font(size: 16,weight: .regular))
                         .font(.font(size: 16,weight: .regular))
                         .frame(height: 16)
                         .frame(height: 16)
-                    Spacer().frame(height: 20)
+                    Spacer().frame(height: 16)
                     Text(timeString)
                     Text(timeString)
                         .foregroundColor(.white.opacity(0.6))
                         .foregroundColor(.white.opacity(0.6))
                         .font(.font(size: 14,weight: .medium))
                         .font(.font(size: 14,weight: .medium))

+ 1 - 1
AIEmoji/Business/TSSetingVC/SetingVC/View/TSSettingListView.swift

@@ -52,7 +52,7 @@ struct TSSettingListView: View {
                 VStack(spacing:0) {
                 VStack(spacing:0) {
                     SettingListItemView(type: .deleteAllData, publisher: publisher, rightView: EmptyView(), rightArrow: true)
                     SettingListItemView(type: .deleteAllData, publisher: publisher, rightView: EmptyView(), rightArrow: true)
                     SettingListItemView(type: .lookAllData, publisher: publisher,rightView: EmptyView(), rightArrow: true)
                     SettingListItemView(type: .lookAllData, publisher: publisher,rightView: EmptyView(), rightArrow: true)
-                    SettingListItemView(type: .videoTimesAdd, publisher: publisher,rightView: EmptyView(), rightArrow: true)
+//                    SettingListItemView(type: .videoTimesAdd, publisher: publisher,rightView: EmptyView(), rightArrow: true)
                     SettingListItemView(type: .videoTimesReduce, publisher: publisher,rightView: EmptyView(), rightArrow: true)
                     SettingListItemView(type: .videoTimesReduce, publisher: publisher,rightView: EmptyView(), rightArrow: true)
                 }.cornerRadius(16)
                 }.cornerRadius(16)
 #endif
 #endif

+ 14 - 0
AIEmoji/Business/VIewTool/TSGeneratorloadingView/TSGeneratorErrorView.swift

@@ -17,6 +17,8 @@ class TSGeneratorErrorView: TSBaseView {
                 netWorkErrorView()
                 netWorkErrorView()
             case .generateTooMuch:
             case .generateTooMuch:
                 generateTooMuchView()
                 generateTooMuchView()
+            case .generateToMax:
+                generateToMaxView()
             default:
             default:
                 generalErrorView()
                 generalErrorView()
             }
             }
@@ -130,4 +132,16 @@ extension TSGeneratorErrorView {
 
 
         textLabel.text = "Your photo may contain nudity, gore or violence that does not comply with the health policy, please replace the photo and try again.".localized
         textLabel.text = "Your photo may contain nudity, gore or violence that does not comply with the health policy, please replace the photo and try again.".localized
     }
     }
+    
+    
+    func generateToMaxView() {
+        submitBtn.setTitle("Try Again".localized, for: .normal)
+        errorImageView.image = UIImage(named: "yellow_warning")
+        
+        errorImageView.snp.updateConstraints { make in
+            make.width.height.equalTo(56)
+        }
+        textLabel.text = "You have used all your video effect generations".localized
+    }
+    
 }
 }

+ 2 - 0
AIEmoji/Business/VIewTool/TSGeneratorloadingView/TSGeneratorloadingView.swift

@@ -20,6 +20,7 @@ class TSGeneratorView: TSBaseView {
         case sensitiveError   //敏感类的错误
         case sensitiveError   //敏感类的错误
         case netWorkError //网络错误
         case netWorkError //网络错误
         case generateTooMuch //生成次数过多
         case generateTooMuch //生成次数过多
+        case generateToMax //生成次数用完了 vip的次数
     }
     }
     
     
     var style:Style = .generalError
     var style:Style = .generalError
@@ -178,6 +179,7 @@ extension TSGeneratorView{
         showError(text: text.isEmpty ? kGenerateFailed : text)
         showError(text: text.isEmpty ? kGenerateFailed : text)
         isRotating = false
         isRotating = false
         setBackgroundGenerateBtnHidden(true)
         setBackgroundGenerateBtnHidden(true)
+
     }
     }
     
     
     func updateShowSuccess(){
     func updateShowSuccess(){

+ 22 - 1
AIEmoji/Business2/DisCover/TSAIGenerateVC/TSAIGenerateVC.swift

@@ -54,6 +54,8 @@ class TSAIGenerateVC: TSAIGenerateBaseVC {
                 clickTryAgainBtn()
                 clickTryAgainBtn()
             case .sensitiveError:
             case .sensitiveError:
                 pickSinglePhoto()
                 pickSinglePhoto()
+            case .generateToMax:
+                clickTryAgainBtn()
             default:
             default:
                 self.dismiss(animated: false, completion: nil)
                 self.dismiss(animated: false, completion: nil)
                 break
                 break
@@ -342,7 +344,12 @@ extension TSAIGenerateVC {
         progressState = state
         progressState = state
         switch state {
         switch state {
         case let .failed(errorStr, code):
         case let .failed(errorStr, code):
-            showError(text: errorStr, code: code)
+            if handleGenerateToMax(code: code,completion: { [weak self]  in
+                guard let self = self else { return }
+                self.showError(text: errorStr, code: code)
+            }){}else {
+                showError(text: errorStr, code: code)
+            }
         case .success:
         case .success:
             if let model = model {
             if let model = model {
                 showSuccess(model: model)
                 showSuccess(model: model)
@@ -389,3 +396,17 @@ extension TSAIGenerateVC {
         kFirstSaveRateAction()
         kFirstSaveRateAction()
     }
     }
 }
 }
+
+extension TSAIGenerateVC {
+    
+    func handleGenerateToMax(code:Int,completion: (() -> Void)? = nil) -> Bool {
+        //如果是vip次数超限,则主动触发,让 vc去谈起购买次数的弹窗
+        let style = TSNetWorkCode.getGeneratorStyle(code: code)
+        if style == .generateToMax{
+            kPresentModalVC(target: self, modelVC: TSPurchaseVideoTimesVC(isShowAlertModel: true),transitionStyle:.crossDissolve,completion: completion)
+            return true
+        }
+        
+        return false
+    }
+}

+ 4 - 4
AIEmoji/Common/NetworkManager/TSNetWork/TSNetWork+Business.swift

@@ -170,7 +170,7 @@ enum TSNetWorkCode : Int {
         case .generateTooMuch:
         case .generateTooMuch:
             return TSGeneratorView.Style.generateTooMuch
             return TSGeneratorView.Style.generateTooMuch
         case .generateToMax:
         case .generateToMax:
-            return TSGeneratorView.Style.generateTooMuch
+            return TSGeneratorView.Style.generateToMax
         default:
         default:
             return TSGeneratorView.Style.generalError
             return TSGeneratorView.Style.generalError
         }
         }
@@ -371,14 +371,14 @@ extension TSNetworkManager {
         progressHandler: @escaping (Float) -> Void, // 上传进度回调
         progressHandler: @escaping (Float) -> Void, // 上传进度回调
         completion: @escaping (Any?, Error?) -> Void)
         completion: @escaping (Any?, Error?) -> Void)
     -> Request?{
     -> Request?{
-        var vipFreeNumType:VipFreeNumType = vipFreeNumType == .videoV2 ? .videoV2 : .aiGenerate
-        ///需要校验且需要判断是否超过最大次数
+        let vipFreeNumType:VipFreeNumType = vipFreeNumType == .videoV2 ? .videoV2 : .aiGenerate
+        ///需要校验,是否超出了 vip 生成的次数,且需要判断是否超过最大次数
         if vipFreeNumType == .videoV2, PurchaseManager.default.isExceedsVipGeneratedNum(vipFreeNumType: .videoV2) {
         if vipFreeNumType == .videoV2, PurchaseManager.default.isExceedsVipGeneratedNum(vipFreeNumType: .videoV2) {
             completion(nil,NSError(domain: "", code: TSNetWorkCode.generateToMax.rawValue))
             completion(nil,NSError(domain: "", code: TSNetWorkCode.generateToMax.rawValue))
             return nil
             return nil
         }
         }
         
         
-        ///需要校验。且需要判断是否超过最大次数
+        ///需要校验。且需要判断是否超过每天生成的最大次数
         if PurchaseManager.default.isExceedsDayGeneratedNum(vipFreeNumType: vipFreeNumType) {
         if PurchaseManager.default.isExceedsDayGeneratedNum(vipFreeNumType: vipFreeNumType) {
             completion(nil,NSError(domain: "", code: TSNetWorkCode.generateTooMuch.rawValue))
             completion(nil,NSError(domain: "", code: TSNetWorkCode.generateTooMuch.rawValue))
             return nil
             return nil

+ 5 - 4
AIEmoji/Common/Purchase/TSPurchaseManager+Free.swift

@@ -11,11 +11,11 @@ extension PurchaseManager {
     
     
     /// 使用一次免费次数
     /// 使用一次免费次数
     func useOnceForFree(type: VipFreeNumType) {
     func useOnceForFree(type: VipFreeNumType) {
-        if freeNum(type: type) > 0 {
-            saveForFreeNum(type: type) //非会员的免费次数
-        }else{
+        if isVip || videoAvailableNum > 0 {
             saveForDayGeneratedNum(type: type)
             saveForDayGeneratedNum(type: type)
             saveForVipGeneratedNum(type: type)
             saveForVipGeneratedNum(type: type)
+        }else{
+            saveForFreeNum(type: type) //非会员的免费次数
         }
         }
     }
     }
     
     
@@ -103,7 +103,8 @@ extension PurchaseManager {
 
 
     /// 免费次数是否可用
     /// 免费次数是否可用
     func freeNumAvailable(type: VipFreeNumType) -> Bool {
     func freeNumAvailable(type: VipFreeNumType) -> Bool {
-        if isVip == true {
+//        if isVip == true {
+        if isVip == true ||  (type == .videoV2 && videoAvailableNum > 0) {
             return true
             return true
         } else {
         } else {
             if freeNum(type: type) > 0 {
             if freeNum(type: type) > 0 {

+ 2 - 1
AIEmoji/Common/Purchase/TSPurchaseManager+PurchasedNum.swift

@@ -46,7 +46,8 @@ extension PurchaseManager {
     //视频生成可用的次数
     //视频生成可用的次数
     var videoAvailableNum:Int {
     var videoAvailableNum:Int {
         let vipFreeNumType:VipFreeNumType = .videoV2
         let vipFreeNumType:VipFreeNumType = .videoV2
-        let vipNum = vipType.creatVideoMaxNum - loadVipGeneratedNum(type:vipFreeNumType) //会员自身带的额度
+        var vipNum = vipType.creatVideoMaxNum - loadVipGeneratedNum(type:vipFreeNumType) //会员自身带的额度
+        vipNum = max(0, vipNum)
         let purchaseNum = TSDBTimesManager.purchaseVideo.times //用户后面购买的次数
         let purchaseNum = TSDBTimesManager.purchaseVideo.times //用户后面购买的次数
         let total = vipNum + purchaseNum
         let total = vipNum + purchaseNum
         dePrint("视频可用次数total=\(total),vipNum=\(vipNum),purchaseNum=\(purchaseNum)")
         dePrint("视频可用次数total=\(total),vipNum=\(vipNum),purchaseNum=\(purchaseNum)")

+ 6 - 6
AIEmoji/Common/Purchase/TSPurchaseManager.swift

@@ -121,9 +121,9 @@ public class PurchaseManager: NSObject {
     }
     }
 
 
     @objc public var isVip: Bool {
     @objc public var isVip: Bool {
-#if DEBUG
-        return vipType != .none
-#endif
+//#if DEBUG
+//        return vipType != .none
+//#endif
         guard let expiresDate = expiredDate else {
         guard let expiresDate = expiredDate else {
             return false
             return false
         }
         }
@@ -135,9 +135,9 @@ public class PurchaseManager: NSObject {
     }
     }
 
 
     public var vipType: PremiumPeriod {
     public var vipType: PremiumPeriod {
-#if DEBUG
-        return PremiumPeriod.week(.week)
-#endif
+//#if DEBUG
+//        return PremiumPeriod.none
+//#endif
         guard isVip, let type = vipInformation["type"] as? String else {
         guard isVip, let type = vipInformation["type"] as? String else {
             return .none
             return .none
         }
         }