From 1468a7b8782ed806e94bd44f62ae3f3e924a6f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sun, 3 Nov 2024 15:49:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Shop/BbsShopAccountDto.cs | 19 +++++++ .../Services/Shop/BbsShopService.cs | 22 +++++++- .../Etos/SetAccountInfoEto.cs | 27 ++++++++++ .../Services/CollectiblesService.cs | 46 +++-------------- .../SetAccountInfoEventHandler.cs | 29 +++++++++++ .../Managers/CollectiblesManager.cs | 51 ++++++++++++++++++- 6 files changed, 153 insertions(+), 41 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/BbsShopAccountDto.cs create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/SetAccountInfoEto.cs create mode 100644 Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/EventHandlers/SetAccountInfoEventHandler.cs diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/BbsShopAccountDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/BbsShopAccountDto.cs new file mode 100644 index 00000000..56e7575e --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Shop/BbsShopAccountDto.cs @@ -0,0 +1,19 @@ +namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Shop; + +public class BbsShopAccountDto +{ + /// + /// 钱钱 + /// + public decimal Money { get; set; } + + /// + /// 积分 + /// + public int Points { get; set; } + + /// + /// 价值 + /// + public decimal Value { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Shop/BbsShopService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Shop/BbsShopService.cs index 482e5f5d..766c17b5 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Shop/BbsShopService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Shop/BbsShopService.cs @@ -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 _repository; private readonly ISqlSugarRepository _applyRepository; private readonly BbsShopManager _bbsShopManager; + private readonly ISqlSugarRepository _bbsUserRepository; + private ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetRequiredService(); public BbsShopService(ISqlSugarRepository repository, - ISqlSugarRepository applyRepository, BbsShopManager bbsShopManager) + ISqlSugarRepository applyRepository, BbsShopManager bbsShopManager, + ISqlSugarRepository bbsUserRepository) { _repository = repository; _applyRepository = applyRepository; _bbsShopManager = bbsShopManager; + _bbsUserRepository = bbsUserRepository; } //商城列表 @@ -76,7 +83,18 @@ public class BbsShopService : ApplicationService /// 获取该用户汇总信息(钱钱、积分、价值) /// [Authorize] - public async Task GetAccountAsync() + public async Task 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; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/SetAccountInfoEto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/SetAccountInfoEto.cs new file mode 100644 index 00000000..ab09799c --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/SetAccountInfoEto.cs @@ -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; } + + + /// + /// 钱钱 + /// + public decimal Money { get; set; } + + /// + /// 积分 + /// + public int Points { get; set; } + + /// + /// 价值 + /// + public decimal Value { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/CollectiblesService.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/CollectiblesService.cs index e94e430c..3b1d9054 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/CollectiblesService.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/CollectiblesService.cs @@ -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 _collectiblesUserStoreRepository; + private readonly CollectiblesManager _collectiblesManager; - - public CollectiblesService(ISqlSugarRepository collectiblesUserStoreRepository) + public CollectiblesService(ISqlSugarRepository collectiblesUserStoreRepository, + CollectiblesManager collectiblesManager) { _collectiblesUserStoreRepository = collectiblesUserStoreRepository; + _collectiblesManager = collectiblesManager; } public bool GetEnable() { - return LazyServiceProvider.LazyGetRequiredService().GetValue("IsEnableCollectibles"); + return LazyServiceProvider.LazyGetRequiredService().GetValue("IsEnableCollectibles"); } /// @@ -40,43 +43,10 @@ public class CollectiblesService : ApplicationService public async Task GetAccountInfoAsync() { var userId = CurrentUser.GetId(); - var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable - .Where(store => store.UserId == userId) - .LeftJoin((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 }; } diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/EventHandlers/SetAccountInfoEventHandler.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/EventHandlers/SetAccountInfoEventHandler.cs new file mode 100644 index 00000000..ebdc1937 --- /dev/null +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/EventHandlers/SetAccountInfoEventHandler.cs @@ -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, 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; + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/CollectiblesManager.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/CollectiblesManager.cs index 6f7dc729..b0e3bdd3 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/CollectiblesManager.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/CollectiblesManager.cs @@ -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; /// @@ -7,5 +10,51 @@ namespace Yi.Framework.DigitalCollectibles.Domain.Managers; /// public class CollectiblesManager:DomainService { - + private readonly ISqlSugarRepository _collectiblesUserStoreRepository; + + public CollectiblesManager(ISqlSugarRepository collectiblesUserStoreRepository) + { + _collectiblesUserStoreRepository = collectiblesUserStoreRepository; + } + + + public async Task GetAccountValueAsync(Guid userId) + { + var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable + .Where(store => store.UserId == userId) + .LeftJoin((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; + } } \ No newline at end of file