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

@@ -0,0 +1,19 @@
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Shop;
public class BbsShopAccountDto
{
/// <summary>
/// 钱钱
/// </summary>
public decimal Money { get; set; }
/// <summary>
/// 积分
/// </summary>
public int Points { get; set; }
/// <summary>
/// 价值
/// </summary>
public decimal Value { get; set; }
}

View File

@@ -4,12 +4,15 @@ using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.EventBus.Local;
using Volo.Abp.Users;
using Yi.Framework.Bbs.Application.Contracts.Dtos.Shop;
using Yi.Framework.Bbs.Domain.Entities;
using Yi.Framework.Bbs.Domain.Entities.Shop;
using Yi.Framework.Bbs.Domain.Managers;
using Yi.Framework.Bbs.Domain.Managers.Shop;
using Yi.Framework.Bbs.Domain.Shared.Enums;
using Yi.Framework.Bbs.Domain.Shared.Etos;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Bbs.Application.Services.Shop;
@@ -22,13 +25,17 @@ public class BbsShopService : ApplicationService
private readonly ISqlSugarRepository<BbsGoodsAggregateRoot> _repository;
private readonly ISqlSugarRepository<BbsGoodsApplyAggregateRoot> _applyRepository;
private readonly BbsShopManager _bbsShopManager;
private readonly ISqlSugarRepository<BbsUserExtraInfoEntity> _bbsUserRepository;
private ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetRequiredService<ILocalEventBus>();
public BbsShopService(ISqlSugarRepository<BbsGoodsAggregateRoot> repository,
ISqlSugarRepository<BbsGoodsApplyAggregateRoot> applyRepository, BbsShopManager bbsShopManager)
ISqlSugarRepository<BbsGoodsApplyAggregateRoot> applyRepository, BbsShopManager bbsShopManager,
ISqlSugarRepository<BbsUserExtraInfoEntity> bbsUserRepository)
{
_repository = repository;
_applyRepository = applyRepository;
_bbsShopManager = bbsShopManager;
_bbsUserRepository = bbsUserRepository;
}
//商城列表
@@ -76,7 +83,18 @@ public class BbsShopService : ApplicationService
/// 获取该用户汇总信息(钱钱、积分、价值)
/// </summary>
[Authorize]
public async Task GetAccountAsync()
public async Task<BbsShopAccountDto> GetAccountAsync()
{
var userId = CurrentUser.GetId();
var output = new BbsShopAccountDto();
var money = await _bbsUserRepository._DbQueryable.Where(x => x.UserId == userId).Select(x => x.Money)
.FirstAsync();
var eto = new SetAccountInfoEto(userId);
await LocalEventBus.PublishAsync(eto, false);
//钱钱累加
output.Money += eto.Money;
output.Points = eto.Points;
output.Value = eto.Value;
return output;
}
}

View File

@@ -0,0 +1,27 @@
namespace Yi.Framework.Bbs.Domain.Shared.Etos;
public class SetAccountInfoEto
{
public SetAccountInfoEto(Guid userId)
{
UserId = userId;
}
public Guid UserId { get; set; }
/// <summary>
/// 钱钱
/// </summary>
public decimal Money { get; set; }
/// <summary>
/// 积分
/// </summary>
public int Points { get; set; }
/// <summary>
/// 价值
/// </summary>
public decimal Value { get; set; }
}

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