2025-09-22 14:41:47 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2025-09-18 16:13:37 +08:00
|
|
|
|
import 'package:get/get.dart';
|
2025-09-22 14:41:47 +08:00
|
|
|
|
import 'package:loopin/IM/controller/im_user_info_controller.dart';
|
|
|
|
|
import 'package:loopin/IM/im_friend_listeners.dart';
|
|
|
|
|
import 'package:loopin/api/common_api.dart';
|
2025-09-18 16:13:37 +08:00
|
|
|
|
import 'package:loopin/pages/my/merchant/balance/model.dart';
|
2025-09-22 14:41:47 +08:00
|
|
|
|
import 'package:loopin/service/http.dart';
|
|
|
|
|
import 'package:loopin/utils/wxsdk.dart';
|
2025-09-18 16:13:37 +08:00
|
|
|
|
|
|
|
|
|
class BalanceController extends GetxController {
|
|
|
|
|
/// 钱包余额
|
|
|
|
|
final balance = 0.0.obs;
|
|
|
|
|
|
|
|
|
|
final data = <AccountBill>[].obs;
|
|
|
|
|
|
|
|
|
|
int currentPage = 1;
|
|
|
|
|
|
|
|
|
|
final isLoading = false.obs;
|
|
|
|
|
|
|
|
|
|
/// 是否还有更多
|
|
|
|
|
var hasMore = true.obs;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onInit() {
|
|
|
|
|
super.onInit();
|
|
|
|
|
getData(reset: true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 充值
|
2025-09-22 14:41:47 +08:00
|
|
|
|
Future<void> recharge({required String money}) async {
|
|
|
|
|
// 获取支付参数
|
|
|
|
|
final data = {"orderType": "RECHARGE", "clientType": "APP", "paymentMethod": "WECHAT", "paymentClient": "APP", "money": money};
|
|
|
|
|
final res = await Http.post(CommonApi.addBalance, data: data);
|
|
|
|
|
logger.w(res);
|
|
|
|
|
final payParams = res['data'];
|
|
|
|
|
logger.w(payParams);
|
|
|
|
|
// 拉起支付
|
|
|
|
|
await Wxsdk.payWithWx(
|
|
|
|
|
appId: payParams['appid'],
|
|
|
|
|
partnerId: payParams['partnerid'],
|
|
|
|
|
prepayId: payParams['prepayid'],
|
|
|
|
|
packageValue: payParams['package'],
|
|
|
|
|
nonceStr: payParams['noncestr'],
|
|
|
|
|
timestamp: int.parse(payParams['timestamp']),
|
|
|
|
|
sign: payParams['sign'],
|
|
|
|
|
);
|
|
|
|
|
// 在回调结果中获取新的数据
|
|
|
|
|
// getData(reset: true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 提现
|
|
|
|
|
Future<void> withDraw({required String money}) async {
|
|
|
|
|
final infoCtl = Get.find<ImUserInfoController>();
|
|
|
|
|
final openId = infoCtl.customInfo['openId'];
|
|
|
|
|
if (openId == null || openId.isEmpty) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: Get.context!,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('微信授权'),
|
|
|
|
|
content: const Text('余额提现至您的微信零钱内,是否前往微信授权?', style: TextStyle(fontSize: 16.0)),
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
surfaceTintColor: Colors.white,
|
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
|
|
|
|
|
elevation: 2.0,
|
|
|
|
|
actionsPadding: const EdgeInsets.all(15.0),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(onPressed: () => {Get.back()}, child: Text('取消', style: TextStyle(color: Colors.red))),
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
//去授权
|
|
|
|
|
await Wxsdk.login();
|
|
|
|
|
Get.back();
|
|
|
|
|
},
|
|
|
|
|
child: Text('确认')),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
// final res = await Http.post(CommonApi.withdraw, data: {
|
|
|
|
|
// "money": money,
|
|
|
|
|
// "method": "1",
|
|
|
|
|
// });
|
|
|
|
|
// MyDialog.('提现成功,系统将在一个工作日内将余额提现至您绑定的微信内');
|
|
|
|
|
showDialog(
|
|
|
|
|
context: Get.context!,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('提现成功'),
|
|
|
|
|
content: const Text('系统将在一个工作日内将余额提现至您绑定的微信内', style: TextStyle(fontSize: 16.0)),
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
surfaceTintColor: Colors.white,
|
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
|
|
|
|
|
elevation: 2.0,
|
|
|
|
|
actionsPadding: const EdgeInsets.all(15.0),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(onPressed: () => {Get.back()}, child: Text('确认')),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
getData(reset: true);
|
2025-09-18 16:13:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 分页数据
|
|
|
|
|
Future<void> getData({bool reset = false}) async {
|
2025-09-22 14:41:47 +08:00
|
|
|
|
if (isLoading.value) {
|
|
|
|
|
logger.w('正在加载中,跳过');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 16:13:37 +08:00
|
|
|
|
isLoading.value = true;
|
2025-09-22 14:41:47 +08:00
|
|
|
|
logger.w('开始加载数据,reset: $reset, currentPage: $currentPage');
|
|
|
|
|
|
|
|
|
|
await Future.delayed(const Duration(seconds: 2));
|
2025-09-18 16:13:37 +08:00
|
|
|
|
|
|
|
|
|
if (reset) {
|
2025-09-22 14:41:47 +08:00
|
|
|
|
logger.w('重置数据');
|
2025-09-18 16:13:37 +08:00
|
|
|
|
currentPage = 1;
|
|
|
|
|
data.clear();
|
|
|
|
|
hasMore.value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<AccountBill> newData = List.generate(
|
|
|
|
|
10,
|
2025-09-22 14:41:47 +08:00
|
|
|
|
(index) {
|
|
|
|
|
int id = currentPage * 10 + index + 1;
|
|
|
|
|
// logger.w('生成数据: id=$id');
|
|
|
|
|
return AccountBill(
|
|
|
|
|
id: id,
|
|
|
|
|
source: '来源 $currentPage-${index + 1}',
|
|
|
|
|
changeAmount: (index + 1) * 10.0,
|
|
|
|
|
changeType: index % 2 + 1,
|
|
|
|
|
createTime: DateTime.now().toString(),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-09-18 16:13:37 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
data.addAll(newData);
|
2025-09-22 14:41:47 +08:00
|
|
|
|
logger.w('添加了 ${newData.length} 条数据,总数据量: ${data.length}');
|
|
|
|
|
|
2025-09-18 16:13:37 +08:00
|
|
|
|
currentPage++;
|
2025-09-22 14:41:47 +08:00
|
|
|
|
logger.w('页码增加到: $currentPage');
|
2025-09-18 16:13:37 +08:00
|
|
|
|
|
2025-09-22 14:41:47 +08:00
|
|
|
|
if (currentPage > 5) {
|
2025-09-18 16:13:37 +08:00
|
|
|
|
hasMore.value = false;
|
2025-09-22 14:41:47 +08:00
|
|
|
|
logger.w('没有更多数据了');
|
2025-09-18 16:13:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isLoading.value = false;
|
2025-09-22 14:41:47 +08:00
|
|
|
|
logger.w('加载完成');
|
2025-09-18 16:13:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|