From 4115f64fffb1548798c8c72e101054105f01f26d Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Sat, 25 Jul 2026 23:54:57 +0330 Subject: [PATCH] feat(payment): add manual credit charge functionality and update related components - Introduced new manual credit charge endpoints in ADMIN-SERVICES.md. - Updated ReportLabels.cs and LedgerTransactions.razor to include manual credit wallet charge options. - Enhanced NavMenu.razor with a link to the manual credit charges page. - Bumped Foursat.CMSMicroservice.Protobuf version to 0.0.205 for compatibility with new features. --- docs/ADMIN-SERVICES.md | 2 + src/BackOffice/BackOffice.csproj | 2 +- .../Common/Utilities/ReportLabels.cs | 1 + .../Components/ManualCreditChargeDialog.razor | 106 +++++++++++++ .../Pages/Payment/LedgerTransactions.razor | 1 + .../Pages/Payment/ManualCreditCharges.razor | 149 ++++++++++++++++++ src/BackOffice/Shared/NavMenu.razor | 6 + 7 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 src/BackOffice/Pages/Payment/Components/ManualCreditChargeDialog.razor create mode 100644 src/BackOffice/Pages/Payment/ManualCreditCharges.razor diff --git a/docs/ADMIN-SERVICES.md b/docs/ADMIN-SERVICES.md index 794cf1d..e0fa681 100644 --- a/docs/ADMIN-SERVICES.md +++ b/docs/ADMIN-SERVICES.md @@ -167,6 +167,8 @@ |---|-------------|---------------|-----------------|--------| | 11.1 | `UserWalletContract.GetAllUserWalletByFilter` | `UserWalletContract` | `/wallets` | لیست کیف پول کاربران | | 11.2 | `UserWalletHistoryContract.GetAllUserWalletHistoryByFilter` | `UserWalletHistoryContract` | `/wallets` (تب تاریخچه) | لاگ تغییرات کیف پول | +| 11.3 | `UserWalletContract.AdminManualCreditCharge` | `UserWalletContract` | `/payment/manual-credit-charges` | شارژ دستی کیف پول اصلی (Balance) | +| 11.4 | `UserWalletContract.GetManualCreditCharges` | `UserWalletContract` | `/payment/manual-credit-charges` | لیست شارژهای دستی (Type=17) | --- diff --git a/src/BackOffice/BackOffice.csproj b/src/BackOffice/BackOffice.csproj index 78d7ffa..9d6ea7f 100644 --- a/src/BackOffice/BackOffice.csproj +++ b/src/BackOffice/BackOffice.csproj @@ -143,7 +143,7 @@ - + diff --git a/src/BackOffice/Common/Utilities/ReportLabels.cs b/src/BackOffice/Common/Utilities/ReportLabels.cs index 4c6c281..912915d 100644 --- a/src/BackOffice/Common/Utilities/ReportLabels.cs +++ b/src/BackOffice/Common/Utilities/ReportLabels.cs @@ -36,6 +36,7 @@ public static class ReportLabels TransactionType.MagicWalletDeposit => "واریز کیف جادویی", TransactionType.MagicWalletBonus => "بونوس کیف جادویی", TransactionType.CreditWalletCharge => "شارژ کیف اصلی", + TransactionType.ManualCreditWalletCharge => "شارژ دستی کیف اصلی", _ => type?.ToString() ?? "—" }; diff --git a/src/BackOffice/Pages/Payment/Components/ManualCreditChargeDialog.razor b/src/BackOffice/Pages/Payment/Components/ManualCreditChargeDialog.razor new file mode 100644 index 0000000..e281003 --- /dev/null +++ b/src/BackOffice/Pages/Payment/Components/ManualCreditChargeDialog.razor @@ -0,0 +1,106 @@ +@using BackOffice.Pages.AutoComplete +@using CMSMicroservice.Protobuf.Protos.UserWallet + +@inject UserWalletContract.UserWalletContractClient WalletClient + + + + + + مبلغ مستقیماً به کیف پول اصلی (Balance) کاربر اضافه می‌شود و در دفتر مالی با نوع «شارژ دستی کیف اصلی» ثبت می‌گردد. + + + + + + + + + + + انصراف + + @if (_isSubmitting) + { + + } + ثبت شارژ + + + + +@code { + [CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!; + + private long? _userId; + private long _amount = 10000; + private string? _note; + private bool _isSubmitting; + + private void Cancel() => MudDialog.Cancel(); + + private async Task Submit() + { + if (!_userId.HasValue || _userId.Value <= 0) + { + Snackbar.Add("لطفاً کاربر را انتخاب کنید", Severity.Warning); + return; + } + + if (_amount < 10000) + { + Snackbar.Add("حداقل مبلغ شارژ ۱۰,۰۰۰ تومان است", Severity.Warning); + return; + } + + bool? confirm = await DialogService.ShowMessageBox( + "تأیید شارژ دستی", + $"آیا از شارژ {_amount:N0} تومان به کیف پول اصلی کاربر #{_userId.Value} مطمئن هستید؟", + yesText: "بله، شارژ شود", cancelText: "لغو"); + + if (confirm != true) + return; + + _isSubmitting = true; + try + { + var request = new AdminManualCreditChargeRequest + { + UserId = _userId.Value, + Amount = _amount + }; + if (!string.IsNullOrWhiteSpace(_note)) + request.Note = _note.Trim(); + + var response = await WalletClient.AdminManualCreditChargeAsync(request); + + if (response.Success) + { + Snackbar.Add( + $"شارژ موفق — تراکنش #{response.TransactionId}، موجودی جدید: {response.NewBalance:N0}", + Severity.Success); + MudDialog.Close(DialogResult.Ok(true)); + } + else + { + Snackbar.Add(response.Message ?? "شارژ ناموفق بود", Severity.Error); + } + } + catch (Exception ex) + { + Snackbar.Add($"خطا: {ex.Message}", Severity.Error); + } + finally + { + _isSubmitting = false; + } + } +} diff --git a/src/BackOffice/Pages/Payment/LedgerTransactions.razor b/src/BackOffice/Pages/Payment/LedgerTransactions.razor index 2ea08eb..5448f2a 100644 --- a/src/BackOffice/Pages/Payment/LedgerTransactions.razor +++ b/src/BackOffice/Pages/Payment/LedgerTransactions.razor @@ -44,6 +44,7 @@ واریز کیف جادویی بونوس کیف جادویی شارژ کیف اصلی + شارژ دستی کیف اصلی diff --git a/src/BackOffice/Pages/Payment/ManualCreditCharges.razor b/src/BackOffice/Pages/Payment/ManualCreditCharges.razor new file mode 100644 index 0000000..b284d15 --- /dev/null +++ b/src/BackOffice/Pages/Payment/ManualCreditCharges.razor @@ -0,0 +1,149 @@ +@page "/payment/manual-credit-charges" +@attribute [Authorize(Roles = "Administrator")] + +@using BackOffice.Common.BaseComponents +@using BackOffice.Pages.AutoComplete +@using BackOffice.Pages.Payment.Components +@using CMSMicroservice.Protobuf.Protos +@using CMSMicroservice.Protobuf.Protos.UserWallet +@using DateTimeConverterCL +@using Google.Protobuf.WellKnownTypes + +@inject UserWalletContract.UserWalletContractClient WalletClient + + + + + + شارژ دستی کیف پول اصلی (Balance) — بدون درگاه. جدا از «پرداخت‌های دستی» عضویت باشگاه. + + + + + + + + + + + + + + + + + + + شارژ دستی کیف پول اصلی + + + شارژ دستی جدید + + + + + + + + + @context.Item.Amount.ToString("N0") + + + + + @context.Item.NewBalance.ToString("N0") + + + + + + + @(context.Item.Created?.ToDateTime().ToLocalTime().MiladiToJalaliWithTime() ?? "-") + + + + + موردی یافت نشد. + + + + + + + + +@code { + private BasePageComponent? _basePage; + private MudDataGrid? _dataGrid; + private long? _userIdFilter; + private long? _transactionIdFilter; + private string? _refIdFilter; + private DateTime? _createdFrom; + private DateTime? _createdTo; + + private async Task> LoadData(GridState state) + { + var request = new GetManualCreditChargesRequest + { + PaginationState = new PaginationState + { + PageNumber = state.Page + 1, + PageSize = state.PageSize + }, + Filter = new GetManualCreditChargesFilter() + }; + + if (_userIdFilter.HasValue) + request.Filter.UserId = _userIdFilter.Value; + if (_transactionIdFilter.HasValue) + request.Filter.TransactionId = _transactionIdFilter.Value; + if (!string.IsNullOrWhiteSpace(_refIdFilter)) + request.Filter.RefId = _refIdFilter.Trim(); + if (_createdFrom.HasValue) + request.Filter.CreatedFrom = Timestamp.FromDateTime(DateTime.SpecifyKind(_createdFrom.Value, DateTimeKind.Utc)); + if (_createdTo.HasValue) + request.Filter.CreatedTo = Timestamp.FromDateTime(DateTime.SpecifyKind(_createdTo.Value, DateTimeKind.Utc)); + + var response = await WalletClient.GetManualCreditChargesAsync(request); + + return new GridData + { + Items = response.Models.ToList(), + TotalItems = (int)(response.MetaData?.TotalCount ?? 0) + }; + } + + private async Task OnFilterSubmit() + { + if (_dataGrid != null) + await _dataGrid.ReloadServerData(); + } + + private async Task OnFilterCleared() + { + _userIdFilter = null; + _transactionIdFilter = null; + _refIdFilter = null; + _createdFrom = null; + _createdTo = null; + if (_dataGrid != null) + await _dataGrid.ReloadServerData(); + } + + private async Task OpenCreateDialog() + { + var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.Small, FullWidth = true }; + var dialog = DialogService.Show("شارژ دستی کیف پول اصلی", options); + var result = await dialog.Result; + if (result is { Canceled: false } && _dataGrid != null) + await _dataGrid.ReloadServerData(); + } +} diff --git a/src/BackOffice/Shared/NavMenu.razor b/src/BackOffice/Shared/NavMenu.razor index 77418c8..e228e37 100644 --- a/src/BackOffice/Shared/NavMenu.razor +++ b/src/BackOffice/Shared/NavMenu.razor @@ -200,6 +200,12 @@ } + + شارژ دستی کیف پول + +