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.
 
 
 
 
 

223 lines
8.3 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';
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;
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;
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 ? '免费加入' : '去相亲';
} 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': '礼物收益范围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 == 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;
}
initDataList();
}
@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].subCategory;
Get.back(result: 1);
}
} catch (e) {
print('87$e');
}
}
@override
void onClose() {
WidgetsBinding.instance.removeObserver(this);
super.onClose();
}
initDataList() async {
try{
final result = await _userApi.getMatchmakerFee();
if (result.data.isSuccess && result.data.data != null) {
roseList.value = result.data.data!.records;
}
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;
}
}
}
if(matchmakerFlag.value){
final index = roseList.indexWhere((item) => item.subCategory == GlobalData().userData!.matchmakerType!);
enableIndex.value = index >= 0 ? index : 0;
changePayActive(enableIndex.value);
} else {
changePayActive(0);
}
} catch (e) {
print('spread: $e');
}
}
submitOrder() async {
if(activePay.value == 0 && !canApply){
Get.back();
return;
}
try {
var matchmakerOrderType = 1;
var matchmakerType = roseList[activePay.value].subCategory;
if(GlobalData().userData!.matchmakerFlag!){
if(matchmakerType != GlobalData().userData!.matchmakerType){
matchmakerOrderType = 2;
} else {
matchmakerOrderType = 3;
}
} else {
await _userApi.applyMatchmaker({
"phone": GlobalData().userData!.phone,
"name": GlobalData().userData!.name
});
}
final response = await _userApi.submitMatchmakerOrder({
"productSpecId": roseList[activePay.value].productSpecId,
"matchmakerOrderType": matchmakerOrderType
});
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 {
paymentOrderId = data.paymentOrderId!;
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) {
SmartDialog.showToast('下单失败');
}
}
}