Browse Source

feat(model): 添加聊天音频产品模型

- 创建 ChatAudioProductModel 类定义产品数据结构
- 实现 fromJson 工厂构造函数支持 JSON 反序列化
- 实现 toJson 方法支持对象序列化为 JSON
- 添加 isFreeProduct 计算属性判断是否为免费产品
- 定义产品基本信息字段包括 ID、标题、价格等
- 添加字符串表示方法便于调试和日志输出
master
Jolie 2 months ago
parent
commit
7f2d493256
1 changed files with 53 additions and 0 deletions
  1. 53
      lib/model/rtc/chat_audio_product_model.dart

53
lib/model/rtc/chat_audio_product_model.dart

@ -0,0 +1,53 @@
///
class ChatAudioProductModel {
final String isFree; // "true" "false"
final String productId;
final String productSpecId;
final int mainCategory;
final int subCategory;
final String productTitle;
final double unitSellingPrice;
ChatAudioProductModel({
required this.isFree,
required this.productId,
required this.productSpecId,
required this.mainCategory,
required this.subCategory,
required this.productTitle,
required this.unitSellingPrice,
});
factory ChatAudioProductModel.fromJson(Map<String, dynamic> json) {
return ChatAudioProductModel(
isFree: json['isFree']?.toString() ?? 'false',
productId: json['productId']?.toString() ?? '',
productSpecId: json['productSpecId']?.toString() ?? '',
mainCategory: json['mainCategory'] as int? ?? 0,
subCategory: json['subCategory'] as int? ?? 0,
productTitle: json['productTitle']?.toString() ?? '',
unitSellingPrice: (json['unitSellingPrice'] as num?)?.toDouble() ?? 0.0,
);
}
Map<String, dynamic> toJson() {
return {
'isFree': isFree,
'productId': productId,
'productSpecId': productSpecId,
'mainCategory': mainCategory,
'subCategory': subCategory,
'productTitle': productTitle,
'unitSellingPrice': unitSellingPrice,
};
}
///
bool get isFreeProduct => isFree.toLowerCase() == 'true';
@override
String toString() {
return 'ChatAudioProductModel(productId: $productId, productTitle: $productTitle, unitSellingPrice: $unitSellingPrice, isFree: $isFree)';
}
}
Loading…
Cancel
Save