feat: add PackageId to CalculateWeeklyCommissionPoolCommand and related logic for package-specific calculations
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m43s

This commit is contained in:
masoodafar-web
2026-05-04 02:31:26 +03:30
parent c4409491c1
commit 41e7f29a0d
5 changed files with 82 additions and 25 deletions
@@ -222,8 +222,17 @@ public class OrmCommissionCalculationStrategy : ICommissionCalculationStrategy
}
// بررسی وجود استخر
var existingPool = await _context.WeeklyCommissionPools
.FirstOrDefaultAsync(x => x.WeekDefinitionId == weekDefinitionId, cancellationToken);
var existingPoolQuery = _context.WeeklyCommissionPools
.Where(x => x.WeekDefinitionId == weekDefinitionId);
if (packageId.HasValue)
{
existingPoolQuery = existingPoolQuery.Where(x => x.PackageId == packageId.Value);
}
var existingPool = await existingPoolQuery
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(cancellationToken);
if (existingPool == null)
{
@@ -239,9 +248,15 @@ public class OrmCommissionCalculationStrategy : ICommissionCalculationStrategy
}
// بررسی وجود تعادل‌های هفتگی
var weeklyBalances = await _context.NetworkWeeklyBalances
.Where(x => x.WeekDefinitionId == weekDefinitionId)
.ToListAsync(cancellationToken);
var weeklyBalancesQuery = _context.NetworkWeeklyBalances
.Where(x => x.WeekDefinitionId == weekDefinitionId);
if (packageId.HasValue)
{
weeklyBalancesQuery = weeklyBalancesQuery.Where(x => x.PackageId == packageId.Value);
}
var weeklyBalances = await weeklyBalancesQuery.ToListAsync(cancellationToken);
if (!weeklyBalances.Any())
{
@@ -269,9 +284,15 @@ public class OrmCommissionCalculationStrategy : ICommissionCalculationStrategy
// حذف پرداخت‌های قبلی در صورت ForceRecalculate
if (forceRecalculate)
{
var oldPayouts = await _context.UserCommissionPayouts
.Where(p => p.WeekDefinitionId == weekDefinitionId)
.ToListAsync(cancellationToken);
var oldPayoutsQuery = _context.UserCommissionPayouts
.Where(p => p.WeekDefinitionId == weekDefinitionId);
if (packageId.HasValue)
{
oldPayoutsQuery = oldPayoutsQuery.Where(p => p.PackageId == packageId.Value);
}
var oldPayouts = await oldPayoutsQuery.ToListAsync(cancellationToken);
if (oldPayouts.Any())
{