2026-02-07 17:28:46 +08:00
|
|
|
using YD_Event.Application.Setting.Dtos;
|
|
|
|
|
|
|
|
|
|
namespace YD_Event.Application.Setting;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 退款配置服务
|
|
|
|
|
/// </summary>
|
2026-02-07 18:02:21 +08:00
|
|
|
public class RefundConfigService : ITransient
|
2026-02-07 17:28:46 +08:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|