已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
This commit is contained in:
53
apps/user_app/lib/domain/models/cart_item.dart
Normal file
53
apps/user_app/lib/domain/models/cart_item.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
// 功能描述:购物车条目、并发版本和结算快照;版本:1.0.0。
|
||||
import 'primary_models.dart';
|
||||
|
||||
/// 服务端购物车快照;revision 用于阻止过期操作覆盖其他设备的修改。
|
||||
class CartItem {
|
||||
const CartItem({
|
||||
required this.product,
|
||||
required this.quantity,
|
||||
required this.selected,
|
||||
required this.available,
|
||||
required this.revision,
|
||||
this.specification = '',
|
||||
});
|
||||
final ProductSummary product;
|
||||
final int quantity;
|
||||
final bool selected, available;
|
||||
final String revision;
|
||||
final String specification;
|
||||
bool get purchasable => available && quantity > 0 && quantity <= product.stock;
|
||||
int get amount => product.price * quantity;
|
||||
|
||||
factory CartItem.fromJson(Map<String, Object?> json, String Function(String) resolve) {
|
||||
final price = json['price_amount'], stock = json['stock_quantity'], quantity = json['quantity'];
|
||||
if (price is! int ||
|
||||
price < 0 ||
|
||||
stock is! int ||
|
||||
quantity is! int ||
|
||||
quantity < 0 ||
|
||||
quantity > 999 ||
|
||||
json['product_identity'] is! String ||
|
||||
(json['product_identity'] as String).isEmpty ||
|
||||
json['revision'] is! String ||
|
||||
json['selected'] is! bool ||
|
||||
json['available'] is! bool) {
|
||||
throw const FormatException('购物车数据异常');
|
||||
}
|
||||
return CartItem(
|
||||
product: ProductSummary(
|
||||
identity: json['product_identity'] as String,
|
||||
name: json['name'] as String? ?? '',
|
||||
price: price,
|
||||
stock: stock,
|
||||
imageUrl: resolve(json['image_url'] as String? ?? ''),
|
||||
category: json['category_name'] as String? ?? '',
|
||||
),
|
||||
quantity: quantity,
|
||||
selected: json['selected'] as bool,
|
||||
available: json['available'] as bool,
|
||||
revision: json['revision'] as String,
|
||||
specification: json['specification'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user