feat: enhance WithdrawalRequests page with payout selection and improved submission logic; add sorting options for products
Build and Deploy / build (push) Successful in 1m18s

This commit is contained in:
masoodafar-web
2025-12-27 06:22:41 +03:30
parent 43cdf7c897
commit e3521af071
10 changed files with 228 additions and 57 deletions
@@ -11,17 +11,52 @@
<!-- فرم درخواست برداشت جدید --> <!-- فرم درخواست برداشت جدید -->
<MudPaper Elevation="2" Class="pa-4 rounded-lg"> <MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-2">ثبت درخواست برداشت جدید</MudText> <MudText Typo="Typo.h6" Class="mb-3">ثبت درخواست برداشت جدید</MudText>
@if (!_availablePayouts.Any())
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined" Class="mb-3">
<MudText>در حال حاضر واریزی برای برداشت وجود ندارد.</MudText>
</MudAlert>
}
else
{
<MudStack Spacing="2"> <MudStack Spacing="2">
<MudTextField @bind-Value="_withdrawPayoutId" <MudSelect T="CommissionPayoutDto" @bind-Value="_selectedPayout"
Label="شناسه واریز (PayoutId)" Label="انتخاب واریز"
Variant="Variant.Outlined" Variant="Variant.Outlined"
Type="MudBlazor.InputType.Number" AnchorOrigin="Origin.BottomLeft"
Required="true" /> Required="true"
ToStringFunc="@(p => p != null ? $"{p.WeekDisplayName} - {p.AmountFormatted}" : "")">
@foreach (var payout in _availablePayouts)
{
<MudSelectItem T="CommissionPayoutDto" Value="@payout">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Class="w-100">
<MudText>@payout.WeekDisplayName</MudText>
<MudChip T="string" Color="Color.Success" Size="Size.Small" Variant="Variant.Filled">
@payout.AmountFormatted
</MudChip>
</MudStack>
</MudSelectItem>
}
</MudSelect>
@if (_selectedPayout != null)
{
<MudAlert Severity="Severity.Success" Variant="Variant.Text" Dense="true">
مبلغ قابل برداشت: <strong>@_selectedPayout.AmountFormatted</strong>
</MudAlert>
}
<MudRadioGroup T="WithdrawalMethodClient" @bind-Value="_withdrawMethod" Row="true"> <MudRadioGroup T="WithdrawalMethodClient" @bind-Value="_withdrawMethod" Row="true">
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Cash" Color="Color.Primary">برداشت نقدی (نیاز به شبا)</MudRadio> <MudRadio T="WithdrawalMethodClient" Value="@WithdrawalMethodClient.Cash" Color="Color.Primary">
<MudRadio T="WithdrawalMethodClient" Option="@WithdrawalMethodClient.Diamond" Color="Color.Secondary">الماس/غیرنقدی</MudRadio> برداشت نقدی (نیاز به شبا)
</MudRadio>
<MudRadio T="WithdrawalMethodClient" Disabled="true" Value="@WithdrawalMethodClient.Diamond" Color="Color.Secondary">
الماس/غیرنقدی
</MudRadio>
</MudRadioGroup> </MudRadioGroup>
<MudTextField @bind-Value="_withdrawIban" <MudTextField @bind-Value="_withdrawIban"
Label="شماره شبا" Label="شماره شبا"
Variant="Variant.Outlined" Variant="Variant.Outlined"
@@ -29,10 +64,12 @@
Placeholder="IRxxxxxxxxxxxx" Placeholder="IRxxxxxxxxxxxx"
Adornment="Adornment.Start" Adornment="Adornment.Start"
AdornmentText="IR" /> AdornmentText="IR" />
<MudText Typo="Typo.caption" Class="mud-text-secondary"> <MudText Typo="Typo.caption" Class="mud-text-secondary">
حداقل مبلغ برداشت: @FormatPrice(_minWithdrawalAmount) حداقل مبلغ برداشت: @FormatPrice(_minWithdrawalAmount)
</MudText> </MudText>
<MudButton Disabled="_isSubmittingWithdrawal"
<MudButton Disabled="@(_isSubmittingWithdrawal || _selectedPayout == null)"
Variant="Variant.Filled" Variant="Variant.Filled"
Color="Color.Primary" Color="Color.Primary"
StartIcon="@Icons.Material.Filled.Outbound" StartIcon="@Icons.Material.Filled.Outbound"
@@ -40,6 +77,7 @@
@(_isSubmittingWithdrawal ? "در حال ثبت..." : "ثبت درخواست برداشت") @(_isSubmittingWithdrawal ? "در حال ثبت..." : "ثبت درخواست برداشت")
</MudButton> </MudButton>
</MudStack> </MudStack>
}
</MudPaper> </MudPaper>
<!-- فیلتر وضعیت --> <!-- فیلتر وضعیت -->
@@ -6,12 +6,15 @@ namespace FrontOffice.Main.Pages.Profile;
public partial class WithdrawalRequests : ComponentBase public partial class WithdrawalRequests : ComponentBase
{ {
[Inject] private CommissionService CommissionService { get; set; } = default!;
private long _minWithdrawalAmount = 1_000_000; private long _minWithdrawalAmount = 1_000_000;
private List<WalletWithdrawal> _withdrawals = new(); private List<WalletWithdrawal> _withdrawals = new();
private List<CommissionPayoutDto> _availablePayouts = new();
private string _statusFilter = "all"; private string _statusFilter = "all";
private bool _isLoading = true; private bool _isLoading = true;
private bool _isSubmittingWithdrawal; private bool _isSubmittingWithdrawal;
private long _withdrawPayoutId; private CommissionPayoutDto? _selectedPayout;
private WithdrawalMethodClient _withdrawMethod = WithdrawalMethodClient.Cash; private WithdrawalMethodClient _withdrawMethod = WithdrawalMethodClient.Cash;
private string? _withdrawIban; private string? _withdrawIban;
@@ -26,6 +29,7 @@ public partial class WithdrawalRequests : ComponentBase
try try
{ {
_withdrawals = await WalletService.GetWithdrawalsAsync(); _withdrawals = await WalletService.GetWithdrawalsAsync();
_availablePayouts = await CommissionService.GetWithdrawablePayoutsAsync();
var settings = await WalletService.GetWithdrawalSettingsAsync(); var settings = await WalletService.GetWithdrawalSettingsAsync();
if (settings.MinWithdrawalAmount > 0) if (settings.MinWithdrawalAmount > 0)
_minWithdrawalAmount = settings.MinWithdrawalAmount; _minWithdrawalAmount = settings.MinWithdrawalAmount;
@@ -40,9 +44,9 @@ public partial class WithdrawalRequests : ComponentBase
private async Task SubmitWithdrawal() private async Task SubmitWithdrawal()
{ {
if (_withdrawPayoutId <= 0) if (_selectedPayout == null)
{ {
Snackbar.Add("شناسه واریز (PayoutId) الزامی است.", Severity.Warning); Snackbar.Add("لطفاً یک واریز را انتخاب کنید.", Severity.Warning);
return; return;
} }
if (_withdrawMethod == WithdrawalMethodClient.Cash && string.IsNullOrWhiteSpace(_withdrawIban)) if (_withdrawMethod == WithdrawalMethodClient.Cash && string.IsNullOrWhiteSpace(_withdrawIban))
@@ -54,14 +58,14 @@ public partial class WithdrawalRequests : ComponentBase
try try
{ {
_isSubmittingWithdrawal = true; _isSubmittingWithdrawal = true;
await WalletService.RequestWithdrawalAsync(_withdrawPayoutId, _withdrawMethod, _withdrawIban); await WalletService.RequestWithdrawalAsync(_selectedPayout.Id, _withdrawMethod, _withdrawIban);
Snackbar.Add("درخواست برداشت ثبت شد.", Severity.Success); Snackbar.Add("درخواست برداشت ثبت شد.", Severity.Success);
// بروزرسانی لیست // بروزرسانی لیست
await LoadData(); await LoadData();
// ریست فرم // ریست فرم
_withdrawPayoutId = 0; _selectedPayout = null;
_withdrawIban = null; _withdrawIban = null;
} }
catch (Exception ex) catch (Exception ex)
+66 -12
View File
@@ -4,36 +4,90 @@
<PageTitle>محصولات</PageTitle> <PageTitle>محصولات</PageTitle>
<MudContainer MaxWidth="MaxWidth.Large" Class="pa-2 pa-md-6"> <MudContainer MaxWidth="MaxWidth.Large" Class="pa-2 pa-md-6">
<MudPaper Elevation="1" Class="pa-4 mb-4 rounded-lg"> <MudPaper Elevation="1" Class="pa-3 pa-md-4 mb-4 rounded-lg">
<MudGrid Spacing="2" AlignItems="AlignItems.Center"> <MudGrid Spacing="2" AlignItems="AlignItems.Center">
<MudItem xs="12" md="8"> @* ردیف اول: جستجو و دکمه‌ها *@
<MudItem xs="12" md="6">
<MudTextField @bind-Value="_query" <MudTextField @bind-Value="_query"
Placeholder="جستجو در محصولات..." Placeholder="جستجو در محصولات..."
AdornmentIcon="@Icons.Material.Filled.Search" AdornmentIcon="@Icons.Material.Filled.Search"
Adornment="Adornment.Start" Adornment="Adornment.Start"
Immediate="true" Immediate="true"
OnKeyUp="OnQueryChanged" OnKeyUp="OnQueryChanged"
Class="w-100"/> Variant="Variant.Outlined"
Margin="Margin.Dense"/>
</MudItem> </MudItem>
<MudItem xs="12" md="4" Class="d-flex justify-end flex-wrap gap-2"> <MudItem xs="12" md="6" Class="d-flex justify-start justify-md-end gap-2">
<MudButton Class="w-100-mobile" Variant="Variant.Outlined" Color="Color.Primary" <MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary"
StartIcon="@Icons.Material.Filled.ViewList" Href="@RouteConstants.Store.Categories"> StartIcon="@Icons.Material.Filled.Category" Href="@RouteConstants.Store.Categories">
دسته‌بندی‌ها دسته‌بندی‌ها
</MudButton> </MudButton>
<MudButton Class="w-100-mobile" Variant="Variant.Filled" Color="Color.Primary" <MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary"
StartIcon="@Icons.Material.Filled.ShoppingCart" Href="@RouteConstants.Store.Cart"> StartIcon="@Icons.Material.Filled.ShoppingCart" Href="@RouteConstants.Store.Cart">
سبد خرید (@Cart.Count) سبد خرید
@if (Cart.Count > 0)
{
<MudBadge Content="@Cart.Count" Color="Color.Error" Overlap="true" Class="ms-2"/>
}
</MudButton> </MudButton>
</MudItem> </MudItem>
</MudGrid>
@* ردیف دوم: فیلترها و مرتب‌سازی *@
<MudItem xs="12">
<MudDivider Class="my-2"/>
</MudItem>
<MudItem xs="6" sm="4" md="3">
<MudSelect T="ProductSortOption" @bind-Value="_sortOption"
@bind-Value:after="OnSortChanged"
Label="مرتب‌سازی"
Variant="Variant.Outlined"
Margin="Margin.Dense"
AnchorOrigin="Origin.BottomCenter"
AdornmentIcon="@Icons.Material.Filled.Sort">
<MudSelectItem Value="ProductSortOption.PriceDesc">
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.ArrowDownward" Size="Size.Small"/>
گران‌ترین
</div>
</MudSelectItem>
<MudSelectItem Value="ProductSortOption.PriceAsc">
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.ArrowUpward" Size="Size.Small"/>
ارزان‌ترین
</div>
</MudSelectItem>
<MudSelectItem Value="ProductSortOption.Newest">
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.NewReleases" Size="Size.Small"/>
جدیدترین
</div>
</MudSelectItem>
<MudSelectItem Value="ProductSortOption.Title">
<div class="d-flex align-center gap-2">
<MudIcon Icon="@Icons.Material.Filled.SortByAlpha" Size="Size.Small"/>
الفبایی
</div>
</MudSelectItem>
</MudSelect>
</MudItem>
<MudItem xs="6" sm="8" md="9" Class="d-flex align-center">
@if (_activeCategoryId.HasValue) @if (_activeCategoryId.HasValue)
{ {
<MudStack Spacing="1" Class="mt-3"> <MudChip T="string" Color="Color.Info" Variant="Variant.Filled" Size="Size.Small"
<MudChip T="string" Color="Color.Info" Variant="Variant.Filled" Closeable="true" OnClose="ClearCategoryFilter"> Icon="@Icons.Material.Filled.FilterAlt"
Closeable="true" OnClose="ClearCategoryFilter">
@(_activeCategoryTitle ?? $"دسته‌بندی #{_activeCategoryId}") @(_activeCategoryTitle ?? $"دسته‌بندی #{_activeCategoryId}")
</MudChip> </MudChip>
</MudStack>
} }
else
{
<MudText Typo="Typo.body2" Class="mud-text-secondary">
<MudIcon Icon="@Icons.Material.Filled.Inventory2" Size="Size.Small" Class="me-1"/>
@(_products.Count) محصول
</MudText>
}
</MudItem>
</MudGrid>
</MudPaper> </MudPaper>
@if (_loading) @if (_loading)
@@ -7,6 +7,14 @@ using FrontOffice.Main.Utilities;
namespace FrontOffice.Main.Pages.Store; namespace FrontOffice.Main.Pages.Store;
public enum ProductSortOption
{
PriceDesc, // گران‌ترین (پیش‌فرض)
PriceAsc, // ارزان‌ترین
Newest, // جدیدترین
Title // الفبایی
}
public partial class Products : ComponentBase, IDisposable public partial class Products : ComponentBase, IDisposable
{ {
[Inject] private ProductService ProductService { get; set; } = default!; [Inject] private ProductService ProductService { get; set; } = default!;
@@ -20,6 +28,8 @@ public partial class Products : ComponentBase, IDisposable
private long? _activeCategoryId; private long? _activeCategoryId;
private string? _activeCategoryTitle; private string? _activeCategoryTitle;
private ProductSortOption _sortOption = ProductSortOption.PriceDesc; // پیش‌فرض: گران‌ترین
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
// لود سبد خرید (فقط اگر کاربر لاگین کرده باشد) // لود سبد خرید (فقط اگر کاربر لاگین کرده باشد)
@@ -43,13 +53,31 @@ public partial class Products : ComponentBase, IDisposable
{ {
_loading = true; _loading = true;
UpdateCategoryFilterFromUri(); UpdateCategoryFilterFromUri();
_products = await ProductService.GetProductsAsync(_query, _activeCategoryId); var sortBy = GetSortByValue();
_products = await ProductService.GetProductsAsync(_query, _activeCategoryId, sortBy);
_activeCategoryTitle = _activeCategoryId is { } categoryId _activeCategoryTitle = _activeCategoryId is { } categoryId
? (await CategoryService.GetByIdAsync(categoryId))?.Title ? (await CategoryService.GetByIdAsync(categoryId))?.Title
: null; : null;
_loading = false; _loading = false;
} }
private string GetSortByValue()
{
return _sortOption switch
{
ProductSortOption.PriceDesc => "price desc",
ProductSortOption.PriceAsc => "price asc",
ProductSortOption.Newest => "id desc",
ProductSortOption.Title => "title asc",
_ => "price desc"
};
}
private async Task OnSortChanged()
{
await Load();
}
private async Task OnQueryChanged(KeyboardEventArgs _) private async Task OnQueryChanged(KeyboardEventArgs _)
{ {
await Load(); await Load();
+1 -1
View File
@@ -4,7 +4,7 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fa"> <html lang="fa" dir="rtl">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
@@ -21,7 +21,7 @@
<MudStack Spacing="3"> <MudStack Spacing="3">
@* اطلاعات نسخه با انیمیشن *@ @* اطلاعات نسخه با انیمیشن *@
<MudPaper Class="pa-4 rounded-lg" Elevation="0" <MudPaper Class="pa-4 rounded-lg" Elevation="0"
Style="background: linear-gradient(135deg, var(--mud-palette-primary-lighten) 0%, var(--mud-palette-background) 100%);"> Style="">
<MudGrid Spacing="2"> <MudGrid Spacing="2">
<MudItem xs="6"> <MudItem xs="6">
<MudStack AlignItems="AlignItems.Center" Spacing="1"> <MudStack AlignItems="AlignItems.Center" Spacing="1">
@@ -191,6 +191,46 @@ public class CommissionService
#region Helper Methods #region Helper Methods
/// <summary>
/// Get payouts that are eligible for withdrawal (all statuses except Withdrawn=3)
/// </summary>
public async Task<List<CommissionPayoutDto>> GetWithdrawablePayoutsAsync()
{
try
{
// Get all payouts that are not yet withdrawn
// We'll get all and filter out Withdrawn (status=3) on client side
var request = new GetMyCommissionPayoutsRequest
{
PageNumber = 1,
PageSize = 100
// No status filter - get all
};
var response = await _client.GetMyCommissionPayoutsAsync(request);
// Filter: exclude already withdrawn (status text contains "برداشت" or status=3)
return response.Payouts
.Where(p => !p.Status.Contains("برداشت") && p.Status != "Withdrawn")
.Select(p => new CommissionPayoutDto
{
Id = p.Id,
WeekDefinitionId = p.WeekDefinitionId,
WeekDisplayName = p.WeekDisplayName,
BalancesEarned = p.BalancesEarned,
TotalAmount = p.TotalAmount,
AmountFormatted = p.AmountFormatted,
Status = p.Status,
StatusBadgeColor = p.StatusBadgeColor,
DatePersian = p.DatePersian
}).ToList();
}
catch
{
return new List<CommissionPayoutDto>();
}
}
private static WeeklyBalanceDto CreateEmptyWeeklyBalance() private static WeeklyBalanceDto CreateEmptyWeeklyBalance()
{ {
return new WeeklyBalanceDto return new WeeklyBalanceDto
@@ -58,7 +58,7 @@ public class ProductService
_client = client; _client = client;
} }
public async Task<List<Product>> GetProductsAsync(string? query = null, long? categoryId = null) public async Task<List<Product>> GetProductsAsync(string? query = null, long? categoryId = null, string? sortBy = null)
{ {
try try
{ {
@@ -78,6 +78,11 @@ public class ProductService
request.Filter.CategoryId = value; request.Filter.CategoryId = value;
} }
if (!string.IsNullOrEmpty(sortBy))
{
request.SortBy = sortBy;
}
var resp = await _client.GetAllProductsByFilterAsync(request); var resp = await _client.GetAllProductsByFilterAsync(request);
return MapAndCache(resp.Models); return MapAndCache(resp.Models);
} }
@@ -49,6 +49,8 @@ html, body {
font-weight: 400; font-weight: 400;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
direction: rtl;
text-align: right;
} }
/* Apply Vazir to common Mud components */ /* Apply Vazir to common Mud components */
@@ -27,7 +27,7 @@
var doc = iframe.contentDocument || iframe.contentWindow.document; var doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open(); doc.open();
doc.write("<!DOCTYPE html><html lang='fa'><head><meta charset='utf-8'>"+ doc.write("<!DOCTYPE html><html lang='fa' dir='rtl'><head><meta charset='utf-8'>"+
"<title>"+ title +"</title>"+ "<title>"+ title +"</title>"+
"<link rel='stylesheet' href='/_content/MudBlazor/MudBlazor.min.css'>"+ "<link rel='stylesheet' href='/_content/MudBlazor/MudBlazor.min.css'>"+
"<link rel='stylesheet' href='/css/site.css'>"+ "<link rel='stylesheet' href='/css/site.css'>"+