|
@@ -24,48 +24,112 @@ namespace ZhonTai.Admin.Services.Project
|
|
{
|
|
{
|
|
private readonly IProjectRepository _projectRepository;
|
|
private readonly IProjectRepository _projectRepository;
|
|
private readonly IProjectPriceRepository _projectPriceRepository;
|
|
private readonly IProjectPriceRepository _projectPriceRepository;
|
|
|
|
+ private readonly IProjectConfigRepository _projectConfigRepository;
|
|
|
|
|
|
- public ProjectPriceService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository)
|
|
|
|
|
|
+ public ProjectPriceService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository, IProjectConfigRepository projectConfigRepository)
|
|
{
|
|
{
|
|
_projectRepository = projectRepository;
|
|
_projectRepository = projectRepository;
|
|
_projectPriceRepository = projectPriceRepository;
|
|
_projectPriceRepository = projectPriceRepository;
|
|
|
|
+ _projectConfigRepository = projectConfigRepository;
|
|
}
|
|
}
|
|
|
|
+ #region 公司默认抽成比例
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 查询公司抽成比例
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [HttpGet]
|
|
|
|
+ public async Task<CompanyDrawOutput> GetCompanyDrawAsync()
|
|
|
|
+ {
|
|
|
|
+ var list = await _projectConfigRepository.Select.Where(m => m.ProjectId == 0 && m.ProjectPriceId == 0 && m.Status == 1)
|
|
|
|
+ .ToListAsync(a => new
|
|
|
|
+ {
|
|
|
|
+ a.Id,
|
|
|
|
+ a.DrawRatio,
|
|
|
|
+ a.EffectDate
|
|
|
|
+ });
|
|
|
|
+ CompanyDrawOutput output = new CompanyDrawOutput();
|
|
|
|
+ if (list.Count > 1)
|
|
|
|
+ {
|
|
|
|
+ DateTime dtnow = DateTime.Today;
|
|
|
|
+ var current = list.FirstOrDefault(m => m.EffectDate <= dtnow);
|
|
|
|
+ var next = list.FirstOrDefault(m => m.EffectDate > dtnow);
|
|
|
|
+ output.CurrentRatio = current.DrawRatio;
|
|
|
|
+ output.NextRatio = current.DrawRatio;
|
|
|
|
+ output.NextEffectDate = current.EffectDate;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ output.CurrentRatio = list[0].DrawRatio;
|
|
|
|
+ output.NextRatio = 0;
|
|
|
|
+ }
|
|
|
|
+ return output;
|
|
|
|
+ }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 修改公司抽成比例
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [HttpPost]
|
|
|
|
+ public async Task EditCompanyDrawAsync(CompanyDrawInput input)
|
|
|
|
+ {
|
|
|
|
+ CheckDrawRatio(input.DrawRatio);
|
|
|
|
+
|
|
|
|
+ CheckDrawRatioEffect(input.EffectDate);
|
|
|
|
+
|
|
|
|
+ //删除旧的未生效记录
|
|
|
|
+ var listDeleteId = await _projectConfigRepository.Select.Where(m => m.ProjectId == 0 && m.ProjectPriceId == 0 && m.Status == 1 && m.EffectDate > DateTime.Today)
|
|
|
|
+ .ToListAsync(m => m.Id);
|
|
|
|
+ if (listDeleteId.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ await _projectConfigRepository.SoftDeleteAsync(m => listDeleteId.Contains(m.Id));
|
|
|
|
+ }
|
|
|
|
+ //添加新的比例
|
|
|
|
+ await _projectConfigRepository.InsertAsync(new ProjectConfigEntity()
|
|
|
|
+ {
|
|
|
|
+ ProjectId = 0,
|
|
|
|
+ ProjectPriceId = 0,
|
|
|
|
+ DrawRatio = input.DrawRatio,
|
|
|
|
+ EffectDate = input.EffectDate,
|
|
|
|
+ Status = 1
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ #endregion
|
|
|
|
|
|
|
|
+ #region 项目抽成比例
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 查询分页
|
|
|
|
|
|
+ /// 查询项目分页
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[HttpPost]
|
|
- public async Task<PageOutput<PriceGetPageOutput>> GetPageAsync(PageInput<PriceGetPageInput> input)
|
|
|
|
|
|
+ public async Task<PageOutput<GetProjectPricePageOutput>> GetProjectPageAsync(PageInput<GetProjectPricePageInput> input)
|
|
{
|
|
{
|
|
var list = await _projectRepository.Select
|
|
var list = await _projectRepository.Select
|
|
.Count(out var total)
|
|
.Count(out var total)
|
|
.OrderByDescending(true, a => a.Id)
|
|
.OrderByDescending(true, a => a.Id)
|
|
.Page(input.CurrentPage, input.PageSize)
|
|
.Page(input.CurrentPage, input.PageSize)
|
|
- .ToListAsync(a => new PriceGetPageOutput()
|
|
|
|
|
|
+ .ToListAsync(a => new GetProjectPricePageOutput()
|
|
{
|
|
{
|
|
Id = a.Id,
|
|
Id = a.Id,
|
|
Name = a.Name,
|
|
Name = a.Name,
|
|
Logo = a.Logo,
|
|
Logo = a.Logo,
|
|
- prices = _projectPriceRepository.Select.Where(m => m.ProjectId == a.Id).ToList<PriceGetPageOutput_Price>()
|
|
|
|
|
|
+ Prices = _projectPriceRepository.Select.Where(m => m.ProjectId == a.Id).ToList<PriceGetPageOutput_Price>()
|
|
});
|
|
});
|
|
|
|
|
|
- var data = new PageOutput<PriceGetPageOutput>()
|
|
|
|
|
|
+ var data = new PageOutput<GetProjectPricePageOutput>()
|
|
{
|
|
{
|
|
- List = Mapper.Map<List<PriceGetPageOutput>>(list),
|
|
|
|
|
|
+ List = Mapper.Map<List<GetProjectPricePageOutput>>(list),
|
|
Total = total
|
|
Total = total
|
|
};
|
|
};
|
|
|
|
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 项目设置价格
|
|
|
|
|
|
+ /// 项目价格设价
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[HttpPost]
|
|
- public async Task<long> SetPriceAsync(PriceSetInput input)
|
|
|
|
|
|
+ public async Task<long> SetProjectPriceAsync(ProjectPriceSetInput input)
|
|
{
|
|
{
|
|
//验证项目价格信息是否存在
|
|
//验证项目价格信息是否存在
|
|
var price = await _projectPriceRepository.GetAsync(input.Id);
|
|
var price = await _projectPriceRepository.GetAsync(input.Id);
|
|
@@ -110,5 +174,34 @@ namespace ZhonTai.Admin.Services.Project
|
|
}
|
|
}
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ #region 校验
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 校验抽成比例
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="drawRatio"></param>
|
|
|
|
+ private void CheckDrawRatio(decimal drawRatio)
|
|
|
|
+ {
|
|
|
|
+ //抽成比例
|
|
|
|
+ if (drawRatio < 0 || drawRatio > 100)
|
|
|
|
+ {
|
|
|
|
+ throw ResultOutput.Exception("抽成比例有效范围在0-100");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 校验抽成比例生效时间
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="effectDate"></param>
|
|
|
|
+ private void CheckDrawRatioEffect(DateTime effectDate)
|
|
|
|
+ {
|
|
|
|
+ //生效时间
|
|
|
|
+ if (effectDate > DateTime.Today)
|
|
|
|
+ {
|
|
|
|
+ throw ResultOutput.Exception("生效日期,最短为次日生效");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ #endregion
|
|
}
|
|
}
|
|
}
|
|
}
|