You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

207 lines
7.5 KiB

import 'package:dating_touchme_app/controller/global.dart';
import 'package:dating_touchme_app/model/mine/rose_data.dart';
import 'package:dating_touchme_app/network/user_api.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:fluwx/fluwx.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import '../../generated/assets.dart';
class SpreadController extends GetxController with WidgetsBindingObserver {
// UserApi实例
late UserApi _userApi;
final roseList = <RoseData>[].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;
bool canApply = false;
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;
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 {
button.value = '立即续费';
}
} else if(activePay.value == 0){
button.value = canApply ? '立即加入' : '去相亲';
} else {
button.value = '立即加入';
}
// 实习红娘
if(roseList[activePay.value].subCategory == 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].subCategory == 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].subCategory == 88802){
revenue.value = [
{'icon': '1', 'desc': '礼物收益固定40%,邀请嘉宾,嘉宾消费的分成10%'},
{'icon': '3', 'desc': '红娘推荐的嘉宾成为红娘,赚取入驻费的20%分成;'},
{'icon': '4', 'desc': '新徒弟首月收益的10%(平台奖励)'},
];
} else if(roseList[activePay.value].subCategory == 88801){
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%(平台奖励)'},
];
}
}
// 倒计时秒数
final countdownSeconds = 0.obs;
@override
void onInit() {
super.onInit();
WidgetsBinding.instance.addObserver(this);
_userApi = Get.find<UserApi>();
if(GlobalData().userData!.matchmakerFlag != null && GlobalData().userData!.matchmakerFlag!){
matchmakerFlag.value = true;
}
getRoseList();
getChatInfo();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if(state == AppLifecycleState.resumed){
if (countdownSeconds.value > 0) {
startCountdown();
}
}
}
// 开始倒计时
void startCountdown() async {
try{
final response = await _userApi.getAuditMatchmaker();
if (response.data.isSuccess && response.data.data != null) {
bool 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].subCategory;
Get.back(result: 1);
}
}
} catch (e) {
print('87$e');
}
}
@override
void onClose() {
WidgetsBinding.instance.removeObserver(this);
super.onClose();
}
getChatInfo() async {
try{
final response = await _userApi.getChatStaticsInfo();
if (response.data.isSuccess && response.data.data != null) {
final data = response.data.data!;
if(roseList[activePay.value].liveDurationHours != null){
int hours = int.parse(roseList[activePay.value].liveDurationHours!);
if(hours > 0 && data.liveDurationMins >= 60 * hours && !matchmakerFlag.value){
canApply = true;
}
}
}
} catch (e) {
print('spread: $e');
}
}
getRoseList() async {
try{
final response = await _userApi.getMatchmakerFee();
if (response.data.isSuccess && response.data.data != null) {
final data = response.data.data!.records;
roseList.addAll(data.toList());
if(matchmakerFlag.value){
final index = roseList.indexWhere((item) => item.subCategory == GlobalData().userData!.matchmakerType!);
enableIndex.value = index >= 0 ? index : 0;
changePayActive(enableIndex.value);
}
}
} catch (e) {
print('玫瑰列表获取失败: $e');
}
}
submitOrder() async {
if(activePay.value == 0 && !canApply){
Get.back();
return;
}
try {
final response = await _userApi.submitOrder({
"productSpecId": roseList[activePay.value].productSpecId
});
if (response.data.isSuccess && response.data.data != null) {
final data = response.data.data;
if(data!.freeSettlement!){
SmartDialog.showToast('加入成功');
GlobalData().userData!.matchmakerFlag = true;
GlobalData().userData!.matchmakerType = roseList[activePay.value].subCategory;
Get.back(result: 1);
} else {
fluwx.open(target: MiniProgram(
username: 'gh_9ea8d46add6f',
path: "pages/index/index?amount=${roseList[activePay.value].unitSellingPrice}&paymentOrderId=${data!.paymentOrderId}&url=match-fee",
miniProgramType: WXMiniProgramType.preview
));
countdownSeconds.value = 3;
SmartDialog.showToast('开始支付');
}
} else {
// 响应失败,抛出异常
SmartDialog.showToast(response.data.message ?? '网络异常');
}
} catch (e) {
print('玫瑰列表获取失败: $e');
SmartDialog.showToast('下单失败');
}
}
}