60 lines
1.6 KiB
C#
Raw Normal View History

2026-02-07 17:28:46 +08:00
using YD_Event.Application.Setting.Dtos;
namespace YD_Event.Application.Setting;
/// <summary>
/// 退款配置服务
/// </summary>
public class RefundConfigService : IRefundConfigService
{
private readonly ISqlSugarRepository<RefundConfig> _repository;
private readonly IIdGenerator _idGenerator;
public RefundConfigService(ISqlSugarRepository<RefundConfig> repository, IIdGenerator idGenerator)
{
_repository = repository;
_idGenerator = idGenerator;
}
/// <summary>
/// 获取退款配置
/// </summary>
/// <returns></returns>
public async Task<RefundConfigOutput> GetConfig()
{
var config = await _repository.GetFirstAsync(x => true);
if (config == null)
{
// 如果没有配置,返回默认值
return new RefundConfigOutput
{
DeductPercentageBefore7Days = 0,
DeductPercentage3To7Days = 0,
DeductPercentageWithin3Days = 0
};
}
return config.Adapt<RefundConfigOutput>();
}
/// <summary>
/// 更新退款配置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task UpdateConfig(RefundConfigInput input)
{
var config = await _repository.GetFirstAsync(x => true);
if (config == null)
{
config = input.Adapt<RefundConfig>();
config.Id = _idGenerator.NextId();
await _repository.InsertAsync(config);
}
else
{
input.Adapt(config);
await _repository.UpdateAsync(config);
}
}
}