|
@@ -26,6 +26,7 @@ using ZhonTai.Admin.Domain.ProjectLink;
|
|
|
using ZhonTai.Common.Extensions;
|
|
|
using ZhonTai.Admin.Repositories.Project;
|
|
|
using ZhonTai.Admin.Services.Project.Dto;
|
|
|
+using ZhonTai.Admin.Repositories.ProjectLink;
|
|
|
|
|
|
namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
{
|
|
@@ -43,6 +44,7 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
private OSSConfig _oSSConfig => LazyGetRequiredService<IOptions<OSSConfig>>().Value;
|
|
|
private IHttpContextAccessor _httpContextAccessor => LazyGetRequiredService<IHttpContextAccessor>();
|
|
|
private IProjectLinkRepository _projectLinkRepository => LazyGetRequiredService<IProjectLinkRepository>();
|
|
|
+ private IProjectConfigRepository _projectConfigRepository => LazyGetRequiredService<IProjectConfigRepository>();
|
|
|
|
|
|
public ProjectStatService()
|
|
|
{
|
|
@@ -197,7 +199,7 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if (datatable.Columns["二维码编号"] == null || datatable.Columns["作业日期"] == null|| !IsComplete)
|
|
|
+ if (datatable.Columns["二维码编号"] == null || datatable.Columns["作业日期"] == null || !IsComplete)
|
|
|
{
|
|
|
throw new Exception($"导入格式不正确");
|
|
|
}
|
|
@@ -210,17 +212,21 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
throw new Exception($"请删除作业时间已结算的数据");
|
|
|
}
|
|
|
//是否有覆盖数据存在
|
|
|
- var listFuGai = await _projectStatRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == ProjectId && listDateInt.Contains(m.EffectDateNum) && m.IsSettle == 0).ToListAsync(m=>m.EffectDateNum);
|
|
|
+ var listFuGai = await _projectStatRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == ProjectId && listDateInt.Contains(m.EffectDateNum) && m.IsSettle == 0).ToListAsync(m => m.EffectDateNum);
|
|
|
if (listFuGai.Count() > 0)
|
|
|
{
|
|
|
listFuGai = listFuGai.Distinct().ToList();
|
|
|
|
|
|
await _projectStatRepository.Orm.Delete<ProjectStatEntity>().DisableGlobalFilter(FilterNames.Tenant).Where(m => listFuGai.Contains(m.EffectDateNum)).ExecuteAffrowsAsync();
|
|
|
- //await _projectStatRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => listFuGai.Contains(m.EffectDateNum)).ToDelete().ExecuteAffrowsAsync();
|
|
|
- //await _projectStatRepository.DisableGlobalFilter(FilterNames.Tenant).SetSource(new ProjectStatEntity() {
|
|
|
- // IsDeleted=true
|
|
|
- //}).UpdateColumns(m =>new { m.IsDeleted}).Where(m => listFuGai.Contains(m.EffectDateNum)).ExecuteUpdatedAsync();
|
|
|
}
|
|
|
+ //二维码编号列表
|
|
|
+ List<string> lstID = (from d in datatable.AsEnumerable() select d.Field<string>("二维码编号")).ToList();
|
|
|
+ var listLink = await _projectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == ProjectId && lstID.Contains(m.Num)).ToListAsync();
|
|
|
+ var listTenant = listLink.Select(m => m.TenantId).Distinct().ToList();
|
|
|
+ //抽成
|
|
|
+ var listDraw = await _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant).ToListAsync();
|
|
|
+
|
|
|
+
|
|
|
List<ProjectStatEntity> list = new List<ProjectStatEntity>();
|
|
|
foreach (DataRow row in datatable.Rows)
|
|
|
{
|
|
@@ -228,10 +234,40 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
DateTime EffectDate = row["作业日期"].ToDateTime();
|
|
|
int EffectDateNum = EffectDate.ToString("yyyyMMdd").ToInt();
|
|
|
|
|
|
- var link = await _projectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == ProjectId && m.Num==num ).ToOneAsync();
|
|
|
+ var link = await _projectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == ProjectId && m.Num == num).ToOneAsync();
|
|
|
foreach (var price in listPrice)
|
|
|
{
|
|
|
- var model=new ProjectStatEntity()
|
|
|
+ decimal ratio = 0m;
|
|
|
+ int drawway = 0;
|
|
|
+ //平台单独抽成
|
|
|
+ var drawtenant = listDraw.Where(m => m.DrawType == 3 && m.TenantId == link.TenantId && m.EffectDate >= EffectDate).OrderBy(m => m.EffectDate).FirstOrDefault();
|
|
|
+ if (drawtenant != null)
|
|
|
+ {
|
|
|
+ drawway = 2;
|
|
|
+ ratio = drawtenant.DrawAmount.Value;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //项目单独设置
|
|
|
+ var drawproject= listDraw.Where(m => m.DrawType == 2 && m.ProjectId == price.ProjectId && m.ProjectPriceId == price.Id && m.EffectDate >= EffectDate).OrderBy(m => m.EffectDate).FirstOrDefault();
|
|
|
+ if (drawproject != null)
|
|
|
+ {
|
|
|
+ drawway = 2;
|
|
|
+ ratio = drawproject.DrawAmount.Value;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //公司单独设价
|
|
|
+ var drawcompany = listDraw.Where(m => m.DrawType == 1 && m.ProjectId == 0 && m.ProjectPriceId == 0 && m.EffectDate >= EffectDate).OrderBy(m => m.EffectDate).FirstOrDefault();
|
|
|
+ if (drawcompany != null)
|
|
|
+ {
|
|
|
+ drawway = 1;
|
|
|
+ ratio = drawcompany.DrawRatio;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var commission= GetCommission(price.Price, ratio, drawway);
|
|
|
+ var model = new ProjectStatEntity()
|
|
|
{
|
|
|
Num = num,
|
|
|
EffectDate = EffectDate,
|
|
@@ -243,7 +279,11 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
CommissionPrice = 0,
|
|
|
IsSettle = 0,
|
|
|
TenantId = link?.TenantId,
|
|
|
- UsedUserId=link?.UsedUserId
|
|
|
+ UsedUserId = link?.UsedUserId,
|
|
|
+ CompanyCommission=commission.CompanyCommission,
|
|
|
+ CompanyRatio=commission.CompanyRatio,
|
|
|
+ TenantCommission=commission.TenantCommission,
|
|
|
+ TenantyRatio=commission.TenantRatio,
|
|
|
};
|
|
|
list.Add(model);
|
|
|
}
|
|
@@ -287,9 +327,9 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
///<param name="EffecDate">状态 2上架 3下架 4暂停</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet]
|
|
|
- public async Task UpdateSettleAsync(long ProjectId,int EffecDate)
|
|
|
+ public async Task UpdateSettleAsync(long ProjectId, int EffecDate)
|
|
|
{
|
|
|
- var count = await _projectStatRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId==ProjectId&&m.EffectDateNum== EffecDate&&m.IsSettle==0).CountAsync();
|
|
|
+ var count = await _projectStatRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == ProjectId && m.EffectDateNum == EffecDate && m.IsSettle == 0).CountAsync();
|
|
|
if (count <= 0)
|
|
|
{
|
|
|
throw ResultOutput.Exception("无可结算数据");
|
|
@@ -298,12 +338,40 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
await _projectStatRepository.UpdateDiy.SetSource(
|
|
|
new ProjectStatEntity()
|
|
|
{
|
|
|
- IsSettle=1,
|
|
|
- SettleTime=DateTime.Now
|
|
|
+ IsSettle = 1,
|
|
|
+ SettleTime = DateTime.Now
|
|
|
})
|
|
|
- .UpdateColumns(a => new { a.IsSettle,a.SettleTime })
|
|
|
+ .UpdateColumns(a => new { a.IsSettle, a.SettleTime })
|
|
|
.Where(m => m.ProjectId == ProjectId && m.EffectDateNum == EffecDate && m.IsSettle == 0)
|
|
|
- .DisableGlobalFilter(FilterNames.Tenant).ExecuteAffrowsAsync();
|
|
|
+ .DisableGlobalFilter(FilterNames.Tenant).ExecuteAffrowsAsync();
|
|
|
+ }
|
|
|
+ #region 私有方法
|
|
|
+ /// <summary>
|
|
|
+ /// 获取佣金
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="price">项目价格</param>
|
|
|
+ /// <param name="ratio">公司抽成比率,抽成方式是2,则抽成金额</param>
|
|
|
+ /// <param name="drawType">抽成方式1比率 2佣金</param>
|
|
|
+ private GetCommissionOutput GetCommission(decimal price, decimal ratio, int drawType)
|
|
|
+ {
|
|
|
+ GetCommissionOutput output = new GetCommissionOutput();
|
|
|
+ decimal compnayCommssion = 0m;
|
|
|
+ if (drawType == 1)
|
|
|
+ {
|
|
|
+ compnayCommssion = UtilConvertExtension.ToDecimalCutWithN(price * ratio * 0.01m, 0m, 1);
|
|
|
+ }
|
|
|
+ else if (drawType == 2)
|
|
|
+ {
|
|
|
+ compnayCommssion = price - ratio;
|
|
|
+ }
|
|
|
+
|
|
|
+ var tenatCommssion = price - compnayCommssion;
|
|
|
+ output.TenantCommission = tenatCommssion;
|
|
|
+ output.TenantRatio = 0m;
|
|
|
+ output.CompanyCommission = compnayCommssion;
|
|
|
+ output.CompanyRatio = ratio;
|
|
|
+ return output;
|
|
|
}
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|