diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Records/MarketRecordDto.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Records/MarketRecordDto.cs index f23bf269..4ce86b85 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Records/MarketRecordDto.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Records/MarketRecordDto.cs @@ -5,6 +5,11 @@ namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Records; public class MarketRecordDto:EntityDto { + /// + /// 当前这条数据是否为购买者,否则为出售者 + /// + public bool IsBuyer { get; set; } + public DateTime CreationTime { get; set; } /// /// 出售数量 diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Record/CollectiblesServiceRecordService.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Record/CollectiblesRecordService.cs similarity index 62% rename from Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Record/CollectiblesServiceRecordService.cs rename to Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Record/CollectiblesRecordService.cs index 276834c5..cfbe9e32 100644 --- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Record/CollectiblesServiceRecordService.cs +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Record/CollectiblesRecordService.cs @@ -8,15 +8,16 @@ using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Collectibles; using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Records; using Yi.Framework.DigitalCollectibles.Domain.Entities; using Yi.Framework.DigitalCollectibles.Domain.Entities.Record; +using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts; using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.DigitalCollectibles.Application.Services.Record; -public class CollectiblesServiceRecordService : ApplicationService +public class CollectiblesRecordService : ApplicationService { private readonly ISqlSugarRepository _miningPoolRecordRepository; private readonly ISqlSugarRepository _marketRecordRepository; - public CollectiblesServiceRecordService(ISqlSugarRepository miningPoolRecordRepository, ISqlSugarRepository marketRecordRepository) + public CollectiblesRecordService(ISqlSugarRepository miningPoolRecordRepository, ISqlSugarRepository marketRecordRepository) { _miningPoolRecordRepository = miningPoolRecordRepository; _marketRecordRepository = marketRecordRepository; @@ -41,11 +42,21 @@ public class CollectiblesServiceRecordService : ApplicationService new MiningPoolRecordDto { Id = x.Id, - Collectibles = new CollectiblesDto() + CreationTime = x.CreationTime, + Collectibles = new CollectiblesDto { - Id = c.Id + 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 } - },true + + } ) .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); @@ -64,21 +75,43 @@ public class CollectiblesServiceRecordService : ApplicationService var userId = CurrentUser.GetId(); var output = await _marketRecordRepository._DbQueryable.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) - .Where(x => x.SellUserId == userId) + + //交易:是购买和出售,都需要展示 + .Where(x => x.SellUserId == userId||x.BuyId ==userId) .OrderByDescending(x => x.CreationTime) .LeftJoin((x, c) => x.CollectiblesId==c.Id) .Select((x, c) => new MarketRecordDto { Id = x.Id, + CreationTime=x.CreationTime, + SellUserId = x.SellUserId, + SellNumber = x.SellNumber, + RealTotalPrice=x.RealTotalPrice, + BuyId = x.BuyId, + UnitPrice=x.UnitPrice, Collectibles = new CollectiblesDto() { - Id = c.Id - } - },true + 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 + }, + } ) .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); + foreach (var dto in output) + { + dto.IsBuyer = dto.BuyId == userId; + } + + 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/Tool/CollectiblesToolService.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Tool/CollectiblesToolService.cs new file mode 100644 index 00000000..83ee46b2 --- /dev/null +++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Tool/CollectiblesToolService.cs @@ -0,0 +1,107 @@ +using System.IO.Compression; +using Volo.Abp.Application.Services; +using Yi.Framework.DigitalCollectibles.Domain.Entities; +using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace Yi.Framework.DigitalCollectibles.Application.Services.Tool; + +public class CollectiblesToolService : ApplicationService +{ + private ISqlSugarRepository _repository; + + public CollectiblesToolService(ISqlSugarRepository repository) + { + _repository = repository; + } + + public async Task DeleteInitAsync() + { + var directoryPath = Path.Combine("wwwroot", "dc", "data"); + var dataPath = Path.Combine("wwwroot", "dc", "data", "data.zip"); + if (!Directory.Exists(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } + + if (!File.Exists(dataPath)) + { + throw new UserFriendlyException($"{dataPath}路径不存在数据"); + } + + ZipFile.ExtractToDirectory(dataPath, directoryPath, true); // true 表示覆盖已有文件 + + + var txtPath = Path.Combine("wwwroot", "dc","data", "data.txt"); + if (!File.Exists(txtPath)) + { + throw new UserFriendlyException($"{txtPath}路径不存在文本"); + } + + var lines = await File.ReadAllLinesAsync(txtPath); + var errData = new List(); + //自动开启事务 + List entities = new List(); + for (int i = 0; i < lines.Length; i++) + { + var line = lines[i]; + if (string.IsNullOrEmpty(line)) + { + continue; + } + var items = line.Split(",").ToList(); + + + if (items.Count!=6) + { + errData.Add($"{i}行数据存,数据不对,只能6个数据"); + } + + var fileName = items[0]; + var code = Path.GetFileName(fileName) ; + var name = items[1]; + var value = decimal.Parse(items[2]); + var url = $"https://ccnetcore.com/prod-api/wwwroot/dc/data/{fileName}"; + var rarity = int.Parse(items[3]); + var des = items[4]; + var find = int.Parse(items[5]); + + var entity = new CollectiblesAggregateRoot + { + Code = code, + Name = name, + Describe = des, + ValueNumber = value, + Url = url, + Rarity = (RarityEnum)Enum.ToObject(typeof(RarityEnum), rarity), + FindTotal = find, + OrderNum = 0 + }; + entities.Add(entity); + + if (!File.Exists(Path.Combine(directoryPath,fileName))) + { + errData.Add($"文件不存在:{Path.Combine(directoryPath,fileName)}"); + } + + + } + + if (errData.Any()) + { + return new { ok = false, errData }; + } + + var allCode = await _repository._DbQueryable.Select(x => x.Code).ToListAsync(); + + var existCodes = allCode.Intersect(entities.Select(x => x.Code)).ToList(); + if (existCodes.Count > 0) + { + return new { ok = false, existCodes }; + } + + + await _repository.InsertRangeAsync(entities); + return new { ok = true,entities }; + } +} \ 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 ca64478c..940ac7d8 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 @@ -39,6 +39,11 @@ public class MarketManager : DomainService /// public async Task ShelvedGoodsAsync(Guid userId, Guid collectiblesId, int number, decimal money) { + if (number<=0) + { + throw new UserFriendlyException("上架藏品数量需大于0"); + } + var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable .Where(x=>x.UserId==userId) .Where(x => x.IsAtMarketing == false) @@ -75,6 +80,10 @@ public class MarketManager : DomainService /// public async Task PurchaseGoodsAsync(Guid userId, Guid marketGoodsId, int number) { + if (number<=0) + { + throw new UserFriendlyException("交易藏品数量需大于0"); + } //1-市场扣减或者关闭该商品 //2-出售者新增钱,购买者扣钱 //3-出售者删除对应库存,购买者新增对应库存 @@ -102,7 +111,8 @@ public class MarketManager : DomainService var marketTaxRate = decimal.Parse(await _settingProvider.GetOrNullAsync("MarketTaxRate")); //价格*扣减税 var realTotalPrice = (number*marketGoods.UnitPrice) * (1 - marketTaxRate); - await _localEventBus.PublishAsync(new MoneyChangeEventArgs() { UserId = userId, Number = realTotalPrice },false); + //出售者实际加钱 + await _localEventBus.PublishAsync(new MoneyChangeEventArgs() { UserId = marketGoods.SellUserId, Number = realTotalPrice },false); //3-出售者删除对应库存,购买者新增对应库存(只需更改用户者即可) var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable.Where(x => x.IsAtMarketing == true)