Phase 2: Replace all deprecated SystemConstants with Package entity reads
- ActivateClubMembership: Load Package, set First/Last fields, PackageId on Cycle+Pool - AcceptClubMembershipContract: Load Package, set First/Last fields, PackageId on Pool - CalculateWeeklyBalances: Load base package, use package.MaxBalancesPerLeg/MaxNetworkLevel, set PackageId on NetworkWeeklyBalance - ProcessUserPayouts: Load base package, use package.MaxNetworkLevel, set PackageId on UserCommissionPayout - CheckAndProcessDayaLoans: Load base package (IsBasePackage), replace DayaLoanAmount→package.Price, fix hardcoded p.Id==4 - CreateManualPayment: Load base package, replace BasePackageAmount→package.Price, use DiscountMultiplier - InitiateBasePackagePayment: Remove hardcoded BasePackageId=4, load from IsBasePackage, use package.Price/Id - VerifyBasePackagePayment: Load Package from order.PackageId, use package.Price+DiscountMultiplier - ChargeMagicWallet: Load user's package from current cycle, use package.MagicWalletMaxDeposit - VerifyMagicWalletCharge: Load user's package, use package.MagicWalletMultiplier/MagicWalletMaxDeposit - OrmCommissionCalculationStrategy: Load base package in both methods, set PackageId on Balance+Payout - ConfigurationService: Inject IApplicationDbContext, read package values from DB instead of SystemConstants - UserOrderService: Load user's package for EXIT trigger MagicWalletMaxDeposit check - UserWalletService: Load user's package for GetMagicWalletStatus display All 9 deprecated SystemConstants now have ZERO usages outside SystemConstants.cs Build: 0 errors, 521 warnings (all pre-existing)
This commit is contained in:
@@ -2,37 +2,42 @@ using CMSMicroservice.Application.ClubFeatureCQ.Queries.GetUserClubFeatures;
|
||||
using CMSMicroservice.Application.Common.Authorization;
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Domain.Common;
|
||||
using CMSMicroservice.Domain.Entities;
|
||||
using CMSMicroservice.Protobuf.Protos.Configuration;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Grpc.Core;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.WebApi.Services;
|
||||
|
||||
/// <summary>
|
||||
/// سرویس تنظیمات سیستم - خواندن از SystemConstants
|
||||
/// سرویس تنظیمات سیستم — مقادیر پکیجی از Package entity خوانده میشوند
|
||||
/// </summary>
|
||||
public class ConfigurationService : ConfigurationContract.ConfigurationContractBase
|
||||
{
|
||||
private readonly ILogger<ConfigurationService> _logger;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public ConfigurationService(
|
||||
ILogger<ConfigurationService> logger,
|
||||
ICurrentUserService currentUserService,
|
||||
IMediator mediator)
|
||||
IMediator mediator,
|
||||
IApplicationDbContext context)
|
||||
{
|
||||
_logger = logger;
|
||||
_currentUserService = currentUserService;
|
||||
_mediator = mediator;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// دریافت تنظیمات با کلید خاص
|
||||
/// </summary>
|
||||
public override Task<GetConfigurationByKeyResponse> GetConfigurationByKey(GetConfigurationByKeyRequest request, ServerCallContext context)
|
||||
public override async Task<GetConfigurationByKeyResponse> GetConfigurationByKey(GetConfigurationByKeyRequest request, ServerCallContext context)
|
||||
{
|
||||
var response = new GetConfigurationByKeyResponse
|
||||
{
|
||||
@@ -43,30 +48,33 @@ public class ConfigurationService : ConfigurationContract.ConfigurationContractB
|
||||
LastModified = Timestamp.FromDateTime(DateTime.UtcNow)
|
||||
};
|
||||
|
||||
// خواندن مقدار از SystemConstants بر اساس کلید
|
||||
response.Value = GetConfigurationValue(request.Key);
|
||||
// برای کلیدهای پکیجی، از دیتابیس میخوانیم
|
||||
var package = await GetBasePackageAsync(context.CancellationToken);
|
||||
response.Value = GetConfigurationValue(request.Key, package);
|
||||
response.Description = GetConfigurationDescription(request.Key);
|
||||
|
||||
_logger.LogDebug("Configuration requested: Key={Key}, Value={Value}", request.Key, response.Value);
|
||||
|
||||
return Task.FromResult(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// دریافت تنظیمات باشگاه مشتریان
|
||||
/// </summary>
|
||||
public override Task<GetClubConfigurationResponse> GetClubConfiguration(Empty request, ServerCallContext context)
|
||||
public override async Task<GetClubConfigurationResponse> GetClubConfiguration(Empty request, ServerCallContext context)
|
||||
{
|
||||
var package = await GetBasePackageAsync(context.CancellationToken);
|
||||
|
||||
var response = new GetClubConfigurationResponse
|
||||
{
|
||||
ActivationFee = SystemConstants.ClubActivationFee,
|
||||
MembershipGiftValue = SystemConstants.ClubMembershipGiftValue
|
||||
ActivationFee = package.ActivationFee,
|
||||
MembershipGiftValue = package.ActivationFee
|
||||
};
|
||||
|
||||
_logger.LogDebug("Club configuration requested: ActivationFee={ActivationFee}, GiftValue={GiftValue}",
|
||||
response.ActivationFee, response.MembershipGiftValue);
|
||||
|
||||
return Task.FromResult(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,18 +119,19 @@ public class ConfigurationService : ConfigurationContract.ConfigurationContractB
|
||||
/// دریافت تمام تنظیمات
|
||||
/// </summary>
|
||||
[RequiresPermission(PermissionNames.SettingsView)]
|
||||
public override Task<GetAllConfigurationsResponse> GetAllConfigurations(GetAllConfigurationsRequest request, ServerCallContext context)
|
||||
public override async Task<GetAllConfigurationsResponse> GetAllConfigurations(GetAllConfigurationsRequest request, ServerCallContext context)
|
||||
{
|
||||
var package = await GetBasePackageAsync(context.CancellationToken);
|
||||
var response = new GetAllConfigurationsResponse();
|
||||
|
||||
// Club Settings
|
||||
response.Models.Add(CreateConfigModel("Club.ActivationFee", SystemConstants.ClubActivationFee.ToString(), "هزینه فعالسازی عضویت باشگاه", 2));
|
||||
response.Models.Add(CreateConfigModel("Club.MembershipGiftValue", SystemConstants.ClubMembershipGiftValue.ToString(), "مبلغ هدیه حق عضویت باشگاه", 2));
|
||||
// Club Settings (از Package)
|
||||
response.Models.Add(CreateConfigModel("Club.ActivationFee", package.ActivationFee.ToString(), "هزینه فعالسازی عضویت باشگاه", 2));
|
||||
response.Models.Add(CreateConfigModel("Club.MembershipGiftValue", package.ActivationFee.ToString(), "مبلغ هدیه حق عضویت باشگاه", 2));
|
||||
|
||||
// Commission Settings
|
||||
// Commission Settings (سقفها از Package)
|
||||
response.Models.Add(CreateConfigModel("Commission.MinWithdrawalAmount", SystemConstants.CommissionMinWithdrawalAmount.ToString(), "حداقل مبلغ برداشت", 3));
|
||||
response.Models.Add(CreateConfigModel("Commission.MaxWeeklyBalancesPerLeg", SystemConstants.CommissionMaxWeeklyBalancesPerLeg.ToString(), "سقف تعادل هفتگی برای هر دست", 3));
|
||||
response.Models.Add(CreateConfigModel("Commission.MaxNetworkLevel", SystemConstants.CommissionMaxNetworkLevel.ToString(), "حداکثر عمق شبکه برای محاسبه کمیسیون", 3));
|
||||
response.Models.Add(CreateConfigModel("Commission.MaxWeeklyBalancesPerLeg", package.MaxBalancesPerLeg.ToString(), "سقف تعادل هفتگی برای هر دست", 3));
|
||||
response.Models.Add(CreateConfigModel("Commission.MaxNetworkLevel", package.MaxNetworkLevel.ToString(), "حداکثر عمق شبکه برای محاسبه کمیسیون", 3));
|
||||
response.Models.Add(CreateConfigModel("Commission.CashWithdrawalEnabled", SystemConstants.CommissionCashWithdrawalEnabled.ToString(), "امکان برداشت نقدی", 3));
|
||||
response.Models.Add(CreateConfigModel("Commission.CalculationStrategy", SystemConstants.CommissionCalculationStrategy, "روش محاسبه کمیسیون", 3));
|
||||
|
||||
@@ -130,9 +139,9 @@ public class ConfigurationService : ConfigurationContract.ConfigurationContractB
|
||||
response.Models.Add(CreateConfigModel("Network.AllowOrphanNodes", SystemConstants.NetworkAllowOrphanNodes.ToString(), "اجازه حذف والدین با فرزند", 1));
|
||||
response.Models.Add(CreateConfigModel("Network.MaxChildrenPerLeg", SystemConstants.NetworkMaxChildrenPerLeg.ToString(), "حداکثر تعداد فرزند مستقیم در هر پا", 1));
|
||||
|
||||
// Package Settings
|
||||
response.Models.Add(CreateConfigModel("Package.BasePackageAmount", SystemConstants.BasePackageAmount.ToString(), "مبلغ پکیج پایه", 0));
|
||||
response.Models.Add(CreateConfigModel("Package.DayaLoanAmount", SystemConstants.DayaLoanAmount.ToString(), "مبلغ وام دایا", 0));
|
||||
// Package Settings (از Package)
|
||||
response.Models.Add(CreateConfigModel("Package.BasePackageAmount", package.Price.ToString(), "مبلغ پکیج پایه", 0));
|
||||
response.Models.Add(CreateConfigModel("Package.DayaLoanAmount", package.Price.ToString(), "مبلغ وام دایا", 0));
|
||||
|
||||
// System Settings
|
||||
response.Models.Add(CreateConfigModel("System.MaintenanceMode", SystemConstants.SystemMaintenanceMode.ToString(), "حالت تعمیر و نگهداری", 0));
|
||||
@@ -141,7 +150,7 @@ public class ConfigurationService : ConfigurationContract.ConfigurationContractB
|
||||
// Shop Settings
|
||||
response.Models.Add(CreateConfigModel("Shop.VAT", SystemConstants.ShopVAT.ToString(), "مالیات بر ارزش افزوده", 0));
|
||||
|
||||
return Task.FromResult(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -173,21 +182,21 @@ public class ConfigurationService : ConfigurationContract.ConfigurationContractB
|
||||
|
||||
#region Private Helpers
|
||||
|
||||
private static string GetConfigurationValue(string key)
|
||||
private static string GetConfigurationValue(string key, Package? package)
|
||||
{
|
||||
return key switch
|
||||
{
|
||||
"Club.ActivationFee" => SystemConstants.ClubActivationFee.ToString(),
|
||||
"Club.MembershipGiftValue" => SystemConstants.ClubMembershipGiftValue.ToString(),
|
||||
"Club.ActivationFee" => (package?.ActivationFee ?? 0).ToString(),
|
||||
"Club.MembershipGiftValue" => (package?.ActivationFee ?? 0).ToString(),
|
||||
"Commission.MinWithdrawalAmount" => SystemConstants.CommissionMinWithdrawalAmount.ToString(),
|
||||
"Commission.MaxWeeklyBalancesPerLeg" => SystemConstants.CommissionMaxWeeklyBalancesPerLeg.ToString(),
|
||||
"Commission.MaxNetworkLevel" => SystemConstants.CommissionMaxNetworkLevel.ToString(),
|
||||
"Commission.MaxWeeklyBalancesPerLeg" => (package?.MaxBalancesPerLeg ?? 0).ToString(),
|
||||
"Commission.MaxNetworkLevel" => (package?.MaxNetworkLevel ?? 0).ToString(),
|
||||
"Commission.CashWithdrawalEnabled" => SystemConstants.CommissionCashWithdrawalEnabled.ToString(),
|
||||
"Commission.CalculationStrategy" => SystemConstants.CommissionCalculationStrategy,
|
||||
"Network.AllowOrphanNodes" => SystemConstants.NetworkAllowOrphanNodes.ToString(),
|
||||
"Network.MaxChildrenPerLeg" => SystemConstants.NetworkMaxChildrenPerLeg.ToString(),
|
||||
"Package.BasePackageAmount" => SystemConstants.BasePackageAmount.ToString(),
|
||||
"Package.DayaLoanAmount" => SystemConstants.DayaLoanAmount.ToString(),
|
||||
"Package.BasePackageAmount" => (package?.Price ?? 0).ToString(),
|
||||
"Package.DayaLoanAmount" => (package?.Price ?? 0).ToString(),
|
||||
"System.MaintenanceMode" => SystemConstants.SystemMaintenanceMode.ToString(),
|
||||
"System.EnableAuditLog" => SystemConstants.SystemEnableAuditLog.ToString(),
|
||||
"Shop.VAT" => SystemConstants.ShopVAT.ToString(),
|
||||
@@ -195,6 +204,13 @@ public class ConfigurationService : ConfigurationContract.ConfigurationContractB
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<Package> GetBasePackageAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Packages
|
||||
.FirstOrDefaultAsync(p => p.IsBasePackage && !p.IsDeleted, cancellationToken)
|
||||
?? throw new RpcException(new Status(StatusCode.Internal, "پکیج پایه یافت نشد"));
|
||||
}
|
||||
|
||||
private static string GetConfigurationDescription(string key)
|
||||
{
|
||||
return key switch
|
||||
|
||||
@@ -344,9 +344,18 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
.Include(u => u.ClubMembership)
|
||||
.FirstOrDefaultAsync(u => u.Id == userId, context.CancellationToken);
|
||||
|
||||
if (wallet.WalletMode == WalletMode.Magic
|
||||
&& wallet.MagicTotalDeposited >= SystemConstants.MagicWalletMaxDeposit)
|
||||
if (wallet.WalletMode == WalletMode.Magic)
|
||||
{
|
||||
// بارگذاری پکیج کاربر برای سقف کیفپول جادویی
|
||||
var userCycle = await _context.ClubMembershipCycles
|
||||
.FirstOrDefaultAsync(c => c.UserId == userId && c.IsCurrentCycle, context.CancellationToken);
|
||||
var userPackage = userCycle != null
|
||||
? await _context.Packages.FirstOrDefaultAsync(p => p.Id == userCycle.PackageId, context.CancellationToken)
|
||||
: await _context.Packages.FirstOrDefaultAsync(p => p.IsBasePackage && !p.IsDeleted, context.CancellationToken);
|
||||
var magicMaxDeposit = userPackage?.MagicWalletMaxDeposit ?? 1_000_000_000;
|
||||
|
||||
if (wallet.MagicTotalDeposited >= magicMaxDeposit)
|
||||
{
|
||||
// ── EXIT Magic Mode ──
|
||||
// هر دو شرط: Balance=0 و سقف 100M پر شده
|
||||
wallet.WalletMode = WalletMode.Normal;
|
||||
@@ -366,6 +375,7 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
{
|
||||
user.PackagePurchaseMethod = PackagePurchaseMethod.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (wallet.WalletMode == WalletMode.Normal
|
||||
&& user != null
|
||||
|
||||
@@ -227,13 +227,21 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
||||
var cycleCount = await _context.ClubMembershipCycles
|
||||
.CountAsync(c => c.UserId == userId, context.CancellationToken);
|
||||
|
||||
// بارگذاری پکیج کاربر برای سقف کیفپول جادویی
|
||||
var currentCycle = await _context.ClubMembershipCycles
|
||||
.FirstOrDefaultAsync(c => c.UserId == userId && c.IsCurrentCycle, context.CancellationToken);
|
||||
var package = currentCycle != null
|
||||
? await _context.Packages.FirstOrDefaultAsync(p => p.Id == currentCycle.PackageId, context.CancellationToken)
|
||||
: await _context.Packages.FirstOrDefaultAsync(p => p.IsBasePackage && !p.IsDeleted, context.CancellationToken);
|
||||
var magicMaxDeposit = package?.MagicWalletMaxDeposit ?? 1_000_000_000;
|
||||
|
||||
var response = new GetMagicWalletStatusResponse
|
||||
{
|
||||
WalletMode = (int)wallet.WalletMode,
|
||||
MagicTotalDeposited = wallet.MagicTotalDeposited,
|
||||
MagicTotalCredited = wallet.MagicTotalCredited,
|
||||
MagicMaxDeposit = SystemConstants.MagicWalletMaxDeposit,
|
||||
MagicRemainingDeposit = Math.Max(0, SystemConstants.MagicWalletMaxDeposit - wallet.MagicTotalDeposited),
|
||||
MagicMaxDeposit = magicMaxDeposit,
|
||||
MagicRemainingDeposit = Math.Max(0, magicMaxDeposit - wallet.MagicTotalDeposited),
|
||||
Balance = wallet.Balance,
|
||||
PurchaseCycleCount = cycleCount
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user