From 3865faaed430ce10bb1c1c64c7b77345eebb76a4 Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Sun, 5 Jun 2022 00:58:24 +0800 Subject: [PATCH] Introduce BookingOrderLinePriceOverrider --- .../Booking/BookingOrderLinePriceOverrider.cs | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 plugins/Booking/src/EasyAbp.EShop.Orders.Booking.Application/EasyAbp/EShop/Orders/Booking/BookingOrderLinePriceOverrider.cs diff --git a/plugins/Booking/src/EasyAbp.EShop.Orders.Booking.Application/EasyAbp/EShop/Orders/Booking/BookingOrderLinePriceOverrider.cs b/plugins/Booking/src/EasyAbp.EShop.Orders.Booking.Application/EasyAbp/EShop/Orders/Booking/BookingOrderLinePriceOverrider.cs new file mode 100644 index 00000000..1f8c9209 --- /dev/null +++ b/plugins/Booking/src/EasyAbp.EShop.Orders.Booking.Application/EasyAbp/EShop/Orders/Booking/BookingOrderLinePriceOverrider.cs @@ -0,0 +1,94 @@ +using System.Linq; +using System.Threading.Tasks; +using EasyAbp.EShop.Orders.Orders; +using EasyAbp.EShop.Orders.Orders.Dtos; +using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories; +using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos; +using EasyAbp.EShop.Plugins.Booking.ProductAssets; +using EasyAbp.EShop.Plugins.Booking.ProductAssets.Dtos; +using EasyAbp.EShop.Products.Products.Dtos; +using Volo.Abp.DependencyInjection; + +namespace EasyAbp.EShop.Orders.Booking; + +public class BookingOrderLinePriceOverrider : IOrderLinePriceOverrider, ITransientDependency +{ + private readonly IProductAssetAppService _productAssetAppService; + private readonly IProductAssetCategoryAppService _productAssetCategoryAppService; + + public BookingOrderLinePriceOverrider( + IProductAssetAppService productAssetAppService, + IProductAssetCategoryAppService productAssetCategoryAppService) + { + _productAssetAppService = productAssetAppService; + _productAssetCategoryAppService = productAssetCategoryAppService; + } + + public virtual async Task GetUnitPriceOrNullAsync(CreateOrderDto input, CreateOrderLineDto inputOrderLine, + ProductDto product, ProductSkuDto productSku) + { + if (inputOrderLine.FindBookingAssetId() is not null) + { + return await GetAssetBookingUnitPriceAsync(input, inputOrderLine); + } + + if (inputOrderLine.FindBookingAssetCategoryId() is not null) + { + return await GetAssetCategoryBookingUnitPriceAsync(input, inputOrderLine); + } + + return null; + } + + public virtual async Task GetAssetBookingUnitPriceAsync(CreateOrderDto input, + CreateOrderLineDto inputOrderLine) + { + var productAsset = (await _productAssetAppService.GetListAsync( + new GetProductAssetDto + { + MaxResultCount = 1, + StoreId = input.StoreId, + ProductId = inputOrderLine.ProductId, + ProductSkuId = inputOrderLine.ProductSkuId, + AssetId = inputOrderLine.GetBookingAssetId(), + PeriodSchemeId = inputOrderLine.GetBookingPeriodSchemeId() + } + )).Items.First(); + + var productAssetPeriod = + productAsset.Periods.FirstOrDefault(x => x.PeriodId == inputOrderLine.GetBookingPeriodId()); + + if (productAssetPeriod is not null) + { + return productAssetPeriod.Price; + } + + return productAsset.Price; + } + + public virtual async Task GetAssetCategoryBookingUnitPriceAsync(CreateOrderDto input, + CreateOrderLineDto inputOrderLine) + { + var productAssetCategory = (await _productAssetCategoryAppService.GetListAsync( + new GetProductAssetCategoryDto + { + MaxResultCount = 1, + StoreId = input.StoreId, + ProductId = inputOrderLine.ProductId, + ProductSkuId = inputOrderLine.ProductSkuId, + AssetCategoryId = inputOrderLine.GetBookingAssetCategoryId(), + PeriodSchemeId = inputOrderLine.GetBookingPeriodSchemeId() + } + )).Items.First(); + + var productAssetCategoryPeriod = + productAssetCategory.Periods.FirstOrDefault(x => x.PeriodId == inputOrderLine.GetBookingPeriodId()); + + if (productAssetCategoryPeriod is not null) + { + return productAssetCategoryPeriod.Price; + } + + return productAssetCategory.Price; + } +} \ No newline at end of file