From 7f2d493256f41c6bccbbe0a6c33d56e215e68323 Mon Sep 17 00:00:00 2001 From: Jolie <412895109@qq.com> Date: Sun, 4 Jan 2026 16:46:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(model):=20=E6=B7=BB=E5=8A=A0=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E9=9F=B3=E9=A2=91=E4=BA=A7=E5=93=81=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建 ChatAudioProductModel 类定义产品数据结构 - 实现 fromJson 工厂构造函数支持 JSON 反序列化 - 实现 toJson 方法支持对象序列化为 JSON - 添加 isFreeProduct 计算属性判断是否为免费产品 - 定义产品基本信息字段包括 ID、标题、价格等 - 添加字符串表示方法便于调试和日志输出 --- lib/model/rtc/chat_audio_product_model.dart | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/model/rtc/chat_audio_product_model.dart diff --git a/lib/model/rtc/chat_audio_product_model.dart b/lib/model/rtc/chat_audio_product_model.dart new file mode 100644 index 0000000..faa52d1 --- /dev/null +++ b/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 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 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)'; + } +} +