using YD_Event.Application.Setting.Dtos;
namespace YD_Event.Application.Setting;
///
/// 退款配置服务
///
public class RefundConfigService : ITransient
{
private readonly ISqlSugarRepository _repository;
private readonly IIdGenerator _idGenerator;
public RefundConfigService(ISqlSugarRepository repository, IIdGenerator idGenerator)
{
_repository = repository;
_idGenerator = idGenerator;
}
///
/// 获取退款配置
///
///
public async Task GetConfig()
{
var config = await _repository.GetFirstAsync(x => true);
if (config == null)
{
// 如果没有配置,返回默认值
return new RefundConfigOutput
{
DeductPercentageBefore7Days = 0,
DeductPercentage3To7Days = 0,
DeductPercentageWithin3Days = 0
};
}
return config.Adapt();
}
///
/// 更新退款配置
///
///
///
public async Task UpdateConfig(RefundConfigInput input)
{
var config = await _repository.GetFirstAsync(x => true);
if (config == null)
{
config = input.Adapt();
config.Id = _idGenerator.NextId();
await _repository.InsertAsync(config);
}
else
{
input.Adapt(config);
await _repository.UpdateAsync(config);
}
}
}