This commit is contained in:
masoodafar-web
2025-12-02 03:32:39 +03:30
parent f5dc44df00
commit a8e6693c70
7 changed files with 300 additions and 6284 deletions
@@ -1,21 +1,125 @@
using FrontOffice.Main.Utilities;
using Microsoft.AspNetCore.Components;
using MudBlazor;
namespace FrontOffice.Main.Pages.Profile;
public partial class Wallet : ComponentBase
{
[Inject] private ISnackbar Snackbar { get; set; } = default!;
private (string Credit, string Network) _balances = ("-", "-");
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.NetworkBalance));
_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;
if (long.TryParse(_filterReferenceId, out var parsed) && parsed > 0)
{
refId = parsed;
}
bool? isIncrease = _filterType switch
{
"in" => true,
"out" => false,
_ => 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 => "الماس",
_ => "-"
};
}