3bffc13ffd
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 2m33s
T4.2: Conditional Payment in Checkout - Load package flags via PackageService.GetAllPackagesAsync - Respect SupportsDirectPurchase/SupportsDayaPurchase flags - Add Daya loan payment button when supported - Show alert when no payment method available T4.3: MyPackages Re-Purchase Logic - Load MagicWallet status to detect cycle completion - Show re-purchase CTA when magic cycle is complete - Show magic wallet progress bar during active cycle - Display deposit progress, remaining, and credited amounts F3: PV Display in Order Details - Add CalculateOrderPVAsync to OrderService - Show per-product PV and total PV in Store OrderDetail - Update NuGet to v0.0.188
118 lines
3.7 KiB
C#
118 lines
3.7 KiB
C#
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
|
using Mapster;
|
|
|
|
namespace FrontOffice.Main.Utilities;
|
|
|
|
// public enum PaymentMethod
|
|
// {
|
|
// Wallet = 1,
|
|
// }
|
|
//
|
|
// public enum OrderStatus
|
|
// {
|
|
// Pending = 0,
|
|
// Paid = 1,
|
|
// }
|
|
|
|
// public record OrderItem(long ProductId, string Title, string ImageUrl, long UnitPrice, int Quantity)
|
|
// {
|
|
// public long LineTotal => UnitPrice * Quantity;
|
|
// }
|
|
//
|
|
// public class Order
|
|
// {
|
|
// public long Id { get; set; }
|
|
// public DateTime CreatedAt { get; set; } = DateTime.Now;
|
|
// public OrderStatus Status { get; set; } = OrderStatus.Pending;
|
|
// public PaymentMethod PaymentMethod { get; set; } = PaymentMethod.Wallet;
|
|
// public long AddressId { get; set; }
|
|
// public string AddressSummary { get; set; } = string.Empty;
|
|
// public List<OrderItem> Items { get; set; } = new();
|
|
// public long Total => Items.Sum(i => i.LineTotal);
|
|
// }
|
|
|
|
public class OrderService
|
|
{
|
|
private long _seq = 1000;
|
|
private readonly List<GetUserOrderResponse> _orders = new();
|
|
private readonly CMSMicroservice.Protobuf.Protos.UserOrder.UserOrderContract.UserOrderContractClient _userOrderContractClient;
|
|
|
|
public OrderService(CMSMicroservice.Protobuf.Protos.UserOrder.UserOrderContract.UserOrderContractClient userOrderContractClient)
|
|
{
|
|
_userOrderContractClient = userOrderContractClient;
|
|
}
|
|
|
|
public async Task<List<GetUserOrderResponse>> GetOrdersAsync()
|
|
{
|
|
var result = await _userOrderContractClient.GetCustomerOrdersAsync(new());
|
|
if (result != null && result.Models.Count > 0)
|
|
{
|
|
foreach (var item in result.Models)
|
|
{
|
|
var order = new GetUserOrderResponse();
|
|
if (_orders.All(a => a.Id != item.Id))
|
|
{
|
|
TypeAdapterConfig.GlobalSettings.NewConfig<GetUserOrderResponseFactorDetail, GetUserOrderResponseFactorDetail>()
|
|
.Map(dest => dest.ProductThumbnailPath, src => src.ProductThumbnailPath);
|
|
order= item.Adapt<GetUserOrderResponse>();
|
|
order.FactorDetails.AddRange(item.FactorDetails.Adapt<List<GetUserOrderResponseFactorDetail>>());
|
|
_orders.Add(order);
|
|
}
|
|
}
|
|
}
|
|
|
|
return _orders.OrderByDescending(o => o.PaymentDate).ToList();
|
|
}
|
|
|
|
public async Task<GetUserOrderResponse?> GetOrderAsync(long id)
|
|
{
|
|
var order = _orders.FirstOrDefault(o => o.Id == id);
|
|
if (order == null)
|
|
{
|
|
var result = await _userOrderContractClient.GetCustomerOrderAsync(new GetUserOrderRequest()
|
|
{
|
|
Id = id
|
|
});
|
|
_orders.Add(result);
|
|
return result;
|
|
}
|
|
|
|
return order;
|
|
}
|
|
|
|
/// <summary>
|
|
/// دریافت نرخ مالیات بر ارزش افزوده
|
|
/// </summary>
|
|
public async Task<double> GetVATRateAsync()
|
|
{
|
|
try
|
|
{
|
|
// TODO: Use Configuration service to get VAT rate
|
|
// return await _userOrderContractClient.GetVATRateAsync(new Google.Protobuf.WellKnownTypes.Empty());
|
|
return 0.10; // Default 10%
|
|
}
|
|
catch
|
|
{
|
|
// در صورت خطا، مقادیر پیشفرض
|
|
return 0.10;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// محاسبه PV سفارش
|
|
/// </summary>
|
|
public async Task<CalculateOrderPVResponse?> CalculateOrderPVAsync(long orderId)
|
|
{
|
|
try
|
|
{
|
|
return await _userOrderContractClient.CalculateOrderPVAsync(new CalculateOrderPVRequest
|
|
{
|
|
OrderId = orderId
|
|
});
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
} |