From 260d87c97e559d77ced3198bd4a4077805662396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Thu, 17 Oct 2024 00:27:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Collectibles/CollectiblesDto.cs | 47 ++++++++ .../CollectiblesUserGetOutputDto.cs | 10 +- .../Dtos/Market/MarketGetListOutputDto.cs | 39 ++---- .../Dtos/Market/PurchaseGoodsDto.cs | 8 ++ .../Dtos/Market/ShelvedGoodsDto.cs | 10 ++ .../Dtos/MiningPool/MiningResultOutput.cs | 1 - .../Services/CollectiblesService.cs | 28 ++++- .../Services/MarketService.cs | 68 +++++++++-- .../Services/MiningPoolService.cs | 12 ++ .../DigitalCollectiblesSettingProvider.cs | 19 +-- ...k.DigitalCollectibles.Domain.Shared.csproj | 2 +- .../CollectiblesUserStoreAggregateRoot.cs | 25 +++- .../Entities/OnHookAggregateRoot.cs | 26 +++- .../Managers/MarketManager.cs | 111 +++++++++++++++++- .../Managers/MiningPoolManager.cs | 14 +++ 15 files changed, 361 insertions(+), 59 deletions(-) create mode 100644 Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Collectibles/CollectiblesDto.cs create mode 100644 Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/PurchaseGoodsDto.cs create mode 100644 Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/ShelvedGoodsDto.cs diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Collectibles/CollectiblesDto.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Collectibles/CollectiblesDto.cs new file mode 100644 index 00000000..16d0c26b --- /dev/null +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Collectibles/CollectiblesDto.cs @@ -0,0 +1,47 @@ +using Volo.Abp.Application.Dtos; +using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts; + +namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Collectibles; + +public class CollectiblesDto : EntityDto +{ + /// + /// 藏品编号 + /// + public string Code { get; set; } + + /// + /// 藏品名称 + /// + public string Name { get; set; } + + /// + /// 藏品描述 + /// + public string? Describe { get; set; } + + /// + /// 价值数 + /// + public decimal ValueNumber { get; set; } + + /// + /// 藏品地址 + /// + public string Url { get; set; } + + /// + /// 稀有度 + /// + public RarityEnum Rarity{ get; set; } + + /// + /// 总共出现次数 + /// + public int FindTotal { get; set; } + + /// + /// 排序 + /// + public int OrderNum { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Collectibles/CollectiblesUserGetOutputDto.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Collectibles/CollectiblesUserGetOutputDto.cs index 17de60d2..c733ec76 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Collectibles/CollectiblesUserGetOutputDto.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Collectibles/CollectiblesUserGetOutputDto.cs @@ -2,7 +2,15 @@ namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Collectibles; -public class CollectiblesUserGetOutputDto:EntityDto +public class CollectiblesUserGetOutputDto : EntityDto { + /// + /// 藏品 + /// + public CollectiblesDto Collectibles{ get; set; } + /// + /// 数量 + /// + public int Number { get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/MarketGetListOutputDto.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/MarketGetListOutputDto.cs index 2facd9f7..92745847 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/MarketGetListOutputDto.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/MarketGetListOutputDto.cs @@ -1,4 +1,5 @@ using Volo.Abp.Application.Dtos; +using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Collectibles; using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts; namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Market; @@ -6,42 +7,24 @@ namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Market; public class MarketGetListOutputDto:EntityDto { /// - /// 藏品编号 + /// 上架时间 /// - public string Code { get; set; } - + public DateTime CreationTime{ get; set; } /// - /// 藏品名称 + /// 出售者用户id /// - public string Name { get; set; } - + public Guid SellUserId { get; set; } /// - /// 藏品描述 + /// 出售数量 /// - public string? Describe { get; set; } - - /// - /// 价值数 - /// - public decimal ValueNumber { get; set; } - - /// - /// 藏品地址 - /// - public string Url { get; set; } + public int SellNumber{ get; set; } /// - /// 稀有度 + /// 出售单价 /// - public RarityEnum Rarity{ get; set; } - + public decimal UnitPrice{ get; set; } /// - /// 总共出现次数 + /// 藏品 /// - public int FindTotal { get; set; } - - /// - /// 排序 - /// - public int OrderNum { get; set; } + public CollectiblesDto Collectibles{ get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/PurchaseGoodsDto.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/PurchaseGoodsDto.cs new file mode 100644 index 00000000..26b9da54 --- /dev/null +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/PurchaseGoodsDto.cs @@ -0,0 +1,8 @@ +namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Market; + +public class PurchaseGoodsDto +{ + public Guid MarketGoodsId{ get; set; } + + public int Number{ get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/ShelvedGoodsDto.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/ShelvedGoodsDto.cs new file mode 100644 index 00000000..5c74a17f --- /dev/null +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Market/ShelvedGoodsDto.cs @@ -0,0 +1,10 @@ +namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Market; + +public class ShelvedGoodsDto +{ + + public Guid CollectiblesId { get; set; } + public int Number { get; set; } + + public decimal Mmoney { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/MiningPool/MiningResultOutput.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/MiningPool/MiningResultOutput.cs index a8c73427..f6e17601 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/MiningPool/MiningResultOutput.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/MiningPool/MiningResultOutput.cs @@ -5,7 +5,6 @@ namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.MiningPool public class MiningResultOutput { - public MiningResultEnum Result { get; set; } public CollectiblesUserGetOutputDto? Collectibles { 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 51c80905..8690f713 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 @@ -7,6 +7,7 @@ using Volo.Abp.Application.Services; 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.Shared.Consts; using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.DigitalCollectibles.Application.Services; @@ -35,12 +36,31 @@ public class CollectiblesService : ApplicationService CollectiblesUserGetInput input) { RefAsync total = 0; - var entities = await _collectiblesUserStoreRepository._DbQueryable.WhereIF( + var output = await _collectiblesUserStoreRepository._DbQueryable.WhereIF( input.StartTime is not null && input.EndTime is not null, - x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) - .OrderByDescending(x => x.CreationTime) + u => u.CreationTime >= input.StartTime && u.CreationTime <= input.EndTime) + .LeftJoin((u, c) => u.CollectiblesId == c.Id) + .GroupBy((u, c) => u.CollectiblesId) + .Select((u, c) => + new CollectiblesUserGetOutputDto + { + Id = c.Id, + Collectibles = new CollectiblesDto + { + Id = c.Id, + Code = c.Code, + Name = c.Name, + Describe = c.Describe, + ValueNumber = c.ValueNumber, + Url = c.Url, + Rarity = c.Rarity, + FindTotal = c.FindTotal, + OrderNum = c.OrderNum + }, + Number = SqlFunc.AggregateCount(u.CollectiblesId) + }) + .OrderBy(dto => dto.Collectibles.OrderNum) .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); - var output = entities.Adapt>(); return new PagedResultDto(total, output); } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/MarketService.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/MarketService.cs index f5222f45..774b4dd7 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/MarketService.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/MarketService.cs @@ -1,23 +1,33 @@ using Mapster; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using SqlSugar; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; +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; namespace Yi.Framework.DigitalCollectibles.Application.Services; /// -/// 市场应用服务 +/// 交易市场应用服务 /// -public class MarketService:ApplicationService +public class MarketService : ApplicationService { private readonly ISqlSugarRepository _marketGoodsRepository; - public MarketService(ISqlSugarRepository marketGoodsRepository) + private readonly MarketManager _marketManager; + + public MarketService(ISqlSugarRepository marketGoodsRepository, + MarketManager marketManager) { _marketGoodsRepository = marketGoodsRepository; + _marketManager = marketManager; } /// @@ -28,12 +38,56 @@ public class MarketService:ApplicationService public async Task> GetListAsync(MarketGetListInput input) { RefAsync total = 0; - var entities = await _marketGoodsRepository._DbQueryable.WhereIF( + var output = await _marketGoodsRepository._DbQueryable.WhereIF( input.StartTime is not null && input.EndTime is not null, - x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) - .OrderByDescending(x => x.CreationTime) + m => m.CreationTime >= input.StartTime && m.CreationTime <= input.EndTime) + + .LeftJoin((m, c) => m.CollectiblesId == c.Id) + .Select((m, c) => + + new MarketGetListOutputDto + { + Id = m.Id, + CreationTime = m.CreationTime, + SellUserId = m.SellUserId, + SellNumber = m.SellNumber, + Collectibles = new CollectiblesDto + { + Id = c.Id, + Code = c.Code, + Name = c.Name, + Describe = c.Describe, + ValueNumber = c.ValueNumber, + Url = c.Url, + Rarity =c.Rarity, + FindTotal = c.FindTotal, + OrderNum = c.OrderNum + } + } + ) + .OrderByDescending(dto => dto.CreationTime) .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); - var output = entities.Adapt>(); return new PagedResultDto(total, output); } + + + /// + /// 上架商品 + /// + [HttpPost("shelved")] + [Authorize] + public async Task ShelvedGoodsAsync(ShelvedGoodsDto input) + { + await _marketManager.ShelvedGoodsAsync(CurrentUser.GetId(), input.CollectiblesId, input.Number, input.Mmoney); + } + + /// + /// 购买商品 + /// + [HttpPut("purchase")] + [Authorize] + public async Task PurchaseGoodsAsync(PurchaseGoodsDto input) + { + await _marketManager.PurchaseGoodsAsync(CurrentUser.GetId(),input.MarketGoodsId, input.Number); + } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/MiningPoolService.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/MiningPoolService.cs index 04cf3594..1e88447e 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/MiningPoolService.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/MiningPoolService.cs @@ -8,10 +8,22 @@ using Yi.Framework.DigitalCollectibles.Domain.Managers; namespace Yi.Framework.DigitalCollectibles.Application.Services; +/// +/// 矿池应用服务 +/// public class MiningPoolService : ApplicationService { private readonly MiningPoolManager _manager; + /// + /// 内测-白嫖-获取自动挖矿卡 + /// + [HttpPost("mining-pool/on-hook")] + public async Task GetOnHookAsync() + { + await _manager.GetOnHookAsync(CurrentUser.GetId()); + } + /// /// 获取矿池状态 /// diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain.Shared/Settings/DigitalCollectiblesSettingProvider.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain.Shared/Settings/DigitalCollectiblesSettingProvider.cs index 6b8f4716..63926c9c 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain.Shared/Settings/DigitalCollectiblesSettingProvider.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain.Shared/Settings/DigitalCollectiblesSettingProvider.cs @@ -15,17 +15,20 @@ namespace Yi.Abp.Domain.Shared.Settings public override void Define(ISettingDefinitionContext context) { context.Add( - //每日矿池最大上限 + //每日矿池最大上限--控制矿池膨胀率 new SettingDefinition("MaxPoolLimit", "50"), - - //每日挖矿最大上限 + + //每日挖矿最大上限--控制无限挖矿 new SettingDefinition("MiningMaxLimit", "36"), - - //每次挖矿最小间隔(秒) + + //每次挖矿最小间隔(秒)--控制暴力挖矿 new SettingDefinition("MiningMinIntervalSeconds", "5"), - - //每次挖到矿的概率 - new SettingDefinition("MiningMinProbability", "0.06") + + //每次挖到矿的概率--控制爆率 + new SettingDefinition("MiningMinProbability", "0.06"), + + //交易税率--控制频繁交易 + new SettingDefinition("MarketTaxRate", "0.2") ); } } diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain.Shared/Yi.Framework.DigitalCollectibles.Domain.Shared.csproj b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain.Shared/Yi.Framework.DigitalCollectibles.Domain.Shared.csproj index 5a8191e1..1bc26ce1 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain.Shared/Yi.Framework.DigitalCollectibles.Domain.Shared.csproj +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain.Shared/Yi.Framework.DigitalCollectibles.Domain.Shared.csproj @@ -6,7 +6,7 @@ - + diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/CollectiblesUserStoreAggregateRoot.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/CollectiblesUserStoreAggregateRoot.cs index e6345b4a..79194398 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/CollectiblesUserStoreAggregateRoot.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/CollectiblesUserStoreAggregateRoot.cs @@ -8,7 +8,7 @@ namespace Yi.Framework.DigitalCollectibles.Domain.Entities; /// 表示用户与藏品的库存关系 /// [SugarTable("DC_CollectiblesUserStore")] -public class CollectiblesUserStoreAggregateRoot:FullAuditedAggregateRoot +public class CollectiblesUserStoreAggregateRoot : FullAuditedAggregateRoot { /// /// 用户id @@ -24,4 +24,27 @@ public class CollectiblesUserStoreAggregateRoot:FullAuditedAggregateRoot /// 用户是否已读 /// public bool IsRead { get; set; } + + /// + /// 是否正在市场交易 + /// + public bool IsAtMarketing { get; set; } + + + /// + /// 上架货物 + /// + public void ShelvedMarket() + { + IsAtMarketing = true; + } + + /// + /// 交易货物 + /// + public void PurchaseMarket(Guid userId) + { + UserId = userId; + IsAtMarketing = false; + } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/OnHookAggregateRoot.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/OnHookAggregateRoot.cs index fd115499..a3eacccd 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/OnHookAggregateRoot.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/OnHookAggregateRoot.cs @@ -9,8 +9,22 @@ namespace Yi.Framework.DigitalCollectibles.Domain.Entities; /// 用于定时任务处理自动挖矿 /// [SugarTable("DC_OnHook")] -public class OnHookAggregateRoot:FullAuditedAggregateRoot +public class OnHookAggregateRoot : FullAuditedAggregateRoot { + public OnHookAggregateRoot() + { + } + + public OnHookAggregateRoot(Guid userId, int effectiveHours) + { + UserId = userId; + EffectiveHours = effectiveHours; + StarTime = DateTime.Now; + EndTime = DateTime.Now.AddHours(effectiveHours); + IsActive = true; + } + + /// /// 用户id /// @@ -20,19 +34,19 @@ public class OnHookAggregateRoot:FullAuditedAggregateRoot /// 开始时间 /// public DateTime? StarTime { get; set; } - + /// /// 结束时间 /// public DateTime? EndTime { get; set; } - + /// /// 有效小时数 /// - public int EffectiveHours{ get; set; } - + public int EffectiveHours { get; set; } + /// /// 是否激活 /// - public bool IsActive{ get; set; } + public bool IsActive { get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/MarketManager.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/MarketManager.cs index ed5a3bd0..3c9cdd99 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/MarketManager.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/MarketManager.cs @@ -1,4 +1,9 @@ using Volo.Abp.Domain.Services; +using Volo.Abp.EventBus.Local; +using Volo.Abp.Settings; +using Yi.Framework.Bbs.Domain.Shared.Etos; +using Yi.Framework.DigitalCollectibles.Domain.Entities; +using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.DigitalCollectibles.Domain.Managers; @@ -6,7 +11,109 @@ namespace Yi.Framework.DigitalCollectibles.Domain.Managers; /// 市场领域服务 /// 处理交易市场相关业务,例如交易等 /// -public class MarketManager:DomainService +public class MarketManager : DomainService { - + private readonly ISqlSugarRepository _collectiblesUserStoreRepository; + + private readonly ISqlSugarRepository _marketGoodsRepository; + + private readonly ILocalEventBus _localEventBus; + public readonly ISettingProvider _settingProvider; + public MarketManager(ISqlSugarRepository collectiblesUserStoreRepository, + ISqlSugarRepository marketGoodsRepository, ILocalEventBus localEventBus, ISettingProvider settingProvider) + { + _collectiblesUserStoreRepository = collectiblesUserStoreRepository; + _marketGoodsRepository = marketGoodsRepository; + _localEventBus = localEventBus; + _settingProvider = settingProvider; + } + + /// + /// 上架货物 + /// + /// 上架者 + /// 上架的收藏品id + /// 上架数量 + /// 上架单价 + /// + public async Task ShelvedGoodsAsync(Guid userId, Guid collectiblesId, int number, decimal money) + { + var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable.Where(x => x.IsAtMarketing == false) + .Where(x => x.CollectiblesId == collectiblesId).ToListAsync(); + if (collectiblesList.Count < number) + { + throw new UserFriendlyException($"您的藏品不足{number}个,上架失败"); + } + + //上架收藏品 + var shelvedcollectibles = collectiblesList.Take(2); + foreach (var store in shelvedcollectibles) + { + store.ShelvedMarket(); + } + + await _collectiblesUserStoreRepository.UpdateRangeAsync(shelvedcollectibles.ToList()); + + await _marketGoodsRepository.InsertAsync(new MarketGoodsAggregateRoot + { + SellUserId = userId, + CollectiblesId = collectiblesId, + SellNumber = number, + UnitPrice = money + }); + } + + /// + /// 购买商品 + /// + /// 购买者用户 + /// 商品id + /// 购买数量 + /// + public async Task PurchaseGoodsAsync(Guid userId, Guid marketGoodsId, int number) + { + //1-市场扣减或者关闭该商品 + //2-出售者新增钱,购买者扣钱 + //3-出售者删除对应库存,购买者新增对应库存 + var marketGoods = await _marketGoodsRepository.GetAsync(x => x.Id == marketGoodsId); + + //1-市场扣减或者关闭该商品 + if (marketGoods.SellNumber == number) + { + await _marketGoodsRepository.DeleteAsync(x => x.Id == marketGoodsId); + } + else if (marketGoods.SellNumber >= number) + { + marketGoods.SellNumber -= number; + await _marketGoodsRepository.UpdateAsync(marketGoods); + } + else + { + throw new UserFriendlyException($"交易失败,当前交易市场库存不足"); + } + + //2-出售者新增钱,购买者扣钱 + //发布一个其他领域的事件-购买者扣钱 + await _localEventBus.PublishAsync(new MoneyChangeEventArgs() { UserId = userId, Number = -number },false); + //发布一个其他领域的事件-出售者加钱,同时扣税 + var marketTaxRate = decimal.Parse(await _settingProvider.GetOrNullAsync("MarketTaxRate")); + await _localEventBus.PublishAsync(new MoneyChangeEventArgs() { UserId = userId, Number = number*(1-marketTaxRate) },false); + + //3-出售者删除对应库存,购买者新增对应库存 + var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable.Where(x => x.IsAtMarketing == true) + .Where(x => x.UserId == marketGoods.SellUserId) + .Where(x => x.CollectiblesId == marketGoods.CollectiblesId) + .ToListAsync(); + if (collectiblesList.Count < number) + { + throw new UserFriendlyException($"交易失败,当前出售者库存不足"); + } + + var updateStore = collectiblesList.Take(number); + foreach (var userStore in updateStore) + { + userStore.PurchaseMarket(userId); + } + await _collectiblesUserStoreRepository.UpdateRangeAsync(updateStore.ToList()); + } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/MiningPoolManager.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/MiningPoolManager.cs index 07b6ac08..7ff831ce 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/MiningPoolManager.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/MiningPoolManager.cs @@ -55,6 +55,20 @@ public class MiningPoolManager : DomainService return pool; } + public async Task GetOnHookAsync(Guid userId) + { + var onHook = await _onHookRepository._DbQueryable.Where(x => x.UserId == userId) + .Where(x => x.IsActive == true) + .Where(x => x.EndTime <= DateTime.Now) + .FirstAsync(); + + if (onHook is not null) + { + throw new UserFriendlyException($"当前你正在进行自动挂机,结束时间:{onHook.EndTime.Value.ToString("MM月dd日HH分mm秒")})"); + } + + await _onHookRepository.InsertAsync(new OnHookAggregateRoot(userId, 24)); + } /// /// 校验挖矿限制