feat: 完成商城系统
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.EventBus;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Managers;
|
||||
|
||||
namespace Yi.Framework.DigitalCollectibles.Domain.EventHandlers;
|
||||
|
||||
public class SetAccountInfoEventHandler : ILocalEventHandler<SetAccountInfoEto>, ITransientDependency
|
||||
{
|
||||
private readonly CollectiblesManager _collectiblesManager;
|
||||
private readonly InvitationCodeManager _invitationCodeManager;
|
||||
|
||||
public SetAccountInfoEventHandler(CollectiblesManager collectiblesManager,
|
||||
InvitationCodeManager invitationCodeManager)
|
||||
{
|
||||
_collectiblesManager = collectiblesManager;
|
||||
_invitationCodeManager = invitationCodeManager;
|
||||
}
|
||||
|
||||
public async Task HandleEventAsync(SetAccountInfoEto eventData)
|
||||
{
|
||||
var userId = eventData.UserId;
|
||||
//设置价值
|
||||
eventData.Value = await _collectiblesManager.GetAccountValueAsync(userId);
|
||||
|
||||
//设置积分
|
||||
eventData.Points = (await _invitationCodeManager.TryGetOrAddAsync(userId)).PointsNumber;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Entities;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.DigitalCollectibles.Domain.Managers;
|
||||
/// <summary>
|
||||
@@ -7,5 +10,51 @@ namespace Yi.Framework.DigitalCollectibles.Domain.Managers;
|
||||
/// </summary>
|
||||
public class CollectiblesManager:DomainService
|
||||
{
|
||||
|
||||
private readonly ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> _collectiblesUserStoreRepository;
|
||||
|
||||
public CollectiblesManager(ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> collectiblesUserStoreRepository)
|
||||
{
|
||||
_collectiblesUserStoreRepository = collectiblesUserStoreRepository;
|
||||
}
|
||||
|
||||
|
||||
public async Task<decimal> GetAccountValueAsync(Guid userId)
|
||||
{
|
||||
var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable
|
||||
.Where(store => store.UserId == userId)
|
||||
.LeftJoin<CollectiblesAggregateRoot>((store, c) => store.CollectiblesId == c.Id)
|
||||
.Select((store, c) =>
|
||||
new
|
||||
{
|
||||
c.Id,
|
||||
c.ValueNumber
|
||||
}
|
||||
).ToListAsync();
|
||||
var groupBy = collectiblesList.GroupBy(x => x.Id);
|
||||
decimal totalValue = 0;
|
||||
|
||||
//首个价值百分之百,后续每个只有百分之40,最大10个
|
||||
foreach (var groupByItem in groupBy)
|
||||
{
|
||||
foreach (var item in groupByItem.Select((value, index) => new { value, index }))
|
||||
{
|
||||
|
||||
if (item.index == 0)
|
||||
{
|
||||
totalValue += item.value.ValueNumber;
|
||||
}
|
||||
else if (item.index == 10)
|
||||
{
|
||||
//到第11个,直接跳出循环
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
totalValue += item.value.ValueNumber * 0.4m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return totalValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user