189 lines
4.8 KiB
Dart
189 lines
4.8 KiB
Dart
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||
|
|
|
||
|
|
class Buyer {
|
||
|
|
String id;
|
||
|
|
String bizName;
|
||
|
|
String bizAddress;
|
||
|
|
String bizType;
|
||
|
|
int numOfShops;
|
||
|
|
String shopAddress;
|
||
|
|
String status;
|
||
|
|
String userName;
|
||
|
|
String userID;
|
||
|
|
String phoneNumber;
|
||
|
|
DateTime regDate;
|
||
|
|
List<BuyerProduct> buyerProducts = [];
|
||
|
|
String comment;
|
||
|
|
String nricFrontUrl;
|
||
|
|
String nricBackUrl;
|
||
|
|
int dailyQuota;
|
||
|
|
int maxQuota;
|
||
|
|
int dailyQuotaUsed;
|
||
|
|
int maxQuotaUsed;
|
||
|
|
Map<String, int> dailyQuotaUsedProducts;
|
||
|
|
Map<String, int> maxQuotaUsedProducts;
|
||
|
|
|
||
|
|
String get phone => phoneNumber != null && phoneNumber.startsWith("959")
|
||
|
|
? "0${phoneNumber.substring(2)}"
|
||
|
|
: phoneNumber;
|
||
|
|
|
||
|
|
Buyer(
|
||
|
|
{this.bizName,
|
||
|
|
this.bizAddress,
|
||
|
|
this.numOfShops,
|
||
|
|
this.status,
|
||
|
|
this.bizType,
|
||
|
|
this.regDate,
|
||
|
|
this.userName,
|
||
|
|
this.userID,
|
||
|
|
this.phoneNumber,
|
||
|
|
this.id,
|
||
|
|
this.comment,
|
||
|
|
this.nricBackUrl,
|
||
|
|
this.nricFrontUrl,
|
||
|
|
this.shopAddress,
|
||
|
|
this.dailyQuota,
|
||
|
|
this.maxQuota,
|
||
|
|
this.dailyQuotaUsed,
|
||
|
|
this.maxQuotaUsed,
|
||
|
|
this.dailyQuotaUsedProducts,
|
||
|
|
this.maxQuotaUsedProducts});
|
||
|
|
|
||
|
|
factory Buyer.fromJson(Map<String, dynamic> json) {
|
||
|
|
var _regDate = DateTime.parse(json['reg_date']);
|
||
|
|
|
||
|
|
return Buyer(
|
||
|
|
bizName: json['biz_name'],
|
||
|
|
bizAddress: json['biz_address'],
|
||
|
|
numOfShops: json['num_of_shops'],
|
||
|
|
shopAddress: json['shop_address'],
|
||
|
|
status: json['status'],
|
||
|
|
bizType: json['biz_type'],
|
||
|
|
regDate: _regDate,
|
||
|
|
userName: json['user_name'],
|
||
|
|
userID: json['user_id'],
|
||
|
|
phoneNumber: json['phone_number'],
|
||
|
|
id: json['id'],
|
||
|
|
comment: json['comment'],
|
||
|
|
nricBackUrl: json['nric_back_url'],
|
||
|
|
nricFrontUrl: json['nric_front_url']);
|
||
|
|
}
|
||
|
|
|
||
|
|
factory Buyer.fromMap(Map<String, dynamic> map, String id) {
|
||
|
|
var _regDate = (map['reg_date'] as Timestamp);
|
||
|
|
return Buyer(
|
||
|
|
id: id,
|
||
|
|
bizName: map['biz_name'],
|
||
|
|
bizAddress: map['biz_address'],
|
||
|
|
bizType: map['biz_type'],
|
||
|
|
numOfShops: map['num_of_shops'],
|
||
|
|
shopAddress: map['shop_address'],
|
||
|
|
status: map['status'],
|
||
|
|
userName: map['user_name'],
|
||
|
|
userID: map['user_id'],
|
||
|
|
phoneNumber: map['phone_number'],
|
||
|
|
nricFrontUrl: map['nric_front_url'],
|
||
|
|
nricBackUrl: map['nric_back_url'],
|
||
|
|
dailyQuota: map['daily_quota'],
|
||
|
|
maxQuota: map['max_quota'],
|
||
|
|
dailyQuotaUsed: map['daily_quota_used'] ?? 0,
|
||
|
|
maxQuotaUsed: map['max_quota_used'] ?? 0,
|
||
|
|
dailyQuotaUsedProducts:
|
||
|
|
Map.from(map['daily_quota_used_products'] ?? Map<String, int>()),
|
||
|
|
maxQuotaUsedProducts:
|
||
|
|
Map.from(map['max_quota_used_products'] ?? Map<String, int>()),
|
||
|
|
regDate: _regDate?.toDate(),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, dynamic> toMap() {
|
||
|
|
List products = buyerProducts.map((l) => l.toMap()).toList();
|
||
|
|
return {
|
||
|
|
'id': id,
|
||
|
|
'biz_name': bizName,
|
||
|
|
'biz_address': bizAddress,
|
||
|
|
'biz_type': bizType,
|
||
|
|
'num_of_shops': numOfShops,
|
||
|
|
'shop_address': shopAddress,
|
||
|
|
'buyer_products': products,
|
||
|
|
'user_name': userName,
|
||
|
|
'user_id': userID,
|
||
|
|
'phone_number': phoneNumber,
|
||
|
|
'comment': comment,
|
||
|
|
'nric_front_url': nricFrontUrl,
|
||
|
|
'nric_back_url': nricBackUrl,
|
||
|
|
'daily_quota': dailyQuota,
|
||
|
|
'max_quota': maxQuota,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
bool isApproved() {
|
||
|
|
return status != null && status == "approved";
|
||
|
|
}
|
||
|
|
|
||
|
|
bool isPending() {
|
||
|
|
return status != null && status == "pending";
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
String toString() {
|
||
|
|
return 'Buyer{bizName:$bizName,bizAddress:$bizAddress,numOfShops:$numOfShops,status:$status}';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class BuyerProduct {
|
||
|
|
String productID;
|
||
|
|
String productName;
|
||
|
|
int dailySaleQty;
|
||
|
|
int storageCapacityQty;
|
||
|
|
int dailyQuota;
|
||
|
|
int maxQuota;
|
||
|
|
String action;
|
||
|
|
|
||
|
|
BuyerProduct(
|
||
|
|
{this.productID,
|
||
|
|
this.productName,
|
||
|
|
this.dailySaleQty,
|
||
|
|
this.storageCapacityQty,
|
||
|
|
this.dailyQuota,
|
||
|
|
this.maxQuota,
|
||
|
|
this.action});
|
||
|
|
|
||
|
|
factory BuyerProduct.fromMap(Map<String, dynamic> map, String id) {
|
||
|
|
return BuyerProduct(
|
||
|
|
productID: map['product_id'],
|
||
|
|
productName: map['product_name'],
|
||
|
|
dailySaleQty: map['daily_sale_qty'],
|
||
|
|
storageCapacityQty: map['storage_capacity_qty'],
|
||
|
|
dailyQuota: map['daily_quota'],
|
||
|
|
maxQuota: map['max_quota'],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, dynamic> toMap() {
|
||
|
|
return {
|
||
|
|
'product_id': productID,
|
||
|
|
'product_name': productName,
|
||
|
|
'daily_sale_qty': dailySaleQty,
|
||
|
|
'storage_capacity_qty': storageCapacityQty,
|
||
|
|
'daily_quota': dailyQuota,
|
||
|
|
'max_quota': maxQuota,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
bool operator ==(other) {
|
||
|
|
if (identical(this, other)) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return (other.productID == this.productID);
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
int get hashCode {
|
||
|
|
int result = 17;
|
||
|
|
result = 37 * result + productID.hashCode;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|