update
This commit is contained in:
@@ -72,6 +72,12 @@
|
||||
<MudText Typo="Typo.h5" Color="Color.Primary">@_walletCredit</MudText>
|
||||
</MudStack>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
<MudStack>
|
||||
<MudText Typo="Typo.subtitle2" Class="mud-text-secondary">موجودی تخفیف باشگاه</MudText>
|
||||
<MudText Typo="Typo.h5" Color="Color.Primary">@_walletDiscount</MudText>
|
||||
</MudStack>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
<MudStack>
|
||||
<MudText Typo="Typo.subtitle2" Class="mud-text-secondary">موجودی شبکه</MudText>
|
||||
|
||||
@@ -51,12 +51,15 @@ public partial class Index
|
||||
}
|
||||
|
||||
private string _walletCredit = "-";
|
||||
private string _walletDiscount = "-";
|
||||
private string _walletNetwork = "-";
|
||||
private async Task LoadWallet()
|
||||
{
|
||||
var b = await WalletService.GetBalancesAsync();
|
||||
_walletCredit = FormatPrice(b.CreditBalance);
|
||||
var discount = FormatPrice(b.DiscountBalance);
|
||||
_walletNetwork = FormatPrice(b.NetworkBalance);
|
||||
_walletDiscount = discount;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
<MudText Typo="Typo.h4" Color="Color.Primary">@_balances.Credit</MudText>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.subtitle2" Class="mud-text-secondary">موجودی تخفیف باشگاه</MudText>
|
||||
<MudText Typo="Typo.h4" Color="Color.Primary">@_balances.Discount</MudText>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">در انتظار اتصال CMS برای مقدار واقعی</MudText>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.subtitle2" Class="mud-text-secondary">موجودی شبکه</MudText>
|
||||
@@ -24,9 +31,62 @@
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">درخواست برداشت از موجودی شبکه</MudText>
|
||||
<MudStack Spacing="2">
|
||||
<MudTextField @bind-Value="_withdrawPayoutId"
|
||||
Label="شناسه واریز (PayoutId)"
|
||||
Variant="Variant.Outlined"
|
||||
Type="MudBlazor.InputType.Number"
|
||||
Required="true" />
|
||||
<MudRadioGroup @bind-SelectedOption="_withdrawMethod" Row="true">
|
||||
<MudRadio Option="@WithdrawalMethodClient.Cash" Label="برداشت نقدی (نیاز به شبا)" />
|
||||
<MudRadio Option="@WithdrawalMethodClient.Diamond" Label="الماس/غیرنقدی" />
|
||||
</MudRadioGroup>
|
||||
<MudTextField @bind-Value="_withdrawIban"
|
||||
Label="شماره شبا"
|
||||
Variant="Variant.Outlined"
|
||||
Disabled="_withdrawMethod == WithdrawalMethodClient.Diamond"
|
||||
Placeholder="IRxxxxxxxxxxxx"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentText="IR" />
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">
|
||||
حداقل مبلغ برداشت: @FormatPrice(_minWithdrawalAmount)
|
||||
</MudText>
|
||||
<MudButton Disabled="_isSubmittingWithdrawal"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Outbound"
|
||||
OnClick="SubmitWithdrawal">
|
||||
@(_isSubmittingWithdrawal ? "در حال ثبت..." : "ثبت درخواست برداشت")
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">تراکنشها و مسیرهای شارژ</MudText>
|
||||
|
||||
<MudStack Row="true" Spacing="2" Class="mb-3" AlignItems="AlignItems.End">
|
||||
<MudTextField @bind-Value="_filterReferenceId"
|
||||
Label="شناسه ارجاع"
|
||||
Variant="Variant.Outlined"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search" />
|
||||
<MudSelect T="string" @bind-Value="_filterType" Label="نوع تراکنش" Variant="Variant.Outlined">
|
||||
<MudSelectItem Value="all">همه</MudSelectItem>
|
||||
<MudSelectItem Value="in">ورودی (شارژ)</MudSelectItem>
|
||||
<MudSelectItem Value="out">خروجی (برداشت/خرید)</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudSelect T="string" @bind-Value="_withdrawStatusFilter" Label="وضعیت برداشت" Variant="Variant.Outlined">
|
||||
<MudSelectItem Value="all">همه</MudSelectItem>
|
||||
<MudSelectItem Value="pending">Pending</MudSelectItem>
|
||||
<MudSelectItem Value="requested">Requested</MudSelectItem>
|
||||
<MudSelectItem Value="withdrawn">Withdrawn</MudSelectItem>
|
||||
<MudSelectItem Value="cancelled">Cancelled</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudButton Variant="Variant.Outlined" OnClick="ApplyFilters" StartIcon="@Icons.Material.Filled.FilterList">اعمال فیلتر</MudButton>
|
||||
</MudStack>
|
||||
|
||||
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
|
||||
<MudTable Items="_txs" Dense="true">
|
||||
<HeaderContent>
|
||||
@@ -62,5 +122,49 @@
|
||||
</MudStack>
|
||||
</MudHidden>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">درخواستهای برداشت ثبتشده</MudText>
|
||||
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
|
||||
<MudTable Items="_withdrawals" Dense="true">
|
||||
<HeaderContent>
|
||||
<MudTh>هفته</MudTh>
|
||||
<MudTh>مبلغ</MudTh>
|
||||
<MudTh>وضعیت</MudTh>
|
||||
<MudTh>روش</MudTh>
|
||||
<MudTh>تاریخ</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>@context.WeekNumber</MudTd>
|
||||
<MudTd>@FormatPrice(context.Amount)</MudTd>
|
||||
<MudTd>
|
||||
<MudChip Color="@(ResolveStatusColor(context.Status))" Variant="Variant.Outlined" Size="Size.Small">
|
||||
@ResolveStatusText(context.Status)
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
<MudTd>@ResolveMethodText(context.Method)</MudTd>
|
||||
<MudTd>@context.Created</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</MudHidden>
|
||||
|
||||
<MudHidden Breakpoint="Breakpoint.MdAndUp">
|
||||
<MudStack Spacing="2">
|
||||
@foreach (var wd in _withdrawals)
|
||||
{
|
||||
<MudPaper Class="pa-3 rounded-lg" Outlined="true">
|
||||
<MudStack Spacing="1">
|
||||
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
|
||||
<MudText>@wd.WeekNumber</MudText>
|
||||
<MudText Color="Color.Primary">@FormatPrice(wd.Amount)</MudText>
|
||||
</MudStack>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">وضعیت: @ResolveStatusText(wd.Status) | روش: @ResolveMethodText(wd.Method)</MudText>
|
||||
<MudText Typo="Typo.caption" Class="mud-text-secondary">@wd.Created</MudText>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
}
|
||||
</MudStack>
|
||||
</MudHidden>
|
||||
</MudPaper>
|
||||
</MudStack>
|
||||
</MudContainer>
|
||||
|
||||
@@ -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 => "الماس",
|
||||
_ => "-"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,8 +4,15 @@ using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace FrontOffice.Main.Utilities;
|
||||
|
||||
public record WalletBalances(long CreditBalance, long NetworkBalance);
|
||||
public record WalletBalances(long CreditBalance, long DiscountBalance, long NetworkBalance);
|
||||
public record WalletTransaction(string Date, long Amount, string Channel, string Description);
|
||||
public record WalletWithdrawal(long Id, string WeekNumber, long Amount, int Status, int? Method, string? Iban, string Created);
|
||||
public enum WithdrawalMethodClient
|
||||
{
|
||||
Cash = 0,
|
||||
Diamond = 1
|
||||
}
|
||||
public record WithdrawalSettings(long MinWithdrawalAmount);
|
||||
|
||||
public class WalletService
|
||||
{
|
||||
@@ -21,26 +28,35 @@ public class WalletService
|
||||
try
|
||||
{
|
||||
var response = await _client.GetUserWalletAsync(new Empty());
|
||||
return new WalletBalances(response.Balance, response.NetworkBalance);
|
||||
return new WalletBalances(response.Balance, response.DiscountBalance, response.NetworkBalance);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to mock data if backend is unavailable
|
||||
return new WalletBalances(350_000, 1_250_000);
|
||||
return new WalletBalances(350_000, 0, 1_250_000);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<WalletTransaction>> GetTransactionsAsync()
|
||||
public async Task<List<WalletTransaction>> GetTransactionsAsync(long? referenceId = null, bool? isIncrease = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _client.GetAllUserWalletChangeLogAsync(new Empty());
|
||||
var request = new GetAllUserWalletChangeLogRequest();
|
||||
if (referenceId.HasValue)
|
||||
{
|
||||
request.ReferenceId = referenceId.Value;
|
||||
}
|
||||
if (isIncrease.HasValue)
|
||||
{
|
||||
request.IsIncrease = isIncrease.Value;
|
||||
}
|
||||
var response = await _client.GetAllUserWalletChangeLogAsync(request);
|
||||
return response.Models
|
||||
.Select(t => new WalletTransaction(
|
||||
ResolveTransactionDate(t),
|
||||
t.CurrentBalance,
|
||||
t.ChangeValue != 0 ? t.ChangeValue : t.CurrentBalance,
|
||||
t.RefrenceId?.ToString() ?? "-",
|
||||
t.IsIncrease ? "شارژ کیف پول" : "برداشت از کیف پول"))
|
||||
ResolveDescription(t)))
|
||||
.OrderByDescending(t => t.Date)
|
||||
.ToList();
|
||||
}
|
||||
@@ -74,5 +90,61 @@ public class WalletService
|
||||
|
||||
return DateTime.Now.MiladiToJalaliWithTime();
|
||||
}
|
||||
}
|
||||
|
||||
private static string ResolveDescription(GetAllUserWalletChangeLogResponseModel model)
|
||||
{
|
||||
if (model.ChangeValue > 0) return "شارژ کیف پول";
|
||||
if (model.ChangeValue < 0) return "برداشت/خرید";
|
||||
return "تراکنش کیف پول";
|
||||
}
|
||||
|
||||
public async Task<bool> RequestWithdrawalAsync(long payoutId, WithdrawalMethodClient method, string? iban)
|
||||
{
|
||||
var request = new WithdrawBalanceRequest
|
||||
{
|
||||
PayoutId = payoutId,
|
||||
WithdrawalMethod = (int)method
|
||||
};
|
||||
if (!string.IsNullOrWhiteSpace(iban))
|
||||
{
|
||||
request.IbanNumber = iban;
|
||||
}
|
||||
try
|
||||
{
|
||||
await _client.WithdrawBalanceAsync(request);
|
||||
return true;
|
||||
}
|
||||
catch (Grpc.Core.RpcException ex)
|
||||
{
|
||||
// surface backend error text
|
||||
throw new InvalidOperationException(ex.Status.Detail ?? "خطا در ثبت برداشت", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<WalletWithdrawal>> GetWithdrawalsAsync(int? status = null)
|
||||
{
|
||||
var request = new GetUserWithdrawalsRequest();
|
||||
if (status.HasValue)
|
||||
{
|
||||
request.Status = status.Value;
|
||||
}
|
||||
|
||||
var response = await _client.GetUserWithdrawalsAsync(request);
|
||||
return response.Models
|
||||
.Select(m => new WalletWithdrawal(
|
||||
m.Id,
|
||||
m.WeekNumber,
|
||||
m.TotalAmount,
|
||||
m.Status,
|
||||
m.WithdrawalMethod?.Value,
|
||||
m.IbanNumber,
|
||||
m.Created.ToDateTime().MiladiToJalaliWithTime()))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<WithdrawalSettings> GetWithdrawalSettingsAsync()
|
||||
{
|
||||
var response = await _client.GetWithdrawalSettingsAsync(new Empty());
|
||||
return new WithdrawalSettings(response.MinWithdrawalAmount);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user