feat: Add package management features and update checkout summary

- Added PackageService to handle package-related operations.
- Introduced MyPackages and Packages pages for user package management.
- Updated CheckoutSummary to display VAT calculations.
- Enhanced OrderDetail to show financial details including VAT.
- Added ChangePassword page for user profile management.
- Implemented OrderTracking page for tracking order status.
- Updated RouteConstants to include new routes for packages and password change.
This commit is contained in:
masoodafar-web
2025-12-05 17:27:04 +03:30
parent feaaeada47
commit 68c114e43e
14 changed files with 1011 additions and 4 deletions
@@ -101,10 +101,24 @@
}
</MudList>
<MudDivider Class="my-2" />
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.subtitle2">مبلغ قابل پرداخت</MudText>
<MudText Typo="Typo.subtitle2" Color="Color.Primary">@FormatPrice(Cart.Total)</MudText>
@* نمایش جزئیات مالی با مالیات *@
<MudStack Spacing="1">
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.body2">جمع کالاها:</MudText>
<MudText Typo="Typo.body2">@FormatPrice(Cart.Total)</MudText>
</MudStack>
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.body2" Class="mud-text-secondary">مالیات بر ارزش افزوده (۹%):</MudText>
<MudText Typo="Typo.body2" Class="mud-text-secondary">@FormatPrice(CalculateVAT())</MudText>
</MudStack>
<MudDivider Class="my-1" />
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.subtitle1" Style="font-weight: bold;">مبلغ قابل پرداخت:</MudText>
<MudText Typo="Typo.subtitle1" Color="Color.Primary" Style="font-weight: bold;">@FormatPrice(Cart.Total + CalculateVAT())</MudText>
</MudStack>
</MudStack>
<MudButton Disabled="@(!CanPlaceOrder)" Class="mt-3 w-100-mobile" Variant="Variant.Filled" Color="Color.Primary" OnClick="PlaceOrder" StartIcon="@Icons.Material.Filled.CheckCircle">ثبت سفارش</MudButton>
}
</MudPaper>
@@ -91,6 +91,11 @@ public partial class CheckoutSummary : ComponentBase
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);
/// <summary>
/// محاسبه مالیات بر ارزش افزوده (۹%)
/// </summary>
private long CalculateVAT() => (long)(Cart.Total * 0.09);
private static string GetProductImageUrl(string? imageUrl)
=> string.IsNullOrWhiteSpace(imageUrl) ? "/images/product-placeholder.svg" : imageUrl;
}
@@ -74,7 +74,29 @@ else
</MudStack>
</MudHidden>
<MudDivider Class="my-2" />
<MudText Typo="Typo.h6" Align="Align.End">مبلغ کل: @FormatPrice(_order.FactorDetails.Sum(s=>s.UnitPrice.Value*s.Count.Value))</MudText>
@* نمایش جزئیات مالی *@
@{
var subtotal = _order.FactorDetails.Sum(s => s.UnitPrice.Value * s.Count.Value);
var vatAmount = (long)(subtotal * 0.09);
var totalWithVat = subtotal + vatAmount;
}
<MudStack Spacing="1" Class="pa-2" Style="background-color: var(--mud-palette-background-grey); border-radius: 8px;">
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.body2">جمع کالاها:</MudText>
<MudText Typo="Typo.body2">@FormatPrice(subtotal)</MudText>
</MudStack>
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.body2" Class="mud-text-secondary">مالیات بر ارزش افزوده (۹%):</MudText>
<MudText Typo="Typo.body2" Class="mud-text-secondary">@FormatPrice(vatAmount)</MudText>
</MudStack>
<MudDivider Class="my-1" />
<MudStack Row="true" Justify="Justify.SpaceBetween">
<MudText Typo="Typo.subtitle1" Style="font-weight: bold;">مبلغ قابل پرداخت:</MudText>
<MudText Typo="Typo.subtitle1" Color="Color.Primary" Style="font-weight: bold;">@FormatPrice(totalWithVat)</MudText>
</MudStack>
</MudStack>
</MudStack>
</MudPaper>
</MudContainer>
@@ -0,0 +1,102 @@
@using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder
@attribute [Route(RouteConstants.Store.OrderTracking + "{id:long}")]
<PageTitle>پیگیری سفارش</PageTitle>
<MudContainer MaxWidth="MaxWidth.Medium" Class="py-6">
@if (_loading)
{
<MudStack AlignItems="AlignItems.Center">
<MudProgressCircular Indeterminate="true" Color="Color.Primary" />
<MudText Class="mt-2 mud-text-secondary">در حال بارگذاری...</MudText>
</MudStack>
}
else if (_order is null)
{
<MudAlert Severity="Severity.Warning">سفارش یافت نشد.</MudAlert>
<MudButton Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ArrowBack"
Href="@RouteConstants.Store.Orders">
بازگشت به سفارش‌ها
</MudButton>
}
else
{
<MudStack Spacing="3">
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
<MudText Typo="Typo.h5">پیگیری سفارش #@_order.Id</MudText>
<MudButton Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ArrowBack"
Href="@(RouteConstants.Store.OrderDetail + id)">
جزئیات سفارش
</MudButton>
</MudStack>
@* Timeline سفارش *@
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-4">وضعیت سفارش</MudText>
<MudTimeline TimelinePosition="TimelinePosition.Start">
@foreach (var step in _trackingSteps)
{
<MudTimelineItem Color="@(step.IsCompleted ? Color.Success : (step.IsCurrent ? Color.Primary : Color.Default))"
Variant="@(step.IsCompleted || step.IsCurrent ? Variant.Filled : Variant.Outlined)"
Size="Size.Medium">
<ItemContent>
<MudStack Spacing="0">
<MudText Typo="Typo.subtitle1"
Color="@(step.IsCompleted ? Color.Success : (step.IsCurrent ? Color.Primary : Color.Default))">
@step.Title
</MudText>
<MudText Typo="Typo.caption" Class="mud-text-secondary">@step.Description</MudText>
@if (!string.IsNullOrEmpty(step.Date))
{
<MudText Typo="Typo.caption" Class="mud-text-secondary mt-1">
<MudIcon Icon="@Icons.Material.Filled.Schedule" Size="Size.Small" Class="me-1" />
@step.Date
</MudText>
}
</MudStack>
</ItemContent>
</MudTimelineItem>
}
</MudTimeline>
</MudPaper>
@* اطلاعات ارسال *@
<MudPaper Elevation="2" Class="pa-4 rounded-lg">
<MudText Typo="Typo.h6" Class="mb-3">اطلاعات ارسال</MudText>
<MudGrid>
<MudItem xs="12" sm="6">
<MudStack Spacing="1">
<MudText Typo="Typo.caption" Class="mud-text-secondary">آدرس تحویل</MudText>
<MudText>@(_order.UserAddressText ?? "---")</MudText>
</MudStack>
</MudItem>
<MudItem xs="12" sm="6">
<MudStack Spacing="1">
<MudText Typo="Typo.caption" Class="mud-text-secondary">روش پرداخت</MudText>
<MudText>@GetPaymentMethodText(_order.PaymentMethod)</MudText>
</MudStack>
</MudItem>
</MudGrid>
</MudPaper>
@* پشتیبانی *@
<MudPaper Elevation="1" Class="pa-4 rounded-lg" Style="background-color: var(--mud-palette-background-grey);">
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3">
<MudIcon Icon="@Icons.Material.Filled.HeadsetMic" Size="Size.Large" Color="Color.Primary" />
<MudStack Spacing="0">
<MudText Typo="Typo.subtitle1">سوالی دارید؟</MudText>
<MudText Typo="Typo.body2" Class="mud-text-secondary">
با پشتیبانی ما تماس بگیرید: ۰۲۱-۱۲۳۴۵۶۷۸
</MudText>
</MudStack>
<MudSpacer />
<MudButton Variant="Variant.Outlined" Color="Color.Primary" Href="@RouteConstants.Contact.Index">
تماس با ما
</MudButton>
</MudStack>
</MudPaper>
</MudStack>
}
</MudContainer>
@@ -0,0 +1,125 @@
using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
using FrontOffice.Main.Utilities;
using Microsoft.AspNetCore.Components;
namespace FrontOffice.Main.Pages.Store;
public partial class OrderTracking : ComponentBase
{
[Inject] private OrderService OrderService { get; set; } = default!;
[Parameter] public long id { get; set; }
private GetUserOrderResponse? _order;
private bool _loading = true;
private List<TrackingStep> _trackingSteps = new();
protected override async Task OnInitializedAsync()
{
await LoadOrderAsync();
}
private async Task LoadOrderAsync()
{
_loading = true;
StateHasChanged();
try
{
var response = await OrderService.GetOrderAsync(id);
if (response is not null)
{
_order = response;
BuildTrackingSteps();
}
}
finally
{
_loading = false;
StateHasChanged();
}
}
private void BuildTrackingSteps()
{
if (_order is null) return;
// Build tracking steps based on PaymentStatus
var isPaid = _order.PaymentStatus == PaymentStatus.Success;
_trackingSteps = new List<TrackingStep>
{
new()
{
Title = "ثبت سفارش",
Description = "سفارش شما با موفقیت ثبت شد",
IsCompleted = true,
Date = FormatDate(_order.PaymentDate)
},
new()
{
Title = "در انتظار پرداخت",
Description = "منتظر تایید پرداخت هستیم",
IsCompleted = isPaid,
IsCurrent = !isPaid,
Date = isPaid ? FormatDate(_order.PaymentDate) : ""
},
new()
{
Title = "تایید پرداخت",
Description = "پرداخت شما تایید شد",
IsCompleted = isPaid,
IsCurrent = false,
Date = isPaid ? FormatDate(_order.PaymentDate) : ""
},
new()
{
Title = "در حال پردازش",
Description = "سفارش شما در حال آماده‌سازی است",
IsCompleted = false,
IsCurrent = isPaid,
Date = ""
},
new()
{
Title = "ارسال شده",
Description = "سفارش شما به پست تحویل داده شد",
IsCompleted = false,
IsCurrent = false,
Date = ""
},
new()
{
Title = "تحویل داده شده",
Description = "سفارش به دست شما رسید",
IsCompleted = false,
IsCurrent = false,
Date = ""
}
};
}
private static string FormatDate(Google.Protobuf.WellKnownTypes.Timestamp? timestamp)
{
if (timestamp is null) return "";
var date = timestamp.ToDateTime();
var persianCalendar = new System.Globalization.PersianCalendar();
return $"{persianCalendar.GetYear(date)}/{persianCalendar.GetMonth(date):00}/{persianCalendar.GetDayOfMonth(date):00}";
}
private static string GetPaymentMethodText(PaymentMethod method) => method switch
{
PaymentMethod.Ipg => "پرداخت آنلاین",
PaymentMethod.Wallet => "کیف پول",
_ => "نامشخص"
};
private class TrackingStep
{
public string Title { get; set; } = "";
public string Description { get; set; } = "";
public bool IsCompleted { get; set; }
public bool IsCurrent { get; set; }
public string Date { get; set; } = "";
}
}