diff --git a/src/FrontOffice.Main/ConfigureServices.cs b/src/FrontOffice.Main/ConfigureServices.cs index cec07a8..3744901 100644 --- a/src/FrontOffice.Main/ConfigureServices.cs +++ b/src/FrontOffice.Main/ConfigureServices.cs @@ -10,6 +10,7 @@ using FrontOffice.BFF.Transaction.Protobuf.Protos.Transaction; using FrontOffice.BFF.User.Protobuf.Protos.User; using FrontOffice.BFF.UserAddress.Protobuf.Protos.UserAddress; using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder; +using FrontOffice.BFF.UserWallet.Protobuf.Protos.UserWallet; using FrontOffice.BFF.ShopingCart.Protobuf.Protos.ShopingCart; using FrontOffice.Main.Utilities; @@ -76,6 +77,7 @@ public static class ConfigureServices services.AddScoped(CreateAuthenticatedClient); services.AddScoped(CreateAuthenticatedClient); services.AddScoped(CreateAuthenticatedClient); + services.AddScoped(CreateAuthenticatedClient); // Products gRPC services.AddScoped(CreateAuthenticatedClient); services.AddScoped(CreateAuthenticatedClient); diff --git a/src/FrontOffice.Main/FrontOffice.Main.csproj b/src/FrontOffice.Main/FrontOffice.Main.csproj index 85c3fa6..5246787 100644 --- a/src/FrontOffice.Main/FrontOffice.Main.csproj +++ b/src/FrontOffice.Main/FrontOffice.Main.csproj @@ -13,9 +13,10 @@ - + - + + diff --git a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs index 34f3c6b..e6de09a 100644 --- a/src/FrontOffice.Main/Pages/Profile/Index.razor.cs +++ b/src/FrontOffice.Main/Pages/Profile/Index.razor.cs @@ -18,7 +18,6 @@ public partial class Index { [Inject] private UserContract.UserContractClient UserContract { get; set; } = default!; [Inject] private UserAddressContract.UserAddressContractClient UserAddressContract { get; set; } = default!; - [Inject] private WalletService WalletService { get; set; } = default!; private GetUserResponse _userProfile = new(); private UpdateUserRequest _updateUserRequest = new(); diff --git a/src/FrontOffice.Main/Pages/Profile/Wallet.razor.cs b/src/FrontOffice.Main/Pages/Profile/Wallet.razor.cs index f22291c..303862e 100644 --- a/src/FrontOffice.Main/Pages/Profile/Wallet.razor.cs +++ b/src/FrontOffice.Main/Pages/Profile/Wallet.razor.cs @@ -5,7 +5,6 @@ namespace FrontOffice.Main.Pages.Profile; public partial class Wallet : ComponentBase { - [Inject] private WalletService WalletService { get; set; } = default!; private (string Credit, string Network) _balances = ("-", "-"); private List _txs = new(); diff --git a/src/FrontOffice.Main/Pages/RegisterWizard.razor b/src/FrontOffice.Main/Pages/RegisterWizard.razor index 566fce8..93e2590 100644 --- a/src/FrontOffice.Main/Pages/RegisterWizard.razor +++ b/src/FrontOffice.Main/Pages/RegisterWizard.razor @@ -58,7 +58,7 @@ { - ویزارد ثبت‌نام + مراحل ثبت‌نام ۳ مرحله diff --git a/src/FrontOffice.Main/Pages/Store/Cart.razor b/src/FrontOffice.Main/Pages/Store/Cart.razor index f5b4312..05d15df 100644 --- a/src/FrontOffice.Main/Pages/Store/Cart.razor +++ b/src/FrontOffice.Main/Pages/Store/Cart.razor @@ -10,71 +10,166 @@ @if (CartData.Items.Count == 0) { سبد خرید شما خالی است. - بازگشت به محصولات + بازگشت به محصولات + } else { - - - - محصول - قیمت واحد - تعداد - قیمت کل - - - - - - - @context.Title - - - @FormatPrice(context.UnitPrice) - - - - @FormatPrice(context.LineTotal) - - - - - - + + + + محصول + قیمت واحد + تعداد + قیمت کل + + + + + + + + @context.Title + + @if (context.Discount > 0 || !string.IsNullOrWhiteSpace(context.Created) || !string.IsNullOrWhiteSpace(context.Description)) + { + + @if (context.Discount > 0) + { + @($"{context.Discount}% تخفیف") + } + @if (!string.IsNullOrWhiteSpace(context.Description)) + { + @context.Description + } + @if (!string.IsNullOrWhiteSpace(context.Created)) + { + تاریخ + افزودن: @context.Created + } + + } + + + @FormatPrice(context.UnitPrice) + + + + @context.Quantity + + + + @FormatPrice(context.LineTotal) + + + + + + @foreach (var item in CartData.Items) { - + - - - @item.Title - - @FormatPrice(item.UnitPrice) واحد - + + + @item.Title + + @if (item.Discount > 0) + { + @($"{item.Discount}% ") + } - - جمع: @FormatPrice(item.LineTotal) - + + @if (item.Discount > 0 || !string.IsNullOrWhiteSpace(item.Created) || !string.IsNullOrWhiteSpace(item.Description)) + { + + + @if (!string.IsNullOrWhiteSpace(item.Description)) + { + @item.Description + } + @* @if (!string.IsNullOrWhiteSpace(item.Created)) *@ + @* { *@ + @* تاریخ افزودن: @item.Created *@ + @* } *@ + + } + + + + @FormatPrice(item.UnitPrice) واحد + + + @item.Quantity + + + + + جمع: @FormatPrice(item.LineTotal) + + } + @if (DeviceDetector.IsMobile()) + { + + تخفیف کل: @FormatPrice(CartData.TotalDiscount) + مبلغ کل: @FormatPrice(CartData.Total) - - مبلغ قابل پرداخت: @FormatPrice(CartData.Total) - - افزودن محصول - ادامه فرایند خرید - + + + افزودن محصول + + ادامه فرایند خرید + + + } + else + { + + تخفیف کل: @FormatPrice(CartData.TotalDiscount) + مبلغ کل: @FormatPrice(CartData.Total) + + افزودن محصول + + ادامه فرایند خرید + + + } } diff --git a/src/FrontOffice.Main/Pages/Store/Cart.razor.cs b/src/FrontOffice.Main/Pages/Store/Cart.razor.cs index 5785560..3bb472c 100644 --- a/src/FrontOffice.Main/Pages/Store/Cart.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/Cart.razor.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Components; using FrontOffice.Main.Utilities; +using System.Linq; namespace FrontOffice.Main.Pages.Store; @@ -14,14 +15,28 @@ public partial class Cart : ComponentBase, IDisposable CartService.OnChange += StateHasChanged; } + private async Task IncrementQty(long productId) + { + var item = CartData.Items.FirstOrDefault(i => i.ProductId == productId); + if (item is null) return; + await CartService.UpdateQuantity(productId, item.Quantity + 1); + } + + private async Task DecrementQty(long productId) + { + var item = CartData.Items.FirstOrDefault(i => i.ProductId == productId); + if (item is null) return; + await CartService.UpdateQuantity(productId, item.Quantity - 1); + } + private async Task ChangeQty(long productId, int value) { await CartService.UpdateQuantity(productId, value); } - private async Task Remove(long productId) + private async Task Remove(long cartId) { - await CartService.Remove(productId); + await CartService.Remove(cartId); } private void ProceedCheckout() @@ -29,7 +44,7 @@ public partial class Cart : ComponentBase, IDisposable Navigation.NavigateTo(RouteConstants.Store.CheckoutSummary); } - private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price); + private static string FormatPrice(long price) => string.Format("{0:N0} ", price); public void Dispose() { diff --git a/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor b/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor index e1615ca..982ffe6 100644 --- a/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor +++ b/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor @@ -1,3 +1,4 @@ +@using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder @attribute [Route(RouteConstants.Store.CheckoutSummary)] خلاصه خرید @@ -20,7 +21,7 @@ هیچ آدرسی ثبت نشده است. لطفاً از بخش پروفایل آدرس خود را اضافه کنید. - افزودن آدرس + افزودن آدرس } else { @@ -51,7 +52,15 @@ روش پرداخت - کیف پول + + @* *@ + @* 20000 *@ + + کیف پول + @(FormatPrice(walletBalance)) + + + در حال حاضر تنها پرداخت از طریق کیف پول فعال است. @@ -70,9 +79,15 @@ @foreach (var item in Cart.Items) { - - @item.Title x @item.Quantity - @FormatPrice(item.LineTotal) + + + @item.Title x @item.Quantity + @FormatPrice(item.LineTotal) + + @if (item.Discount > 0) + { + @($"تخفیف: {item.Discount}%") + } } diff --git a/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor.cs b/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor.cs index 0eb41af..11e6b27 100644 --- a/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor.cs @@ -1,4 +1,5 @@ using FrontOffice.BFF.UserAddress.Protobuf.Protos.UserAddress; +using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder; using FrontOffice.Main.Utilities; using Microsoft.AspNetCore.Components; using MudBlazor; @@ -10,11 +11,13 @@ public partial class CheckoutSummary : ComponentBase [Inject] private CartService Cart { get; set; } = default!; [Inject] private OrderService OrderService { get; set; } = default!; [Inject] private UserAddressContract.UserAddressContractClient UserAddressContract { get; set; } = default!; + [Inject] private UserOrderContract.UserOrderContractClient UserOrderContract { get; set; } = default!; // Snackbar and Navigation are injected via _Imports.razor private List _addresses = new(); private GetAllUserAddressByFilterResponseModel? _selectedAddress; private bool _loadingAddresses; + private long walletBalance; private PaymentMethod _payment = PaymentMethod.Wallet; @@ -23,6 +26,13 @@ public partial class CheckoutSummary : ComponentBase protected override async Task OnInitializedAsync() { await LoadAddresses(); + await LoadWalletBalance(); + } + + private async Task LoadWalletBalance() + { + var walletResult = await WalletService.GetBalancesAsync(); + walletBalance = walletResult.CreditBalance + walletResult.NetworkBalance; } private async Task LoadAddresses() @@ -61,21 +71,23 @@ public partial class CheckoutSummary : ComponentBase return; } - // Simulate wallet payment success and create local order - var order = new Order + try { - Status = OrderStatus.Paid, - PaymentMethod = _payment, - AddressId = _selectedAddress.Id, - AddressSummary = _selectedAddress.Address, - Items = Cart.Items.Select(i => new OrderItem(i.ProductId, i.Title, i.ImageUrl, i.UnitPrice, i.Quantity)).ToList() - }; + var request = new SubmitShopBuyOrderRequest + { + TotalAmount = Cart.Total + }; - var id = await OrderService.CreateOrderAsync(order); - await Cart.Clear(); - Snackbar.Add("سفارش با موفقیت ثبت شد.", Severity.Success); - Navigation.NavigateTo($"{RouteConstants.Store.OrderDetail}{id}"); + var response = await UserOrderContract.SubmitShopBuyOrderAsync(request); + await Cart.Clear(); + Snackbar.Add("سفارش با موفقیت ثبت شد.", Severity.Success); + Navigation.NavigateTo($"{RouteConstants.Store.OrderDetail}{response.Id}"); + } + catch (Exception ex) + { + Snackbar.Add($"خطا در ثبت سفارش: {ex.Message}", Severity.Error); + } } private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price); -} +} \ No newline at end of file diff --git a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor index 223a72d..08a4f47 100644 --- a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor +++ b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor @@ -24,13 +24,13 @@ else سفارش #@_order.Id - تاریخ: @_order.CreatedAt.ToString("yyyy/MM/dd HH:mm") - وضعیت: @GetStatusText(_order.Status) - روش پرداخت: کیف پول - آدرس: @_order.AddressSummary + تاریخ: @_order.PaymentDate.ToDateTime().MiladiToJalaliWithTime() + وضعیت: @GetStatusText(_order.PaymentStatus) + روش پرداخت: @GetPaymentMethodText(_order.PaymentMethod) + آدرس: @_order.UserAddressText - + محصول قیمت واحد @@ -40,39 +40,39 @@ else - - @context.Title + + @context.ProductTitle - @FormatPrice(context.UnitPrice) - @context.Quantity - @FormatPrice(context.LineTotal) + @FormatPrice(context.UnitPrice.Value) + @context.Count + @FormatPrice(context.UnitPrice.Value*context.Count.Value) - @foreach (var it in _order.Items) + @foreach (var it in _order.FactorDetails) { - - @it.Title + + @it.ProductTitle - @FormatPrice(it.UnitPrice) واحد - تعداد: @it.Quantity + @FormatPrice(it.UnitPrice.Value) واحد + تعداد: @it.Count - جمع: @FormatPrice(it.LineTotal) + جمع: @FormatPrice(it.UnitPrice.Value*it.Count.Value) } - مبلغ کل: @FormatPrice(_order.Total) + مبلغ کل: @FormatPrice(_order.FactorDetails.Sum(s=>s.UnitPrice.Value*s.Count.Value)) diff --git a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor.cs b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor.cs index 4415e51..0ead158 100644 --- a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor.cs @@ -1,3 +1,4 @@ +using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder; using FrontOffice.Main.Utilities; using Microsoft.AspNetCore.Components; @@ -9,7 +10,7 @@ public partial class OrderDetail : ComponentBase [Parameter] public long id { get; set; } - private Order? _order; + private GetUserOrderResponse? _order; private bool _loading; protected override async Task OnParametersSetAsync() @@ -20,10 +21,26 @@ public partial class OrderDetail : ComponentBase } private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price); - private static string GetStatusText(OrderStatus status) => status switch + + private string GetStatusText(PaymentStatus orderPaymentStatus) { - OrderStatus.Paid => "پرداخت‌شده", - _ => "در انتظار", - }; + return orderPaymentStatus switch + { + PaymentStatus.Pending => "در انتظار پرداخت", + PaymentStatus.Success => "پرداخت شده", + PaymentStatus.Reject => "پرداخت ناموفق", + _ => "نامشخص", + }; + } + + private string GetPaymentMethodText(PaymentMethod orderPaymentMethod) + { + return orderPaymentMethod switch + { + PaymentMethod.Wallet => "کیف پول", + PaymentMethod.Ipg => "درگاه پرداخت اینترنتی", + _ => "نامشخص", + }; + } } diff --git a/src/FrontOffice.Main/Pages/Store/Orders.razor b/src/FrontOffice.Main/Pages/Store/Orders.razor index de4afe8..97b9321 100644 --- a/src/FrontOffice.Main/Pages/Store/Orders.razor +++ b/src/FrontOffice.Main/Pages/Store/Orders.razor @@ -28,11 +28,11 @@ @context.Id - @context.CreatedAt.ToString("yyyy/MM/dd HH:mm") - @GetStatusText(context.Status) - @FormatPrice(context.Total) + @context.PaymentDate.ToDateTime().MiladiToJalaliWithTime() + @GetStatusText(context.PaymentStatus) + @FormatPrice(context.FactorDetails.Sum(s=>s.UnitPrice.Value*s.Count.Value)) - جزئیات + جزئیات @@ -46,11 +46,11 @@ سفارش #@o.Id - @o.CreatedAt.ToString("yy/MM/dd HH:mm") + @o.PaymentDate.ToDateTime().MiladiToJalaliWithTime() - وضعیت: @GetStatusText(o.Status) - @FormatPrice(o.Total) + وضعیت: @GetStatusText(o.PaymentStatus) + @FormatPrice(o.FactorDetails.Sum(s=>s.UnitPrice.Value*s.Count.Value))) جزئیات diff --git a/src/FrontOffice.Main/Pages/Store/Orders.razor.cs b/src/FrontOffice.Main/Pages/Store/Orders.razor.cs index f24289a..c897c77 100644 --- a/src/FrontOffice.Main/Pages/Store/Orders.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/Orders.razor.cs @@ -1,3 +1,4 @@ +using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder; using FrontOffice.Main.Utilities; using Microsoft.AspNetCore.Components; @@ -7,7 +8,7 @@ public partial class Orders : ComponentBase { [Inject] private OrderService OrderService { get; set; } = default!; - private List _orders = new(); + private List _orders = new(); private bool _loading; protected override async Task OnInitializedAsync() @@ -18,10 +19,17 @@ public partial class Orders : ComponentBase } private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price); - private static string GetStatusText(OrderStatus status) => status switch + + + private string GetStatusText(PaymentStatus contextPaymentStatus) { - OrderStatus.Paid => "پرداخت‌شده", - _ => "در انتظار", - }; + return contextPaymentStatus switch + { + PaymentStatus.Pending => "در انتظار پرداخت", + PaymentStatus.Success => "پرداخت شده", + PaymentStatus.Reject => "پرداخت ناموفق", + _ => "نامشخص", + }; + } } diff --git a/src/FrontOffice.Main/Shared/MainLayout.razor b/src/FrontOffice.Main/Shared/MainLayout.razor index cd96809..cfed022 100644 --- a/src/FrontOffice.Main/Shared/MainLayout.razor +++ b/src/FrontOffice.Main/Shared/MainLayout.razor @@ -3,10 +3,10 @@ کارا بازار سلامت - - - - + + + + @@ -15,86 +15,118 @@ + OnClick="@ToggleDrawer"/>
- - - - کارا بازار سلامت + + + + کارا بازار سلامت
-
- @* @if (_isAuthenticated && false) *@ - @* { *@ - @* محصولات *@ - @* سبد خرید *@ - @* سفارشات من *@ - @* } *@ - سوالات متداول - ارتباط با ما - درباره ما +
+ @if (_isAuthenticated) + { + + محصولات + + سبد خرید + + سفارشات + من + + } + سوالات متداول + + ارتباط با + ما + + درباره ما +
@if (_isAuthenticated) { - پروفایل - + + پروفایل + + خروج از حساب } else { - + } + Icon="@(_isDark ? Icons.Material.Filled.DarkMode : Icons.Material.Filled.LightMode)"/>
- + - @* @if (_isAuthenticated) *@ - @* { *@ - @* محصولات *@ - @* سبد خرید *@ - @* سفارشات من *@ - @* } *@ - سوالات متداول - درباره ما - ارتباط با ما - - @if (_isAuthenticated) { - پروفایل - خروج از حساب + محصولات + + سبد خرید + + سفارشات من + + } + + سوالات متداول + + + درباره ما + + + ارتباط با ما + + + + @if (_isAuthenticated) + { + پروفایل + + خروج از حساب + } else { - ورود + ورود + } @Body -