import 'package:dating_touchme_app/controller/global.dart'; import 'package:dating_touchme_app/model/mine/chat_static_data.dart'; import 'package:dating_touchme_app/model/mine/matchmaker_requirement_data.dart'; import 'package:dating_touchme_app/network/user_api.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:fluwx/fluwx.dart'; import 'package:get/get.dart'; class SpreadController extends GetxController { // UserApi实例 late UserApi _userApi; final roseList = [].obs; final loading = true.obs; final roseNum = 0.obs; final payChecked = true.obs; final activePay = 0.obs; final enableIndex = (-1).obs; final Fluwx fluwx = Fluwx(); final matchmakerFlag = false.obs; final button = '立即申请'.obs; final canApply = false.obs; String paymentOrderId = ''; final revenue = [ {'icon': '1', 'desc': '礼物收益范围15%-30%,嘉宾消费的分成3%;'}, {'icon': '2', 'desc': '每天前5人连麦的礼物收益15%,第6-10人连麦的礼物收益20%,第11-15人连麦的礼物收益25%,第16人以上连麦的礼物收益30%;'}, {'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'}, {'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'}, ].obs; final userData = GlobalData().userData.obs; final userId = GlobalData().userId.obs; final consumption = ChatStaticData().obs; // final nowBankCard = BankCardData().obs; // changePayActive(int index){ // if(index < enableIndex.value && enableIndex.value >= 0){ // return; // } // activePay.value = index; // if(matchmakerFlag.value){ // if(activePay.value > enableIndex.value){ // button.value = '立即升级'; // } else if(activePay.value == 0){ // button.value = '去直播'; // } else { // button.value = '立即续费'; // } // } else if(activePay.value == 0){ // button.value = canApply.value ? '免费加入' : '去相亲'; // } else { // button.value = '立即加入'; // } // // 实习红娘 // if(roseList[activePay.value].type == 88804){ // revenue.value = [ // {'icon': '1', 'desc': '礼物收益范围15%-30%,嘉宾消费的分成3%;'}, // {'icon': '2', 'desc': '每天前5人连麦的礼物收益15%,第6-10人连麦的礼物收益20%,第11-15人连麦的礼物收益25%,第16人以上连麦的礼物收益30%;'}, // {'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'}, // {'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'}, // ]; // } else if(roseList[activePay.value].type == 88803){ // revenue.value = [ // {'icon': '1', 'desc': '礼物收益范围30%-40%,嘉宾消费的分成6%;'}, // {'icon': '2', 'desc': '每天前5人连麦的礼物收益30%,第6-10人连麦的礼物收益35%,第11人以上连麦的礼物收益40%;'}, // {'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'}, // {'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'}, // ]; // } else if(roseList[activePay.value].type == 88802){ // revenue.value = [ // {'icon': '1', 'desc': '礼物收益范围40%,嘉宾消费的分成10%;'}, // // {'icon': '2', 'desc': '每天前5人连麦的礼物收益15%,第6-10人连麦的礼物收益20%,第11-15人连麦的礼物收益25%,第16人以上连麦的礼物收益30%;'}, // {'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'}, // {'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'}, // ]; // } else if(roseList[activePay.value].type == 88801){ // revenue.value = [ // {'icon': '1', 'desc': '礼物收益范围40%,嘉宾消费的分成10%;'}, // // {'icon': '2', 'desc': '每天前5人连麦的礼物收益15%,第6-10人连麦的礼物收益20%,第11-15人连麦的礼物收益25%,第16人以上连麦的礼物收益30%;'}, // {'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'}, // {'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'}, // ]; // } // // } // 倒计时秒数 final countdownSeconds = 0.obs; @override void onInit() { super.onInit(); // WidgetsBinding.instance.addObserver(this); _userApi = Get.find(); if(GlobalData().userData!.matchmakerFlag != null && GlobalData().userData!.matchmakerFlag!){ matchmakerFlag.value = true; } initDataList(); } changePayActive(int index){ if(index < enableIndex.value && enableIndex.value >= 0){ return; } activePay.value = index; canApply.value = false; if(enableIndex.value == roseList.length){ return; } int hours = roseList[activePay.value].liveDurationHours!; int rose = roseList[activePay.value].liveConsumptionAmount!; if(hours > 0 && consumption.value.liveDurationMins! >= 60 * hours){ if(rose <= 0){ canApply.value = true; } else if(consumption.value.liveConsumptionAmount! >= rose){ canApply.value = true; } } button.value = canApply.value ? '立即申请' : '条件不满足'; // 实习红娘 if(roseList[activePay.value].type == 1){ revenue.value = [ {'icon': '1', 'desc': '礼物收益范围15%-30%,嘉宾消费的分成3%;'}, {'icon': '2', 'desc': '每天前5人连麦的礼物收益15%,第6-10人连麦的礼物收益20%,第11-15人连麦的礼物收益25%,第16人以上连麦的礼物收益30%;'}, {'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'}, {'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'}, ]; } else if(roseList[activePay.value].type == 2){ revenue.value = [ {'icon': '1', 'desc': '礼物收益范围30%-40%,嘉宾消费的分成6%;'}, {'icon': '2', 'desc': '每天前5人连麦的礼物收益30%,第6-10人连麦的礼物收益35%,第11人以上连麦的礼物收益40%;'}, {'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'}, {'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'}, ]; } else if(roseList[activePay.value].type == 3){ revenue.value = [ {'icon': '1', 'desc': '礼物收益范围40%,嘉宾消费的分成10%;'}, // {'icon': '2', 'desc': '每天前5人连麦的礼物收益15%,第6-10人连麦的礼物收益20%,第11-15人连麦的礼物收益25%,第16人以上连麦的礼物收益30%;'}, {'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'}, {'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'}, ]; } } String getNameByType(int type) { if(type == 1){ return '实习红娘'; } if(type == 2){ return '线上红娘'; } if(type == 3){ return '签约红娘'; } return ''; // 直播显示直播间按钮(放在HI位置) } // @override // void didChangeAppLifecycleState(AppLifecycleState state) { // if(state == AppLifecycleState.resumed){ // if (countdownSeconds.value > 0) { // startCountdown(); // } // } // } // 开始倒计时 // void startCountdown() async { // try{ // bool audit = false; // if(matchmakerFlag.value){ // // 如果是红娘,那么就要检测支付单是否支付成功, // // } else { // // 如果是不是红娘,那么就要检测用户是否变成了红娘, // final response = await _userApi.getAuditMatchmaker(); // if (response.data.isSuccess && response.data.data != null) { // audit = response.data.data['needAudit']; // } // } // if(audit){ // Future.delayed(const Duration(milliseconds: 300), () { // if (countdownSeconds.value > 0) { // countdownSeconds.value--; // startCountdown(); // } // }); // } else { // countdownSeconds.value = 0; // GlobalData().userData!.matchmakerFlag = true; // GlobalData().userData!.matchmakerType = roseList[activePay.value].type; // Get.back(result: 1); // } // } catch (e) { // print('87$e'); // } // } @override void onClose() { // WidgetsBinding.instance.removeObserver(this); super.onClose(); } initDataList() async { try{ loading.value = true; final result = await _userApi.getMatchmakerRequirement(); if (result.data.isSuccess && result.data.data != null) { roseList.value = result.data.data!; } final response = await _userApi.getChatStaticsInfo(); if (response.data.isSuccess && response.data.data != null) { consumption.value = response.data.data!; if(roseList[activePay.value].liveDurationHours != null){ int hours = roseList[activePay.value].liveDurationHours!; int rose = roseList[activePay.value].liveConsumptionAmount!; if(hours > 0 && consumption.value.liveDurationMins! >= 60 * hours){ if(rose <= 0){ canApply.value = true; } else if(consumption.value.liveConsumptionAmount! >= rose){ canApply.value = true; } } } } if(matchmakerFlag.value){ final index = roseList.indexWhere((item) => item.type == GlobalData().userData!.matchmakerType!); enableIndex.value = index >= 0 ? index + 1 : 0; changePayActive(enableIndex.value); } else { changePayActive(0); } } catch (e) { print('spread: $e'); } finally { loading.value = false; } } submitOrder() async { if(!canApply.value){ return; } try { final response = await _userApi.applyLiveMatchmaker({ "behavior": GlobalData().userData!.matchmakerFlag! ? 2 : 1, "type": roseList[activePay.value].type }); if (response.data.isSuccess) { SmartDialog.showToast('申请成功,请等待审核'); Get.back(); } } catch (e) { SmartDialog.showToast('申请失败'); } } }