Files
platforms/apps/user_app/lib/domain/models/delivery_detail.dart
czl231 3ef33b531d 已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
2026-09-13 00:57:32 +08:00

67 lines
3.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 功能描述用户可见的配送人员、资质、配送点及订单交付快照版本1.0.0。
class DeliveryProduct {
const DeliveryProduct({required this.name, required this.quantity});
final String name;
final int quantity;
}
/// 只接受本人配送接口的显式事实;不可用能力保留布尔状态,不由客户端猜测。
class DeliveryDetail {
DeliveryDetail.fromJson(Map<String, Object?> data)
: identity = _required(data, 'identity'),
orderNo = _required(data, 'order_no'),
statusName = _required(data, 'status_name'),
statusMessage = _required(data, 'status_message'),
address = _required(data, 'address'),
contactName = _required(data, 'contact_name'),
contactPhoneMasked = _required(data, 'contact_phone_masked'),
stationName = _text(data, 'station_name'),
deliveryName = _text(data, 'delivery_name'),
deliveryAddress = _text(data, 'delivery_address'),
staffName = _text(data, 'staff_name'),
staffAvatar = _text(data, 'staff_avatar'),
credentialType = _text(data, 'credential_type'),
appointmentAt = DateTime.parse(_required(data, 'appointment_at')).toLocal(),
trackUpdatedAt = _date(data['track_updated_at']),
staffAssigned = _flag(data, 'staff_assigned'),
credentialVerified = _flag(data, 'credential_verified'),
trackAvailable = _flag(data, 'track_available'),
controlledCallAvailable = _flag(data, 'controlled_call_available'),
messageAvailable = _flag(data, 'message_available'),
vehicleConfigured = _flag(data, 'vehicle_configured'),
products = List.unmodifiable([
for (final row in data['products'] as List)
DeliveryProduct(
name: _required(Map<String, Object?>.from(row as Map), 'name'),
quantity: (row['quantity'] as int?) ?? 0,
),
]) {
if (products.any((item) => item.quantity < 1)) throw const FormatException('配送商品数量异常');
}
final String identity, orderNo, statusName, statusMessage, address, contactName;
final String contactPhoneMasked, stationName, deliveryName, deliveryAddress, staffName;
final String staffAvatar;
final String credentialType;
final DateTime appointmentAt;
final DateTime? trackUpdatedAt;
final bool staffAssigned, credentialVerified, trackAvailable;
final bool controlledCallAvailable, messageAvailable, vehicleConfigured;
final List<DeliveryProduct> products;
static String _text(Map<String, Object?> data, String key) => data[key] as String? ?? '';
static String _required(Map<String, Object?> data, String key) {
final value = _text(data, key);
if (value.trim().isEmpty) throw FormatException('配送资料不完整:$key');
return value;
}
static bool _flag(Map<String, Object?> data, String key) {
if (data[key] is! bool) throw FormatException('配送状态异常:$key');
return data[key] as bool;
}
static DateTime? _date(Object? value) =>
value == null ? null : DateTime.tryParse('$value')?.toLocal();
}