feat: 完成商城系统

This commit is contained in:
橙子
2024-11-03 15:49:41 +08:00
parent fe7211860f
commit 1468a7b878
6 changed files with 153 additions and 41 deletions

View File

@@ -9,6 +9,7 @@ using Volo.Abp.Users;
using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Collectibles;
using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Market;
using Yi.Framework.DigitalCollectibles.Domain.Entities;
using Yi.Framework.DigitalCollectibles.Domain.Managers;
using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts;
using Yi.Framework.SqlSugarCore.Abstractions;
@@ -20,16 +21,18 @@ namespace Yi.Framework.DigitalCollectibles.Application.Services;
public class CollectiblesService : ApplicationService
{
private readonly ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> _collectiblesUserStoreRepository;
private readonly CollectiblesManager _collectiblesManager;
public CollectiblesService(ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> collectiblesUserStoreRepository)
public CollectiblesService(ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> collectiblesUserStoreRepository,
CollectiblesManager collectiblesManager)
{
_collectiblesUserStoreRepository = collectiblesUserStoreRepository;
_collectiblesManager = collectiblesManager;
}
public bool GetEnable()
{
return LazyServiceProvider.LazyGetRequiredService<IConfiguration>().GetValue<bool>("IsEnableCollectibles");
return LazyServiceProvider.LazyGetRequiredService<IConfiguration>().GetValue<bool>("IsEnableCollectibles");
}
/// <summary>
@@ -40,43 +43,10 @@ public class CollectiblesService : ApplicationService
public async Task<CollectiblesAccountInfoDto> GetAccountInfoAsync()
{
var userId = CurrentUser.GetId();
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;
}
}
}
var value = await _collectiblesManager.GetAccountValueAsync(userId);
return new CollectiblesAccountInfoDto
{
TotalValue = totalValue
TotalValue = value
};
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}