|
@@ -31,6 +31,8 @@ using ZhonTai.Admin.Domain.KuaKe;
|
|
|
using ZhonTai.Admin.Domain.Platform;
|
|
|
using ZhonTai.Admin.Repositories.Platform;
|
|
|
using StackExchange.Profiling.Data;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
+using ZhonTai.Admin.Core.Attributes;
|
|
|
|
|
|
namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
{
|
|
@@ -51,6 +53,7 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
private IProjectConfigRepository _projectConfigRepository => LazyGetRequiredService<IProjectConfigRepository>();
|
|
|
private IKuaKeRepository _kuaKeRepository => LazyGetRequiredService<IKuaKeRepository>();
|
|
|
private IPlatformUserRepository _platformUserRepository => LazyGetRequiredService<IPlatformUserRepository>();
|
|
|
+ private IUserBillsRepository _userBillsRepository => LazyGetRequiredService<IUserBillsRepository>();
|
|
|
|
|
|
public ProjectStatService()
|
|
|
{
|
|
@@ -74,6 +77,7 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
.WhereIf(IsSettele.HasValue && IsSettele.Value >= 0, a => a.IsSettle == IsSettele)
|
|
|
.WhereIf(EffectDate.HasValue, a => a.EffectDate == EffectDate)
|
|
|
.GroupBy(m => new { m.ProjectId, m.TenantId, m.EffectDate })
|
|
|
+ .OrderByDescending(m => m.Key.EffectDate)
|
|
|
.Count(out var total)
|
|
|
.Page(input.CurrentPage, input.PageSize)
|
|
|
.ToList(m => new ProjectStatManagePageOutput()
|
|
@@ -327,7 +331,7 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
CompanyRatio = drawcommission?.CompanyRatio,
|
|
|
TenantCommission = drawcommission.TenantCommission,
|
|
|
TenantyRatio = drawcommission.TenantRatio,
|
|
|
- UserRole =UserRole,
|
|
|
+ UserRole = UserRole,
|
|
|
};
|
|
|
list.Add(model);
|
|
|
}
|
|
@@ -477,23 +481,18 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
///<param name="ProjectId">项目Id</param>
|
|
|
///<param name="EffecDate">状态 2上架 3下架 4暂停</param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpGet]
|
|
|
+ [HttpGet]
|
|
|
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();
|
|
|
- if (count <= 0)
|
|
|
+ var list = await _projectStatRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == ProjectId && m.EffectDateNum == EffecDate && m.IsSettle == 0).ToListAsync();
|
|
|
+ if (list.Count <= 0)
|
|
|
{
|
|
|
throw ResultOutput.Exception("无可结算数据");
|
|
|
}
|
|
|
- //更新项目
|
|
|
- await _projectStatRepository.UpdateDiy.SetDto(
|
|
|
- new
|
|
|
+ foreach (var item in list)
|
|
|
{
|
|
|
- IsSettle = 1,
|
|
|
- SettleTime = DateTime.Now
|
|
|
- })
|
|
|
- .Where(m => m.ProjectId == ProjectId && m.EffectDateNum == EffecDate && m.IsSettle == 0)
|
|
|
- .DisableGlobalFilter(FilterNames.Tenant).ExecuteAffrowsAsync();
|
|
|
+ await SettleCommission(item);
|
|
|
+ }
|
|
|
}
|
|
|
#region 私有方法
|
|
|
/// <summary>
|
|
@@ -529,6 +528,80 @@ namespace ZhonTai.Admin.Services.ProjectStat
|
|
|
output.UserCommission = userCommission;
|
|
|
return output;
|
|
|
}
|
|
|
+ [Transaction]
|
|
|
+ private async Task SettleCommission(ProjectStatEntity item)
|
|
|
+ {
|
|
|
+ //更新状态
|
|
|
+ await _projectStatRepository.UpdateDiy.SetDto(
|
|
|
+ new
|
|
|
+ {
|
|
|
+ IsSettle = 1,
|
|
|
+ SettleTime = DateTime.Now
|
|
|
+ })
|
|
|
+ .Where(m => m.IsSettle == 0 && m.Id == item.Id)
|
|
|
+ .DisableGlobalFilter(FilterNames.Tenant).ExecuteAffrowsAsync();
|
|
|
+ throw (Exception)ResultOutput.NotOk("asdfa");
|
|
|
+ //更新用户佣金 余额,资金明细
|
|
|
+ var user = await _platformUserRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.Id == item.UsedUserId).ToOneAsync();
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ //如果用户是管理员,佣金=团队佣金+用户佣金
|
|
|
+ decimal commission = item.UserCommission.HasValue ? item.UserCommission.Value : 0;
|
|
|
+ if (user.Role == "2")
|
|
|
+ {
|
|
|
+ commission += item.TenantCommission.HasValue ? item.TenantCommission.Value : 0;
|
|
|
+ }
|
|
|
+ if (commission > 0)
|
|
|
+ {
|
|
|
+ decimal afterAmount = user.Amount + commission;
|
|
|
+ await _platformUserRepository.UpdateDiy.Set(m => new PlatformUserEntity
|
|
|
+ {
|
|
|
+ Amount = afterAmount
|
|
|
+ }).Where(m => m.Id == user.Id && m.Amount == user.Amount).DisableGlobalFilter(FilterNames.Tenant).ExecuteAffrowsAsync();
|
|
|
+
|
|
|
+ await _userBillsRepository.InsertAsync(new UserBillsEntity()
|
|
|
+ {
|
|
|
+ BillType = 1,
|
|
|
+ Commission = commission,
|
|
|
+ AfterAmount = afterAmount,
|
|
|
+ EffectDate = item.EffectDate,
|
|
|
+ PriceId = item.ProjectPriceId,
|
|
|
+ ProjectId = item.ProjectId,
|
|
|
+ UserId = user.Id,
|
|
|
+ TenantId = user.TenantId,
|
|
|
+ ValidCount = item.ValidCount,
|
|
|
+ Remark = "",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //上级分佣 余额,资金明细
|
|
|
+ if (user.Role != "2")
|
|
|
+ {
|
|
|
+ var inituser = await _platformUserRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.TenantId == item.TenantId && m.Role == "2").ToOneAsync();
|
|
|
+ if (inituser != null)
|
|
|
+ {
|
|
|
+ decimal afterAmount = inituser.Amount + item.TenantCommission.Value;
|
|
|
+ await _platformUserRepository.UpdateDiy.Set(m => new PlatformUserEntity
|
|
|
+ {
|
|
|
+ Amount = afterAmount
|
|
|
+ }).Where(m => m.Id == inituser.Id && m.Amount == inituser.Amount).DisableGlobalFilter(FilterNames.Tenant).ExecuteAffrowsAsync();
|
|
|
+
|
|
|
+ await _userBillsRepository.InsertAsync(new UserBillsEntity()
|
|
|
+ {
|
|
|
+ BillType = 2,
|
|
|
+ Commission = commission,
|
|
|
+ AfterAmount = afterAmount,
|
|
|
+ EffectDate = item.EffectDate,
|
|
|
+ PriceId = item.ProjectPriceId,
|
|
|
+ ProjectId = item.ProjectId,
|
|
|
+ UserId = inituser.Id,
|
|
|
+ TenantId = inituser.TenantId,
|
|
|
+ ValidCount = item.ValidCount,
|
|
|
+ Remark = "",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
}
|
|
|
}
|