fix: ultra-fake orders
This commit is contained in:
@@ -16,7 +16,7 @@ Future<List<GymHistoryItem>> getHistory() async {
|
||||
return history;
|
||||
}
|
||||
|
||||
Future<void> addToHistory(GymHistoryItem item) async {
|
||||
Future<void> addToHistory(GymHistoryItemDetail item) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String historyString = prefs.getString('history') ?? "[]";
|
||||
List<GymHistoryItem> history = [];
|
||||
@@ -29,6 +29,10 @@ Future<void> addToHistory(GymHistoryItem item) async {
|
||||
for (var historyItem in jsonDecode(detailHistoryString) as List<dynamic>) {
|
||||
detailHistory.add(GymHistoryItemDetail.fromJson(historyItem));
|
||||
}
|
||||
List<Map<String, dynamic>> providers = [];
|
||||
for (final provider in item.providers) {
|
||||
providers.add(provider.toJson());
|
||||
}
|
||||
var json = {
|
||||
"id": item.id,
|
||||
"date": DateTime.now()
|
||||
@@ -40,58 +44,23 @@ Future<void> addToHistory(GymHistoryItem item) async {
|
||||
.split('.')
|
||||
.reversed
|
||||
.join('.'),
|
||||
"sum": Random().nextInt(100000).toString(),
|
||||
"pay_url": [null, "https://example.org"][Random().nextInt(2)],
|
||||
"receiver": "Иванов Иван Иванович ${Random().nextInt(100000).toString()}",
|
||||
"email": "a${Random().nextInt(100000).toString()}@a.ru",
|
||||
"address":
|
||||
"г. ${['Москва', 'Петербург', 'Новгород'][Random().nextInt(3)]}, ул. ${[
|
||||
'Пушкина',
|
||||
'Ленина',
|
||||
'Лермонтова'
|
||||
][Random().nextInt(3)]}, д. ${Random().nextInt(100).toString()}",
|
||||
"providers": [
|
||||
{
|
||||
"id": Random().nextInt(100000).toString(),
|
||||
"name": "Поставщик ${Random().nextInt(100000).toString()}",
|
||||
"status": ["Доставлен", "Доставляется", "Ожидает"][Random().nextInt(3)],
|
||||
"items": [
|
||||
{
|
||||
"photo": "url${Random().nextInt(100000).toString()}",
|
||||
"id": Random().nextInt(100000).toString(),
|
||||
"count": Random().nextInt(100),
|
||||
"price": Random().nextInt(100000).toString()
|
||||
},
|
||||
{
|
||||
"photo": "url${Random().nextInt(100000).toString()}",
|
||||
"id": Random().nextInt(100000).toString(),
|
||||
"count": Random().nextInt(100),
|
||||
"price": Random().nextInt(100000).toString()
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": Random().nextInt(100000).toString(),
|
||||
"name": "Поставщик ${Random().nextInt(100000).toString()}",
|
||||
"status": ["Доставлен", "Доставляется", "Ожидает"][Random().nextInt(3)],
|
||||
"items": [
|
||||
{
|
||||
"photo": "url${Random().nextInt(100000).toString()}",
|
||||
"id": Random().nextInt(100000).toString(),
|
||||
"count": Random().nextInt(100),
|
||||
"price": Random().nextInt(100000).toString()
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"sum": item.sum,
|
||||
"pay_url": item.providers.where((e) => e.status == 'Не оплачен').isNotEmpty
|
||||
? 'https://example.org'
|
||||
: null,
|
||||
"receiver": item.receiver,
|
||||
"email": item.email,
|
||||
"address": item.address,
|
||||
"providers": providers
|
||||
};
|
||||
final detailHistoryItem = GymHistoryItemDetail.fromJson(json);
|
||||
detailHistory.add(detailHistoryItem);
|
||||
history.add(GymHistoryItem(
|
||||
date: detailHistoryItem.date,
|
||||
id: detailHistoryItem.id,
|
||||
photo: 'product.png',
|
||||
sum: detailHistoryItem.sum));
|
||||
date: detailHistoryItem.date,
|
||||
id: detailHistoryItem.id,
|
||||
photo: detailHistoryItem.providers[0].items[0].photo,
|
||||
sum: detailHistoryItem.sum,
|
||||
));
|
||||
prefs.setString('history', jsonEncode(history));
|
||||
prefs.setString('detail_history', jsonEncode(detailHistory));
|
||||
}
|
||||
@@ -106,3 +75,25 @@ Future<GymHistoryItemDetail?> getHistoryDetail(String id) async {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> payOrder(String id) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String historyString = prefs.getString('detail_history') ?? "[]";
|
||||
List<GymHistoryItemDetail> history = [];
|
||||
for (var historyItem in jsonDecode(historyString) as List<dynamic>) {
|
||||
history.add(GymHistoryItemDetail.fromJson(historyItem));
|
||||
}
|
||||
List<GymHistoryItemDetail> newHistory = [];
|
||||
for (final historyItem in history) {
|
||||
if (historyItem.id == id) {
|
||||
for (final provider in historyItem.providers) {
|
||||
if (provider.status == 'Не оплачен') {
|
||||
provider.status = 'Оплачен';
|
||||
}
|
||||
}
|
||||
historyItem.payUrl = null;
|
||||
}
|
||||
newHistory.add(historyItem);
|
||||
}
|
||||
prefs.setString('detail_history', jsonEncode(newHistory));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user