mirror of https://github.com/EasyAbp/EShop.git
committed by
GitHub
36 changed files with 417 additions and 296 deletions
@ -0,0 +1,46 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Volo.Abp; |
|||
|
|||
namespace EasyAbp.EShop.Products.Products; |
|||
|
|||
[Serializable] |
|||
public class GetProductsRealTimePriceContext |
|||
{ |
|||
public DateTime Now { get; } |
|||
|
|||
/// <summary>
|
|||
/// ProductId to IProduct mapping.
|
|||
/// </summary>
|
|||
public Dictionary<Guid, IProduct> Products { get; } |
|||
|
|||
/// <summary>
|
|||
/// ProductSkuId to ProductRealTimePriceInfoModel mapping.
|
|||
/// </summary>
|
|||
public Dictionary<Guid, ProductRealTimePriceInfoModel> Models { get; } |
|||
|
|||
public GetProductsRealTimePriceContext(DateTime now, IEnumerable<IProduct> products, |
|||
IEnumerable<ProductRealTimePriceInfoModel> models) |
|||
{ |
|||
Now = now; |
|||
Products = Check.NotNull(products, nameof(products)).ToDictionary(x => x.Id); |
|||
Models = Check.NotNull(models, nameof(models)).ToDictionary(x => x.ProductSkuId); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Ctor for serializers.
|
|||
/// </summary>
|
|||
public GetProductsRealTimePriceContext(DateTime now, Dictionary<Guid, IProduct> products, |
|||
Dictionary<Guid, ProductRealTimePriceInfoModel> models) |
|||
{ |
|||
Now = now; |
|||
Products = products; |
|||
Models = models; |
|||
} |
|||
|
|||
public ProductRealTimePriceInfoModel GetRealTimePrice(IProductSku productSku) |
|||
{ |
|||
return Models[productSku.Id]; |
|||
} |
|||
} |
|||
@ -1,6 +1,6 @@ |
|||
namespace EasyAbp.EShop.Products.Products; |
|||
|
|||
public interface IHasFullDiscountsForProduct : IHasDiscountsForProduct |
|||
public interface IHasFullDiscountsForSku : IHasDiscountsForSku |
|||
{ |
|||
/// <summary>
|
|||
/// The realtime price without subtracting the discount amount.
|
|||
@ -1,34 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp; |
|||
|
|||
namespace EasyAbp.EShop.Products.Products; |
|||
|
|||
[Serializable] |
|||
public class ProductDiscountContext |
|||
{ |
|||
public DateTime Now { get; } |
|||
|
|||
public decimal PriceFromPriceProvider { get; } |
|||
|
|||
public IProduct Product { get; } |
|||
|
|||
public IProductSku ProductSku { get; } |
|||
|
|||
public List<CandidateProductDiscountInfoModel> CandidateProductDiscounts { get; } |
|||
|
|||
public List<OrderDiscountPreviewInfoModel> OrderDiscountPreviews { get; } |
|||
|
|||
public ProductDiscountContext(DateTime now, IProduct product, IProductSku productSku, |
|||
decimal priceFromPriceProvider, List<CandidateProductDiscountInfoModel> candidateProductDiscounts = null, |
|||
List<OrderDiscountPreviewInfoModel> orderDiscountPreviews = null) |
|||
{ |
|||
Now = now; |
|||
Product = Check.NotNull(product, nameof(product)); |
|||
ProductSku = Check.NotNull(productSku, nameof(productSku)); |
|||
PriceFromPriceProvider = priceFromPriceProvider; |
|||
|
|||
CandidateProductDiscounts = candidateProductDiscounts ?? new List<CandidateProductDiscountInfoModel>(); |
|||
OrderDiscountPreviews = orderDiscountPreviews ?? new List<OrderDiscountPreviewInfoModel>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace EasyAbp.EShop.Products.Products; |
|||
|
|||
public class ProductRealTimePriceInfoModel : IHasDiscountsForSku |
|||
{ |
|||
public Guid ProductId { get; } |
|||
|
|||
public Guid ProductSkuId { get; } |
|||
|
|||
public decimal PriceWithoutDiscount { get; } |
|||
|
|||
public List<CandidateProductDiscountInfoModel> CandidateProductDiscounts { get; } = new(); |
|||
|
|||
public List<ProductDiscountInfoModel> ProductDiscounts { get; } = new(); |
|||
|
|||
public List<OrderDiscountPreviewInfoModel> OrderDiscountPreviews { get; } = new(); |
|||
|
|||
public decimal TotalDiscountAmount => ProductDiscounts.Where(x => x.InEffect).Sum(x => x.DiscountedAmount); |
|||
|
|||
public decimal TotalDiscountedPrice => PriceWithoutDiscount - TotalDiscountAmount; |
|||
|
|||
public ProductRealTimePriceInfoModel(Guid productId, Guid productSkuId, decimal priceWithoutDiscount) |
|||
{ |
|||
ProductId = productId; |
|||
ProductSkuId = productSkuId; |
|||
PriceWithoutDiscount = priceWithoutDiscount; |
|||
} |
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
using System.Linq; |
|||
|
|||
namespace EasyAbp.EShop.Products.Products; |
|||
|
|||
public class RealTimePriceInfoModel |
|||
{ |
|||
public decimal PriceWithoutDiscount { get; } |
|||
|
|||
public DiscountForProductModels Discounts { get; } |
|||
|
|||
public decimal TotalDiscountAmount => |
|||
Discounts.ProductDiscounts.Where(x => x.InEffect).Sum(x => x.DiscountedAmount); |
|||
|
|||
public decimal TotalDiscountedPrice => PriceWithoutDiscount - TotalDiscountAmount; |
|||
|
|||
public RealTimePriceInfoModel(decimal priceWithoutDiscount, DiscountForProductModels discounts) |
|||
{ |
|||
PriceWithoutDiscount = priceWithoutDiscount; |
|||
Discounts = discounts; |
|||
} |
|||
} |
|||
@ -1,13 +1,17 @@ |
|||
using System.Threading.Tasks; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace EasyAbp.EShop.Products.Products |
|||
{ |
|||
public class DefaultProductPriceProvider : IProductPriceProvider, ITransientDependency |
|||
{ |
|||
public virtual Task<decimal> GetPriceAsync(IProduct product, IProductSku productSku) |
|||
public virtual Task<List<ProductRealTimePriceInfoModel>> GetPricesAsync( |
|||
IEnumerable<ProductAndSkuDataModel> models) |
|||
{ |
|||
return Task.FromResult(productSku.Price); |
|||
return Task.FromResult(models.Select(x => |
|||
new ProductRealTimePriceInfoModel(x.Product.Id, x.ProductSku.Id, x.ProductSku.Price)).ToList()); |
|||
} |
|||
} |
|||
} |
|||
@ -1,10 +1,8 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace EasyAbp.EShop.Products.Products; |
|||
|
|||
public interface IProductDiscountResolver |
|||
{ |
|||
Task<DiscountForProductModels> ResolveAsync(IProduct product, IProductSku productSku, |
|||
decimal priceFromPriceProvider, DateTime now); |
|||
Task ResolveAsync(GetProductsRealTimePriceContext context); |
|||
} |
|||
@ -1,9 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace EasyAbp.EShop.Products.Products |
|||
{ |
|||
public interface IProductPriceProvider |
|||
{ |
|||
Task<decimal> GetPriceAsync(IProduct product, IProductSku productSku); |
|||
Task<List<ProductRealTimePriceInfoModel>> GetPricesAsync(IEnumerable<ProductAndSkuDataModel> models); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace EasyAbp.EShop.Products.Products; |
|||
|
|||
public class ProductAndSkuDataModel |
|||
{ |
|||
public Product Product { get; } |
|||
|
|||
public ProductSku ProductSku { get; } |
|||
|
|||
public ProductAndSkuDataModel(Product product, ProductSku productSku) |
|||
{ |
|||
Product = product; |
|||
ProductSku = productSku; |
|||
} |
|||
|
|||
public static IEnumerable<ProductAndSkuDataModel> CreateByProduct(Product product) |
|||
{ |
|||
return product.ProductSkus.Select(sku => new ProductAndSkuDataModel(product, sku)); |
|||
} |
|||
|
|||
public static IEnumerable<ProductAndSkuDataModel> CreateByProducts(IEnumerable<Product> products) |
|||
{ |
|||
return from product in products |
|||
from productSku in product.ProductSkus |
|||
select new ProductAndSkuDataModel(product, productSku); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue