You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
237 lines
8.3 KiB
Dart
237 lines
8.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mohem_flutter_app/api/api_client.dart';
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/get_categories_list.dart';
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart';
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_category_model.dart';
|
|
import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_retailer_model.dart';
|
|
|
|
class OffersAndDiscountsApiClient {
|
|
static final OffersAndDiscountsApiClient _instance = OffersAndDiscountsApiClient._internal();
|
|
|
|
OffersAndDiscountsApiClient._internal();
|
|
|
|
factory OffersAndDiscountsApiClient() => _instance;
|
|
|
|
Future<List<GetCategoriesList>> getSaleCategories() async {
|
|
List<GetCategoriesList> getSaleCategoriesList = [];
|
|
|
|
String url = "${ApiConsts.cocRest}Mohemm_ITG_GetCategories";
|
|
Map<String, dynamic> postParams = {"EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER, "ItgPageSize": 100, "ItgPageNo": 1, "ItgIsActive": true};
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject(
|
|
(response) {
|
|
var body = json.decode(response['Mohemm_ITG_ResponseItem']);
|
|
|
|
GetCategoriesList getSaleCategoriesListObj = GetCategoriesList();
|
|
getSaleCategoriesListObj.id = 0;
|
|
getSaleCategoriesListObj.categoryNameEn = "All";
|
|
getSaleCategoriesListObj.categoryNameAr = "الجميع";
|
|
getSaleCategoriesListObj.isActive = true;
|
|
getSaleCategoriesListObj.content =
|
|
'<svg xmlns="http://www.w3.org/2000/svg" width="26.213" height="26.213" viewBox="0 0 26.213 26.213"> <g id="More_Select" data-name="More Select" transform="translate(-1 -1)"> <path id="Path_4860" data-name="Path 4860" d="M26.844,1H5.874A.874.874,0,0,0,5,1.874v.874H23.349A2.621,2.621,0,0,1,25.97,5.369V23.718h.874a.874.874,0,0,0,.874-.874V1.874A.874.874,0,0,0,26.844,1Z" transform="translate(-0.505)" fill="#2bb8a6"/> <path id="Path_4861" data-name="Path 4861" d="M22.844,5H1.874A.874.874,0,0,0,1,5.874v20.97a.874.874,0,0,0,.874.874h20.97a.874.874,0,0,0,.874-.874V5.874A.874.874,0,0,0,22.844,5ZM18.7,13.164,11.07,20.789a.874.874,0,0,1-1.236,0L6.022,16.977a.874.874,0,1,1,1.236-1.236l3.2,3.195,7.008-7.007A.874.874,0,1,1,18.7,13.165Z" transform="translate(0 -0.505)" fill="#125765"/> </g> </svg>';
|
|
|
|
getSaleCategoriesList.add(getSaleCategoriesListObj);
|
|
|
|
body['result']['data'].forEach((v) {
|
|
getSaleCategoriesList.add(GetCategoriesList.fromJson(v));
|
|
});
|
|
return getSaleCategoriesList;
|
|
},
|
|
url,
|
|
postParams,
|
|
);
|
|
}
|
|
|
|
Future<List<OffersListModel>> getOffersList(int categoryID, int pageSize) async {
|
|
List<OffersListModel> getSaleCategoriesList = [];
|
|
|
|
String url = "${ApiConsts.cocRest}GetOfferDiscountsConfigData";
|
|
Map<String, dynamic> postParams = {"EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER, "ItgPageSize": pageSize, "ItgPageNo": 1, "ItgCategoryID": categoryID};
|
|
|
|
postParams.addAll(AppState().postParamsJson);
|
|
return await ApiClient().postJsonForObject(
|
|
(response) {
|
|
var body = json.decode(response['Mohemm_ITG_ResponseItem']);
|
|
|
|
var bodyData = body['result']['data'];
|
|
|
|
if (bodyData != null) {
|
|
bodyData.forEach((v) {
|
|
getSaleCategoriesList.add(OffersListModel.fromJson(v));
|
|
});
|
|
}
|
|
return getSaleCategoriesList;
|
|
},
|
|
url,
|
|
postParams,
|
|
);
|
|
}
|
|
|
|
Future<List<WalaPlusCategoryModel>> getWalaPlusCategories({BuildContext? context}) async {
|
|
String url = ApiConsts.walaPlusCategories;
|
|
|
|
String? pUserName = AppState().getUserName;
|
|
if (pUserName == null || pUserName.isEmpty) {
|
|
pUserName = "2537367522";
|
|
}
|
|
|
|
String? tokenID = AppState().postParamsObject?.tokenID;
|
|
if (tokenID == null || tokenID.isEmpty || tokenID == "adm!n") {
|
|
tokenID = "@dm!n";
|
|
}
|
|
|
|
String? logInTokenID = AppState().postParamsObject?.logInTokenID;
|
|
if (logInTokenID == null || logInTokenID.isEmpty) {
|
|
logInTokenID = "@dm!n";
|
|
}
|
|
|
|
Map<String, dynamic> postParams = {
|
|
"VersionID": 20,
|
|
"Channel": 31,
|
|
"LanguageID": context != null ? AppState().getLanguageID(context) : 2,
|
|
"LogInTokenID": logInTokenID,
|
|
"TokenID": tokenID,
|
|
"P_USER_NAME": pUserName,
|
|
};
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
(response) {
|
|
List<WalaPlusCategoryModel> categories = [];
|
|
if (response != null && response['WalaPlus_Categories'] != null) {
|
|
var cats = response['WalaPlus_Categories'];
|
|
if (cats is String) {
|
|
cats = json.decode(cats);
|
|
}
|
|
if (cats is List) {
|
|
cats.forEach((v) {
|
|
categories.add(WalaPlusCategoryModel.fromJson(v));
|
|
});
|
|
}
|
|
}
|
|
return categories;
|
|
},
|
|
url,
|
|
postParams,
|
|
);
|
|
}
|
|
|
|
Future<WalaPlusRetailersResponse?> getWalaPlusRetailers({
|
|
String? categoryId,
|
|
int page = 1,
|
|
int perPage = 10,
|
|
String? geoLocation,
|
|
BuildContext? context,
|
|
}) async {
|
|
String url = ApiConsts.walaPlusRetailers;
|
|
|
|
String? pUserName = AppState().getUserName;
|
|
if (pUserName == null || pUserName.isEmpty) {
|
|
pUserName = "2537367522";
|
|
}
|
|
|
|
String? tokenID = AppState().postParamsObject?.tokenID;
|
|
if (tokenID == null || tokenID.isEmpty) {
|
|
tokenID = "adm!n";
|
|
}
|
|
|
|
String? logInTokenID = AppState().postParamsObject?.logInTokenID;
|
|
if (logInTokenID == null || logInTokenID.isEmpty) {
|
|
logInTokenID = "@dm!n";
|
|
}
|
|
|
|
Map<String, dynamic> postParams = {
|
|
"VersionID": 20,
|
|
"Channel": 31,
|
|
"LanguageID": context != null ? AppState().getLanguageID(context) : 2,
|
|
"LogInTokenID": logInTokenID,
|
|
"TokenID": tokenID,
|
|
"P_USER_NAME": pUserName,
|
|
"WP_CategoryID": (categoryId == "all" || categoryId == null) ? "" : categoryId,
|
|
"WP_Page": page,
|
|
"WP_Per_page": perPage,
|
|
};
|
|
|
|
if (geoLocation != null && geoLocation.isNotEmpty) {
|
|
postParams["WP_Geo_Location"] = geoLocation;
|
|
}
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
(response) {
|
|
if (response != null && response['WalaPlus_Retailers'] != null) {
|
|
var val = response['WalaPlus_Retailers'];
|
|
if (val is String) {
|
|
val = json.decode(val);
|
|
}
|
|
if (val is Map<String, dynamic>) {
|
|
return WalaPlusRetailersResponse.fromJson(val);
|
|
} else if (val is Map) {
|
|
return WalaPlusRetailersResponse.fromJson(Map<String, dynamic>.from(val));
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
url,
|
|
postParams,
|
|
);
|
|
}
|
|
|
|
Future<WalaPlusRetailerModel?> getWalaPlusRetailerById({
|
|
required String retailerId,
|
|
BuildContext? context,
|
|
}) async {
|
|
String url = ApiConsts.walaPlusRetailersByID;
|
|
|
|
String? pUserName = AppState().getUserName;
|
|
if (pUserName == null || pUserName.isEmpty) {
|
|
pUserName = "2537367522";
|
|
}
|
|
|
|
String? tokenID = AppState().postParamsObject?.tokenID;
|
|
if (tokenID == null || tokenID.isEmpty) {
|
|
tokenID = "adm!n";
|
|
}
|
|
|
|
String? logInTokenID = AppState().postParamsObject?.logInTokenID;
|
|
if (logInTokenID == null || logInTokenID.isEmpty) {
|
|
logInTokenID = "@dm!n";
|
|
}
|
|
|
|
Map<String, dynamic> postParams = {
|
|
"VersionID": 20,
|
|
"Channel": 31,
|
|
"LanguageID": context != null ? AppState().getLanguageID(context) : 2,
|
|
"LogInTokenID": logInTokenID,
|
|
"TokenID": tokenID,
|
|
"RetailerID": retailerId,
|
|
"P_USER_NAME": pUserName,
|
|
};
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
(response) {
|
|
if (response != null && response['WalaPlus_RetailersByID'] != null) {
|
|
var val = response['WalaPlus_RetailersByID'];
|
|
if (val is String) {
|
|
val = json.decode(val);
|
|
}
|
|
if (val is List && val.isNotEmpty) {
|
|
var item = val.first;
|
|
if (item is Map<String, dynamic>) {
|
|
return WalaPlusRetailerModel.fromJson(item);
|
|
} else if (item is Map) {
|
|
return WalaPlusRetailerModel.fromJson(Map<String, dynamic>.from(item));
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
url,
|
|
postParams,
|
|
);
|
|
}
|
|
}
|