feat: add withdrawal requests feature and update VAT loading mechanism
Build and Deploy / build (push) Successful in 1m25s
Build and Deploy / build (push) Successful in 1m25s
This commit is contained in:
@@ -6,71 +6,20 @@ namespace FrontOffice.Main.Pages.Profile;
|
||||
|
||||
public partial class Wallet : ComponentBase
|
||||
{
|
||||
private long _minWithdrawalAmount = 1_000_000; // مقدار پیشفرض، از CMS خوانده میشود
|
||||
private (string Credit, string Discount, string Network) _balances = ("-", "-", "-");
|
||||
private List<WalletTransaction> _txs = new();
|
||||
private List<WalletWithdrawal> _withdrawals = new();
|
||||
private string? _filterReferenceId;
|
||||
private string _filterType = "all";
|
||||
private string _withdrawStatusFilter = "all";
|
||||
private bool _isSubmittingWithdrawal;
|
||||
private long _withdrawPayoutId;
|
||||
private WithdrawalMethodClient _withdrawMethod = WithdrawalMethodClient.Cash;
|
||||
private string? _withdrawIban;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var b = await WalletService.GetBalancesAsync();
|
||||
_balances = (FormatPrice(b.CreditBalance), FormatPrice(b.DiscountBalance), FormatPrice(b.NetworkBalance));
|
||||
_txs = await WalletService.GetTransactionsAsync();
|
||||
_withdrawals = await WalletService.GetWithdrawalsAsync();
|
||||
var settings = await WalletService.GetWithdrawalSettingsAsync();
|
||||
if (settings.MinWithdrawalAmount > 0)
|
||||
_minWithdrawalAmount = settings.MinWithdrawalAmount;
|
||||
}
|
||||
|
||||
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
|
||||
|
||||
private async Task SubmitWithdrawal()
|
||||
{
|
||||
var target = _withdrawals.FirstOrDefault(x => x.Id == _withdrawPayoutId);
|
||||
if (target is null)
|
||||
{
|
||||
_withdrawals = await WalletService.GetWithdrawalsAsync();
|
||||
target = _withdrawals.FirstOrDefault(x => x.Id == _withdrawPayoutId);
|
||||
}
|
||||
if (target != null && target.Amount < _minWithdrawalAmount)
|
||||
{
|
||||
Snackbar.Add($"مبلغ این واریز کمتر از حداقل برداشت ({_minWithdrawalAmount:N0} تومان) است.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (_withdrawPayoutId <= 0)
|
||||
{
|
||||
Snackbar.Add("شناسه واریز (PayoutId) الزامی است.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (_withdrawMethod == WithdrawalMethodClient.Cash && string.IsNullOrWhiteSpace(_withdrawIban))
|
||||
{
|
||||
Snackbar.Add("برای برداشت نقدی، شماره شبا لازم است.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_isSubmittingWithdrawal = true;
|
||||
await WalletService.RequestWithdrawalAsync(_withdrawPayoutId, _withdrawMethod, _withdrawIban);
|
||||
Snackbar.Add("درخواست برداشت ثبت شد.", Severity.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"خطا در ثبت برداشت: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSubmittingWithdrawal = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApplyFilters()
|
||||
{
|
||||
long? refId = null;
|
||||
@@ -85,39 +34,5 @@ public partial class Wallet : ComponentBase
|
||||
_ => null
|
||||
};
|
||||
_txs = await WalletService.GetTransactionsAsync(refId, isIncrease);
|
||||
int? status = _withdrawStatusFilter switch
|
||||
{
|
||||
"pending" => 1,
|
||||
"requested" => 2,
|
||||
"withdrawn" => 3,
|
||||
"cancelled" => 4,
|
||||
_ => null
|
||||
};
|
||||
_withdrawals = await WalletService.GetWithdrawalsAsync(status);
|
||||
}
|
||||
|
||||
private static string ResolveStatusText(int status) => status switch
|
||||
{
|
||||
0 => "ایجاد شده",
|
||||
1 => "پرداخت شده",
|
||||
2 => "درخواست برداشت",
|
||||
3 => "برداشت شده",
|
||||
4 => "لغو شده",
|
||||
_ => status.ToString()
|
||||
};
|
||||
|
||||
private static Color ResolveStatusColor(int status) => status switch
|
||||
{
|
||||
2 => Color.Warning,
|
||||
3 => Color.Success,
|
||||
4 => Color.Error,
|
||||
_ => Color.Info
|
||||
};
|
||||
|
||||
private static string ResolveMethodText(int? method) => method switch
|
||||
{
|
||||
0 => "نقدی",
|
||||
1 => "الماس",
|
||||
_ => "-"
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user