Files
monisuo/flutter_monisuo/lib/data/models/order_models.dart
2026-04-21 08:09:45 +08:00

251 lines
6.7 KiB
Dart

/// 交易訂單模型
class OrderTrade {
final int id;
final String orderNo;
final int userId;
final String coinCode;
final int direction; // 1=買入, 2=賣出
final String price;
final String quantity;
final String amount;
final int status; // 0=委托中, 1=已成交, 2=失败, 3=已取消
final int? orderType; // 1=市价单, 2=限价单
final DateTime? createTime;
final DateTime? updateTime;
OrderTrade({
required this.id,
required this.orderNo,
required this.userId,
required this.coinCode,
required this.direction,
required this.price,
required this.quantity,
required this.amount,
required this.status,
this.orderType,
this.createTime,
this.updateTime,
});
factory OrderTrade.fromJson(Map<String, dynamic> json) {
return OrderTrade(
id: json['id'] as int? ?? 0,
orderNo: json['orderNo'] as String? ?? '',
userId: json['userId'] as int? ?? 0,
coinCode: json['coinCode'] as String? ?? '',
direction: json['direction'] as int? ?? 1,
price: json['price']?.toString() ?? '0.00',
quantity: json['quantity']?.toString() ?? '0',
amount: json['amount']?.toString() ?? '0.00',
status: json['status'] as int? ?? 1,
orderType: json['orderType'] as int?,
createTime: json['createTime'] != null
? DateTime.tryParse(json['createTime'])
: null,
updateTime: json['updateTime'] != null
? DateTime.tryParse(json['updateTime'])
: null,
);
}
/// 方向文字
String get directionText => direction == 1 ? '買入' : '賣出';
/// 狀態文字
String get statusText {
switch (status) {
case 0:
return '委托中';
case 1:
return '已成交';
case 2:
return '失败';
case 3:
return '已取消';
default:
return '未知';
}
}
/// 是否为委托中
bool get isPending => status == 0;
/// 是否為買入
bool get isBuy => direction == 1;
/// 订单类型文字
String get orderTypeText => orderType == 2 ? '限价' : '市价';
}
/// 充提訂單模型
class OrderFund {
final int id;
final String orderNo;
final int userId;
final String username;
final int type; // 1=充值, 2=提現
final String amount;
final String? fee; // 手續費
final String? receivableAmount; // 應收款項
final int status;
// 充值狀態: 1=待付款, 2=待確認, 3=已完成, 4=已駁回, 5=已取消
// 提現狀態: 1=待審批, 2=已出款, 3=已駁回, 4=已取消, 5=待財務審核
final int? walletId; // 冷錢包ID(充值)
final String? walletAddress; // 錢包地址(充值/提現)
final String? network; // 提現網絡類型
final String? withdrawContact; // 提現聯繫方式
final String remark;
final String? rejectReason;
final String? adminRemark;
final DateTime? createTime;
final DateTime? payTime; // 用戶確認打款時間
final DateTime? confirmTime; // 管理員確認時間
OrderFund({
required this.id,
required this.orderNo,
required this.userId,
required this.username,
required this.type,
required this.amount,
this.fee,
this.receivableAmount,
required this.status,
this.walletId,
this.walletAddress,
this.network,
this.withdrawContact,
required this.remark,
this.rejectReason,
this.adminRemark,
this.createTime,
this.payTime,
this.confirmTime,
});
factory OrderFund.fromJson(Map<String, dynamic> json) {
return OrderFund(
id: json['id'] as int? ?? 0,
orderNo: json['orderNo'] as String? ?? '',
userId: json['userId'] as int? ?? 0,
username: json['username'] as String? ?? '',
type: json['type'] as int? ?? 1,
amount: json['amount']?.toString() ?? '0.00',
fee: json['fee']?.toString(),
receivableAmount: json['receivableAmount']?.toString(),
status: json['status'] as int? ?? 1,
walletId: json['walletId'] as int?,
walletAddress: json['walletAddress'] as String?,
network: json['network'] as String?,
withdrawContact: json['withdrawContact'] as String?,
remark: json['remark']?.toString() ?? '',
rejectReason: json['rejectReason'] as String?,
adminRemark: json['adminRemark'] as String?,
createTime: json['createTime'] != null
? DateTime.tryParse(json['createTime'])
: null,
payTime: json['payTime'] != null
? DateTime.tryParse(json['payTime'])
: null,
confirmTime: json['confirmTime'] != null
? DateTime.tryParse(json['confirmTime'])
: null,
);
}
/// 訂單類型文字
String get typeText => type == 1 ? '充值' : '提現';
/// 狀態文字 (根據類型區分)
String get statusText {
if (type == 1) {
// 充值狀態
switch (status) {
case 1:
return '待付款';
case 2:
return '待確認';
case 3:
return '已完成';
case 4:
return '已駁回';
case 5:
return '已取消';
default:
return '未知';
}
} else {
// 提現狀態
switch (status) {
case 1:
return '待審批';
case 2:
return '已出款';
case 3:
return '已駁回';
case 4:
return '已取消';
case 5:
return '待財務審核';
default:
return '未知';
}
}
}
/// 是否為充值
bool get isDeposit => type == 1;
/// 是否可取消
/// 充值: 僅待付款可取消
/// 提現: 僅待審批可取消
bool get canCancel {
if (type == 1) {
return status == 1; // 充值待付款
} else {
return status == 1; // 提現待審批
}
}
/// 是否可確認打款 (僅充值待付款)
bool get canConfirmPay => type == 1 && status == 1;
}
/// 冷錢包模型
class ColdWallet {
final int id;
final String name;
final String address;
final String network;
final bool isDefault;
final int status; // 0=禁用, 1=啟用
final DateTime? createTime;
ColdWallet({
required this.id,
required this.name,
required this.address,
required this.network,
required this.isDefault,
required this.status,
this.createTime,
});
factory ColdWallet.fromJson(Map<String, dynamic> json) {
return ColdWallet(
id: json['id'] as int? ?? 0,
name: json['name'] as String? ?? '',
address: json['address'] as String? ?? '',
network: json['network'] as String? ?? 'TRC20',
isDefault: json['isDefault'] as bool? ?? false,
status: json['status'] as int? ?? 1,
createTime: json['createTime'] != null
? DateTime.tryParse(json['createTime'])
: null,
);
}
bool get isEnabled => status == 1;
}