feat: 完成
This commit is contained in:
@@ -5,6 +5,11 @@ namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Records;
|
||||
|
||||
public class MarketRecordDto:EntityDto<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前这条数据是否为购买者,否则为出售者
|
||||
/// </summary>
|
||||
public bool IsBuyer { get; set; }
|
||||
|
||||
public DateTime CreationTime { get; set; }
|
||||
/// <summary>
|
||||
/// 出售数量
|
||||
|
||||
@@ -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<MiningPoolRecordAggregateRoot> _miningPoolRecordRepository;
|
||||
private readonly ISqlSugarRepository<MarketRecordAggregateRoot> _marketRecordRepository;
|
||||
public CollectiblesServiceRecordService(ISqlSugarRepository<MiningPoolRecordAggregateRoot> miningPoolRecordRepository, ISqlSugarRepository<MarketRecordAggregateRoot> marketRecordRepository)
|
||||
public CollectiblesRecordService(ISqlSugarRepository<MiningPoolRecordAggregateRoot> miningPoolRecordRepository, ISqlSugarRepository<MarketRecordAggregateRoot> 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<CollectiblesAggregateRoot>((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
|
||||
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);
|
||||
|
||||
foreach (var dto in output)
|
||||
{
|
||||
dto.IsBuyer = dto.BuyId == userId;
|
||||
}
|
||||
|
||||
|
||||
return new PagedResultDto<MarketRecordDto>(total,output);
|
||||
}
|
||||
}
|
||||
@@ -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<CollectiblesAggregateRoot> _repository;
|
||||
|
||||
public CollectiblesToolService(ISqlSugarRepository<CollectiblesAggregateRoot> repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public async Task<object> 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<string>();
|
||||
//自动开启事务
|
||||
List<CollectiblesAggregateRoot> entities = new List<CollectiblesAggregateRoot>();
|
||||
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 };
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,11 @@ public class MarketManager : DomainService
|
||||
/// <returns></returns>
|
||||
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
|
||||
/// <returns></returns>
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user