Browse Source

Introduce MaxNotExpiredCouponQuantityPerUser const and IncludesExpired property

pull/103/head
gdlcf88 5 years ago
parent
commit
57c18d1c70
  1. 7
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Application.Contracts/EasyAbp/EShop/Plugins/Coupons/Coupons/Dtos/GetCouponListInput.cs
  2. 7
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Application/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponAppService.cs
  3. 2
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Domain.Shared/EasyAbp/EShop/Plugins/Coupons/CouponsConsts.cs
  4. 20
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.EntityFrameworkCore/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponRepository.cs
  5. 12
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.EntityFrameworkCore/EasyAbp/EShop/Plugins/Coupons/Coupons/UserCouponQuantityExceedsLimitException.cs
  6. 4
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Web/Pages/EShop/Plugins/Coupons/Coupons/Coupon/index.js

7
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Application.Contracts/EasyAbp/EShop/Plugins/Coupons/Coupons/Dtos/GetCouponListInput.cs

@ -11,5 +11,12 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons.Dtos
public Guid? StoreId { get; set; }
public Guid? UserId { get; set; }
public bool IncludesExpired { get; set; }
public GetCouponListInput()
{
MaxMaxResultCount = CouponsConsts.MaxNotExpiredCouponQuantityPerUser;
}
}
}

7
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Application/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponAppService.cs

@ -37,8 +37,9 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons
protected override IQueryable<Coupon> CreateFilteredQuery(GetCouponListInput input)
{
return input.AvailableOnly ? _repository.GetAvailableCouponQueryable(Clock) : _repository.AsQueryable()
.WhereIf(input.UserId.HasValue, x => x.UserId == input.UserId.Value);
return (input.AvailableOnly ? _repository.GetAvailableCouponQueryable(Clock) : _repository.AsQueryable())
.WhereIf(input.UserId.HasValue, x => x.UserId == input.UserId.Value)
.WhereIf(!input.AvailableOnly && !input.IncludesExpired, x => x.ExpirationTime > Clock.Now);
}
protected virtual CouponDto FillCouponTemplateData(CouponDto couponDto, CouponTemplate couponTemplate)
@ -107,7 +108,7 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons
coupon.SetExpirationTime(couponTemplate.GetCalculatedExpirationTime(Clock));
await Repository.InsertAsync(coupon, autoSave: true);
await _repository.InsertAsync(coupon, autoSave: true);
return FillCouponTemplateData(await MapToGetOutputDtoAsync(coupon), couponTemplate);
}

2
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Domain.Shared/EasyAbp/EShop/Plugins/Coupons/CouponsConsts.cs

@ -5,5 +5,7 @@
public const string OrderCouponIdPropertyName = "CouponId";
public const string OrderCouponDiscountAmountPropertyName = "CouponDiscountAmount";
public const int MaxNotExpiredCouponQuantityPerUser = 100;
}
}

20
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.EntityFrameworkCore/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponRepository.cs

@ -1,6 +1,10 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EasyAbp.EShop.Plugins.Coupons.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Timing;
@ -26,5 +30,21 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons
(coupon, couponTemplate) => coupon
);
}
public override async Task<Coupon> InsertAsync(Coupon entity, bool autoSave = false, CancellationToken cancellationToken = new CancellationToken())
{
var clock = ServiceProvider.GetRequiredService<IClock>();
var notExpiredCouponQuantity =
await DbSet.CountAsync(x => x.UserId == entity.UserId && x.ExpirationTime > clock.Now,
cancellationToken);
if (notExpiredCouponQuantity >= CouponsConsts.MaxNotExpiredCouponQuantityPerUser)
{
throw new UserCouponQuantityExceedsLimitException(CouponsConsts.MaxNotExpiredCouponQuantityPerUser);
}
return await base.InsertAsync(entity, autoSave, cancellationToken);
}
}
}

12
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.EntityFrameworkCore/EasyAbp/EShop/Plugins/Coupons/Coupons/UserCouponQuantityExceedsLimitException.cs

@ -0,0 +1,12 @@
using Volo.Abp;
namespace EasyAbp.EShop.Plugins.Coupons.Coupons
{
public class UserCouponQuantityExceedsLimitException : BusinessException
{
public UserCouponQuantityExceedsLimitException(int maxQuantity) : base("UserCouponQuantityExceedsLimit",
$"User's coupon quantity exceeds the limit: {maxQuantity}.")
{
}
}
}

4
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Web/Pages/EShop/Plugins/Coupons/Coupons/Coupon/index.js

@ -14,7 +14,9 @@ $(function () {
autoWidth: false,
scrollCollapse: true,
order: [[0, "asc"]],
ajax: abp.libs.datatables.createAjax(service.getList),
ajax: abp.libs.datatables.createAjax(service.getList, function () {
return { includesExpired: true }
}),
columnDefs: [
{
rowAction: {

Loading…
Cancel
Save