27 Commits

Author SHA1 Message Date
masoodafar-web fe7179f6e9 chore(k8s): deploy staging apps to namespace kbs-stage
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 21m11s
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-24 21:26:15 +03:30
masoodafar-web f79affb44d feat(transactions): enhance transaction queries with user information
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 21m45s
- Added UserFullName and UserId properties to transaction response models for better user context.
- Updated query handlers to populate user information from related entities, ensuring accurate user details in transaction responses.
- Modified Protobuf definitions to include new fields for user identification and display.
- Adjusted mapping profiles to accommodate new user-related fields in transaction data.
2026-09-24 19:28:01 +03:30
masoodafar-web 6f573c0a29 fix(payment): set TwentyCard package amounts and send rials to gateway
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 2s
Gateway 11,200,000 toman and wallet credit 12,656,000 toman; multiply by 10 when posting to TwentyCard API.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-23 15:12:08 +03:30
masoodafar-web 9b82b45e46 chore(staging): point registry and K8S to 185.252.31.44 after server migration
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 50s
2026-09-22 22:18:43 +03:30
masoodafar-web cbc1225562 fix(payment): update JSON serialization settings and enhance request data structure
- Changed PropertyNamingPolicy in TwentyCardPaymentService from SnakeCaseLower to CamelCase for improved consistency in JSON serialization.
- Added JsonPropertyName attributes for Authority and RedirectUrl properties in TwentyCardRequestData to ensure correct JSON mapping.
2026-09-22 00:59:39 +03:30
masoodafar-web 6ad1341754 feat(config): add DefaultEmail to configuration files for payment processing
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 20h51m56s
- Introduced DefaultEmail field in cms-config.yaml, appsettings.json, and appsettings.Staging.json to standardize email handling in payment requests.
- Updated TwentyCardPaymentService to utilize DefaultEmail when no email is provided in the request, enhancing error handling and user experience.
2026-09-22 00:08:09 +03:30
masoodafar-web e970e516ce fix(config): update GatewayAmountToman values in configuration files
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m0s
- Changed GatewayAmountToman values from 9700000 and 97000000 to 1000 in both cms-config.yaml and appsettings.Staging.json for consistency in payment processing configurations.
2026-09-21 21:37:45 +03:30
masoodafar-web 9d17f174af feat(config): add CallbackBaseUrl to configuration for payment processing
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
- Introduced CallbackBaseUrl in both cms-config.yaml and appsettings.Staging.json to support dynamic callback URLs for payment processing.
- Updated PackageService to utilize the new CallbackBaseUrl for enhanced security and flexibility in payment integration.
2026-09-21 21:35:42 +03:30
masoodafar-web 29426022aa feat(payment): enhance TwentyCard payment integration and update configuration
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
- Added support for optional Email and NationalId fields in PaymentRequest for TwentyCard transactions.
- Updated TwentyCardPaymentService to handle multipart/form-data requests and improved error handling.
- Modified appsettings and configuration files for both production and staging environments to include updated BaseUrl and credentials for TwentyCard.
- Updated README to reflect the new documentation location.
2026-09-21 21:31:17 +03:30
masoodafar-web 2b958bd214 feat(user): add user invitation functionality and enhance OTP verification
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m27s
- Introduced UserInvitation entity and updated IApplicationDbContext to include UserInvitations DbSet.
- Enhanced VerifyOtpTokenCommand and its handler to support optional inviter mobile number for user registration.
- Added new Protobuf definitions for GetMyInvitees and GetInvitationsByFilter RPCs to manage user invitations.
- Updated UserService to implement methods for retrieving invitees and invitations based on filters.
- Bumped Protobuf project version to reflect the addition of new features.
2026-09-20 23:33:03 +03:30
masoodafar-web f31fb5ee39 chore(config): update TwentyCard payment configuration for production and staging environments
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 11m25s
- Changed BaseUrl for TwentyCard from sandbox to production gateway.
- Added TerminalId, TerminalUsername, and TerminalPassword for TwentyCard payment processing in both appsettings.json and appsettings.Staging.json.
2026-09-20 22:30:39 +03:30
masoodafar-web 0b7212ac1c feat(payment): implement multi-gateway support and enhance payment processing
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m44s
- Added support for multiple payment gateways, including ZarinPal and TwentyCard, through a new IPaymentGatewayResolver.
- Updated PaymentRequest DTO to include payer name and invoice number for better transaction tracking.
- Enhanced PackageService to dynamically determine payment amounts based on the selected gateway.
- Updated appsettings to include configuration for TwentyCard payment options.
- Bumped Protobuf project version to reflect the addition of new features and changes.
2026-09-20 22:17:55 +03:30
masoodafar-web 78d1fee89a refactor(network): improve network statistics calculations and update related DTOs
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 7m14s
- Refactored GetNetworkStatisticsQueryHandler to enhance logic for counting active members in left and right legs.
- Updated GetNetworkStatisticsResponseDto to include new properties for LeftLegCount and RightLegCount.
- Modified Protobuf definitions to align with the updated response structure for network statistics.
- Enhanced SQL script to differentiate between all subtree counts and active club member counts.
2026-09-04 04:12:31 +03:30
masoodafar-web 612d6fd141 fix(network): update network statistics and tree documentation
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 10m15s
- Updated README to reflect the new documentation location.
- Refactored GetNetworkStatisticsQueryHandler to improve method naming and logic for loading package holder counts.
- Enhanced GetNetworkStatisticsResponseDto and NetworkTreeDto to clarify the purpose of leg total properties.
- Updated Protobuf definitions to align with the new response structure for network statistics.
- Removed obsolete SQL scripts related to user package purchases and DayaLoan contracts cleanup.
2026-08-28 18:55:48 +03:30
masoodafar-web 87d61abc5b feat(network): add latest package leg totals to network statistics response
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 7m51s
- Introduced new properties for GoldLeftLegTotal, GoldRightLegTotal, SilverLeftLegTotal, and SilverRightLegTotal in GetNetworkStatisticsResponseDto.
- Implemented LoadLatestPackageLegScoresAsync method in GetNetworkStatisticsQueryHandler to fetch the latest leg totals for the user.
- Updated Protobuf definitions to include new fields for leg totals in GetMyNetworkStatisticsResponse.
- Bumped Protobuf project version to reflect the addition of new features.
2026-08-27 21:28:03 +03:30
masoodafar-web ea1d2d4400 feat(network): enrich network tree with package leg scores and update Protobuf definitions
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 12m47s
- Added logic to enrich the network tree with the latest left/right leg totals for gold and silver packages in GetNetworkTreeQueryHandler.
- Introduced new properties in NetworkTreeDto for GoldLeftLegTotal, GoldRightLegTotal, SilverLeftLegTotal, and SilverRightLegTotal.
- Updated Protobuf definitions to include new fields for leg scores in NetworkTreeNodeModel.
- Enhanced mapping in NetworkMembershipProfile and NetworkMembershipService to accommodate new leg score properties.
- Bumped Protobuf project version to reflect the addition of new features.
2026-08-25 22:39:19 +03:30
masoodafar-web 2d23dbc798 feat(withdrawal): normalize IBAN format in withdrawal requests
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 6m38s
- Added IbanNormalizer to validate and normalize IBAN numbers in RequestWithdrawalCommandHandler and UserWalletService.
- Implemented error handling for invalid IBAN formats, ensuring compliance with expected standards.
- Updated relevant methods to handle normalized IBANs for cash withdrawal requests.
2026-08-23 23:01:17 +03:30
masoodafar-web 8ec0910cdf feat(jwt): enhance JWT token generation with user address check
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 6m36s
- Updated GenerateJwtTokenService to include IApplicationDbContext for accessing user addresses.
- Added logic to check if a user has an address and included this information as a claim in the generated JWT token.
- Improved overall token generation process by incorporating additional user data for better context.
2026-08-23 22:32:36 +03:30
masoodafar-web e882f09955 feat(user): enhance GetAllUserByFilter query response with additional fields and update Protobuf definitions
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 6m6s
- Added DefaultAddress and DefaultPostalCode properties to GetAllUserByFilterResponseDto for improved user data representation.
- Updated GetAllUserByFilterQueryHandler to populate new response fields with relevant data.
- Modified Protobuf definitions to include new fields in GetAllUserByFilterResponseModel.
- Bumped Protobuf project version to reflect the addition of new features.
2026-08-14 03:18:58 +03:30
masoodafar-web 6a04a6a270 feat(package): enhance pagination logic in GetCustomerPackagePurchaseRollupQueryHandler
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m42s
- Updated pagination handling to allow for exporting all results when PageSize is set to 0.
- Adjusted page size and number calculations to accommodate the new export functionality.
- Improved clarity in pagination logic by distinguishing between export and paginated results.
2026-08-09 00:40:25 +03:30
masoodafar-web 427d2cce1d feat(package): update package purchase methods and enhance Protobuf definitions
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 6m45s
- Changed package purchase method from DirectPurchase to Manual in multiple command handlers to reflect new business logic.
- Added Manual purchase method to PackagePurchaseMethod enum for clarity.
- Introduced new RPC method GetCustomerPackagePurchaseRollup in Protobuf for summarizing customer package purchases.
- Updated UserPackagePurchaseProfile and UserPackagePurchaseService to support new rollup functionality.
- Bumped Protobuf project version to accommodate new features.
2026-08-08 21:59:14 +03:30
masoodafar-web fb9e3d0109 feat(order): refactor order data mapping for improved clarity and structure
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 13m4s
- Updated GetAllDiscountOrdersQueryHandler to enhance order data mapping by using a more structured approach with AdminOrderDto.
- Refactored user full name construction in GetCustomerOrderQueryHandler and GetCustomerOrdersQueryHandler to utilize UserDisplayName for better readability.
- Added necessary using directives for consistency across query handlers.
2026-08-07 18:39:42 +03:30
masoodafar-web 6c90e4caf0 feat(order): enhance order status management and Protobuf definitions
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 7m46s
- Added AdminNotes handling in UpdateOrderStatusCommandHandler to include delivery descriptions.
- Updated DeliveryStatus enum to include ReadyForOfficePickup.
- Enhanced GetCustomerOrderHistoryQueryHandler and UserOrderService to support new delivery status.
- Updated Protobuf definitions for DeliveryStatus to reflect changes.
- Bumped Protobuf project version to accommodate new features.
2026-08-07 17:25:57 +03:30
masoodafar-web 40da1bd8df feat(order): enhance order details with user contact information and update Protobuf definitions
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m33s
- Added Phone property to UserAddressDto for capturing the user's mobile number.
- Updated GetOrderByIdQueryHandler to include user mobile in order details.
- Enhanced GetCustomerOrderQueryHandler and GetCustomerOrderResponseDto to include PostalCode and UserMobile.
- Modified userorder.proto to add postal_code and user_mobile fields in GetUserOrderResponse.
- Bumped Protobuf project version to reflect the addition of new features.
2026-08-07 15:48:04 +03:30
masoodafar-web 3810146651 feat(wallet): enforce club membership validation for wallet charge operations
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 19m57s
- Added club membership inclusion in user retrieval for ChargeCreditWallet and VerifyCreditWalletCharge command handlers.
- Implemented validation to ensure users have an active club membership before allowing wallet charges, throwing a BadRequestException if not.
- Updated UserWalletService to handle BadRequestException and return appropriate error messages in responses.
2026-08-06 23:59:36 +03:30
masoodafar-web ce98efdd68 feat(sorting): implement ApplyOrderWithInStockPriority method for enhanced product sorting
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
- Added ApplyOrderWithInStockPriority method to prioritize in-stock products in queries.
- Updated GetDiscountProductsQueryHandler and GetCustomerProductsByFilterQueryHandler to utilize the new sorting method, ensuring in-stock items are listed first followed by user-defined sorting or creation date.
- Improved overall query handling for product availability and sorting logic.
2026-07-26 00:17:44 +03:30
masoodafar-web d232399f43 feat(wallet): add manual credit wallet charge functionality and update Protobuf definitions
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
- Introduced ManualCreditWalletCharge enum value to TransactionType for clarity.
- Added AdminManualCreditCharge and GetManualCreditCharges RPC methods in UserWalletService for handling manual credit charges by admin.
- Created corresponding request and response messages for manual credit charge operations in Protobuf.
- Updated Protobuf project version to reflect the addition of new features.
2026-07-25 23:55:08 +03:30
119 changed files with 13375 additions and 347 deletions
+46
View File
@@ -0,0 +1,46 @@
name: Push nuget and docker image Actions Workflow
on:
push:
branches:
- stage_new
jobs:
Deploy:
runs-on: windows
steps:
- name: Checkout
uses: https://git.afrino.co/actions/checkout@v3
- name: Setup dotnet
uses: https://git.afrino.co/actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Remove Package Source
run: dotnet nuget remove source FourSat
continue-on-error: true
- name: Add Package Source
run: dotnet nuget add source --name FourSat --username systemuser --password sZSA7PTiv3pUSQZ https://git.afrino.co/api/packages/FourSat/nuget/index.json --store-password-in-clear-text
- name: Install dependencies
run: dotnet restore ".\src\CMSMicroservice.WebApi\CMSMicroservice.WebApi.csproj"
- name: Build
run: dotnet build ".\src\CMSMicroservice.WebApi\CMSMicroservice.WebApi.csproj" --configuration Release --no-restore
- name: Test
run: dotnet test ".\src\CMSMicroservice.WebApi\CMSMicroservice.WebApi.csproj" --no-restore --verbosity normal
- name: Recycle Apppool
run: |
& "C:\Windows\System32\inetsrv\appcmd.exe" recycle apppool /apppool.name:cms.kbs1.ir
shell: powershell
- name: Stop Website
run: |
& "C:\Windows\System32\inetsrv\appcmd.exe" stop site /site.name:cms.kbs1.ir
shell: powershell
- name: Publish
run: dotnet publish ".\src\CMSMicroservice.WebApi\CMSMicroservice.WebApi.csproj" -c Release -o publish
- name: Copy Publish To IIS Directory
run: Get-ChildItem -Path "publish\*" | Copy-Item -Destination "E:\kbs1.ir\cms.kbs1.ir\" -Recurse -Force
- name: Start Website
run: |
& "C:\Windows\System32\inetsrv\appcmd.exe" start site /site.name:cms.kbs1.ir
shell: powershell
+10 -10
View File
@@ -6,15 +6,15 @@ on:
- kub-stage
env:
REGISTRY: 194.5.195.53:30080
REGISTRY: 185.252.31.44:30080
IMAGE_NAME: admin/cms
K8S_SERVER: 194.5.195.53
K8S_SERVER: 185.252.31.44
jobs:
build-and-deploy:
runs-on: ubuntu-latest
container:
image: 194.5.195.53:32082/docker-sshpass:latest
image: 185.252.31.44:32082/docker-sshpass:latest
options: --privileged
steps:
- name: Start Docker daemon
@@ -22,7 +22,7 @@ jobs:
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << 'DAEMON'
{
"insecure-registries": ["194.5.195.53:30080", "194.5.195.53:32500", "194.5.195.53:32082"]
"insecure-registries": ["185.252.31.44:30080", "185.252.31.44:32500", "185.252.31.44:32082"]
}
DAEMON
echo "🚀 Starting Docker daemon..."
@@ -52,14 +52,14 @@ jobs:
- name: Login to Docker registries
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login 194.5.195.53:32082 -u admin --password-stdin
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login 185.252.31.44:32082 -u admin --password-stdin
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u admin --password-stdin
- name: Publish Protobuf packages
run: |
echo "📦 Publishing Protobuf packages..."
docker run --rm --network host -e CI=true -v $(pwd):/src -w /src \
194.5.195.53:32082/dotnet/sdk:9.0 sh -c '
185.252.31.44:32082/dotnet/sdk:9.0 sh -c '
for proj in $(find . -name "*Protobuf*.csproj" -type f); do
echo "📦 $proj"
dotnet restore "$proj" --configfile src/NuGet.config
@@ -93,11 +93,11 @@ jobs:
# Apply config (Secret) first, then deployment
sshpass -e ssh -o StrictHostKeyChecking=no root@${{ env.K8S_SERVER }} "
kubectl apply -f /tmp/cms-config.yaml &&
kubectl apply -f /tmp/cms-deployment.yaml &&
kubectl apply -n kbs-stage -f /tmp/cms-config.yaml &&
kubectl apply -n kbs-stage -f /tmp/cms-deployment.yaml &&
crictl rmi ${REGISTRY}/${IMAGE_NAME}:latest 2>/dev/null || true &&
kubectl rollout restart deployment/cms &&
kubectl rollout status deployment/cms --timeout=180s &&
kubectl -n kbs-stage rollout restart deployment/cms &&
kubectl -n kbs-stage rollout status deployment/cms --timeout=180s &&
rm -f /tmp/cms-config.yaml /tmp/cms-deployment.yaml
"
echo "✅ Deployed!"
+9 -11
View File
@@ -6,7 +6,7 @@ on:
- production
env:
REGISTRY: 194.5.195.53:30080
REGISTRY: 185.252.31.44:30080
IMAGE_NAME: admin/cms
K8S_SERVER: 45.149.79.127
@@ -14,7 +14,7 @@ jobs:
build-and-deploy:
runs-on: ubuntu-latest
container:
image: 194.5.195.53:32082/docker-sshpass:latest
image: 185.252.31.44:32082/docker-sshpass:latest
options: --privileged
steps:
- name: Start Docker daemon
@@ -22,7 +22,7 @@ jobs:
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << 'DAEMON'
{
"insecure-registries": ["194.5.195.53:30080", "194.5.195.53:32500", "194.5.195.53:32082"]
"insecure-registries": ["185.252.31.44:30080", "185.252.31.44:32500", "185.252.31.44:32082"]
}
DAEMON
echo "🚀 Starting Docker daemon..."
@@ -40,7 +40,7 @@ jobs:
done
if ! docker info >/dev/null 2>&1; then
echo "❌ Docker daemon failed to start"
echo "❌ Docker daemon failed to start after 3 minutes"
exit 1
fi
@@ -50,14 +50,14 @@ jobs:
- name: Login to Docker registries
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login 194.5.195.53:32082 -u admin --password-stdin
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login 185.252.31.44:32082 -u admin --password-stdin
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u admin --password-stdin
- name: Publish Protobuf packages
run: |
echo "📦 Publishing Protobuf packages..."
docker run --rm --network host -v $(pwd):/src -w /src \
194.5.195.53:32082/dotnet/sdk:9.0 sh -c '
185.252.31.44:32082/dotnet/sdk:9.0 sh -c '
for proj in $(find . -name "*Protobuf*.csproj" -type f); do
echo "📦 $proj"
dotnet restore "$proj" --configfile src/NuGet.config
@@ -65,7 +65,7 @@ jobs:
dotnet pack "$proj" -c Release --no-build -o "$(dirname $proj)/nupkg"
for nupkg in $(dirname $proj)/nupkg/*.nupkg; do
[ -f "$nupkg" ] && dotnet nuget push "$nupkg" \
--source "http://194.5.195.53:32081/repository/foursat-nuget-hosted/index.json" \
--source "http://185.252.31.44:32081/repository/foursat-nuget-hosted/index.json" \
--api-key "admin:87zH26nbqT" \
--skip-duplicate --allow-insecure-connections || true
done
@@ -75,10 +75,8 @@ jobs:
- name: Build Docker Image
run: |
DOCKER_BUILDKIT=0 docker build --network host \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:prod \
.
DOCKER_BUILDKIT=0 docker build --network host -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:prod .
- name: Push to Registry
run: |
+3 -3
View File
@@ -1,4 +1,4 @@
FROM 194.5.195.53:32082/dotnet/sdk:9.0 AS build
FROM 185.252.31.44:32082/dotnet/sdk:9.0 AS build
WORKDIR /src
# Copy NuGet config first
@@ -7,11 +7,11 @@ COPY src/NuGet.config ./
# Copy solution and project files
COPY src/ ./
# Restore with Nexus config and publish
# Restore with Nexus config and publish
RUN dotnet restore "CMSMicroservice.WebApi/CMSMicroservice.WebApi.csproj" --configfile NuGet.config
RUN dotnet publish "CMSMicroservice.WebApi/CMSMicroservice.WebApi.csproj" -c Release -o /app/publish --no-restore
FROM 194.5.195.53:32082/dotnet/aspnet:9.0 AS runtime
FROM 185.252.31.44:32082/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
COPY --from=build /app/publish .
ENV ASPNETCORE_URLS=http://+:8080
+2 -2
View File
@@ -1,4 +1,4 @@
# CMS Microservice
Documentation moved to [totalDoc/INDEX.md](../totalDoc/INDEX.md).
Documentation moved to [totalDoc/INDEX.md](../totalDoc/INDEX.md).
+18
View File
@@ -24,6 +24,24 @@ stringData:
"MerchantId": "4225d555-5fa9-4df0-9b61-1ce152cbbba8",
"UseSandbox": false
},
"TwentyCard": {
"BaseUrl": "https://gateway.20card.ir/ipg",
"TerminalId": "165674",
"TerminalUsername": "ea5y1biehi",
"TerminalPassword": "SaLamAT@1404!",
"CreditPortalUrl": "https://userpanel.20card.ir/",
"DefaultEmail": "info@kbs2.ir",
"Packages": {
"4": {
"GatewayAmountToman": 11200000,
"WalletCreditToman": 12656000
},
"1": {
"GatewayAmountToman": 11200000,
"WalletCreditToman": 12656000
}
}
},
"CmsBaseUrl": "https://cms.kbs2.ir",
"FrontOfficeBaseUrl": "https://kbs2.ir",
"JwtSecurityKey": "TvlZVx5TJaHs8e9HgUdGzhGP2CIidoI444nAj+8+g7c=",
+1 -1
View File
@@ -35,7 +35,7 @@ spec:
spec:
containers:
- name: cms
image: 194.5.195.53:30080/admin/cms:prod
image: 185.252.31.44:30080/admin/cms:prod
imagePullPolicy: Always
ports:
- containerPort: 8080
+21 -2
View File
@@ -11,7 +11,7 @@ apiVersion: v1
kind: Secret
metadata:
name: cms-appsettings
namespace: default
namespace: kbs-stage
labels:
app: cms
environment: staging
@@ -24,6 +24,25 @@ stringData:
"MerchantId": "4225d555-5fa9-4df0-9b61-1ce152cbbba8",
"UseSandbox": true
},
"TwentyCard": {
"BaseUrl": "https://gateway.20card.ir/ipg",
"TerminalId": "165674",
"TerminalUsername": "ea5y1biehi",
"TerminalPassword": "SaLamAT@1404!",
"CreditPortalUrl": "https://userpanel.20card.ir/",
"CallbackBaseUrl": "https://kbs2.ir",
"DefaultEmail": "info@kbs2.ir",
"Packages": {
"4": {
"GatewayAmountToman": 11200000,
"WalletCreditToman": 12656000
},
"1": {
"GatewayAmountToman": 11200000,
"WalletCreditToman": 12656000
}
}
},
"CmsBaseUrl": "https://cms.se.kbs1.ir",
"FrontOfficeBaseUrl": "https://frontoffice.se.kbs1.ir",
"FMS": {
@@ -34,7 +53,7 @@ stringData:
"JwtAudience": "https://localhost",
"JwtExpiryInDays": 5,
"ConnectionStrings": {
"DefaultConnection": "Data Source=194.5.195.53,31433; Initial Catalog=Foursat;User ID=sa;Password=87zH26nbqT;Connection Timeout=300000;MultipleActiveResultSets=True;Encrypt=False",
"DefaultConnection": "Data Source=mssql-svc.platform.svc.cluster.local,1433; Initial Catalog=Foursat;User ID=sa;Password=87zH26nbqT;Connection Timeout=300000;MultipleActiveResultSets=True;Encrypt=False",
"providerName": "System.Data.SqlClient"
},
"Otp": {
+11 -6
View File
@@ -4,12 +4,14 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cms-uploads-pvc
namespace: default
namespace: kbs-stage
labels:
app: cms
spec:
accessModes:
- ReadWriteOnce
storageClassName: migrated-local
volumeName: pv-cms-uploads-migrated
resources:
requests:
storage: 20Gi
@@ -20,7 +22,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: cms
namespace: default
namespace: kbs-stage
labels:
app: cms
spec:
@@ -33,10 +35,12 @@ spec:
labels:
app: cms
spec:
imagePullSecrets:
- name: gitea-registry-secret
containers:
- name: cms
image: 194.5.195.53:30080/admin/cms:latest
imagePullPolicy: Always
image: 185.252.31.44:30080/admin/cms:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: http
@@ -89,7 +93,7 @@ apiVersion: v1
kind: Service
metadata:
name: cms-svc
namespace: default
namespace: kbs-stage
spec:
selector:
app: cms
@@ -107,7 +111,7 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cms-ingress
namespace: default
namespace: kbs-stage
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
@@ -115,6 +119,7 @@ metadata:
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
spec:
ingressClassName: nginx
tls:
- hosts:
- cms.se.kbs1.ir
+340
View File
@@ -0,0 +1,340 @@
/*
Cleanup all side-effects of a test FrontOffice user (register + package + club + wallet + invitations).
Usage:
EXEC dbo.usp_CleanupTestUser @Mobile = N'09037437157', @DryRun = 1;
EXEC dbo.usp_CleanupTestUser @Mobile = N'09037437157';
EXEC dbo.usp_CleanupTestUser @Mobile = N'09...', @ReparentChildren = 1;
EXEC dbo.usp_CleanupTestUser @Mobile = N'09...', @ReversePool = 1, @AbortIfPoolCalculated = 1;
Pool reverse: for each ClubMembershipCycle, subtract Packages.ActivationFee
(fallback: ClubMembership.InitialContribution) from CMS.WeeklyCommissionPools
for matching WeekDefinition × PackageId.
Does NOT delete pool rows (shared). Does NOT claw back commission already paid to OTHER users.
Does NOT touch: Packages master, Contracts master, WeekDefinitions, Roles, catalogs.
*/
CREATE OR ALTER PROCEDURE dbo.usp_CleanupTestUser
@UserId BIGINT = NULL,
@Mobile NVARCHAR(20) = NULL,
@HardDeleteUser BIT = 1,
@ReparentChildren BIT = 0,
@ReversePool BIT = 1,
@AbortIfPoolCalculated BIT = 0,
@DryRun BIT = 0
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
SET QUOTED_IDENTIFIER ON;
SET ANSI_NULLS ON;
IF @UserId IS NULL AND (@Mobile IS NULL OR LTRIM(RTRIM(@Mobile)) = N'')
BEGIN
RAISERROR(N'Provide @UserId and/or @Mobile.', 16, 1);
RETURN;
END;
DECLARE @MobileNorm NVARCHAR(20) = NULL;
IF @Mobile IS NOT NULL
BEGIN
SET @MobileNorm = LTRIM(RTRIM(@Mobile));
IF LEFT(@MobileNorm, 3) = N'+98' SET @MobileNorm = N'0' + SUBSTRING(@MobileNorm, 4, 20);
IF LEFT(@MobileNorm, 2) = N'98' AND LEN(@MobileNorm) = 12 SET @MobileNorm = N'0' + SUBSTRING(@MobileNorm, 3, 20);
IF LEFT(@MobileNorm, 1) = N'9' AND LEN(@MobileNorm) = 10 SET @MobileNorm = N'0' + @MobileNorm;
END;
IF @UserId IS NULL
BEGIN
SELECT TOP (1) @UserId = Id
FROM CMS.Users
WHERE Mobile = @MobileNorm
OR Mobile = @Mobile
OR REPLACE(Mobile, N'+98', N'0') = @MobileNorm
ORDER BY IsDeleted ASC, Id DESC;
END;
IF @UserId IS NULL
BEGIN
RAISERROR(N'User not found for given @UserId/@Mobile.', 16, 1);
RETURN;
END;
DECLARE @UserMobile NVARCHAR(20);
SELECT @UserMobile = Mobile FROM CMS.Users WHERE Id = @UserId;
IF @UserMobile IS NULL
BEGIN
RAISERROR(N'UserId %I64d not found.', 16, 1, @UserId);
RETURN;
END;
DECLARE @ChildCount INT =
(SELECT COUNT(*) FROM CMS.Users WHERE NetworkParentId = @UserId AND IsDeleted = 0);
IF @ChildCount > 0 AND @ReparentChildren = 0 AND @HardDeleteUser = 1
BEGIN
RAISERROR(N'User has %d active network children. Pass @ReparentChildren=1 or soft-delete only.', 16, 1, @ChildCount);
RETURN;
END;
PRINT N'=== usp_CleanupTestUser ===';
PRINT N'UserId=' + CAST(@UserId AS NVARCHAR(20)) + N' Mobile=' + ISNULL(@UserMobile, N'?')
+ N' DryRun=' + CAST(@DryRun AS NVARCHAR(1))
+ N' ReversePool=' + CAST(@ReversePool AS NVARCHAR(1));
DECLARE @Wallets TABLE (WalletId BIGINT PRIMARY KEY);
INSERT INTO @Wallets (WalletId)
SELECT Id FROM CMS.UserWallets WHERE UserId = @UserId;
DECLARE @Tx TABLE (TransactionId BIGINT PRIMARY KEY);
INSERT INTO @Tx (TransactionId)
SELECT DISTINCT x.TransactionId
FROM (
SELECT TransactionId FROM CMS.UserPackagePurchases WHERE UserId = @UserId AND TransactionId IS NOT NULL
UNION
SELECT TransactionId FROM CMS.PaymentTransactions WHERE UserId = @UserId AND TransactionId IS NOT NULL
UNION
SELECT TransactionId FROM CMS.UserOrders WHERE UserId = @UserId AND TransactionId IS NOT NULL
UNION
SELECT TransactionId FROM CMS.ManualPayments WHERE UserId = @UserId AND TransactionId IS NOT NULL
UNION
SELECT TransactionId FROM CMS.DayaLoanContracts WHERE UserId = @UserId AND TransactionId IS NOT NULL
UNION
SELECT TransactionId FROM CMS.DiscountOrders WHERE UserId = @UserId AND TransactionId IS NOT NULL
UNION
SELECT h.RefrenceId
FROM CMS.UserWalletHistories h
INNER JOIN @Wallets w ON w.WalletId = h.WalletId
WHERE h.RefrenceId IS NOT NULL
) x
WHERE x.TransactionId IS NOT NULL;
DECLARE @Orders TABLE (OrderId BIGINT PRIMARY KEY);
INSERT INTO @Orders (OrderId)
SELECT Id FROM CMS.UserOrders WHERE UserId = @UserId;
DECLARE @DiscountOrders TABLE (DiscountOrderId BIGINT PRIMARY KEY);
INSERT INTO @DiscountOrders (DiscountOrderId)
SELECT Id FROM CMS.DiscountOrders WHERE UserId = @UserId;
DECLARE @ClubMemberships TABLE (ClubMembershipId BIGINT PRIMARY KEY);
INSERT INTO @ClubMemberships (ClubMembershipId)
SELECT Id FROM CMS.ClubMemberships WHERE UserId = @UserId;
DECLARE @Cycles TABLE (CycleId BIGINT PRIMARY KEY);
INSERT INTO @Cycles (CycleId)
SELECT Id FROM CMS.ClubMembershipCycles WHERE UserId = @UserId
UNION
SELECT Id FROM CMS.ClubMembershipCycles WHERE ClubMembershipId IN (SELECT ClubMembershipId FROM @ClubMemberships);
DECLARE @Payouts TABLE (PayoutId BIGINT PRIMARY KEY);
INSERT INTO @Payouts (PayoutId)
SELECT Id FROM CMS.UserCommissionPayouts WHERE UserId = @UserId;
DECLARE @PoolReversals TABLE (
CycleId BIGINT,
PackageId BIGINT,
WeekDefinitionId BIGINT NULL,
PoolId BIGINT NULL,
Fee BIGINT,
PoolAmountBefore BIGINT NULL,
IsCalculated BIT NULL,
Note NVARCHAR(200)
);
INSERT INTO @PoolReversals (CycleId, PackageId, WeekDefinitionId, PoolId, Fee, PoolAmountBefore, IsCalculated, Note)
SELECT
c.Id,
c.PackageId,
wd.Id,
wp.Id,
ISNULL(NULLIF(cm.InitialContribution, 0), ISNULL(p.ActivationFee, 0)),
wp.TotalPoolAmount,
wp.IsCalculated,
CASE
WHEN wd.Id IS NULL THEN N'NO_WEEK_MATCH'
WHEN wp.Id IS NULL THEN N'NO_POOL_ROW'
WHEN wp.IsCalculated = 1 THEN N'POOL_ALREADY_CALCULATED'
ELSE N'OK'
END
FROM CMS.ClubMembershipCycles c
LEFT JOIN CMS.ClubMemberships cm ON cm.Id = c.ClubMembershipId
LEFT JOIN CMS.Packages p ON p.Id = c.PackageId
LEFT JOIN CMS.WeekDefinitions wd
ON CAST(c.PackagePurchasedAt AS DATE) >= CAST(wd.StartDate AS DATE)
AND CAST(c.PackagePurchasedAt AS DATE) <= CAST(wd.EndDate AS DATE)
AND wd.IsDeleted = 0
LEFT JOIN CMS.WeeklyCommissionPools wp
ON wp.WeekDefinitionId = wd.Id
AND wp.PackageId = c.PackageId
AND wp.IsDeleted = 0
WHERE c.Id IN (SELECT CycleId FROM @Cycles);
SELECT N'Users' AS Entity, COUNT(*) AS Cnt FROM CMS.Users WHERE Id = @UserId
UNION ALL SELECT N'OtpTokens', COUNT(*) FROM CMS.OtpTokens WHERE Mobile IN (@UserMobile, @MobileNorm, @Mobile)
UNION ALL SELECT N'UserInvitations', COUNT(*) FROM CMS.UserInvitations WHERE InviterUserId = @UserId OR InviteeUserId = @UserId
UNION ALL SELECT N'ClubMemberships', COUNT(*) FROM @ClubMemberships
UNION ALL SELECT N'ClubMembershipCycles', COUNT(*) FROM @Cycles
UNION ALL SELECT N'UserPackagePurchases', COUNT(*) FROM CMS.UserPackagePurchases WHERE UserId = @UserId
UNION ALL SELECT N'PaymentTransactions', COUNT(*) FROM CMS.PaymentTransactions WHERE UserId = @UserId OR Mobile = @UserMobile
UNION ALL SELECT N'UserWallets', COUNT(*) FROM @Wallets
UNION ALL SELECT N'UserWalletHistories', COUNT(*) FROM CMS.UserWalletHistories WHERE WalletId IN (SELECT WalletId FROM @Wallets)
UNION ALL SELECT N'Transactions(collected)', COUNT(*) FROM @Tx
UNION ALL SELECT N'NetworkChildren', @ChildCount
UNION ALL SELECT N'UserOrders', COUNT(*) FROM @Orders
UNION ALL SELECT N'DiscountOrders', COUNT(*) FROM @DiscountOrders
UNION ALL SELECT N'UserCommissionPayouts', COUNT(*) FROM @Payouts
UNION ALL SELECT N'PoolReversals(planned)', COUNT(*) FROM @PoolReversals WHERE Fee > 0;
SELECT N'--- Pool reverse plan ---' AS Info;
SELECT * FROM @PoolReversals;
IF @ReversePool = 1 AND @AbortIfPoolCalculated = 1
AND EXISTS (SELECT 1 FROM @PoolReversals WHERE IsCalculated = 1 AND Fee > 0)
BEGIN
RAISERROR(N'One or more target weekly pools are already calculated. Aborting (@AbortIfPoolCalculated=1).', 16, 1);
RETURN;
END;
IF @DryRun = 1
BEGIN
PRINT N'DryRun=1 — no changes committed.';
RETURN;
END;
BEGIN TRANSACTION;
BEGIN TRY
/* ---- Reverse weekly pool charges FIRST (needs cycle + package data) ---- */
IF @ReversePool = 1
BEGIN
UPDATE wp
SET wp.TotalPoolAmount = CASE
WHEN wp.TotalPoolAmount >= r.Fee THEN wp.TotalPoolAmount - r.Fee
ELSE 0
END,
wp.LastModified = SYSUTCDATETIME()
FROM CMS.WeeklyCommissionPools wp
INNER JOIN (
SELECT PoolId, SUM(Fee) AS Fee
FROM @PoolReversals
WHERE PoolId IS NOT NULL AND Fee > 0
GROUP BY PoolId
) r ON r.PoolId = wp.Id;
PRINT N'Pool reverse applied for ' + CAST(@@ROWCOUNT AS NVARCHAR(20)) + N' pool row(s).';
END;
/* ---- Club ---- */
DELETE h FROM CMS.ClubMembershipCycleHistories h
WHERE h.UserId = @UserId OR h.ClubMembershipCycleId IN (SELECT CycleId FROM @Cycles);
DELETE FROM CMS.ClubMembershipCycles
WHERE Id IN (SELECT CycleId FROM @Cycles) OR UserId = @UserId;
DELETE FROM CMS.ClubMembershipHistories WHERE UserId = @UserId
OR ClubMembershipId IN (SELECT ClubMembershipId FROM @ClubMemberships);
DELETE FROM CMS.UserClubFeatures WHERE UserId = @UserId
OR ClubMembershipId IN (SELECT ClubMembershipId FROM @ClubMemberships);
DELETE FROM CMS.ClubMemberships WHERE UserId = @UserId;
/* ---- Commission payouts of THIS user only ---- */
DELETE h FROM CMS.CommissionPayoutHistories h
WHERE h.UserId = @UserId OR h.UserCommissionPayoutId IN (SELECT PayoutId FROM @Payouts);
DELETE FROM CMS.UserCommissionPayouts WHERE UserId = @UserId;
/* ---- Network ---- */
DELETE FROM CMS.NetworkWeeklyBalances WHERE UserId = @UserId;
DELETE FROM CMS.NetworkMembershipHistories
WHERE UserId = @UserId OR OldParentId = @UserId OR NewParentId = @UserId;
IF @ChildCount > 0 AND @ReparentChildren = 1
UPDATE CMS.Users SET NetworkParentId = NULL, LastModified = SYSUTCDATETIME()
WHERE NetworkParentId = @UserId;
/* ---- Invitations ---- */
DELETE FROM CMS.UserInvitations
WHERE InviterUserId = @UserId OR InviteeUserId = @UserId;
/* ---- Package / payment ---- */
DELETE FROM CMS.UserPackagePurchases WHERE UserId = @UserId;
DELETE FROM CMS.PaymentTransactions
WHERE UserId = @UserId OR Mobile = @UserMobile OR Mobile = @MobileNorm;
/* ---- Manual / Daya ---- */
DELETE FROM CMS.ManualPayments WHERE UserId = @UserId;
DELETE FROM CMS.DayaLoanContracts WHERE UserId = @UserId;
/* ---- Discount shop ---- */
DELETE d FROM CMS.DiscountOrderDetails d
WHERE d.DiscountOrderId IN (SELECT DiscountOrderId FROM @DiscountOrders);
DELETE FROM CMS.DiscountOrders WHERE UserId = @UserId;
DELETE FROM CMS.DiscountShoppingCarts WHERE UserId = @UserId;
/* ---- Stock ---- */
DELETE FROM CMS.StockMovements
WHERE PerformedByUserId = @UserId
OR OrderId IN (SELECT OrderId FROM @Orders)
OR DiscountOrderId IN (SELECT DiscountOrderId FROM @DiscountOrders);
/* ---- Orders ---- */
DELETE FROM CMS.FactorDetails WHERE OrderId IN (SELECT OrderId FROM @Orders);
DELETE FROM CMS.OrderVATs WHERE OrderId IN (SELECT OrderId FROM @Orders);
DELETE FROM CMS.UserOrders WHERE UserId = @UserId;
/* ---- Wallet ---- */
DELETE FROM CMS.UserWalletHistories WHERE WalletId IN (SELECT WalletId FROM @Wallets);
DELETE FROM CMS.UserWallets WHERE UserId = @UserId;
/* ---- Cart / address / roles / contracts ---- */
DELETE FROM CMS.UserCarts WHERE UserId = @UserId;
DELETE FROM CMS.UserAddresses WHERE UserId = @UserId;
DELETE FROM CMS.UserRoles WHERE UserId = @UserId;
DELETE FROM CMS.UserContracts WHERE UserId = @UserId;
/* ---- Content authored by test user ---- */
UPDATE CMS.BlogPosts SET IsDeleted = 1, LastModified = SYSUTCDATETIME()
WHERE AuthorUserId = @UserId AND IsDeleted = 0;
UPDATE CMS.PublicMessages SET IsDeleted = 1, LastModified = SYSUTCDATETIME()
WHERE CreatedByUserId = @UserId AND IsDeleted = 0;
/* ---- Transactions ---- */
DELETE t
FROM CMS.Transactions t
WHERE t.Id IN (SELECT TransactionId FROM @Tx)
AND NOT EXISTS (SELECT 1 FROM CMS.UserPackagePurchases p WHERE p.TransactionId = t.Id)
AND NOT EXISTS (SELECT 1 FROM CMS.PaymentTransactions p WHERE p.TransactionId = t.Id)
AND NOT EXISTS (SELECT 1 FROM CMS.UserOrders o WHERE o.TransactionId = t.Id)
AND NOT EXISTS (SELECT 1 FROM CMS.ManualPayments m WHERE m.TransactionId = t.Id)
AND NOT EXISTS (SELECT 1 FROM CMS.DayaLoanContracts d WHERE d.TransactionId = t.Id)
AND NOT EXISTS (SELECT 1 FROM CMS.DiscountOrders d WHERE d.TransactionId = t.Id);
/* ---- OTP ---- */
DELETE FROM CMS.OtpTokens
WHERE Mobile IN (@UserMobile, @MobileNorm, ISNULL(@Mobile, N''));
/* ---- User ---- */
IF @HardDeleteUser = 1
DELETE FROM CMS.Users WHERE Id = @UserId;
ELSE
UPDATE CMS.Users
SET IsDeleted = 1, LastModified = SYSUTCDATETIME()
WHERE Id = @UserId;
COMMIT TRANSACTION;
PRINT N'Cleanup completed successfully.';
SELECT N'DONE' AS Status, @UserId AS UserId, @UserMobile AS Mobile,
@HardDeleteUser AS HardDeleted, @ReversePool AS PoolReversed;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
DECLARE @Err NVARCHAR(4000) = ERROR_MESSAGE();
RAISERROR(N'Cleanup failed: %s', 16, 1, @Err);
END CATCH
END;
GO
@@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.11" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.4.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.10" />
<PackageReference Include="DateTimeConverterCL" Version="1.0.0" />
@@ -163,10 +163,10 @@ public class ActivateClubMembershipCommandHandler : IRequestHandler<ActivateClub
request.UserId
);
// در فعال‌سازی اجباری، اگر PackagePurchaseMethod تنظیم نشده، مقدار DirectPurchase بگذار
// در فعال‌سازی اجباری ادمین، اگر روش خرید تنظیم نشده، دستی در نظر بگیر
if (user.PackagePurchaseMethod == PackagePurchaseMethod.None)
{
user.PackagePurchaseMethod = PackagePurchaseMethod.DirectPurchase;
user.PackagePurchaseMethod = PackagePurchaseMethod.Manual;
_context.Users.Update(user);
await _context.SaveChangesAsync(cancellationToken);
}
@@ -1,3 +1,5 @@
using CMSMicroservice.Application.Common;
namespace CMSMicroservice.Application.CommissionCQ.Commands.RequestWithdrawal;
public class RequestWithdrawalCommandHandler : IRequestHandler<RequestWithdrawalCommand, Unit>
@@ -37,7 +39,10 @@ public class RequestWithdrawalCommandHandler : IRequestHandler<RequestWithdrawal
if (request.Method == WithdrawalMethod.Cash)
{
payout.IbanNumber = request.IbanNumber;
var normalizedIban = IbanNormalizer.TryNormalize(request.IbanNumber);
if (normalizedIban is null)
throw new InvalidOperationException("فرمت شماره شبا معتبر نیست. باید IR و ۲۴ رقم باشد.");
payout.IbanNumber = normalizedIban;
}
_context.UserCommissionPayouts.Update(payout);
@@ -1,3 +1,4 @@
using System.Linq.Expressions;
using System.Linq.Dynamic.Core;
using CMSMicroservice.Domain.Common;
@@ -16,6 +17,21 @@ public static class SortByExtensions
return source.OrderBy(NormalizeSortBy(sortBy));
}
/// <summary>
/// موجودی‌دارها اول، سپس سورت درخواستی کاربر (یا Created desc اگر SortBy خالی باشد).
/// </summary>
public static IQueryable<TSource> ApplyOrderWithInStockPriority<TSource>(
this IQueryable<TSource> source,
string? sortBy,
Expression<Func<TSource, bool>> isInStock) where TSource : BaseAuditableEntity
{
var ordered = source.OrderByDescending(isInStock);
if (string.IsNullOrWhiteSpace(sortBy))
return ordered.ThenByDescending(p => p.Created);
return ordered.ThenBy(NormalizeSortBy(sortBy));
}
/// <summary>
/// Dynamic LINQ treats "-Created" as unary minus on DateTime (invalid).
/// Project convention: leading '-' means descending sort.
@@ -0,0 +1,34 @@
using System.Text.RegularExpressions;
namespace CMSMicroservice.Application.Common;
/// <summary>
/// نرمال‌سازی و اعتبارسنجی شماره شبا ایران (IR + 24 رقم).
/// </summary>
public static class IbanNormalizer
{
private static readonly Regex IranianIbanRegex = new(@"^IR\d{24}$", RegexOptions.Compiled);
/// <summary>
/// فاصله و خط تیره را حذف می‌کند، به حروف بزرگ تبدیل می‌کند و یک پیشوند IR می‌گذارد.
/// در صورت نامعتبر بودن، null برمی‌گرداند.
/// </summary>
public static string? TryNormalize(string? iban)
{
if (string.IsNullOrWhiteSpace(iban))
return null;
var normalized = iban.Trim().ToUpperInvariant()
.Replace(" ", "", StringComparison.Ordinal)
.Replace("-", "", StringComparison.Ordinal);
if (normalized.StartsWith("IR", StringComparison.Ordinal))
normalized = normalized[2..];
normalized = "IR" + normalized;
return IranianIbanRegex.IsMatch(normalized) ? normalized : null;
}
public static bool IsValid(string? iban) => TryNormalize(iban) is not null;
}
@@ -21,6 +21,7 @@ public interface IApplicationDbContext
DbSet<Product> Products { get; }
DbSet<ProductImage> ProductImages { get; }
DbSet<User> Users { get; }
DbSet<UserInvitation> UserInvitations { get; }
DbSet<OtpToken> OtpTokens { get; }
DbSet<Contract> Contracts { get; }
DbSet<UserContract> UserContracts { get; }
@@ -0,0 +1,9 @@
namespace CMSMicroservice.Application.Common.Interfaces;
/// <summary>
/// Resolve payment gateway by provider key (zarinpal, 20card, …).
/// </summary>
public interface IPaymentGatewayResolver
{
IPaymentGatewayService Get(string? provider);
}
@@ -98,6 +98,26 @@ public class PaymentRequest
/// URL بازگشت بعد از پرداخت
/// </summary>
public string CallbackUrl { get; set; } = string.Empty;
/// <summary>
/// نام پرداخت‌کننده (برای درگاه‌هایی مثل ۲۰کارت)
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// شماره فاکتور / سفارش
/// </summary>
public string Invoice { get; set; } = string.Empty;
/// <summary>
/// ایمیل (اختیاری — برای ۲۰کارت)
/// </summary>
public string? Email { get; set; }
/// <summary>
/// کد ملی (اختیاری — برای ۲۰کارت)
/// </summary>
public string? NationalId { get; set; }
}
/// <summary>
@@ -0,0 +1,29 @@
namespace CMSMicroservice.Application.Common;
/// <summary>
/// نام نمایشی کاربر برای گزارش‌ها؛ اگر نام خالی باشد موبایل یا شناسه.
/// </summary>
public static class UserDisplayName
{
public static string From(string? firstName, string? lastName, string? mobile, long userId)
{
var name = string.Join(" ",
new[] { firstName, lastName }.Where(s => !string.IsNullOrWhiteSpace(s)));
if (!string.IsNullOrWhiteSpace(name))
return name;
if (!string.IsNullOrWhiteSpace(mobile))
return mobile.Trim();
return userId > 0 ? $"کاربر {userId}" : "—";
}
public static string From(Domain.Entities.User? user)
{
if (user is null)
return string.Empty;
return From(user.FirstName, user.LastName, user.Mobile, user.Id);
}
}
@@ -35,6 +35,11 @@ public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatus
order.TrackingCode = request.TrackingCode;
}
if (!string.IsNullOrEmpty(request.AdminNotes))
{
order.DeliveryDescription = request.AdminNotes;
}
await _context.SaveChangesAsync(cancellationToken);
return new UpdateOrderStatusResponseDto
@@ -1,3 +1,4 @@
using CMSMicroservice.Application.Common;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Models;
using MediatR;
@@ -80,35 +81,58 @@ public class GetAllDiscountOrdersQueryHandler : IRequestHandler<GetAllDiscountOr
// Apply pagination
var pagination = request.PaginationQuery ?? new PaginationState { PageNumber = 1, PageSize = 20 };
var orders = await query
var rows = await query
.OrderByDescending(o => o.Created)
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
.Take(pagination.PageSize)
.Select(o => new AdminOrderDto
.Select(o => new
{
Id = o.Id,
UserId = o.UserId,
UserFullName = (o.User.FirstName ?? "") + " " + (o.User.LastName ?? ""),
UserMobile = o.User.Mobile,
TotalAmount = o.TotalAmount,
DiscountBalanceUsed = o.DiscountBalanceUsed,
GatewayAmountPaid = o.GatewayAmountPaid,
VatAmount = o.VatAmount,
PaymentStatus = o.PaymentStatus,
PaymentDate = o.PaymentDate,
DeliveryStatus = o.DeliveryStatus,
DeliveryDate = null, // TODO: Add DeliveryDate to DiscountOrder if needed
o.Id,
o.UserId,
FirstName = o.User.FirstName,
LastName = o.User.LastName,
Mobile = o.User.Mobile,
o.TotalAmount,
o.DiscountBalanceUsed,
o.GatewayAmountPaid,
o.VatAmount,
o.PaymentStatus,
o.PaymentDate,
o.DeliveryStatus,
ShippingAddress = o.UserAddress.Address,
ReceiverName = o.UserAddress.Title,
ReceiverMobile = o.User.Mobile,
TrackingCode = o.TrackingCode,
o.TrackingCode,
AdminNote = o.DeliveryDescription,
Created = o.Created,
LastModified = o.LastModified,
o.Created,
o.LastModified,
ItemsCount = o.OrderDetails.Count
})
.ToListAsync(cancellationToken);
var orders = rows.Select(o => new AdminOrderDto
{
Id = o.Id,
UserId = o.UserId,
UserFullName = UserDisplayName.From(o.FirstName, o.LastName, o.Mobile, o.UserId),
UserMobile = o.Mobile,
TotalAmount = o.TotalAmount,
DiscountBalanceUsed = o.DiscountBalanceUsed,
GatewayAmountPaid = o.GatewayAmountPaid,
VatAmount = o.VatAmount,
PaymentStatus = o.PaymentStatus,
PaymentDate = o.PaymentDate,
DeliveryStatus = o.DeliveryStatus,
DeliveryDate = null,
ShippingAddress = o.ShippingAddress,
ReceiverName = o.ReceiverName,
ReceiverMobile = o.Mobile,
TrackingCode = o.TrackingCode,
AdminNote = o.AdminNote,
Created = o.Created,
LastModified = o.LastModified,
ItemsCount = o.ItemsCount
}).ToList();
return new GetAllDiscountOrdersResponseDto
{
MetaData = new MetaData
@@ -57,10 +57,8 @@ public class GetDiscountProductsQueryHandler : IRequestHandler<GetDiscountProduc
query = query.Where(p => p.Price <= request.MaxPrice.Value);
}
if (!string.IsNullOrEmpty(request.SortBy))
query = query.ApplyOrder(request.SortBy);
else
query = query.OrderByDescending(p => p.Created);
// موجودی‌دارها اول، سپس سورت درخواستی
query = query.ApplyOrderWithInStockPriority(request.SortBy, p => p.RemainingCount > 0);
var totalCount = await query.CountAsync(cancellationToken);
@@ -32,6 +32,8 @@ public class UserAddressDto
public string Title { get; set; }
public string Address { get; set; }
public string PostalCode { get; set; }
/// <summary>شماره تماس سفارش‌دهنده (موبایل کاربر) برای برچسب پست</summary>
public string? Phone { get; set; }
}
public class OrderItemDto
@@ -25,6 +25,7 @@ public class GetOrderByIdQueryHandler : IRequestHandler<GetOrderByIdQuery, Order
var order = await query
.Include(o => o.UserAddress)
.Include(o => o.User)
.Include(o => o.OrderDetails)
.ThenInclude(od => od.Product)
.FirstOrDefaultAsync(cancellationToken);
@@ -50,7 +51,8 @@ public class GetOrderByIdQueryHandler : IRequestHandler<GetOrderByIdQuery, Order
{
Title = order.UserAddress.Title,
Address = order.UserAddress.Address,
PostalCode = order.UserAddress.PostalCode
PostalCode = order.UserAddress.PostalCode,
Phone = order.User?.Mobile
},
Items = order.OrderDetails.Select(od => new OrderItemDto
{
@@ -150,8 +150,18 @@ public class CreateManualPaymentCommandHandler : IRequestHandler<CreateManualPay
await _context.UserWalletHistories.AddAsync(walletLog, cancellationToken);
// 9. تنظیم روش خرید پکیج
user.PackagePurchaseMethod = PackagePurchaseMethod.DirectPurchase;
// 9. تنظیم روش خرید پکیج + ثبت ledger خرید دستی
user.PackagePurchaseMethod = PackagePurchaseMethod.Manual;
_context.UserPackagePurchases.Add(new UserPackagePurchase
{
UserId = request.UserId,
PackageId = package.Id,
PurchaseMethod = PackagePurchaseMethod.Manual,
PurchasedAt = DateTime.Now,
Amount = balanceAmount,
TransactionId = transaction.Id
});
// 10. ذخیره همه تغییرات
await _context.SaveChangesAsync(cancellationToken);
@@ -118,7 +118,7 @@ public class ProcessManualMembershipPaymentCommandHandler : IRequestHandler<Proc
};
await _context.UserWalletHistories.AddAsync(balanceLog, cancellationToken);
user.PackagePurchaseMethod = PackagePurchaseMethod.DirectPurchase;
user.PackagePurchaseMethod = PackagePurchaseMethod.Manual;
// 10. به‌روزرسانی ManualPayment با TransactionId
manualPayment.TransactionId = transaction.Id;
await _context.SaveChangesAsync(cancellationToken);
@@ -1,4 +1,5 @@
using CMSMicroservice.Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkStatistics;
@@ -34,17 +35,28 @@ public class GetNetworkStatisticsQueryHandler : IRequestHandler<GetNetworkStatis
}
var allDescendants = GetAllDescendants(userId, allUsers);
// Statistics for the user's network (all descendants)
var totalMembers = allDescendants.Count;
var activeMembers = allDescendants.Count(x => !x.IsDeleted);
// Get direct left and right children
var leftChild = allUsers.FirstOrDefault(x => x.NetworkParentId == userId && x.LegPosition == NetworkLeg.Left);
var rightChild = allUsers.FirstOrDefault(x => x.NetworkParentId == userId && x.LegPosition == NetworkLeg.Right);
// Count all descendants in left and right subtrees
var leftLegCount = leftChild != null ? GetAllDescendants(leftChild.Id, allUsers).Count + 1 : 0; // +1 for leftChild itself
var rightLegCount = rightChild != null ? GetAllDescendants(rightChild.Id, allUsers).Count + 1 : 0; // +1 for rightChild itself
var leftLegUserIds = leftChild != null ? GetSubtreeUserIds(leftChild.Id, allUsers) : new HashSet<long>();
var rightLegUserIds = rightChild != null ? GetSubtreeUserIds(rightChild.Id, allUsers) : new HashSet<long>();
var allLegUserIds = leftLegUserIds.Union(rightLegUserIds).ToList();
// سازمان چپ/راست = فقط اعضای فعال باشگاه در هر پا
var activeClubUserIds = allLegUserIds.Count == 0
? new HashSet<long>()
: (await _context.ClubMemberships
.AsNoTracking()
.Where(cm => cm.IsActive && !cm.IsDeleted && allLegUserIds.Contains(cm.UserId))
.Select(cm => cm.UserId)
.ToListAsync(cancellationToken))
.ToHashSet();
var leftLegCount = leftLegUserIds.Count(id => activeClubUserIds.Contains(id));
var rightLegCount = rightLegUserIds.Count(id => activeClubUserIds.Contains(id));
var totalMembers = leftLegCount + rightLegCount;
var activeMembers = totalMembers;
double leftPercentage = totalMembers > 0 ? (leftLegCount / (double)totalMembers) * 100 : 0;
double rightPercentage = totalMembers > 0 ? (rightLegCount / (double)totalMembers) * 100 : 0;
@@ -124,6 +136,9 @@ public class GetNetworkStatisticsQueryHandler : IRequestHandler<GetNetworkStatis
RightCount = x.RightCount
}).ToList();
var (goldLeft, goldRight, silverLeft, silverRight) =
await LoadPackageHolderCountsByLegAsync(leftLegUserIds, rightLegUserIds, cancellationToken);
return new GetNetworkStatisticsResponseDto
{
TotalMembers = totalMembers,
@@ -136,10 +151,93 @@ public class GetNetworkStatisticsQueryHandler : IRequestHandler<GetNetworkStatis
MaxDepth = maxDepth,
LevelDistribution = levelDistribution,
MonthlyGrowth = monthlyGrowth,
TopUsers = topUserModels
TopUsers = topUserModels,
GoldLeftLegTotal = goldLeft,
GoldRightLegTotal = goldRight,
SilverLeftLegTotal = silverLeft,
SilverRightLegTotal = silverRight
};
}
/// <summary>
/// تعداد اعضای فعال باشگاه با پکیج جاری (IsCurrentCycle) در پای چپ/راست.
/// </summary>
private async Task<(int GoldLeft, int GoldRight, int SilverLeft, int SilverRight)> LoadPackageHolderCountsByLegAsync(
HashSet<long> leftLegUserIds,
HashSet<long> rightLegUserIds,
CancellationToken cancellationToken)
{
if (leftLegUserIds.Count == 0 && rightLegUserIds.Count == 0)
return (0, 0, 0, 0);
var (goldPackageId, silverPackageId) = await ResolveGoldSilverPackageIdsAsync(cancellationToken);
if (!goldPackageId.HasValue && !silverPackageId.HasValue)
return (0, 0, 0, 0);
var allLegUserIds = leftLegUserIds.Union(rightLegUserIds).ToList();
var userPackages = await (
from cm in _context.ClubMemberships.AsNoTracking()
join cc in _context.ClubMembershipCycles.AsNoTracking() on cm.UserId equals cc.UserId
where cm.IsActive
&& !cm.IsDeleted
&& cc.IsCurrentCycle
&& allLegUserIds.Contains(cm.UserId)
select new { cm.UserId, cc.PackageId }
).ToListAsync(cancellationToken);
var packageByUser = userPackages
.GroupBy(x => x.UserId)
.ToDictionary(g => g.Key, g => g.First().PackageId);
int goldLeft = 0, goldRight = 0, silverLeft = 0, silverRight = 0;
if (goldPackageId.HasValue)
{
goldLeft = leftLegUserIds.Count(id =>
packageByUser.TryGetValue(id, out var packageId) && packageId == goldPackageId.Value);
goldRight = rightLegUserIds.Count(id =>
packageByUser.TryGetValue(id, out var packageId) && packageId == goldPackageId.Value);
}
if (silverPackageId.HasValue)
{
silverLeft = leftLegUserIds.Count(id =>
packageByUser.TryGetValue(id, out var packageId) && packageId == silverPackageId.Value);
silverRight = rightLegUserIds.Count(id =>
packageByUser.TryGetValue(id, out var packageId) && packageId == silverPackageId.Value);
}
return (goldLeft, goldRight, silverLeft, silverRight);
}
private async Task<(long? GoldPackageId, long? SilverPackageId)> ResolveGoldSilverPackageIdsAsync(
CancellationToken cancellationToken)
{
var packages = await _context.Packages
.AsNoTracking()
.Where(p => !p.IsDeleted && p.IsActive)
.Select(p => new { p.Id, p.Title, p.IsBasePackage, p.MaxBalancesPerLeg })
.ToListAsync(cancellationToken);
var goldPackageId = packages.FirstOrDefault(p => p.IsBasePackage)?.Id
?? packages.FirstOrDefault(p => p.Title.Contains("طلایی") || p.Title.Contains("طلايی"))?.Id;
var silverPackageId = packages.FirstOrDefault(p =>
!p.IsBasePackage && (p.Title.Contains("نقره") || p.MaxBalancesPerLeg <= 30))?.Id
?? packages.FirstOrDefault(p => !p.IsBasePackage)?.Id;
return (goldPackageId, silverPackageId);
}
private HashSet<long> GetSubtreeUserIds(long rootUserId, List<User> allUsers)
{
var ids = new HashSet<long> { rootUserId };
foreach (var descendant in GetAllDescendants(rootUserId, allUsers))
ids.Add(descendant.Id);
return ids;
}
/// <summary>
/// Recursively get all descendants of a user
/// </summary>
@@ -2,9 +2,13 @@ namespace CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkStat
public class GetNetworkStatisticsResponseDto
{
/// <summary>مجموع اعضای فعال باشگاه در پای چپ و راست (= LeftLegCount + RightLegCount)</summary>
public int TotalMembers { get; set; }
/// <summary>همان TotalMembers — اعضای فعال باشگاه در شبکه کاربر</summary>
public int ActiveMembers { get; set; }
/// <summary>تعداد اعضای فعال باشگاه در زیردرخت پای چپ</summary>
public int LeftLegCount { get; set; }
/// <summary>تعداد اعضای فعال باشگاه در زیردرخت پای راست</summary>
public int RightLegCount { get; set; }
public double LeftPercentage { get; set; }
public double RightPercentage { get; set; }
@@ -13,6 +17,17 @@ public class GetNetworkStatisticsResponseDto
public List<LevelDistributionModel> LevelDistribution { get; set; } = new();
public List<MonthlyGrowthModel> MonthlyGrowth { get; set; } = new();
public List<TopNetworkUserModel> TopUsers { get; set; } = new();
/// <summary>تعداد اعضای فعال باشگاه با پکیج طلایی جاری در پای چپ</summary>
public int GoldLeftLegTotal { get; set; }
/// <summary>تعداد اعضای فعال باشگاه با پکیج طلایی جاری در پای راست</summary>
public int GoldRightLegTotal { get; set; }
/// <summary>تعداد اعضای فعال باشگاه با پکیج نقره‌ای جاری در پای چپ</summary>
public int SilverLeftLegTotal { get; set; }
/// <summary>تعداد اعضای فعال باشگاه با پکیج نقره‌ای جاری در پای راست</summary>
public int SilverRightLegTotal { get; set; }
public string WeakerLeg => LeftLegCount <= RightLegCount ? "Left" : "Right";
}
public class LevelDistributionModel
@@ -1,5 +1,4 @@
using System.Data;
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.NetworkMembershipCQ.Queries.GetNetworkTree;
@@ -60,6 +60,18 @@ public class NetworkTreeDto
public long? PackageId { get; set; }
/// <summary>تعداد اعضای فعال با پکیج طلایی جاری در پای چپ (stats bar)</summary>
public int GoldLeftLegTotal { get; set; }
/// <summary>تعداد اعضای فعال با پکیج طلایی جاری در پای راست (stats bar)</summary>
public int GoldRightLegTotal { get; set; }
/// <summary>تعداد اعضای فعال با پکیج نقره‌ای جاری در پای چپ (stats bar)</summary>
public int SilverLeftLegTotal { get; set; }
/// <summary>تعداد اعضای فعال با پکیج نقره‌ای جاری در پای راست (stats bar)</summary>
public int SilverRightLegTotal { get; set; }
public NetworkTreeDto? LeftChild { get; set; }
public NetworkTreeDto? RightChild { get; set; }
}
@@ -8,6 +8,7 @@ using CMSMicroservice.Domain.Entities.Payment;
using CMSMicroservice.Domain.Enums;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.PackageCQ.Commands.VerifyUserPackagePurchasePayment;
@@ -16,20 +17,23 @@ public class VerifyUserPackagePurchasePaymentCommandHandler
: IRequestHandler<VerifyUserPackagePurchasePaymentCommand, VerifyUserPackagePurchasePaymentResult>
{
private readonly IApplicationDbContext _context;
private readonly IPaymentGatewayService _paymentGateway;
private readonly IPaymentGatewayResolver _paymentGatewayResolver;
private readonly IConfiguration _configuration;
private readonly ISender _sender;
private readonly IUserPaymentLock _paymentLock;
private readonly ILogger<VerifyUserPackagePurchasePaymentCommandHandler> _logger;
public VerifyUserPackagePurchasePaymentCommandHandler(
IApplicationDbContext context,
IPaymentGatewayService paymentGateway,
IPaymentGatewayResolver paymentGatewayResolver,
IConfiguration configuration,
ISender sender,
IUserPaymentLock paymentLock,
ILogger<VerifyUserPackagePurchasePaymentCommandHandler> logger)
{
_context = context;
_paymentGateway = paymentGateway;
_paymentGatewayResolver = paymentGatewayResolver;
_configuration = configuration;
_sender = sender;
_paymentLock = paymentLock;
_logger = logger;
@@ -105,7 +109,8 @@ public class VerifyUserPackagePurchasePaymentCommandHandler
}
var amountInToman = paymentTx?.Amount ?? purchase.Amount;
var verifyResult = await _paymentGateway.VerifyPaymentAsync(
var gateway = _paymentGatewayResolver.Get(paymentTx?.GatewayProvider);
var verifyResult = await gateway.VerifyPaymentAsync(
request.Authority, request.Status, (decimal)amountInToman, ct);
if (!verifyResult.IsSuccess)
@@ -193,17 +198,30 @@ public class VerifyUserPackagePurchasePaymentCommandHandler
await _context.SaveChangesAsync(ct);
}
var discountMultiplier = purchase.Package?.DiscountMultiplier
var packagePrice = purchase.Package?.Price
?? throw new InvalidOperationException("پکیج سفارش یافت نشد");
var discountAmount = (long)(purchase.Amount * (double)discountMultiplier);
wallet.Balance += purchase.Amount;
var discountMultiplier = purchase.Package.DiscountMultiplier;
var discountAmount = (long)(packagePrice * (double)discountMultiplier);
var isTwentyCard = string.Equals(
paymentTx?.GatewayProvider, "20card", StringComparison.OrdinalIgnoreCase);
long balanceCredit = purchase.Amount;
if (isTwentyCard)
{
balanceCredit = _configuration.GetValue<long?>(
$"TwentyCard:Packages:{purchase.PackageId}:WalletCreditToman") ?? 0;
if (balanceCredit <= 0)
throw new InvalidOperationException("WalletCredit ۲۰کارت برای این پکیج پیکربندی نشده است");
}
wallet.Balance += balanceCredit;
wallet.DiscountBalance += discountAmount;
_context.UserWalletHistories.Add(new UserWalletHistory
{
WalletId = wallet.Id,
CurrentBalance = wallet.Balance,
ChangeValue = purchase.Amount,
ChangeValue = balanceCredit,
CurrentNetworkBalance = wallet.NetworkBalance,
ChangeNerworkValue = 0,
CurrentDiscountBalance = wallet.DiscountBalance,
@@ -43,4 +43,5 @@ public class GetAllPaymentTransactionByFilterResponseModel
public long? TransactionId { get; set; }
public string? Description { get; set; }
public DateTimeOffset Created { get; set; }
public string? UserFullName { get; set; }
}
@@ -19,30 +19,43 @@ public class GetAllPaymentTransactionByFilterQueryHandler
.ApplyPaymentTransactionFilter(request.Filter)
.ApplyOrder(sortBy: request.SortBy ?? "-Created");
var models = await (
from x in query.PaginatedListAsync(paginationState: request.PaginationState)
join u in _context.Users.AsNoTracking() on x.UserId equals u.Id into ug
from u in ug.DefaultIfEmpty()
select new GetAllPaymentTransactionByFilterResponseModel
{
Id = x.Id,
UserId = x.UserId,
Mobile = x.Mobile,
GatewayProvider = x.GatewayProvider,
Amount = x.Amount,
Authority = x.Authority,
PaymentStatus = x.PaymentStatus,
VerificationStatusCode = x.VerificationStatusCode,
VerificationStatusMessage = x.VerificationStatusMessage,
RefId = x.RefId,
CardPan = x.CardPan,
OrderId = x.OrderId,
TransactionId = x.TransactionId,
Description = x.Description,
Created = x.Created,
UserFullName = u != null
? ((u.FirstName ?? "") + " " + (u.LastName ?? "")).Trim()
: null
})
.ToListAsync(cancellationToken);
foreach (var model in models)
{
if (string.IsNullOrWhiteSpace(model.UserFullName))
model.UserFullName = "—";
}
return new GetAllPaymentTransactionByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query
.PaginatedListAsync(paginationState: request.PaginationState)
.Select(x => new GetAllPaymentTransactionByFilterResponseModel
{
Id = x.Id,
UserId = x.UserId,
Mobile = x.Mobile,
GatewayProvider = x.GatewayProvider,
Amount = x.Amount,
Authority = x.Authority,
PaymentStatus = x.PaymentStatus,
VerificationStatusCode = x.VerificationStatusCode,
VerificationStatusMessage = x.VerificationStatusMessage,
RefId = x.RefId,
CardPan = x.CardPan,
OrderId = x.OrderId,
TransactionId = x.TransactionId,
Description = x.Description,
Created = x.Created
})
.ToListAsync(cancellationToken)
Models = models
};
}
}
@@ -67,11 +67,8 @@ public class GetCustomerProductsByFilterQueryHandler : IRequestHandler<GetCustom
if (request.IsActive.HasValue)
query = query.Where(x => x.IsDeleted != request.IsActive.Value);
// Apply sorting
if (!string.IsNullOrEmpty(request.SortBy))
query = query.ApplyOrder(request.SortBy);
else
query = query.OrderByDescending(x => x.Created);
// موجودی‌دارها اول، سپس سورت درخواستی
query = query.ApplyOrderWithInStockPriority(request.SortBy, x => x.RemainingCount > 0);
// Pagination
var totalCount = await query.CountAsync(cancellationToken);
@@ -1,3 +1,5 @@
using CMSMicroservice.Application.Common;
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetAllTransactionsByFilter;
public class GetAllTransactionsByFilterQueryHandler : IRequestHandler<GetAllTransactionsByFilterQuery, GetAllTransactionsByFilterResponseDto>
@@ -16,23 +18,106 @@ public class GetAllTransactionsByFilterQueryHandler : IRequestHandler<GetAllTran
.ApplyTransactionFilter(request.Filter)
.ApplyOrder(sortBy: request.SortBy ?? "-Created");
var models = await query
.PaginatedListAsync(paginationState: request.PaginationState)
.Select(x => new GetAllTransactionsByFilterResponseModel
{
Id = x.Id,
Amount = x.Amount,
Description = x.Description,
PaymentStatus = x.PaymentStatus,
PaymentDate = x.PaymentDate,
RefId = x.RefId,
Type = x.Type,
Created = x.Created
})
.ToListAsync(cancellationToken);
await PopulateUserInfoAsync(models, cancellationToken);
return new GetAllTransactionsByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query
.PaginatedListAsync(paginationState: request.PaginationState)
.Select(x => new GetAllTransactionsByFilterResponseModel
{
Id = x.Id,
Amount = x.Amount,
Description = x.Description,
PaymentStatus = x.PaymentStatus,
PaymentDate = x.PaymentDate,
RefId = x.RefId,
Type = x.Type,
Created = x.Created
})
.ToListAsync(cancellationToken)
Models = models
};
}
private async Task PopulateUserInfoAsync(
List<GetAllTransactionsByFilterResponseModel> models,
CancellationToken cancellationToken)
{
if (models.Count == 0)
return;
var txIds = models.Select(m => m.Id).ToList();
var userByTx = new Dictionary<long, long>();
void Merge(IEnumerable<(long TxId, long UserId)> rows)
{
foreach (var (txId, userId) in rows)
{
if (!userByTx.ContainsKey(txId))
userByTx[txId] = userId;
}
}
// Priority: PaymentTransactions → UserPackagePurchases → UserOrders → ManualPayments
var fromPt = await _context.PaymentTransactions.AsNoTracking()
.Where(x => x.TransactionId != null && txIds.Contains(x.TransactionId.Value) && x.UserId != null)
.Select(x => new { TxId = x.TransactionId!.Value, UserId = x.UserId!.Value })
.ToListAsync(cancellationToken);
Merge(fromPt.Select(x => (x.TxId, x.UserId)));
var fromUpp = await _context.UserPackagePurchases.AsNoTracking()
.Where(x => x.TransactionId != null && txIds.Contains(x.TransactionId.Value))
.Select(x => new { TxId = x.TransactionId!.Value, UserId = x.UserId })
.ToListAsync(cancellationToken);
Merge(fromUpp.Select(x => (x.TxId, x.UserId)));
var fromOrders = await _context.UserOrders.AsNoTracking()
.Where(x => x.TransactionId != null && txIds.Contains(x.TransactionId.Value))
.Select(x => new { TxId = x.TransactionId!.Value, UserId = x.UserId })
.ToListAsync(cancellationToken);
Merge(fromOrders.Select(x => (x.TxId, x.UserId)));
var fromManual = await _context.ManualPayments.AsNoTracking()
.Where(x => x.TransactionId != null && txIds.Contains(x.TransactionId.Value))
.Select(x => new { TxId = x.TransactionId!.Value, UserId = x.UserId })
.ToListAsync(cancellationToken);
Merge(fromManual.Select(x => (x.TxId, x.UserId)));
if (userByTx.Count == 0)
{
foreach (var model in models)
model.UserFullName = "—";
return;
}
var userIds = userByTx.Values.Distinct().ToList();
var users = await _context.Users.AsNoTracking()
.Where(u => userIds.Contains(u.Id))
.Select(u => new { u.Id, u.FirstName, u.LastName, u.Mobile })
.ToDictionaryAsync(u => u.Id, cancellationToken);
foreach (var model in models)
{
if (!userByTx.TryGetValue(model.Id, out var userId))
{
model.UserFullName = "—";
continue;
}
model.UserId = userId;
if (users.TryGetValue(userId, out var user))
{
model.Mobile = user.Mobile;
var name = UserDisplayName.From(user.FirstName, user.LastName, user.Mobile, user.Id);
model.UserFullName = string.IsNullOrWhiteSpace(name) ? "—" : name;
}
else
{
model.UserFullName = "—";
}
}
}
}
@@ -25,4 +25,7 @@ public class GetAllTransactionsByFilterResponseDto
//
public TransactionType Type { get; set; }
public DateTime Created { get; set; }
public long? UserId { get; set; }
public string? UserFullName { get; set; }
public string? Mobile { get; set; }
}
@@ -9,5 +9,7 @@ public record VerifyOtpTokenCommand : IRequest<VerifyOtpTokenResponseDto>
public string Code { get; init; }
//کد معرف والد
public string? ParentReferralCode { get; init; }
//شماره موبایل دعوت‌کننده (اختیاری)
public string? InviterMobile { get; init; }
}
@@ -118,6 +118,34 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
else
return new VerifyOtpTokenResponseDto { Success = false, Message = "ظرفیت معرف تکمیل است!!" };
// ── دعوت‌کننده (اختیاری؛ اعتبارسنجی سخت قبل از ایجاد کاربر) ──
User? inviter = null;
if (!string.IsNullOrWhiteSpace(request.InviterMobile))
{
var inviterMobile = request.InviterMobile.NormalizeIranMobile();
if (inviterMobile == mobile)
{
return new VerifyOtpTokenResponseDto
{
Success = false,
Message = "شماره موبایل دعوت‌کننده نمی‌تواند با شماره خودتان یکسان باشد."
};
}
inviter = await _context.Users
.AsNoTracking()
.FirstOrDefaultAsync(u => u.Mobile == inviterMobile, cancellationToken);
if (inviter == null)
{
return new VerifyOtpTokenResponseDto
{
Success = false,
Message = "دعوت‌کننده با این شماره موبایل یافت نشد."
};
}
}
// ایجاد کاربر جدید
user = new User
{
@@ -134,6 +162,15 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
user.AddDomainEvent(new CreateNewUserEvent(user));
await _context.SaveChangesAsync(cancellationToken);
if (inviter != null)
{
await _context.UserInvitations.AddAsync(new UserInvitation
{
InviterUserId = inviter.Id,
InviteeUserId = user.Id
}, cancellationToken);
}
// ایجاد نقش کاربری
var userRole = new UserRole { UserId = user.Id, RoleId = 1 };
await _context.UserRoles.AddAsync(userRole, cancellationToken);
@@ -17,7 +17,7 @@ public class GetAllUserByFilterQueryHandler : IRequestHandler<GetAllUserByFilter
if (request.Filter is not null)
{
query = query
.Where(x => request.Filter.SearchText == null ||
.Where(x => request.Filter.SearchText == null ||
x.FirstName.Contains(request.Filter.SearchText) ||
x.LastName.Contains(request.Filter.SearchText) ||
x.Mobile.Contains(request.Filter.SearchText) ||
@@ -34,14 +34,39 @@ public class GetAllUserByFilterQueryHandler : IRequestHandler<GetAllUserByFilter
.Where(x => request.Filter.SmsNotifications == null || x.SmsNotifications == request.Filter.SmsNotifications)
.Where(x => request.Filter.EmailNotifications == null || x.EmailNotifications == request.Filter.EmailNotifications)
.Where(x => request.Filter.PushNotifications == null || x.PushNotifications == request.Filter.PushNotifications)
.Where(x => request.Filter.BirthDate == null || x.BirthDate == request.Filter.BirthDate)
;
.Where(x => request.Filter.BirthDate == null || x.BirthDate == request.Filter.BirthDate);
}
return new GetAllUserByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllUserByFilterResponseModel>().ToListAsync(cancellationToken)
};
.Select(x => new GetAllUserByFilterResponseModel
{
Id = x.Id,
FirstName = x.FirstName,
LastName = x.LastName,
Mobile = x.Mobile,
NationalCode = x.NationalCode,
AvatarPath = x.AvatarPath,
NetworkParentId = x.NetworkParentId,
ReferralCode = x.ReferralCode,
IsMobileVerified = x.IsMobileVerified,
MobileVerifiedAt = x.MobileVerifiedAt,
EmailNotifications = x.EmailNotifications,
SmsNotifications = x.SmsNotifications,
PushNotifications = x.PushNotifications,
BirthDate = x.BirthDate,
DefaultAddress = x.UserAddresses
.Where(a => a.IsDefault && !a.IsDeleted)
.Select(a => a.Address)
.FirstOrDefault() ?? string.Empty,
DefaultPostalCode = x.UserAddresses
.Where(a => a.IsDefault && !a.IsDeleted)
.Select(a => a.PostalCode)
.FirstOrDefault() ?? string.Empty
})
.ToListAsync(cancellationToken)
};
}
}
@@ -36,4 +36,8 @@ public class GetAllUserByFilterResponseDto
public bool PushNotifications { get; set; }
//تاریخ تولد
public DateTime? BirthDate { get; set; }
//آدرس پیش‌فرض
public string DefaultAddress { get; set; } = string.Empty;
//کدپستی پیش‌فرض
public string DefaultPostalCode { get; set; } = string.Empty;
}
@@ -0,0 +1,46 @@
using CMSMicroservice.Application.Common.Models;
using MediatR;
namespace CMSMicroservice.Application.UserCQ.Queries.GetInvitationsByFilter;
public class GetInvitationsByFilterQuery : IRequest<GetInvitationsByFilterResult>
{
public PaginationState? PaginationState { get; set; }
public string? SortBy { get; set; }
public GetInvitationsByFilterFilterDto? Filter { get; set; }
}
public class GetInvitationsByFilterFilterDto
{
public string? InviterMobile { get; set; }
public string? InviterFirstName { get; set; }
public string? InviterLastName { get; set; }
public string? InviteeMobile { get; set; }
public string? InviteeFirstName { get; set; }
public string? InviteeLastName { get; set; }
public bool? InviteeClubActive { get; set; }
public DateTime? CreatedFrom { get; set; }
public DateTime? CreatedTo { get; set; }
}
public class GetInvitationsByFilterResult
{
public MetaData MetaData { get; set; } = new();
public List<InvitationReportDto> Models { get; set; } = new();
}
public class InvitationReportDto
{
public long Id { get; set; }
public long InviterUserId { get; set; }
public string? InviterFirstName { get; set; }
public string? InviterLastName { get; set; }
public string InviterMobile { get; set; } = string.Empty;
public long InviteeUserId { get; set; }
public string? InviteeFirstName { get; set; }
public string? InviteeLastName { get; set; }
public string InviteeMobile { get; set; } = string.Empty;
public DateTime InviteeRegisteredAt { get; set; }
public bool InviteeClubActive { get; set; }
public DateTime InvitedAt { get; set; }
}
@@ -0,0 +1,96 @@
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Models;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.UserCQ.Queries.GetInvitationsByFilter;
public class GetInvitationsByFilterQueryHandler
: IRequestHandler<GetInvitationsByFilterQuery, GetInvitationsByFilterResult>
{
private readonly IApplicationDbContext _context;
public GetInvitationsByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetInvitationsByFilterResult> Handle(
GetInvitationsByFilterQuery request,
CancellationToken cancellationToken)
{
var filter = request.Filter ?? new GetInvitationsByFilterFilterDto();
var query = _context.UserInvitations
.AsNoTracking()
.Select(x => new InvitationReportDto
{
Id = x.Id,
InviterUserId = x.InviterUserId,
InviterFirstName = x.Inviter.FirstName,
InviterLastName = x.Inviter.LastName,
InviterMobile = x.Inviter.Mobile,
InviteeUserId = x.InviteeUserId,
InviteeFirstName = x.Invitee.FirstName,
InviteeLastName = x.Invitee.LastName,
InviteeMobile = x.Invitee.Mobile,
InviteeRegisteredAt = x.Invitee.Created,
InviteeClubActive = x.Invitee.ClubMembership != null && x.Invitee.ClubMembership.IsActive,
InvitedAt = x.Created
});
if (!string.IsNullOrWhiteSpace(filter.InviterMobile))
query = query.Where(x => x.InviterMobile.Contains(filter.InviterMobile));
if (!string.IsNullOrWhiteSpace(filter.InviterFirstName))
query = query.Where(x => x.InviterFirstName != null && x.InviterFirstName.Contains(filter.InviterFirstName));
if (!string.IsNullOrWhiteSpace(filter.InviterLastName))
query = query.Where(x => x.InviterLastName != null && x.InviterLastName.Contains(filter.InviterLastName));
if (!string.IsNullOrWhiteSpace(filter.InviteeMobile))
query = query.Where(x => x.InviteeMobile.Contains(filter.InviteeMobile));
if (!string.IsNullOrWhiteSpace(filter.InviteeFirstName))
query = query.Where(x => x.InviteeFirstName != null && x.InviteeFirstName.Contains(filter.InviteeFirstName));
if (!string.IsNullOrWhiteSpace(filter.InviteeLastName))
query = query.Where(x => x.InviteeLastName != null && x.InviteeLastName.Contains(filter.InviteeLastName));
if (filter.InviteeClubActive.HasValue)
query = query.Where(x => x.InviteeClubActive == filter.InviteeClubActive.Value);
if (filter.CreatedFrom.HasValue)
query = query.Where(x => x.InvitedAt >= filter.CreatedFrom.Value);
if (filter.CreatedTo.HasValue)
query = query.Where(x => x.InvitedAt <= filter.CreatedTo.Value);
// پیش‌فرض: جدیدترین
query = (request.SortBy?.Trim().ToLowerInvariant()) switch
{
"oldest" or "created_asc" => query.OrderBy(x => x.InvitedAt),
_ => query.OrderByDescending(x => x.InvitedAt)
};
var paginationState = request.PaginationState ?? new PaginationState { PageNumber = 1, PageSize = 20 };
if (paginationState.PageNumber < 1) paginationState.PageNumber = 1;
if (paginationState.PageSize < 1) paginationState.PageSize = 20;
var totalCount = await query.CountAsync(cancellationToken);
var models = await query
.Skip((paginationState.PageNumber - 1) * paginationState.PageSize)
.Take(paginationState.PageSize)
.ToListAsync(cancellationToken);
var totalPage = totalCount == 0
? 0
: (int)Math.Ceiling((double)totalCount / paginationState.PageSize);
return new GetInvitationsByFilterResult
{
MetaData = new MetaData
{
TotalCount = totalCount,
CurrentPage = paginationState.PageNumber,
PageSize = paginationState.PageSize,
TotalPage = totalPage,
HasPrevious = paginationState.PageNumber > 1,
HasNext = paginationState.PageNumber < totalPage
},
Models = models
};
}
}
@@ -0,0 +1,36 @@
using CMSMicroservice.Application.Common.Models;
using MediatR;
namespace CMSMicroservice.Application.UserCQ.Queries.GetMyInvitees;
public class GetMyInviteesQuery : IRequest<GetMyInviteesResult>
{
public long UserId { get; set; }
public PaginationState? PaginationState { get; set; }
/// <summary>ALL | ACTIVE | INACTIVE — ClubMembership.IsActive</summary>
public string? ClubStatusFilter { get; set; }
}
public class GetMyInviteesResult
{
public MetaData MetaData { get; set; } = new();
public List<InviteeDto> Invitees { get; set; } = new();
public InviteeStatsDto Stats { get; set; } = new();
}
public class InviteeDto
{
public long UserId { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string Mobile { get; set; } = string.Empty;
public DateTime RegisteredAt { get; set; }
public bool IsClubActive { get; set; }
}
public class InviteeStatsDto
{
public int TotalInvitees { get; set; }
public int ClubActiveCount { get; set; }
public int ClubInactiveCount { get; set; }
}
@@ -0,0 +1,98 @@
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Models;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.UserCQ.Queries.GetMyInvitees;
public class GetMyInviteesQueryHandler : IRequestHandler<GetMyInviteesQuery, GetMyInviteesResult>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public GetMyInviteesQueryHandler(IApplicationDbContext context, ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<GetMyInviteesResult> Handle(GetMyInviteesQuery request, CancellationToken cancellationToken)
{
var userId = request.UserId == 0
? (long.TryParse(_currentUser.UserId, out var id) ? id : 0)
: request.UserId;
if (userId == 0)
throw new UnauthorizedAccessException("User ID not found in JWT token");
var baseQuery = _context.UserInvitations
.AsNoTracking()
.Where(x => x.InviterUserId == userId)
.Select(x => new
{
x.InviteeUserId,
InviteeFirstName = x.Invitee.FirstName,
InviteeLastName = x.Invitee.LastName,
InviteeMobile = x.Invitee.Mobile,
RegisteredAt = x.Invitee.Created,
IsClubActive = x.Invitee.ClubMembership != null && x.Invitee.ClubMembership.IsActive,
InvitedAt = x.Created
});
var all = await baseQuery.ToListAsync(cancellationToken);
var total = all.Count;
var clubActive = all.Count(x => x.IsClubActive);
var clubInactive = total - clubActive;
var filtered = all.AsEnumerable();
var status = request.ClubStatusFilter?.Trim().ToUpperInvariant();
if (status == "ACTIVE")
filtered = filtered.Where(x => x.IsClubActive);
else if (status == "INACTIVE")
filtered = filtered.Where(x => !x.IsClubActive);
var ordered = filtered.OrderByDescending(x => x.InvitedAt).ToList();
var paginationState = request.PaginationState ?? new PaginationState { PageNumber = 1, PageSize = 10 };
if (paginationState.PageNumber < 1) paginationState.PageNumber = 1;
if (paginationState.PageSize < 1) paginationState.PageSize = 10;
var totalCount = ordered.Count;
var pageItems = ordered
.Skip((paginationState.PageNumber - 1) * paginationState.PageSize)
.Take(paginationState.PageSize)
.ToList();
var totalPage = totalCount == 0
? 0
: (int)Math.Ceiling((double)totalCount / paginationState.PageSize);
return new GetMyInviteesResult
{
MetaData = new MetaData
{
TotalCount = totalCount,
CurrentPage = paginationState.PageNumber,
PageSize = paginationState.PageSize,
TotalPage = totalPage,
HasPrevious = paginationState.PageNumber > 1,
HasNext = paginationState.PageNumber < totalPage
},
Stats = new InviteeStatsDto
{
TotalInvitees = total,
ClubActiveCount = clubActive,
ClubInactiveCount = clubInactive
},
Invitees = pageItems.Select(x => new InviteeDto
{
UserId = x.InviteeUserId,
FirstName = x.InviteeFirstName,
LastName = x.InviteeLastName,
Mobile = x.InviteeMobile,
RegisteredAt = x.RegisteredAt,
IsClubActive = x.IsClubActive
}).ToList()
};
}
}
@@ -1,3 +1,4 @@
using CMSMicroservice.Application.Common;
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities;
@@ -50,8 +51,10 @@ public class GetCustomerOrderQueryHandler : IRequestHandler<GetCustomerOrderQuer
DeliveryStatus = order.DeliveryStatus,
TrackingCode = order.TrackingCode ?? "",
DeliveryDescription = order.DeliveryDescription ?? "",
UserFullName = $"{order.User?.FirstName ?? ""} {order.User?.LastName ?? ""}".Trim(),
UserFullName = UserDisplayName.From(order.User),
UserNationalCode = order.User?.NationalCode ?? "",
PostalCode = order.UserAddress?.PostalCode ?? "",
UserMobile = order.User?.Mobile ?? "",
VatAmount = order.OrderVAT?.VATAmount ?? 0,
VatPercentage = order.OrderVAT != null ? (double)order.OrderVAT.VATRate * 100 : 0,
FactorDetails = order.FactorDetails?.Select(fd => new FactorDetailDto
@@ -20,6 +20,8 @@ public class GetCustomerOrderResponseDto
public string DeliveryDescription { get; set; }
public string UserFullName { get; set; }
public string UserNationalCode { get; set; }
public string PostalCode { get; set; } = string.Empty;
public string UserMobile { get; set; } = string.Empty;
public long VatAmount { get; set; }
public double VatPercentage { get; set; }
}
@@ -113,6 +113,7 @@ public class GetCustomerOrderHistoryQueryHandler : IRequestHandler<GetCustomerOr
DeliveryStatus.Delivered => 4,
DeliveryStatus.Cancelled => 5,
DeliveryStatus.Returned => 6,
DeliveryStatus.ReadyForOfficePickup => 7,
_ => 0
};
}
@@ -127,6 +128,7 @@ public class GetCustomerOrderHistoryQueryHandler : IRequestHandler<GetCustomerOr
DeliveryStatus.Delivered => "تحویل داده شد",
DeliveryStatus.Cancelled => "لغو شده",
DeliveryStatus.Returned => "مرجوع شده",
DeliveryStatus.ReadyForOfficePickup => "آماده تحویل در دفتر",
_ => "نامشخص"
};
}
@@ -1,3 +1,4 @@
using CMSMicroservice.Application.Common;
using CMSMicroservice.Application.Common.Extensions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Models;
@@ -72,7 +73,7 @@ public class GetCustomerOrdersQueryHandler : IRequestHandler<GetCustomerOrdersQu
DeliveryStatus = order.DeliveryStatus,
TrackingCode = order.TrackingCode ?? "",
DeliveryDescription = order.DeliveryDescription ?? "",
UserFullName = $"{order.User?.FirstName ?? ""} {order.User?.LastName ?? ""}".Trim(),
UserFullName = UserDisplayName.From(order.User),
UserNationalCode = order.User?.NationalCode ?? "",
VatAmount = order.OrderVAT?.VATAmount ?? 0,
VatPercentage = order.OrderVAT != null ? (double)order.OrderVAT.VATRate * 100 : 0,
@@ -0,0 +1,51 @@
using CMSMicroservice.Domain.Enums;
namespace CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetCustomerPackagePurchaseRollup;
public record GetCustomerPackagePurchaseRollupQuery : IRequest<GetCustomerPackagePurchaseRollupResponseDto>
{
public PaginationState? PaginationState { get; init; }
public GetCustomerPackagePurchaseRollupFilter? Filter { get; init; }
}
public class GetCustomerPackagePurchaseRollupFilter
{
public long? UserId { get; set; }
public PackagePurchaseMethod? PurchaseMethod { get; set; }
public DateTime? PurchasedFrom { get; set; }
public DateTime? PurchasedTo { get; set; }
}
public class GetCustomerPackagePurchaseRollupResponseDto
{
public MetaData MetaData { get; set; } = new();
public List<CustomerPackagePurchaseRollupModel> Models { get; set; } = new();
}
public class CustomerPackagePurchaseRollupModel
{
public long UserId { get; set; }
public string UserName { get; set; } = string.Empty;
public string UserMobile { get; set; } = string.Empty;
public long FirstPackageId { get; set; }
public string FirstPackageName { get; set; } = string.Empty;
public long FirstAmount { get; set; }
public DateTime FirstPurchasedAt { get; set; }
public long LastPackageId { get; set; }
public string LastPackageName { get; set; } = string.Empty;
public long LastAmount { get; set; }
public DateTime LastPurchasedAt { get; set; }
public PackagePurchaseMethod LastPurchaseMethod { get; set; }
public int PurchaseCount { get; set; }
public long TotalAmount { get; set; }
public int DayaCount { get; set; }
public long DayaAmount { get; set; }
public int ManualCount { get; set; }
public long ManualAmount { get; set; }
public int GatewayCount { get; set; }
public long GatewayAmount { get; set; }
}
@@ -0,0 +1,136 @@
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Models;
using CMSMicroservice.Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetCustomerPackagePurchaseRollup;
public class GetCustomerPackagePurchaseRollupQueryHandler
: IRequestHandler<GetCustomerPackagePurchaseRollupQuery, GetCustomerPackagePurchaseRollupResponseDto>
{
private readonly IApplicationDbContext _context;
public GetCustomerPackagePurchaseRollupQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetCustomerPackagePurchaseRollupResponseDto> Handle(
GetCustomerPackagePurchaseRollupQuery request,
CancellationToken cancellationToken)
{
var filter = request.Filter;
var pagination = request.PaginationState ?? new PaginationState { PageNumber = 1, PageSize = 20 };
if (pagination.PageNumber < 1) pagination.PageNumber = 1;
// PageSize == 0 → خروجی کامل (بدون صفحه‌بندی)، مثلاً Excel
var exportAll = pagination.PageSize == 0;
if (!exportAll && pagination.PageSize < 1) pagination.PageSize = 20;
// خرید معتبر: بدون تراکنش یا تراکنش موفق
var purchases = _context.UserPackagePurchases
.AsNoTracking()
.Include(x => x.User)
.Include(x => x.Package)
.Include(x => x.Transaction)
.Where(x => x.TransactionId == null
|| (x.Transaction != null && x.Transaction.PaymentStatus == PaymentStatus.Success));
if (filter?.UserId is > 0)
purchases = purchases.Where(x => x.UserId == filter.UserId.Value);
if (filter?.PurchaseMethod != null)
purchases = purchases.Where(x => x.PurchaseMethod == filter.PurchaseMethod.Value);
if (filter?.PurchasedFrom != null)
purchases = purchases.Where(x => x.PurchasedAt >= filter.PurchasedFrom.Value);
if (filter?.PurchasedTo != null)
purchases = purchases.Where(x => x.PurchasedAt <= filter.PurchasedTo.Value);
var rows = await purchases
.Select(x => new
{
x.UserId,
FirstName = x.User != null ? x.User.FirstName : null,
LastName = x.User != null ? x.User.LastName : null,
Mobile = x.User != null ? x.User.Mobile : null,
x.PackageId,
PackageName = x.Package != null ? x.Package.Title : null,
x.Amount,
x.PurchasedAt,
x.PurchaseMethod
})
.ToListAsync(cancellationToken);
var grouped = rows
.GroupBy(x => x.UserId)
.Select(g =>
{
var ordered = g.OrderBy(x => x.PurchasedAt).ThenBy(x => x.PackageId).ToList();
var first = ordered.First();
var last = ordered.Last();
var userName = string.Join(" ",
new[] { first.FirstName, first.LastName }.Where(s => !string.IsNullOrWhiteSpace(s))).Trim();
return new CustomerPackagePurchaseRollupModel
{
UserId = g.Key,
UserName = string.IsNullOrWhiteSpace(userName)
? (!string.IsNullOrWhiteSpace(first.Mobile) ? first.Mobile! : $"کاربر {g.Key}")
: userName,
UserMobile = first.Mobile ?? string.Empty,
FirstPackageId = first.PackageId,
FirstPackageName = first.PackageName ?? string.Empty,
FirstAmount = first.Amount,
FirstPurchasedAt = first.PurchasedAt,
LastPackageId = last.PackageId,
LastPackageName = last.PackageName ?? string.Empty,
LastAmount = last.Amount,
LastPurchasedAt = last.PurchasedAt,
LastPurchaseMethod = last.PurchaseMethod,
PurchaseCount = ordered.Count,
TotalAmount = ordered.Sum(x => x.Amount),
DayaCount = ordered.Count(x => x.PurchaseMethod == PackagePurchaseMethod.DayaLoan),
DayaAmount = ordered.Where(x => x.PurchaseMethod == PackagePurchaseMethod.DayaLoan).Sum(x => x.Amount),
ManualCount = ordered.Count(x => x.PurchaseMethod == PackagePurchaseMethod.Manual),
ManualAmount = ordered.Where(x => x.PurchaseMethod == PackagePurchaseMethod.Manual).Sum(x => x.Amount),
GatewayCount = ordered.Count(x => x.PurchaseMethod == PackagePurchaseMethod.DirectPurchase),
GatewayAmount = ordered.Where(x => x.PurchaseMethod == PackagePurchaseMethod.DirectPurchase).Sum(x => x.Amount)
};
})
.OrderByDescending(x => x.LastPurchasedAt)
.ToList();
var totalCount = grouped.Count;
var pageNumber = exportAll ? 1 : pagination.PageNumber;
var pageSize = exportAll ? totalCount : pagination.PageSize;
var totalPage = exportAll || pageSize <= 0
? (totalCount > 0 ? 1 : 0)
: (int)Math.Ceiling(totalCount / (double)pageSize);
var pageModels = exportAll
? grouped
: grouped
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.ToList();
return new GetCustomerPackagePurchaseRollupResponseDto
{
MetaData = new MetaData
{
CurrentPage = pageNumber,
PageSize = pageSize,
TotalCount = totalCount,
TotalPage = totalPage,
HasPrevious = !exportAll && pageNumber > 1,
HasNext = !exportAll && pageNumber < totalPage
},
Models = pageModels
};
}
}
@@ -0,0 +1,19 @@
using MediatR;
namespace CMSMicroservice.Application.WalletCQ.Commands.AdminManualCreditCharge;
public class AdminManualCreditChargeCommand : IRequest<AdminManualCreditChargeResult>
{
public long UserId { get; set; }
public long Amount { get; set; }
public string? Note { get; set; }
public string? PerformedByAdminId { get; set; }
}
public class AdminManualCreditChargeResult
{
public bool Success { get; set; }
public string Message { get; set; } = string.Empty;
public long TransactionId { get; set; }
public long NewBalance { get; set; }
}
@@ -0,0 +1,105 @@
using CMSMicroservice.Application.Common;
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities;
using CMSMicroservice.Domain.Enums;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.WalletCQ.Commands.AdminManualCreditCharge;
public class AdminManualCreditChargeCommandHandler
: IRequestHandler<AdminManualCreditChargeCommand, AdminManualCreditChargeResult>
{
private readonly IApplicationDbContext _context;
private readonly ILogger<AdminManualCreditChargeCommandHandler> _logger;
private readonly IUserPaymentLock _paymentLock;
public AdminManualCreditChargeCommandHandler(
IApplicationDbContext context,
ILogger<AdminManualCreditChargeCommandHandler> logger,
IUserPaymentLock paymentLock)
{
_context = context;
_logger = logger;
_paymentLock = paymentLock;
}
public Task<AdminManualCreditChargeResult> Handle(
AdminManualCreditChargeCommand request,
CancellationToken cancellationToken) =>
_paymentLock.ExecuteAsync(
PaymentLockScopes.Initiate(request.UserId),
PaymentLockStrategy.FailFast,
ct => HandleCore(request, ct),
cancellationToken);
private async Task<AdminManualCreditChargeResult> HandleCore(
AdminManualCreditChargeCommand request,
CancellationToken cancellationToken)
{
var user = await _context.Users
.FirstOrDefaultAsync(u => u.Id == request.UserId, cancellationToken)
?? throw new NotFoundException(nameof(User), request.UserId);
var wallet = await _context.UserWallets
.FirstOrDefaultAsync(w => w.UserId == user.Id, cancellationToken)
?? throw new NotFoundException($"کیف پول کاربر با شناسه {request.UserId} یافت نشد");
var oldBalance = wallet.Balance;
wallet.Balance += request.Amount;
var refId = $"MANUAL-{Guid.NewGuid():N}";
var notePart = string.IsNullOrWhiteSpace(request.Note)
? string.Empty
: $" — {request.Note.Trim()}";
var adminPart = string.IsNullOrWhiteSpace(request.PerformedByAdminId)
? string.Empty
: $" (ادمین: {request.PerformedByAdminId})";
var transaction = new Transaction
{
Amount = request.Amount,
Description = $"شارژ دستی کیف پول اصلی - کاربر {user.Id}{notePart}{adminPart}",
PaymentStatus = PaymentStatus.Success,
PaymentDate = DateTime.Now,
RefId = refId,
Type = TransactionType.ManualCreditWalletCharge
};
_context.Transactions.Add(transaction);
await _context.SaveChangesAsync(cancellationToken);
_context.UserWalletHistories.Add(new UserWalletHistory
{
WalletId = wallet.Id,
CurrentBalance = wallet.Balance,
ChangeValue = request.Amount,
CurrentNetworkBalance = wallet.NetworkBalance,
ChangeNerworkValue = 0,
CurrentDiscountBalance = wallet.DiscountBalance,
ChangeDiscountValue = 0,
IsIncrease = true,
RefrenceId = transaction.Id
});
await _context.SaveChangesAsync(cancellationToken);
_logger.LogInformation(
"Manual credit charge: UserId={UserId}, Amount={Amount}, OldBalance={Old}, NewBalance={New}, TxId={TxId}, Admin={Admin}",
user.Id,
request.Amount,
oldBalance,
wallet.Balance,
transaction.Id,
request.PerformedByAdminId);
return new AdminManualCreditChargeResult
{
Success = true,
Message = "شارژ دستی کیف پول اصلی با موفقیت انجام شد",
TransactionId = transaction.Id,
NewBalance = wallet.Balance
};
}
}
@@ -0,0 +1,20 @@
using CMSMicroservice.Domain.Common;
using FluentValidation;
namespace CMSMicroservice.Application.WalletCQ.Commands.AdminManualCreditCharge;
public class AdminManualCreditChargeCommandValidator : AbstractValidator<AdminManualCreditChargeCommand>
{
public AdminManualCreditChargeCommandValidator()
{
RuleFor(x => x.UserId)
.GreaterThan(0)
.WithMessage("شناسه کاربر باید بزرگتر از صفر باشد");
RuleFor(x => x.Amount)
.GreaterThanOrEqualTo(SystemConstants.DiscountWalletMinCharge)
.WithMessage("حداقل مبلغ شارژ ۱۰,۰۰۰ تومان است")
.LessThanOrEqualTo(SystemConstants.WalletMaxSafeAmount)
.WithMessage("مبلغ وارد شده بیش از حد مجاز است");
}
}
@@ -55,9 +55,16 @@ public class ChargeCreditWalletCommandHandler
request.Amount);
var user = await _context.Users
.Include(u => u.ClubMembership)
.FirstOrDefaultAsync(u => u.Id == request.UserId, cancellationToken)
?? throw new NotFoundException(nameof(User), request.UserId);
if (user.ClubMembership?.IsActive != true)
{
throw new BadRequestException(
"برای شارژ کیف پول اصلی ابتدا باید پکیج را خریداری کرده و قرارداد باشگاه مشتریان را امضا کنید.");
}
var wallet = await _context.UserWallets
.FirstOrDefaultAsync(w => w.UserId == request.UserId, cancellationToken)
?? throw new NotFoundException("کیف پول کاربر یافت نشد");
@@ -51,9 +51,16 @@ public class VerifyCreditWalletChargeCommandHandler
request.Authority);
var user = await _context.Users
.Include(u => u.ClubMembership)
.FirstOrDefaultAsync(u => u.Id == request.UserId, cancellationToken)
?? throw new NotFoundException(nameof(User), request.UserId);
if (user.ClubMembership?.IsActive != true)
{
throw new BadRequestException(
"برای شارژ کیف پول اصلی ابتدا باید پکیج را خریداری کرده و قرارداد باشگاه مشتریان را امضا کنید.");
}
var paymentTx = await _context.PaymentTransactions
.FirstOrDefaultAsync(pt => pt.Authority == request.Authority, cancellationToken);
@@ -0,0 +1,39 @@
using CMSMicroservice.Application.Common.Models;
using MediatR;
namespace CMSMicroservice.Application.WalletCQ.Queries.GetManualCreditCharges;
public class GetManualCreditChargesQuery : IRequest<GetManualCreditChargesResponseDto>
{
public PaginationState? PaginationState { get; set; }
public string? SortBy { get; set; }
public GetManualCreditChargesFilter? Filter { get; set; }
}
public class GetManualCreditChargesFilter
{
public long? UserId { get; set; }
public long? TransactionId { get; set; }
public string? RefId { get; set; }
public DateTime? CreatedFrom { get; set; }
public DateTime? CreatedTo { get; set; }
}
public class GetManualCreditChargesResponseDto
{
public MetaData MetaData { get; set; } = new();
public List<ManualCreditChargeModelDto> Models { get; set; } = new();
}
public class ManualCreditChargeModelDto
{
public long TransactionId { get; set; }
public long UserId { get; set; }
public string UserName { get; set; } = string.Empty;
public long Amount { get; set; }
public string Description { get; set; } = string.Empty;
public string? RefId { get; set; }
public long NewBalance { get; set; }
public DateTime Created { get; set; }
public DateTime? PaymentDate { get; set; }
}
@@ -0,0 +1,69 @@
using CMSMicroservice.Application.Common.Extensions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Enums;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.WalletCQ.Queries.GetManualCreditCharges;
public class GetManualCreditChargesQueryHandler
: IRequestHandler<GetManualCreditChargesQuery, GetManualCreditChargesResponseDto>
{
private readonly IApplicationDbContext _context;
public GetManualCreditChargesQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetManualCreditChargesResponseDto> Handle(
GetManualCreditChargesQuery request,
CancellationToken cancellationToken)
{
var filter = request.Filter;
var query =
from t in _context.Transactions.AsNoTracking()
where t.Type == TransactionType.ManualCreditWalletCharge
join h in _context.UserWalletHistories.AsNoTracking() on t.Id equals h.RefrenceId
join w in _context.UserWallets.AsNoTracking() on h.WalletId equals w.Id
join u in _context.Users.AsNoTracking() on w.UserId equals u.Id
select new ManualCreditChargeModelDto
{
TransactionId = t.Id,
UserId = w.UserId,
UserName = ((u.FirstName ?? "") + " " + (u.LastName ?? "")).Trim(),
Amount = t.Amount,
Description = t.Description ?? string.Empty,
RefId = t.RefId,
NewBalance = h.CurrentBalance,
Created = t.Created,
PaymentDate = t.PaymentDate
};
if (filter?.UserId is long userId)
query = query.Where(x => x.UserId == userId);
if (filter?.TransactionId is long txId)
query = query.Where(x => x.TransactionId == txId);
if (!string.IsNullOrWhiteSpace(filter?.RefId))
query = query.Where(x => x.RefId != null && x.RefId.Contains(filter.RefId));
if (filter?.CreatedFrom is DateTime from)
query = query.Where(x => x.Created >= from);
if (filter?.CreatedTo is DateTime to)
query = query.Where(x => x.Created <= to);
query = query.OrderByDescending(x => x.Created);
return new GetManualCreditChargesResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query
.PaginatedListAsync(paginationState: request.PaginationState)
.ToListAsync(cancellationToken)
};
}
}
@@ -0,0 +1,18 @@
namespace CMSMicroservice.Domain.Entities;
/// <summary>
/// رابطه دعوت‌کننده ↔ دعوت‌شونده (جدا از معرف شبکه / NetworkParent).
/// کد دعوت = شماره موبایل دعوت‌کننده.
/// </summary>
public class UserInvitation : BaseAuditableEntity
{
/// <summary>کاربری که دعوت کرده</summary>
public long InviterUserId { get; set; }
public virtual User Inviter { get; set; } = null!;
/// <summary>کاربری که دعوت شده (حداکثر یک دعوت‌کننده)</summary>
public long InviteeUserId { get; set; }
public virtual User Invitee { get; set; } = null!;
}
@@ -15,5 +15,7 @@ public enum DeliveryStatus
Returned = 4,
// لغو شده
Cancelled = 5,
// آماده تحویل حضوری در دفتر
ReadyForOfficePickup = 6,
}
@@ -18,5 +18,10 @@ public enum PackagePurchaseMethod
/// <summary>
/// از طریق پرداخت مستقیم درگاه بانکی
/// </summary>
DirectPurchase = 2
DirectPurchase = 2,
/// <summary>
/// ثبت دستی توسط ادمین
/// </summary>
Manual = 3
}
@@ -41,4 +41,9 @@ public enum TransactionType
/// شارژ کیف پول اصلی از درگاه
/// </summary>
CreditWalletCharge = 16,
/// <summary>
/// شارژ دستی کیف پول اصلی توسط ادمین
/// </summary>
ManualCreditWalletCharge = 17,
}
@@ -77,27 +77,33 @@ public static class ConfigureServices
});
}
// Payment Gateway Service - Multi-Provider Architecture
// پشتیبانی از درگاه‌های مختلف: ZarinPal, Daya, Mock
// Payment Gateway — default provider + multi-gateway resolver (ZarinPal + TwentyCard coexist)
var paymentProvider = configuration.GetValue<string>("PaymentProvider", "Mock")?.ToLowerInvariant();
services.AddHttpClient<ZarinPalPaymentService>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5));
services.AddHttpClient<TwentyCardPaymentService>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5));
switch (paymentProvider)
{
case "zarinpal":
services.AddHttpClient<IPaymentGatewayService, ZarinPalPaymentService>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5));
services.AddScoped<IPaymentGatewayService>(sp => sp.GetRequiredService<ZarinPalPaymentService>());
break;
case "daya":
services.AddHttpClient<IPaymentGatewayService, DayaPaymentService>()
services.AddHttpClient<DayaPaymentService>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5));
services.AddScoped<IPaymentGatewayService>(sp => sp.GetRequiredService<DayaPaymentService>());
break;
case "mock":
default:
services.AddScoped<IPaymentGatewayService, MockPaymentGatewayService>();
break;
}
services.AddScoped<IPaymentGatewayResolver, PaymentGatewayResolver>();
services.AddScoped<IApplicationDbContext>(p => p.GetRequiredService<ApplicationDbContext>());
@@ -86,6 +86,7 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext
public DbSet<Product> Products => Set<Product>();
public DbSet<ProductImage> ProductImages => Set<ProductImage>();
public DbSet<User> Users => Set<User>();
public DbSet<UserInvitation> UserInvitations => Set<UserInvitation>();
public DbSet<OtpToken> OtpTokens => Set<OtpToken>();
public DbSet<Contract> Contracts => Set<Contract>();
public DbSet<UserContract> UserContracts => Set<UserContract>();
@@ -13,7 +13,7 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
builder.Property(entity => entity.Id).UseIdentityColumn();
builder.Property(entity => entity.FirstName).IsRequired(false);
builder.Property(entity => entity.LastName).IsRequired(false);
builder.Property(entity => entity.Mobile).IsRequired(true);
builder.Property(entity => entity.Mobile).IsRequired(true).HasMaxLength(20);
builder.Property(entity => entity.NationalCode).IsRequired(false);
builder.Property(entity => entity.AvatarPath).IsRequired(false);
builder.Property(entity => entity.ReferralCode).IsRequired(true);
@@ -48,5 +48,10 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
builder.HasIndex(e => e.LegPosition)
.HasDatabaseName("IX_User_LegPosition");
// موبایل یکتا برای کاربران فعال (lookup دعوت‌کننده)
builder.HasIndex(e => e.Mobile)
.IsUnique()
.HasFilter("[IsDeleted] = 0")
.HasDatabaseName("IX_User_Mobile_Active");
}
}
@@ -0,0 +1,38 @@
using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class UserInvitationConfiguration : IEntityTypeConfiguration<UserInvitation>
{
public void Configure(EntityTypeBuilder<UserInvitation> builder)
{
builder.ToTable("UserInvitations");
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
builder.HasKey(entity => entity.Id);
builder.Property(entity => entity.Id).UseIdentityColumn();
builder.Property(entity => entity.InviterUserId).IsRequired();
builder.Property(entity => entity.InviteeUserId).IsRequired();
builder.HasOne(entity => entity.Inviter)
.WithMany()
.HasForeignKey(entity => entity.InviterUserId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne(entity => entity.Invitee)
.WithMany()
.HasForeignKey(entity => entity.InviteeUserId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasIndex(e => e.InviteeUserId)
.IsUnique()
.HasDatabaseName("IX_UserInvitations_InviteeUserId");
builder.HasIndex(e => new { e.InviterUserId, e.Created })
.HasDatabaseName("IX_UserInvitations_InviterUserId_Created");
}
}
@@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20260222155925_u21")]
[Migration("20260222160755_u21")]
partial class u21
{
/// <inheritdoc />
@@ -0,0 +1,103 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class AddUserInvitations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Mobile",
schema: "CMS",
table: "Users",
type: "nvarchar(20)",
maxLength: 20,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
migrationBuilder.CreateTable(
name: "UserInvitations",
schema: "CMS",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
InviterUserId = table.Column<long>(type: "bigint", nullable: false),
InviteeUserId = table.Column<long>(type: "bigint", nullable: false),
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserInvitations", x => x.Id);
table.ForeignKey(
name: "FK_UserInvitations_Users_InviteeUserId",
column: x => x.InviteeUserId,
principalSchema: "CMS",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_UserInvitations_Users_InviterUserId",
column: x => x.InviterUserId,
principalSchema: "CMS",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_User_Mobile_Active",
schema: "CMS",
table: "Users",
column: "Mobile",
unique: true,
filter: "[IsDeleted] = 0");
migrationBuilder.CreateIndex(
name: "IX_UserInvitations_InviteeUserId",
schema: "CMS",
table: "UserInvitations",
column: "InviteeUserId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_UserInvitations_InviterUserId_Created",
schema: "CMS",
table: "UserInvitations",
columns: new[] { "InviterUserId", "Created" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UserInvitations",
schema: "CMS");
migrationBuilder.DropIndex(
name: "IX_User_Mobile_Active",
schema: "CMS",
table: "Users");
migrationBuilder.AlterColumn<string>(
name: "Mobile",
schema: "CMS",
table: "Users",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(20)",
oldMaxLength: 20);
}
}
}
@@ -3574,7 +3574,7 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Property<string>("Mobile")
.IsRequired()
.HasColumnType("nvarchar(max)");
.HasColumnType("nvarchar(450)");
b.Property<DateTime?>("MobileVerifiedAt")
.HasColumnType("datetime2");
@@ -3606,6 +3606,11 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.HasIndex("LegPosition")
.HasDatabaseName("IX_User_LegPosition");
b.HasIndex("Mobile")
.IsUnique()
.HasDatabaseName("IX_User_Mobile_Active")
.HasFilter("[IsDeleted] = 0");
b.HasIndex("NetworkParentId")
.HasDatabaseName("IX_User_NetworkParentId");
@@ -3750,6 +3755,47 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.ToTable("UserContracts", "CMS");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserInvitation", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.HasColumnType("nvarchar(max)");
b.Property<long>("InviteeUserId")
.HasColumnType("bigint");
b.Property<long>("InviterUserId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<string>("LastModifiedBy")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("InviteeUserId")
.IsUnique()
.HasDatabaseName("IX_UserInvitations_InviteeUserId");
b.HasIndex("InviterUserId", "Created")
.HasDatabaseName("IX_UserInvitations_InviterUserId_Created");
b.ToTable("UserInvitations", "CMS");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserOrder", b =>
{
b.Property<long>("Id")
@@ -4871,6 +4917,25 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Navigation("User");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserInvitation", b =>
{
b.HasOne("CMSMicroservice.Domain.Entities.User", "Invitee")
.WithMany()
.HasForeignKey("InviteeUserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("CMSMicroservice.Domain.Entities.User", "Inviter")
.WithMany()
.HasForeignKey("InviterUserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Invitee");
b.Navigation("Inviter");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserOrder", b =>
{
b.HasOne("CMSMicroservice.Domain.Entities.Package", "Package")
@@ -1,136 +0,0 @@
-- =============================================
-- Stored Procedure: GetNetworkTree
-- Description: دریافت درخت شبکه باینری با CTE recursive
-- Author: FourSat Team
-- Updated: 2026-04-30 — اضافه کردن IsNewActivation، PackageName، PackageId
-- منطق هفته‌بندی از ActivatedAt به PackagePurchasedAt تغییر کرد
-- =============================================
CREATE OR ALTER PROCEDURE [CMS].[GetNetworkTree]
@RootUserId BIGINT,
@MaxDepth INT = 100,
@IsClubActive BIT = NULL,
@ActivationWeekDefinitionId BIGINT = NULL
AS
BEGIN
SET NOCOUNT ON;
-- تاریخ شروع و پایان هفته فیلتر
DECLARE @WeekStartDate DATETIME = NULL;
DECLARE @WeekEndDate DATETIME = NULL;
IF @ActivationWeekDefinitionId IS NOT NULL
BEGIN
SELECT @WeekStartDate = StartDate, @WeekEndDate = EndDate
FROM [CMS].[WeekDefinitions]
WHERE Id = @ActivationWeekDefinitionId;
END
-- CTE برای پیمایش درخت باینری به صورت recursive
;WITH NetworkTreeCTE AS (
-- Base case: ریشه درخت
SELECT
u.Id AS UserId,
u.Mobile,
u.FirstName,
u.LastName,
u.ReferralCode,
u.LegPosition,
u.NetworkParentId AS ParentId,
0 AS NetworkLevel,
u.Created AS UserCreated
FROM [CMS].[Users] u
WHERE u.Id = @RootUserId
AND u.IsDeleted = 0
UNION ALL
-- Recursive case: فرزندان
SELECT
u.Id AS UserId,
u.Mobile,
u.FirstName,
u.LastName,
u.ReferralCode,
u.LegPosition,
u.NetworkParentId AS ParentId,
parent.NetworkLevel + 1 AS NetworkLevel,
u.Created AS UserCreated
FROM [CMS].[Users] u
INNER JOIN NetworkTreeCTE parent ON u.NetworkParentId = parent.UserId
WHERE u.IsDeleted = 0
AND parent.NetworkLevel < @MaxDepth
)
SELECT
t.UserId,
t.Mobile,
t.FirstName,
t.LastName,
t.ReferralCode,
t.LegPosition,
t.ParentId,
t.NetworkLevel,
cm.ActivatedAt AS ClubActivatedAt,
ISNULL(cm.IsActive, 0) AS IsClubActive,
-- هفته فعال‌سازی بر اساس Cycle جاری (PackagePurchasedAt)
wd.Id AS ActivationWeekDefinitionId,
wd.DisplayName AS ActivationWeekDisplayName,
-- آیا کاربر در هفته هدف Cycle داشته؟
CASE WHEN cc_target.UserId IS NOT NULL THEN 1 ELSE 0 END AS IsActivatedInTargetWeek,
-- نوع فعال‌سازی: 1=جدید، 0=تمدید/خرید مجدد، NULL=بدون Cycle
CASE
WHEN cc_eff.CycleNumber IS NULL THEN NULL
WHEN cc_eff.CycleNumber = 1 THEN 1
ELSE 0
END AS IsNewActivation,
-- نام پکیج موثر (هفته هدف اگر فیلتر باشد، وگرنه پکیج فعلی)
ISNULL(p_eff.Title, '') AS PackageName,
cc_eff.PackageId AS PackageId,
t.UserCreated
FROM NetworkTreeCTE t
LEFT JOIN [CMS].[ClubMemberships] cm ON cm.UserId = t.UserId AND cm.IsDeleted = 0
-- Cycle جاری — برای نمایش هفته و پکیج وقتی فیلتر هفته نیست
OUTER APPLY (
SELECT TOP 1 CycleNumber, PackageId, PackagePurchasedAt
FROM [CMS].[ClubMembershipCycles]
WHERE UserId = t.UserId AND IsCurrentCycle = 1
) cc_current
-- Cycle هفته هدف — برای IsActivatedInTargetWeek و نوع فعال‌سازی
OUTER APPLY (
SELECT TOP 1 UserId, CycleNumber, PackageId
FROM [CMS].[ClubMembershipCycles]
WHERE UserId = t.UserId
AND @WeekStartDate IS NOT NULL
AND PackagePurchasedAt >= @WeekStartDate
AND PackagePurchasedAt < @WeekEndDate
ORDER BY CycleNumber ASC
) cc_target
-- Cycle موثر: اگر هفته فیلتر داریم → cc_target، وگرنه → cc_current
CROSS APPLY (
SELECT
CASE WHEN @WeekStartDate IS NOT NULL AND cc_target.UserId IS NOT NULL
THEN cc_target.CycleNumber ELSE cc_current.CycleNumber END AS CycleNumber,
CASE WHEN @WeekStartDate IS NOT NULL AND cc_target.UserId IS NOT NULL
THEN cc_target.PackageId ELSE cc_current.PackageId END AS PackageId
) cc_eff
-- پکیج موثر
LEFT JOIN [CMS].[Packages] p_eff ON p_eff.Id = cc_eff.PackageId AND p_eff.IsDeleted = 0
-- هفته بر اساس PackagePurchasedAt سایکل جاری
LEFT JOIN [CMS].[WeekDefinitions] wd
ON cc_current.PackagePurchasedAt >= wd.StartDate
AND cc_current.PackagePurchasedAt < wd.EndDate
WHERE (@IsClubActive IS NULL OR ISNULL(cm.IsActive, 0) = @IsClubActive OR t.NetworkLevel = 0)
ORDER BY t.NetworkLevel, t.ParentId, t.LegPosition
OPTION (MAXRECURSION 0);
END
@@ -1,5 +1,6 @@
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System.Collections.Generic;
@@ -13,10 +14,12 @@ namespace CMSMicroservice.Infrastructure.Services;
public class GenerateJwtTokenService : IGenerateJwtToken
{
private readonly IConfiguration _configuration;
private readonly IApplicationDbContext _context;
public GenerateJwtTokenService(IConfiguration configuration)
public GenerateJwtTokenService(IConfiguration configuration, IApplicationDbContext context)
{
_configuration = configuration;
_context = context;
}
public async Task<string> GenerateJwtToken(User user, int? expiryDays = null)
@@ -58,6 +61,10 @@ public class GenerateJwtTokenService : IGenerateJwtToken
claims.Add(new Claim("HasPurchasedPackage",
(user.PackagePurchaseMethod != PackagePurchaseMethod.None).ToString()));
var hasAddress = await _context.UserAddresses
.AnyAsync(a => a.UserId == user.Id && !a.IsDeleted);
claims.Add(new Claim("HasAddress", hasAddress.ToString()));
if (user.UserRoles != null && user.UserRoles.Any())
{
foreach (var userRole in user.UserRoles)
@@ -0,0 +1,35 @@
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Infrastructure.Services.Payment;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace CMSMicroservice.Infrastructure.Services.Payment;
public class PaymentGatewayResolver : IPaymentGatewayResolver
{
private readonly IServiceProvider _serviceProvider;
private readonly IConfiguration _configuration;
public PaymentGatewayResolver(IServiceProvider serviceProvider, IConfiguration configuration)
{
_serviceProvider = serviceProvider;
_configuration = configuration;
}
public IPaymentGatewayService Get(string? provider)
{
var key = Normalize(provider)
?? Normalize(_configuration["PaymentProvider"])
?? "zarinpal";
return key switch
{
"20card" or "twentycard" => _serviceProvider.GetRequiredService<TwentyCardPaymentService>(),
"zarinpal" => _serviceProvider.GetRequiredService<ZarinPalPaymentService>(),
_ => _serviceProvider.GetRequiredService<IPaymentGatewayService>()
};
}
private static string? Normalize(string? value)
=> string.IsNullOrWhiteSpace(value) ? null : value.Trim().ToLowerInvariant();
}
@@ -0,0 +1,306 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using CMSMicroservice.Application.Common.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Infrastructure.Services.Payment;
/// <summary>
/// درگاه پرداخت بیست‌کارت (20Card IPG Merchant API).
/// مبلغ ورودی به تومان است. درخواست‌ها به‌صورت multipart/form-data ارسال می‌شوند.
/// </summary>
public class TwentyCardPaymentService : IPaymentGatewayService
{
private readonly HttpClient _httpClient;
private readonly ILogger<TwentyCardPaymentService> _logger;
private readonly string _terminalId;
private readonly string _terminalUsername;
private readonly string _terminalPassword;
private readonly string _defaultEmail;
private static readonly JsonSerializerOptions JsonOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
public TwentyCardPaymentService(
HttpClient httpClient,
IConfiguration configuration,
ILogger<TwentyCardPaymentService> logger)
{
_httpClient = httpClient;
_logger = logger;
var baseUrl = configuration["TwentyCard:BaseUrl"]
?? throw new InvalidOperationException("TwentyCard:BaseUrl is not configured.");
_terminalId = configuration["TwentyCard:TerminalId"]
?? throw new InvalidOperationException("TwentyCard:TerminalId is not configured.");
_terminalUsername = configuration["TwentyCard:TerminalUsername"]
?? throw new InvalidOperationException("TwentyCard:TerminalUsername is not configured.");
_terminalPassword = configuration["TwentyCard:TerminalPassword"]
?? throw new InvalidOperationException("TwentyCard:TerminalPassword is not configured.");
_defaultEmail = configuration["TwentyCard:DefaultEmail"] ?? "info@kbs2.ir";
_httpClient.BaseAddress = new Uri(baseUrl.TrimEnd('/') + "/");
if (!_httpClient.DefaultRequestHeaders.Contains("Accept"))
_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json");
_logger.LogInformation("TwentyCard payment service initialized. BaseUrl={BaseUrl}", baseUrl);
}
public async Task<PaymentInitiateResult> InitiatePaymentAsync(
PaymentRequest request,
CancellationToken cancellationToken = default)
{
try
{
// ۲۰کارت amount را به ریال می‌گیرد (تومان × ۱۰)
var amountRial = ((long)request.Amount) * 10L;
var amount = amountRial.ToString();
var payerName = string.IsNullOrWhiteSpace(request.Name)
? (string.IsNullOrWhiteSpace(request.Mobile) ? "کاربر" : request.Mobile)
: request.Name.Trim();
var invoice = string.IsNullOrWhiteSpace(request.Invoice)
? request.UserId.ToString()
: request.Invoice;
using var content = BuildForm(new Dictionary<string, string>
{
["terminal_id"] = _terminalId,
["terminal_username"] = _terminalUsername,
["terminal_password"] = _terminalPassword,
["amount"] = amount,
["name"] = payerName,
["mobile"] = request.Mobile ?? string.Empty,
["invoice"] = invoice,
["callback"] = request.CallbackUrl,
["description"] = request.Description ?? string.Empty,
// بدون email درگاه ۲۰کارت به‌جای validation، HTTP 500 برمی‌گرداند
["email"] = ResolveEmail(request.Email)
});
if (!string.IsNullOrWhiteSpace(request.NationalId))
AddFormField(content, "national_id", request.NationalId);
_logger.LogInformation(
"TwentyCard payment request: Amount={AmountToman} Toman ({AmountRial} Rial), User={UserId}, Invoice={Invoice}",
(long)request.Amount, amountRial, request.UserId, invoice);
var response = await _httpClient.PostAsync("api/pgw/merchant/request", content, cancellationToken);
var responseBody = await response.Content.ReadAsStringAsync(cancellationToken);
if (!response.IsSuccessStatusCode)
{
_logger.LogError(
"TwentyCard HTTP error on request: StatusCode={StatusCode}, Body={Body}",
(int)response.StatusCode, responseBody);
return new PaymentInitiateResult
{
IsSuccess = false,
ErrorMessage = $"خطای ارتباط با درگاه ۲۰کارت (HTTP {(int)response.StatusCode})"
};
}
var result = JsonSerializer.Deserialize<TwentyCardRequestResponse>(responseBody, JsonOptions);
var authority = result?.Data?.Authority;
var redirectUrl = result?.Data?.RedirectUrl;
if (string.IsNullOrWhiteSpace(authority) || string.IsNullOrWhiteSpace(redirectUrl))
{
_logger.LogError("TwentyCard request failed. Body={Body}", responseBody);
return new PaymentInitiateResult
{
IsSuccess = false,
ErrorMessage = result?.Message
?? result?.Error?.Message
?? "ایجاد تراکنش ۲۰کارت ناموفق بود"
};
}
return new PaymentInitiateResult
{
IsSuccess = true,
RefId = authority,
GatewayUrl = redirectUrl
};
}
catch (Exception ex)
{
_logger.LogError(ex, "TwentyCard InitiatePayment failed");
return new PaymentInitiateResult
{
IsSuccess = false,
ErrorMessage = "خطا در ارتباط با درگاه ۲۰کارت"
};
}
}
public Task<PaymentVerificationResult> VerifyPaymentAsync(
string refId,
string verificationToken,
CancellationToken cancellationToken = default)
=> throw new NotImplementedException("TwentyCard requires VerifyPaymentAsync with amount.");
public async Task<PaymentVerificationResult> VerifyPaymentAsync(
string refId,
string verificationToken,
decimal amountInToman,
CancellationToken cancellationToken = default)
{
try
{
if (!string.Equals(verificationToken, "OK", StringComparison.OrdinalIgnoreCase))
{
return new PaymentVerificationResult
{
IsSuccess = false,
RefId = refId,
Message = "پرداخت توسط کاربر لغو شد یا ناموفق بود",
VerificationCode = 0
};
}
using var content = BuildForm(new Dictionary<string, string>
{
["terminal_id"] = _terminalId,
["terminal_username"] = _terminalUsername,
["terminal_password"] = _terminalPassword,
["authority"] = refId,
["amount"] = (((long)amountInToman) * 10L).ToString()
});
var response = await _httpClient.PostAsync("api/pgw/merchant/verify", content, cancellationToken);
var responseBody = await response.Content.ReadAsStringAsync(cancellationToken);
_logger.LogInformation(
"TwentyCard verify response: Authority={Authority}, StatusCode={StatusCode}, Body={Body}",
refId, (int)response.StatusCode, responseBody);
var result = JsonSerializer.Deserialize<TwentyCardVerifyResponse>(responseBody, JsonOptions);
var paid = result?.Status?.Paid == true;
var verified = result?.Status?.Verified == true;
var noError = result?.Error != true;
if (response.IsSuccessStatusCode && noError && paid && verified)
{
return new PaymentVerificationResult
{
IsSuccess = true,
RefId = refId,
TrackingCode = refId,
Message = result?.Message ?? "تراکنش با موفقیت تایید شد",
VerificationCode = result?.Code ?? 200
};
}
// Code 103 = already verified — treat as success for idempotency
if (result?.Code == 103)
{
return new PaymentVerificationResult
{
IsSuccess = true,
RefId = refId,
TrackingCode = refId,
Message = result.Message ?? "تراکنش قبلاً تایید شده است",
VerificationCode = 103
};
}
return new PaymentVerificationResult
{
IsSuccess = false,
RefId = refId,
Message = result?.Message ?? "تایید تراکنش ۲۰کارت ناموفق بود",
VerificationCode = result?.Code ?? (int)response.StatusCode
};
}
catch (Exception ex)
{
_logger.LogError(ex, "TwentyCard VerifyPayment failed. Authority={Authority}", refId);
return new PaymentVerificationResult
{
IsSuccess = false,
RefId = refId,
Message = "خطا در تایید تراکنش ۲۰کارت"
};
}
}
public Task<PayoutResult> ProcessPayoutAsync(
PayoutRequest request,
CancellationToken cancellationToken = default)
{
return Task.FromResult(new PayoutResult
{
IsSuccess = false,
Message = "واریز از طریق درگاه ۲۰کارت پشتیبانی نمی‌شود"
});
}
private static MultipartFormDataContent BuildForm(Dictionary<string, string> fields)
{
var form = new MultipartFormDataContent();
foreach (var (key, value) in fields)
AddFormField(form, key, value ?? string.Empty);
return form;
}
/// <summary>
/// شبیه curl --form: بدون Content-Type روی هر part ( بعضی بک‌اندهای PHP با charset=utf-8 می‌شکنند).
/// </summary>
private static void AddFormField(MultipartFormDataContent form, string name, string value)
{
var part = new StringContent(value ?? string.Empty);
part.Headers.ContentType = null;
form.Add(part, name);
}
private string ResolveEmail(string? email)
{
if (!string.IsNullOrWhiteSpace(email) && email.Contains('@', StringComparison.Ordinal))
return email.Trim();
return _defaultEmail;
}
private sealed class TwentyCardRequestResponse
{
public string? Message { get; set; }
public TwentyCardRequestData? Data { get; set; }
public TwentyCardErrorBody? Error { get; set; }
}
private sealed class TwentyCardErrorBody
{
public string? Code { get; set; }
public string? Message { get; set; }
}
private sealed class TwentyCardRequestData
{
[JsonPropertyName("authority")]
public string? Authority { get; set; }
[JsonPropertyName("redirectUrl")]
public string? RedirectUrl { get; set; }
}
private sealed class TwentyCardVerifyResponse
{
public bool Error { get; set; }
public int Code { get; set; }
public string? Message { get; set; }
public TwentyCardVerifyStatus? Status { get; set; }
}
private sealed class TwentyCardVerifyStatus
{
public bool Paid { get; set; }
public bool Verified { get; set; }
}
}
@@ -3,7 +3,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.204</Version>
<Version>0.0.214</Version>
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
@@ -118,6 +118,8 @@ enum DeliveryStatus
DELIVERY_SHIPPED = 2;
DELIVERY_DELIVERED = 3;
DELIVERY_CANCELLED = 4;
DELIVERY_READY_FOR_OFFICE = 5;
DELIVERY_RETURNED = 6;
}
// Get Order By Id
@@ -209,6 +209,11 @@ message NetworkTreeNodeModel
google.protobuf.BoolValue is_new_activation = 22; // true=اولین فعال‌سازی، false=خرید مجدد، null=بدون Cycle
string package_name = 23; // نام پکیج موثر
google.protobuf.Int64Value package_id = 24; // شناسه پکیج
// تعداد اعضای فعال با پکیج جاری در پای چپ/راست (طلایی و نقره‌ای)
int32 gold_left_leg_total = 25;
int32 gold_right_leg_total = 26;
int32 silver_left_leg_total = 27;
int32 silver_right_leg_total = 28;
}
// GetHistory Query
@@ -310,6 +315,7 @@ message GetMyNetworkTreeResponse
// GetMyNetworkStatistics - for frontend customer display
message GetMyNetworkStatisticsResponse
{
// اعضای فعال باشگاه: کل = چپ + راست
int32 total_members = 1;
int32 active_members = 2;
int32 left_leg_count = 3;
@@ -323,6 +329,11 @@ message GetMyNetworkStatisticsResponse
string my_network_leg = 11;
string my_referral_code = 12;
CustomerLastMemberModel last_member = 13;
// تعداد اعضای فعال با پکیج جاری در پای چپ/راست — نوار آمار پایین شجره (D3)
int32 gold_left_leg_total = 14;
int32 gold_right_leg_total = 15;
int32 silver_left_leg_total = 16;
int32 silver_right_leg_total = 17;
}
message CustomerLastMemberModel
@@ -249,6 +249,8 @@ message CustomerPurchasePackageRequest
int64 package_id = 1;
PurchaseMethodEnum purchase_method = 2;
string callback_url = 3;
// "zarinpal" (default) | "20card"
string gateway_provider = 4;
}
message CustomerPurchasePackageResponse
@@ -66,6 +66,7 @@ message PaymentTransactionModel
google.protobuf.Int64Value transaction_id = 13;
string description = 14;
google.protobuf.Timestamp created_at = 15;
string user_full_name = 16;
}
message GetPaymentTransactionSummaryRequest
@@ -102,6 +102,10 @@ enum DeliveryStatus
DeliveryStatus_Delivered = 3;
// مرجوع شده
DeliveryStatus_Returned = 4;
// لغو شده
DeliveryStatus_Cancelled = 5;
// آماده تحویل حضوری در دفتر
DeliveryStatus_ReadyForOfficePickup = 6;
}
enum TransactionType
{
@@ -116,6 +120,7 @@ enum TransactionType
MagicWalletDeposit = 14;
MagicWalletBonus = 15;
CreditWalletCharge = 16;
ManualCreditWalletCharge = 17;
}
enum ContractType
{
@@ -192,6 +192,9 @@ message GetAllTransactionsByFilterResponseModel
messages.TransactionType type = 7;
}
google.protobuf.Timestamp created = 8;
google.protobuf.Int64Value user_id = 9;
string user_full_name = 10;
google.protobuf.StringValue mobile = 11;
}
message GetTransactionSummaryRequest
@@ -115,6 +115,16 @@ service UserContract
};
};
rpc GetMyInvitees(GetMyInviteesRequest) returns (GetMyInviteesResponse){
option (google.api.http) = {
get: "/Customer/GetMyInvitees"
};
};
rpc GetInvitationsByFilter(GetInvitationsByFilterRequest) returns (GetInvitationsByFilterResponse){
option (google.api.http) = {
get: "/GetInvitationsByFilter"
};
};
rpc UploadCustomerAvatar(UploadCustomerAvatarRequest) returns (UploadCustomerAvatarResponse){
option (google.api.http) = {
post: "/Customer/UploadAvatar"
@@ -238,6 +248,8 @@ message GetAllUserByFilterResponseModel
bool sms_notifications = 12;
bool push_notifications = 13;
google.protobuf.Timestamp birth_date = 14;
string default_address = 15;
string default_postal_code = 16;
}
message GetJwtTokenRequest
{
@@ -292,6 +304,8 @@ message VerifyOtpTokenRequest
string purpose = 2;
string code = 3;
google.protobuf.StringValue parent_referral_code = 4;
// شماره موبایل دعوت‌کننده (اختیاری؛ فقط برای ثبت‌نام جدید)
google.protobuf.StringValue inviter_mobile = 5;
}
message VerifyOtpTokenResponse
{
@@ -464,3 +478,78 @@ message UpdateCustomerSettingsRequest
google.protobuf.StringValue time_zone = 6;
google.protobuf.BoolValue two_factor_auth_enabled = 7;
}
// ============= Inviter (دعوت‌کننده) — جدا از معرف شبکه =============
message GetMyInviteesRequest
{
city.PaginationState pagination_state = 1;
// ALL | ACTIVE | INACTIVE — بر اساس ClubMembership.IsActive
google.protobuf.StringValue club_status_filter = 2;
}
message GetMyInviteesResponse
{
city.MetaData meta_data = 1;
repeated InviteeModel invitees = 2;
InviteeStats stats = 3;
}
message InviteeModel
{
int64 user_id = 1;
google.protobuf.StringValue first_name = 2;
google.protobuf.StringValue last_name = 3;
string mobile = 4;
google.protobuf.Timestamp registered_at = 5;
bool is_club_active = 6;
}
message InviteeStats
{
int32 total_invitees = 1;
int32 club_active_count = 2;
int32 club_inactive_count = 3;
}
message GetInvitationsByFilterRequest
{
city.PaginationState pagination_state = 1;
google.protobuf.StringValue sort_by = 2;
GetInvitationsByFilterFilter filter = 3;
}
message GetInvitationsByFilterFilter
{
google.protobuf.StringValue inviter_mobile = 1;
google.protobuf.StringValue inviter_first_name = 2;
google.protobuf.StringValue inviter_last_name = 3;
google.protobuf.StringValue invitee_mobile = 4;
google.protobuf.StringValue invitee_first_name = 5;
google.protobuf.StringValue invitee_last_name = 6;
google.protobuf.BoolValue invitee_club_active = 7;
google.protobuf.Timestamp created_from = 8;
google.protobuf.Timestamp created_to = 9;
}
message GetInvitationsByFilterResponse
{
city.MetaData meta_data = 1;
repeated InvitationReportModel models = 2;
}
message InvitationReportModel
{
int64 id = 1;
int64 inviter_user_id = 2;
google.protobuf.StringValue inviter_first_name = 3;
google.protobuf.StringValue inviter_last_name = 4;
string inviter_mobile = 5;
int64 invitee_user_id = 6;
google.protobuf.StringValue invitee_first_name = 7;
google.protobuf.StringValue invitee_last_name = 8;
string invitee_mobile = 9;
google.protobuf.Timestamp invitee_registered_at = 10;
bool invitee_club_active = 11;
google.protobuf.Timestamp invited_at = 12;
}
@@ -220,6 +220,9 @@ message GetUserOrderResponse
google.protobuf.StringValue user_national_code = 16;
// اطلاعات مالیات بر ارزش افزوده
OrderVATInfo vat_info = 17;
// اطلاعات پستی برای برچسب کارتن
google.protobuf.StringValue postal_code = 18;
google.protobuf.StringValue user_mobile = 19;
}
// اطلاعات مالیات بر ارزش افزوده
@@ -21,6 +21,11 @@ service UserPackagePurchaseContract
get: "/UserPackagePurchase/GetSummary"
};
};
rpc GetCustomerPackagePurchaseRollup(GetCustomerPackagePurchaseRollupRequest) returns (GetCustomerPackagePurchaseRollupResponse){
option (google.api.http) = {
get: "/UserPackagePurchase/GetCustomerRollup"
};
};
}
message GetAllUserPackagePurchaseByFilterRequest
@@ -73,3 +78,51 @@ message GetUserPackagePurchaseSummaryResponse
int64 total_count = 1;
int64 total_amount = 2;
}
message GetCustomerPackagePurchaseRollupRequest
{
messages.PaginationState pagination_state = 1;
GetCustomerPackagePurchaseRollupFilter filter = 2;
}
message GetCustomerPackagePurchaseRollupFilter
{
google.protobuf.Int64Value user_id = 1;
google.protobuf.Int32Value purchase_method = 2;
google.protobuf.Timestamp purchased_from = 3;
google.protobuf.Timestamp purchased_to = 4;
}
message GetCustomerPackagePurchaseRollupResponse
{
messages.MetaData meta_data = 1;
repeated CustomerPackagePurchaseRollupModel models = 2;
}
message CustomerPackagePurchaseRollupModel
{
int64 user_id = 1;
string user_name = 2;
string user_mobile = 3;
int64 first_package_id = 4;
string first_package_name = 5;
int64 first_amount = 6;
google.protobuf.Timestamp first_purchased_at = 7;
int64 last_package_id = 8;
string last_package_name = 9;
int64 last_amount = 10;
google.protobuf.Timestamp last_purchased_at = 11;
int32 last_purchase_method = 12;
int32 purchase_count = 13;
int64 total_amount = 14;
int32 daya_count = 15;
int64 daya_amount = 16;
int32 manual_count = 17;
int64 manual_amount = 18;
int32 gateway_count = 19;
int64 gateway_amount = 20;
}
@@ -125,6 +125,20 @@ service UserWalletContract
body: "*"
};
};
// ============= Admin Manual Credit Charge =============
rpc AdminManualCreditCharge(AdminManualCreditChargeRequest) returns (AdminManualCreditChargeResponse){
option (google.api.http) = {
post: "/Admin/ManualCreditCharge"
body: "*"
};
};
rpc GetManualCreditCharges(GetManualCreditChargesRequest) returns (GetManualCreditChargesResponse){
option (google.api.http) = {
get: "/Admin/GetManualCreditCharges"
};
};
}
message CreateNewUserWalletRequest
{
@@ -324,4 +338,56 @@ message VerifyWalletChargeResponse
{
bool success = 1;
string message = 2;
}
// ============= Admin Manual Credit Charge Messages =============
message AdminManualCreditChargeRequest
{
int64 user_id = 1;
int64 amount = 2; // تومان
google.protobuf.StringValue note = 3;
}
message AdminManualCreditChargeResponse
{
bool success = 1;
string message = 2;
int64 transaction_id = 3;
int64 new_balance = 4;
}
message GetManualCreditChargesRequest
{
messages.PaginationState pagination_state = 1;
google.protobuf.StringValue sort_by = 2;
GetManualCreditChargesFilter filter = 3;
}
message GetManualCreditChargesFilter
{
google.protobuf.Int64Value user_id = 1;
google.protobuf.Int64Value transaction_id = 2;
google.protobuf.StringValue ref_id = 3;
google.protobuf.Timestamp created_from = 4;
google.protobuf.Timestamp created_to = 5;
}
message GetManualCreditChargesResponse
{
messages.MetaData meta_data = 1;
repeated ManualCreditChargeModel models = 2;
}
message ManualCreditChargeModel
{
int64 transaction_id = 1;
int64 user_id = 2;
string user_name = 3;
int64 amount = 4;
string description = 5;
string ref_id = 6;
int64 new_balance = 7;
google.protobuf.Timestamp created = 8;
google.protobuf.Timestamp payment_date = 9;
}
@@ -95,7 +95,11 @@ public class NetworkMembershipProfile : IRegister
IsActivatedInTargetWeek = node.IsActivatedInTargetWeek,
PackageName = node.PackageName ?? string.Empty,
PackageId = node.PackageId.HasValue ? node.PackageId.Value : null,
IsNewActivation = node.IsNewActivation.HasValue ? node.IsNewActivation.Value : null
IsNewActivation = node.IsNewActivation.HasValue ? node.IsNewActivation.Value : null,
GoldLeftLegTotal = node.GoldLeftLegTotal,
GoldRightLegTotal = node.GoldRightLegTotal,
SilverLeftLegTotal = node.SilverLeftLegTotal,
SilverRightLegTotal = node.SilverRightLegTotal
};
if (parentId.HasValue)
@@ -46,7 +46,8 @@ public class PaymentTransactionProfile : IRegister
.Map(dest => dest.OrderId, src => src.OrderId ?? string.Empty)
.Map(dest => dest.TransactionId, src => src.TransactionId)
.Map(dest => dest.Description, src => src.Description ?? string.Empty)
.Map(dest => dest.CreatedAt, src => Timestamp.FromDateTimeOffset(src.Created));
.Map(dest => dest.CreatedAt, src => Timestamp.FromDateTimeOffset(src.Created))
.Map(dest => dest.UserFullName, src => src.UserFullName ?? string.Empty);
config.NewConfig<ProtoPt.GetPaymentTransactionSummaryRequest, AppPtSummary.GetPaymentTransactionSummaryQuery>()
.Map(dest => dest.Filter, src => src.Filter);
@@ -40,7 +40,10 @@ public class TransactionsProfile : IRegister
.Map(dest => dest.PaymentDate, src => src.PaymentDate.HasValue ? Timestamp.FromDateTime(DateTime.SpecifyKind(src.PaymentDate.Value, DateTimeKind.Utc)) : null)
.Map(dest => dest.RefId, src => src.RefId)
.Map(dest => dest.Type, src => src.Type)
.Map(dest => dest.Created, src => Timestamp.FromDateTime(DateTime.SpecifyKind(src.Created, DateTimeKind.Utc)));
.Map(dest => dest.Created, src => Timestamp.FromDateTime(DateTime.SpecifyKind(src.Created, DateTimeKind.Utc)))
.Map(dest => dest.UserId, src => src.UserId)
.Map(dest => dest.UserFullName, src => src.UserFullName ?? string.Empty)
.Map(dest => dest.Mobile, src => src.Mobile);
config.NewConfig<ProtoTx.GetTransactionSummaryRequest, AppTxSummary.GetTransactionSummaryQuery>()
.Map(dest => dest.Filter, src => src.Filter);
@@ -3,6 +3,7 @@ using CMSMicroservice.Domain.Enums;
using Mapster;
using AppUp = CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetAllUserPackagePurchaseByFilter;
using AppUpSummary = CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetUserPackagePurchaseSummary;
using AppRollup = CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetCustomerPackagePurchaseRollup;
using ProtoUp = CMSMicroservice.Protobuf.Protos.UserPackagePurchase;
namespace CMSMicroservice.WebApi.Common.Mappings;
@@ -49,5 +50,41 @@ public class UserPackagePurchaseProfile : IRegister
config.NewConfig<AppUpSummary.GetUserPackagePurchaseSummaryResponseDto, ProtoUp.GetUserPackagePurchaseSummaryResponse>()
.Map(dest => dest.TotalCount, src => src.TotalCount)
.Map(dest => dest.TotalAmount, src => src.TotalAmount);
config.NewConfig<ProtoUp.GetCustomerPackagePurchaseRollupRequest, AppRollup.GetCustomerPackagePurchaseRollupQuery>()
.Map(dest => dest.PaginationState, src => src.PaginationState)
.Map(dest => dest.Filter, src => src.Filter);
config.NewConfig<ProtoUp.GetCustomerPackagePurchaseRollupFilter, AppRollup.GetCustomerPackagePurchaseRollupFilter>()
.Map(dest => dest.UserId, src => src.UserId)
.Map(dest => dest.PurchaseMethod, src => src.PurchaseMethod == null ? null : (PackagePurchaseMethod?)src.PurchaseMethod)
.Map(dest => dest.PurchasedFrom, src => src.PurchasedFrom != null ? src.PurchasedFrom.ToDateTime() : (DateTime?)null)
.Map(dest => dest.PurchasedTo, src => src.PurchasedTo != null ? src.PurchasedTo.ToDateTime() : (DateTime?)null);
config.NewConfig<AppRollup.GetCustomerPackagePurchaseRollupResponseDto, ProtoUp.GetCustomerPackagePurchaseRollupResponse>()
.Map(dest => dest.MetaData, src => src.MetaData)
.Map(dest => dest.Models, src => src.Models);
config.NewConfig<AppRollup.CustomerPackagePurchaseRollupModel, ProtoUp.CustomerPackagePurchaseRollupModel>()
.Map(dest => dest.UserId, src => src.UserId)
.Map(dest => dest.UserName, src => src.UserName)
.Map(dest => dest.UserMobile, src => src.UserMobile)
.Map(dest => dest.FirstPackageId, src => src.FirstPackageId)
.Map(dest => dest.FirstPackageName, src => src.FirstPackageName)
.Map(dest => dest.FirstAmount, src => src.FirstAmount)
.Map(dest => dest.FirstPurchasedAt, src => Timestamp.FromDateTime(DateTime.SpecifyKind(src.FirstPurchasedAt, DateTimeKind.Utc)))
.Map(dest => dest.LastPackageId, src => src.LastPackageId)
.Map(dest => dest.LastPackageName, src => src.LastPackageName)
.Map(dest => dest.LastAmount, src => src.LastAmount)
.Map(dest => dest.LastPurchasedAt, src => Timestamp.FromDateTime(DateTime.SpecifyKind(src.LastPurchasedAt, DateTimeKind.Utc)))
.Map(dest => dest.LastPurchaseMethod, src => (int)src.LastPurchaseMethod)
.Map(dest => dest.PurchaseCount, src => src.PurchaseCount)
.Map(dest => dest.TotalAmount, src => src.TotalAmount)
.Map(dest => dest.DayaCount, src => src.DayaCount)
.Map(dest => dest.DayaAmount, src => src.DayaAmount)
.Map(dest => dest.ManualCount, src => src.ManualCount)
.Map(dest => dest.ManualAmount, src => src.ManualAmount)
.Map(dest => dest.GatewayCount, src => src.GatewayCount)
.Map(dest => dest.GatewayAmount, src => src.GatewayAmount);
}
}
@@ -4,7 +4,10 @@ public class UserProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
//config.NewConfig<Source,Destination>()
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
config.NewConfig<Application.UserCQ.Queries.GetAllUserByFilter.GetAllUserByFilterResponseModel,
CMSMicroservice.Protobuf.Protos.User.GetAllUserByFilterResponseModel>()
.Map(dest => dest.ParentId, src => src.NetworkParentId)
.Map(dest => dest.DefaultAddress, src => src.DefaultAddress ?? string.Empty)
.Map(dest => dest.DefaultPostalCode, src => src.DefaultPostalCode ?? string.Empty);
}
}
+2 -2
View File
@@ -1,12 +1,12 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM 194.5.195.53:32082/dotnet/aspnet:9.0 AS base
FROM 185.252.31.44:32082/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM 194.5.195.53:32082/dotnet/sdk:9.0 AS build
FROM 185.252.31.44:32082/dotnet/sdk:9.0 AS build
WORKDIR /src
COPY ["CMSMicroservice.WebApi/CMSMicroservice.WebApi.csproj", "CMSMicroservice.WebApi/"]
COPY ["CMSMicroservice.Application/CMSMicroservice.Application.csproj", "CMSMicroservice.Application/"]
@@ -99,7 +99,20 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
public override async Task<UpdateOrderStatusResponse> UpdateOrderStatus(UpdateOrderStatusRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<UpdateOrderStatusRequest, UpdateOrderStatusCommand, UpdateOrderStatusResponse>(request, context);
// Proto DeliveryStatus ≠ Domain DeliveryStatus — نگاشت صریح لازم است
var command = new UpdateOrderStatusCommand
{
OrderId = request.OrderId,
DeliveryStatus = MapProtoDeliveryToDomain(request.DeliveryStatus),
TrackingCode = request.TrackingCode,
AdminNotes = request.AdminNotes
};
var result = await _sender.Send(command, context.CancellationToken);
return new UpdateOrderStatusResponse
{
Success = result.Success,
Message = result.Message ?? string.Empty
};
}
public override async Task<GetOrderByIdResponse> GetOrderById(GetOrderByIdRequest request, ServerCallContext context)
@@ -141,6 +154,8 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
Address = result.Address.Address ?? "",
PostalCode = result.Address.PostalCode ?? ""
};
if (!string.IsNullOrWhiteSpace(result.Address.Phone))
response.Address.Phone = result.Address.Phone;
}
foreach (var item in result.Items)
@@ -197,9 +212,98 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
return response;
}
public override async Task<GetAllDiscountOrdersResponse> GetAllDiscountOrders(GetAllDiscountOrdersRequest request, ServerCallContext context)
public override async Task<GetAllDiscountOrdersResponse> GetAllDiscountOrders(
GetAllDiscountOrdersRequest request, ServerCallContext context)
{
return await _dispatchRequestToCQRS.Handle<GetAllDiscountOrdersRequest, GetAllDiscountOrdersQuery, GetAllDiscountOrdersResponse>(request, context);
// Proto PaymentStatus ≠ Domain PaymentStatus (مقادیر int متفاوت) — Adapt خام باعث باگ لیست/فیلتر می‌شود
if (request.PaymentStatus is 3) // PAYMENT_REFUNDED — در دامنه وجود ندارد
{
return new GetAllDiscountOrdersResponse
{
MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
{
TotalCount = 0,
PageSize = request.PageSize > 0 ? request.PageSize : 20,
CurrentPage = request.PageNumber > 0 ? request.PageNumber : 1,
TotalPage = 0
}
};
}
var query = new GetAllDiscountOrdersQuery
{
PaginationQuery = new Application.Common.Models.PaginationState
{
PageNumber = request.PageNumber > 0 ? request.PageNumber : 1,
PageSize = request.PageSize > 0 ? request.PageSize : 20
},
UserId = request.UserId,
UserMobile = request.UserMobile,
TrackingCode = request.TrackingCode,
FromDate = request.FromDate?.ToDateTime(),
ToDate = request.ToDate?.ToDateTime(),
MinAmount = request.MinAmount,
MaxAmount = request.MaxAmount
};
if (request.PaymentStatus is int paymentStatus)
query.PaymentStatus = MapProtoPaymentFilterToDomain(paymentStatus);
if (request.DeliveryStatus is int deliveryStatus)
query.DeliveryStatus = MapProtoDeliveryFilterToDomain(deliveryStatus);
var result = await _sender.Send(query, context.CancellationToken);
var response = new GetAllDiscountOrdersResponse
{
MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
{
TotalCount = result.MetaData.TotalCount,
PageSize = result.MetaData.PageSize,
CurrentPage = result.MetaData.CurrentPage,
TotalPage = result.MetaData.TotalPage,
HasPrevious = result.MetaData.HasPrevious,
HasNext = result.MetaData.HasNext
}
};
foreach (var o in result.Models)
{
var model = new CMSMicroservice.Protobuf.Protos.DiscountOrder.AdminOrderDto
{
Id = o.Id,
UserId = o.UserId,
UserFullName = o.UserFullName ?? string.Empty,
UserMobile = o.UserMobile ?? string.Empty,
TotalAmount = o.TotalAmount,
DiscountBalanceUsed = o.DiscountBalanceUsed,
GatewayAmountPaid = o.GatewayAmountPaid,
VatAmount = o.VatAmount,
PaymentStatus = MapPaymentStatus(o.PaymentStatus),
DeliveryStatus = MapDeliveryStatus(o.DeliveryStatus),
ItemsCount = o.ItemsCount,
Created = Timestamp.FromDateTime(DateTime.SpecifyKind(o.Created, DateTimeKind.Utc))
};
if (o.PaymentDate.HasValue)
model.PaymentDate = Timestamp.FromDateTime(DateTime.SpecifyKind(o.PaymentDate.Value, DateTimeKind.Utc));
if (o.LastModified.HasValue)
model.LastModified = Timestamp.FromDateTime(DateTime.SpecifyKind(o.LastModified.Value, DateTimeKind.Utc));
if (!string.IsNullOrWhiteSpace(o.ShippingAddress))
model.ShippingAddress = o.ShippingAddress;
if (!string.IsNullOrWhiteSpace(o.ReceiverName))
model.ReceiverName = o.ReceiverName;
if (!string.IsNullOrWhiteSpace(o.ReceiverMobile))
model.ReceiverMobile = o.ReceiverMobile;
if (!string.IsNullOrWhiteSpace(o.TrackingCode))
model.TrackingCode = o.TrackingCode;
if (!string.IsNullOrWhiteSpace(o.AdminNote))
model.AdminNote = o.AdminNote;
response.Models.Add(model);
}
return response;
}
public override async Task<GetDiscountSalesReportResponse> GetDiscountSalesReport(GetDiscountSalesReportRequest request, ServerCallContext context)
@@ -359,14 +463,50 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
_ => CMSMicroservice.Protobuf.Protos.DiscountOrder.PaymentStatus.PaymentPending
};
/// <summary>
/// فیلتر UI/proto → دامنه: PENDING=0, COMPLETED=1, FAILED=2
/// </summary>
private static DomainEnums.PaymentStatus MapProtoPaymentFilterToDomain(int protoPaymentStatus) => protoPaymentStatus switch
{
1 => DomainEnums.PaymentStatus.Success, // PAYMENT_COMPLETED
2 => DomainEnums.PaymentStatus.Reject, // PAYMENT_FAILED
_ => DomainEnums.PaymentStatus.Pending // PAYMENT_PENDING (0) و پیش‌فرض
};
private static DeliveryStatus MapDeliveryStatus(DomainEnums.DeliveryStatus status) => status switch
{
DomainEnums.DeliveryStatus.None => DeliveryStatus.DeliveryPending,
DomainEnums.DeliveryStatus.Pending => DeliveryStatus.DeliveryProcessing,
DomainEnums.DeliveryStatus.InTransit => DeliveryStatus.DeliveryShipped,
DomainEnums.DeliveryStatus.Delivered => DeliveryStatus.DeliveryDelivered,
DomainEnums.DeliveryStatus.Returned => DeliveryStatus.DeliveryCancelled,
DomainEnums.DeliveryStatus.Cancelled => DeliveryStatus.DeliveryCancelled,
DomainEnums.DeliveryStatus.ReadyForOfficePickup => DeliveryStatus.DeliveryReadyForOffice,
DomainEnums.DeliveryStatus.Returned => DeliveryStatus.DeliveryReturned,
_ => DeliveryStatus.DeliveryPending
};
/// <summary>
/// فیلتر UI/proto → دامنه DeliveryStatus
/// </summary>
private static DomainEnums.DeliveryStatus MapProtoDeliveryFilterToDomain(int protoDeliveryStatus) => protoDeliveryStatus switch
{
1 => DomainEnums.DeliveryStatus.Pending, // DELIVERY_PROCESSING
2 => DomainEnums.DeliveryStatus.InTransit, // DELIVERY_SHIPPED
3 => DomainEnums.DeliveryStatus.Delivered, // DELIVERY_DELIVERED
4 => DomainEnums.DeliveryStatus.Cancelled, // DELIVERY_CANCELLED
5 => DomainEnums.DeliveryStatus.ReadyForOfficePickup, // DELIVERY_READY_FOR_OFFICE
6 => DomainEnums.DeliveryStatus.Returned, // DELIVERY_RETURNED
_ => DomainEnums.DeliveryStatus.None // DELIVERY_PENDING (0)
};
private static DomainEnums.DeliveryStatus MapProtoDeliveryToDomain(DeliveryStatus status) => status switch
{
DeliveryStatus.DeliveryProcessing => DomainEnums.DeliveryStatus.Pending,
DeliveryStatus.DeliveryShipped => DomainEnums.DeliveryStatus.InTransit,
DeliveryStatus.DeliveryDelivered => DomainEnums.DeliveryStatus.Delivered,
DeliveryStatus.DeliveryCancelled => DomainEnums.DeliveryStatus.Cancelled,
DeliveryStatus.DeliveryReadyForOffice => DomainEnums.DeliveryStatus.ReadyForOfficePickup,
DeliveryStatus.DeliveryReturned => DomainEnums.DeliveryStatus.Returned,
_ => DomainEnums.DeliveryStatus.None
};
}
@@ -185,6 +185,11 @@ public class NetworkMembershipService : NetworkMembershipContract.NetworkMembers
node.PackageId = dto.PackageId.Value;
}
node.GoldLeftLegTotal = dto.GoldLeftLegTotal;
node.GoldRightLegTotal = dto.GoldRightLegTotal;
node.SilverLeftLegTotal = dto.SilverLeftLegTotal;
node.SilverRightLegTotal = dto.SilverRightLegTotal;
if (dto.IsNewActivation.HasValue)
{
node.IsNewActivation = dto.IsNewActivation.Value;
@@ -32,7 +32,7 @@ public class PackageService : PackageContract.PackageContractBase
private readonly ISender _sender;
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUserService;
private readonly IPaymentGatewayService _paymentGateway;
private readonly IPaymentGatewayResolver _paymentGatewayResolver;
private readonly IConfiguration _configuration;
private readonly IUserPaymentLock _paymentLock;
@@ -41,7 +41,7 @@ public class PackageService : PackageContract.PackageContractBase
ISender sender,
IApplicationDbContext context,
ICurrentUserService currentUserService,
IPaymentGatewayService paymentGateway,
IPaymentGatewayResolver paymentGatewayResolver,
IConfiguration configuration,
IUserPaymentLock paymentLock)
{
@@ -49,7 +49,7 @@ public class PackageService : PackageContract.PackageContractBase
_sender = sender;
_context = context;
_currentUserService = currentUserService;
_paymentGateway = paymentGateway;
_paymentGatewayResolver = paymentGatewayResolver;
_configuration = configuration;
_paymentLock = paymentLock;
}
@@ -171,19 +171,38 @@ public class PackageService : PackageContract.PackageContractBase
if (package == null)
throw new RpcException(new Status(StatusCode.NotFound, "پکیج مورد نظر یافت نشد"));
// Create transaction
var gatewayProvider = NormalizeGatewayProvider(request.GatewayProvider);
var isTwentyCard = gatewayProvider == "20card";
long gatewayAmount = package.Price;
if (isTwentyCard)
{
var packageKey = $"TwentyCard:Packages:{package.Id}";
gatewayAmount = _configuration.GetValue<long?>($"{packageKey}:GatewayAmountToman") ?? 0;
var walletCredit = _configuration.GetValue<long?>($"{packageKey}:WalletCreditToman") ?? 0;
if (gatewayAmount <= 0 || walletCredit <= 0)
{
throw new RpcException(new Status(
StatusCode.FailedPrecondition,
"پرداخت ۲۰کارت برای این پکیج پیکربندی نشده است"));
}
}
// Create transaction — 20card: Amount = gateway charge; zarinpal: Package.Price
var transaction = new CMSMicroservice.Domain.Entities.Transaction
{
Amount = package.Price,
Description = $"خرید پکیج {package.Title}",
Amount = gatewayAmount,
Description = isTwentyCard
? $"خرید پکیج {package.Title} (۲۰کارت)"
: $"خرید پکیج {package.Title}",
PaymentStatus = Domain.Enums.PaymentStatus.Pending,
Type = Domain.Enums.TransactionType.Buy
};
_context.Transactions.Add(transaction);
await _context.SaveChangesAsync(cancellationToken);
// Create purchase record
// Create purchase record — UPP.Amount always Package.Price (catalog)
var purchaseMethod = request.PurchaseMethod == PurchaseMethodEnum.PurchaseMethodGateway
? Domain.Enums.PackagePurchaseMethod.DirectPurchase
: Domain.Enums.PackagePurchaseMethod.DayaLoan;
@@ -204,20 +223,32 @@ public class PackageService : PackageContract.PackageContractBase
var user = await _context.Users
.AsNoTracking()
.Where(u => u.Id == userId)
.Select(u => new { u.Mobile })
.Select(u => new { u.Mobile, u.FirstName, u.LastName, u.Email, u.NationalCode })
.FirstOrDefaultAsync(cancellationToken);
// Callback URL از config — نه از ورودی کاربر (امنیت)
var frontOfficeBaseUrl = _configuration["FrontOfficeBaseUrl"] ?? "https://localhost:5268";
var callbackUrl = $"{frontOfficeBaseUrl}/profile/payment-callback?orderId={purchase.Id}";
// ۲۰کارت: CallbackBaseUrl اختیاری (مثلاً استیج → kbs2.ir چون دامنه استیج در ترمینال ثبت نیست)
var frontOfficeBaseUrl = isTwentyCard
? (_configuration["TwentyCard:CallbackBaseUrl"]
?? _configuration["FrontOfficeBaseUrl"]
?? "https://localhost:5268")
: (_configuration["FrontOfficeBaseUrl"] ?? "https://localhost:5268");
var callbackUrl = $"{frontOfficeBaseUrl.TrimEnd('/')}/profile/payment-callback?orderId={purchase.Id}";
var paymentGateway = _paymentGatewayResolver.Get(gatewayProvider);
var payerName = $"{user?.FirstName} {user?.LastName}".Trim();
var paymentResult = await _paymentGateway.InitiatePaymentAsync(new PaymentRequest
var paymentResult = await paymentGateway.InitiatePaymentAsync(new PaymentRequest
{
Amount = package.Price,
Amount = gatewayAmount,
UserId = userId,
Mobile = user?.Mobile ?? string.Empty,
Name = payerName,
Invoice = purchase.Id.ToString(),
Description = $"خرید پکیج {package.Title}",
CallbackUrl = callbackUrl
CallbackUrl = callbackUrl,
Email = user?.Email,
NationalId = user?.NationalCode
}, cancellationToken);
if (!paymentResult.IsSuccess)
@@ -235,12 +266,14 @@ public class PackageService : PackageContract.PackageContractBase
// Save RefId
transaction.RefId = paymentResult.RefId;
// ثبت PaymentTransaction
// ثبت PaymentTransaction — Amount = gateway amount
var paymentTx = new PaymentTransaction
{
GatewayProvider = _configuration["PaymentProvider"] ?? "zarinpal",
MerchantId = _configuration["ZarinPal:MerchantId"] ?? "",
Amount = package.Price,
GatewayProvider = gatewayProvider,
MerchantId = isTwentyCard
? (_configuration["TwentyCard:TerminalId"] ?? "")
: (_configuration["ZarinPal:MerchantId"] ?? ""),
Amount = gatewayAmount,
CallbackUrl = callbackUrl,
Description = $"خرید پکیج {package.Title}",
Mobile = user?.Mobile,
@@ -264,6 +297,14 @@ public class PackageService : PackageContract.PackageContractBase
Authority = paymentResult.RefId ?? string.Empty
};
}
private static string NormalizeGatewayProvider(string? provider)
{
if (string.IsNullOrWhiteSpace(provider))
return "zarinpal";
var key = provider.Trim().ToLowerInvariant();
return key is "20card" or "twentycard" ? "20card" : "zarinpal";
}
public override async Task<CustomerVerifyPackagePurchaseResponse> CustomerVerifyPackagePurchase(
CustomerVerifyPackagePurchaseRequest request,
@@ -121,7 +121,9 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
TrackingCode = result.TrackingCode,
DeliveryDescription = result.DeliveryDescription,
UserFullName = result.UserFullName,
UserNationalCode = result.UserNationalCode
UserNationalCode = result.UserNationalCode,
PostalCode = result.PostalCode,
UserMobile = result.UserMobile
};
// VAT Info
@@ -789,7 +791,9 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
TrackingCode = result.TrackingCode,
DeliveryDescription = result.DeliveryDescription,
UserFullName = result.UserFullName,
UserNationalCode = result.UserNationalCode
UserNationalCode = result.UserNationalCode,
PostalCode = result.PostalCode,
UserMobile = result.UserMobile
};
// VAT Info
@@ -1054,6 +1058,7 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
Domain.Enums.DeliveryStatus.Delivered => "تحویل داده شده",
Domain.Enums.DeliveryStatus.Returned => "مرجوع شده",
Domain.Enums.DeliveryStatus.Cancelled => "لغو شده",
Domain.Enums.DeliveryStatus.ReadyForOfficePickup => "آماده تحویل در دفتر",
_ => status.ToString()
};
}
@@ -2,6 +2,7 @@ using CMSMicroservice.Protobuf.Protos.UserPackagePurchase;
using CMSMicroservice.WebApi.Common.Services;
using CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetAllUserPackagePurchaseByFilter;
using CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetUserPackagePurchaseSummary;
using CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetCustomerPackagePurchaseRollup;
namespace CMSMicroservice.WebApi.Services;
@@ -18,4 +19,8 @@ public class UserPackagePurchaseService : UserPackagePurchaseContract.UserPackag
public override Task<GetUserPackagePurchaseSummaryResponse> GetUserPackagePurchaseSummary(
GetUserPackagePurchaseSummaryRequest request, ServerCallContext context) =>
_dispatch.Handle<GetUserPackagePurchaseSummaryRequest, GetUserPackagePurchaseSummaryQuery, GetUserPackagePurchaseSummaryResponse>(request, context);
public override Task<GetCustomerPackagePurchaseRollupResponse> GetCustomerPackagePurchaseRollup(
GetCustomerPackagePurchaseRollupRequest request, ServerCallContext context) =>
_dispatch.Handle<GetCustomerPackagePurchaseRollupRequest, GetCustomerPackagePurchaseRollupQuery, GetCustomerPackagePurchaseRollupResponse>(request, context);
}
@@ -15,8 +15,11 @@ using CMSMicroservice.Application.UserCQ.Commands.VerifyOtpToken;
using CMSMicroservice.Application.UserCQ.Commands.AcceptContract;
using CMSMicroservice.Application.UserCQ.Queries.GetCustomerProfile;
using CMSMicroservice.Application.UserCQ.Queries.GetCustomerReferrals;
using CMSMicroservice.Application.UserCQ.Queries.GetMyInvitees;
using CMSMicroservice.Application.UserCQ.Queries.GetInvitationsByFilter;
using CMSMicroservice.Application.UserCQ.Queries.GetCustomerSettings;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Authorization;
using Google.Protobuf.WellKnownTypes;
using Microsoft.EntityFrameworkCore;
using Grpc.Core;
@@ -312,6 +315,117 @@ public class UserService : UserContract.UserContractBase
return response;
}
public override async Task<GetMyInviteesResponse> GetMyInvitees(
GetMyInviteesRequest request,
ServerCallContext context)
{
var result = await _sender.Send(new GetMyInviteesQuery
{
UserId = 0,
PaginationState = request.PaginationState?.Adapt<AppModels.PaginationState>(),
ClubStatusFilter = request.ClubStatusFilter
}, context.CancellationToken);
var response = new GetMyInviteesResponse
{
MetaData = new MetaData
{
CurrentPage = result.MetaData.CurrentPage,
TotalPage = result.MetaData.TotalPage,
PageSize = result.MetaData.PageSize,
TotalCount = result.MetaData.TotalCount,
HasPrevious = result.MetaData.HasPrevious,
HasNext = result.MetaData.HasNext
},
Stats = new InviteeStats
{
TotalInvitees = result.Stats.TotalInvitees,
ClubActiveCount = result.Stats.ClubActiveCount,
ClubInactiveCount = result.Stats.ClubInactiveCount
}
};
foreach (var item in result.Invitees)
{
response.Invitees.Add(new InviteeModel
{
UserId = item.UserId,
FirstName = item.FirstName,
LastName = item.LastName,
Mobile = item.Mobile,
RegisteredAt = Timestamp.FromDateTime(DateTime.SpecifyKind(item.RegisteredAt, DateTimeKind.Utc)),
IsClubActive = item.IsClubActive
});
}
return response;
}
[RequiresPermission(PermissionNames.UsersView)]
public override async Task<GetInvitationsByFilterResponse> GetInvitationsByFilter(
GetInvitationsByFilterRequest request,
ServerCallContext context)
{
DateTime? createdFrom = null;
DateTime? createdTo = null;
if (request.Filter?.CreatedFrom != null)
createdFrom = request.Filter.CreatedFrom.ToDateTime();
if (request.Filter?.CreatedTo != null)
createdTo = request.Filter.CreatedTo.ToDateTime();
var result = await _sender.Send(new GetInvitationsByFilterQuery
{
PaginationState = request.PaginationState?.Adapt<AppModels.PaginationState>(),
SortBy = request.SortBy,
Filter = request.Filter == null ? null : new GetInvitationsByFilterFilterDto
{
InviterMobile = request.Filter.InviterMobile,
InviterFirstName = request.Filter.InviterFirstName,
InviterLastName = request.Filter.InviterLastName,
InviteeMobile = request.Filter.InviteeMobile,
InviteeFirstName = request.Filter.InviteeFirstName,
InviteeLastName = request.Filter.InviteeLastName,
InviteeClubActive = request.Filter.InviteeClubActive,
CreatedFrom = createdFrom,
CreatedTo = createdTo
}
}, context.CancellationToken);
var response = new GetInvitationsByFilterResponse
{
MetaData = new MetaData
{
CurrentPage = result.MetaData.CurrentPage,
TotalPage = result.MetaData.TotalPage,
PageSize = result.MetaData.PageSize,
TotalCount = result.MetaData.TotalCount,
HasPrevious = result.MetaData.HasPrevious,
HasNext = result.MetaData.HasNext
}
};
foreach (var m in result.Models)
{
response.Models.Add(new InvitationReportModel
{
Id = m.Id,
InviterUserId = m.InviterUserId,
InviterFirstName = m.InviterFirstName,
InviterLastName = m.InviterLastName,
InviterMobile = m.InviterMobile,
InviteeUserId = m.InviteeUserId,
InviteeFirstName = m.InviteeFirstName,
InviteeLastName = m.InviteeLastName,
InviteeMobile = m.InviteeMobile,
InviteeRegisteredAt = Timestamp.FromDateTime(DateTime.SpecifyKind(m.InviteeRegisteredAt, DateTimeKind.Utc)),
InviteeClubActive = m.InviteeClubActive,
InvitedAt = Timestamp.FromDateTime(DateTime.SpecifyKind(m.InvitedAt, DateTimeKind.Utc))
});
}
return response;
}
public override async Task<UploadCustomerAvatarResponse> UploadCustomerAvatar(UploadCustomerAvatarRequest request, ServerCallContext context)
{
if (request.FileData == null || request.FileData.Length == 0)
@@ -9,12 +9,16 @@ using CMSMicroservice.Application.WalletCQ.Commands.ChargeCreditWallet;
using CMSMicroservice.Application.WalletCQ.Commands.VerifyMagicWalletCharge;
using CMSMicroservice.Application.WalletCQ.Commands.VerifyDiscountWalletCharge;
using CMSMicroservice.Application.WalletCQ.Commands.VerifyCreditWalletCharge;
using CMSMicroservice.Application.WalletCQ.Commands.AdminManualCreditCharge;
using CMSMicroservice.Application.WalletCQ.Queries.GetManualCreditCharges;
using AppManualChargeFilter = CMSMicroservice.Application.WalletCQ.Queries.GetManualCreditCharges.GetManualCreditChargesFilter;
using CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
using CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWalletHistory;
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawals;
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawalSettings;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common;
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Domain.Common;
using CMSMicroservice.Domain.Enums;
@@ -172,7 +176,18 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
// Update payout with withdrawal info
payout.WithdrawalMethod = (Domain.Enums.WithdrawalMethod)request.WithdrawalMethod;
payout.IbanNumber = request.IbanNumber;
if (payout.WithdrawalMethod == Domain.Enums.WithdrawalMethod.Cash)
{
var normalizedIban = IbanNormalizer.TryNormalize(request.IbanNumber);
if (normalizedIban is null)
throw new RpcException(new Status(StatusCode.InvalidArgument,
"فرمت شماره شبا معتبر نیست. باید IR و ۲۴ رقم باشد."));
payout.IbanNumber = normalizedIban;
}
else
{
payout.IbanNumber = null;
}
payout.Status = Domain.Enums.CommissionPayoutStatus.WithdrawRequested;
await _context.SaveChangesAsync(context.CancellationToken);
@@ -274,6 +289,14 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
ErrorMessage = ex.Message
};
}
catch (BadRequestException ex)
{
return new InitiateCreditChargeResponse
{
IsSuccess = false,
ErrorMessage = ex.Message
};
}
}
// ============= Wallet Verify Methods =============
@@ -518,4 +541,116 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
MinWithdrawalAmount = settings.MinWithdrawalAmount
};
}
// ============= Admin Manual Credit Charge =============
public override async Task<AdminManualCreditChargeResponse> AdminManualCreditCharge(
AdminManualCreditChargeRequest request, ServerCallContext context)
{
try
{
var result = await _sender.Send(new AdminManualCreditChargeCommand
{
UserId = request.UserId,
Amount = request.Amount,
Note = request.Note,
PerformedByAdminId = _currentUserService.GetPerformedBy()
}, context.CancellationToken);
return new AdminManualCreditChargeResponse
{
Success = result.Success,
Message = result.Message ?? string.Empty,
TransactionId = result.TransactionId,
NewBalance = result.NewBalance
};
}
catch (PaymentInProgressException ex)
{
return new AdminManualCreditChargeResponse
{
Success = false,
Message = ex.Message
};
}
catch (NotFoundException ex)
{
return new AdminManualCreditChargeResponse
{
Success = false,
Message = ex.Message
};
}
catch (Exception ex)
{
_logger.LogError(ex, "AdminManualCreditCharge failed for UserId={UserId}", request.UserId);
return new AdminManualCreditChargeResponse
{
Success = false,
Message = ex.Message
};
}
}
public override async Task<GetManualCreditChargesResponse> GetManualCreditCharges(
GetManualCreditChargesRequest request, ServerCallContext context)
{
var result = await _sender.Send(new GetManualCreditChargesQuery
{
SortBy = request.SortBy,
PaginationState = request.PaginationState != null
? new Application.Common.Models.PaginationState
{
PageNumber = request.PaginationState.PageNumber,
PageSize = request.PaginationState.PageSize
}
: new Application.Common.Models.PaginationState { PageNumber = 1, PageSize = 20 },
Filter = new AppManualChargeFilter
{
UserId = request.Filter?.UserId,
TransactionId = request.Filter?.TransactionId,
RefId = request.Filter?.RefId,
CreatedFrom = request.Filter?.CreatedFrom?.ToDateTime(),
CreatedTo = request.Filter?.CreatedTo?.ToDateTime()
}
}, context.CancellationToken);
var response = new GetManualCreditChargesResponse
{
MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
{
CurrentPage = result.MetaData.CurrentPage,
TotalPage = result.MetaData.TotalPage,
PageSize = result.MetaData.PageSize,
TotalCount = result.MetaData.TotalCount,
HasPrevious = result.MetaData.HasPrevious,
HasNext = result.MetaData.HasNext
}
};
foreach (var m in result.Models)
{
var model = new ManualCreditChargeModel
{
TransactionId = m.TransactionId,
UserId = m.UserId,
UserName = m.UserName ?? string.Empty,
Amount = m.Amount,
Description = m.Description ?? string.Empty,
RefId = m.RefId ?? string.Empty,
NewBalance = m.NewBalance,
Created = Timestamp.FromDateTime(DateTime.SpecifyKind(m.Created, DateTimeKind.Utc))
};
if (m.PaymentDate.HasValue)
{
model.PaymentDate = Timestamp.FromDateTime(
DateTime.SpecifyKind(m.PaymentDate.Value, DateTimeKind.Utc));
}
response.Models.Add(model);
}
return response;
}
}
@@ -2,16 +2,38 @@
"PaymentProvider": "zarinpal",
"ZarinPal": {
"MerchantId": "4225d555-5fa9-4df0-9b61-1ce152cbbba8",
"UseSandbox": false
"UseSandbox": true
},
"TwentyCard": {
"BaseUrl": "https://gateway.20card.ir/ipg",
"TerminalId": "165674",
"TerminalUsername": "ea5y1biehi",
"TerminalPassword": "SaLamAT@1404!",
"CreditPortalUrl": "https://userpanel.20card.ir/",
"CallbackBaseUrl": "https://kbs2.ir",
"DefaultEmail": "info@kbs2.ir",
"Packages": {
"4": {
"GatewayAmountToman": 11200000,
"WalletCreditToman": 12656000
},
"1": {
"GatewayAmountToman": 11200000,
"WalletCreditToman": 12656000
}
}
},
"CmsBaseUrl": "https://cms.se.kbs1.ir",
"FrontOfficeBaseUrl": "https://frontoffice.se.kbs1.ir",
"FMS": {
"Address": "https://dl.afrino.co"
},
"CmsBaseUrl": "https://cms.kbs2.ir",
"FrontOfficeBaseUrl": "https://kbs2.ir",
"JwtSecurityKey": "TvlZVx5TJaHs8e9HgUdGzhGP2CIidoI444nAj+8+g7c=",
"JwtIssuer": "https://localhost",
"JwtAudience": "https://localhost",
"JwtExpiryInDays": 5,
"ConnectionStrings": {
"DefaultConnection": "Server=mssql-svc;Database=KBS;User Id=sa;Password=YourStrong@Passw0rd;TrustServerCertificate=True;",
"DefaultConnection": "Data Source=185.252.31.44,31433; Initial Catalog=Foursat;User ID=sa;Password=87zH26nbqT;Connection Timeout=300000;MultipleActiveResultSets=True;Encrypt=False",
"providerName": "System.Data.SqlClient"
},
"Otp": {
@@ -20,12 +42,12 @@
},
"Monitoring": {
"SentryEnabled": false,
"SentryDsn": "",
"SentryDsn": "",
"SlackEnabled": false,
"SlackWebhookUrl": "",
"EmailAlertsEnabled": false,
"AdminEmails": [
"admin@example.com"
"admin@example.com"
],
"SmsNotificationsEnabled": false,
"SmsApiKey": "",
@@ -64,7 +86,7 @@
},
"BackgroundJobs": {
"WeeklyCommissionCalculation": {
"Enabled": false,
"Enabled": true,
"CronExpression": "5 0 * * 0"
}
},
@@ -84,13 +106,7 @@
"Audience": "domain_api"
},
"Seq": {
"ServerUrl": "http://seq-svc:5341",
"ServerUrl": "https://seq.afrino.co",
"ApiKey": "oxpvpUzU1pZxMS4s3Fqq"
},
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft.AspNetCore": "Warning"
}
}
}
+35 -20
View File
@@ -2,16 +2,42 @@
"PaymentProvider": "zarinpal",
"ZarinPal": {
"MerchantId": "4225d555-5fa9-4df0-9b61-1ce152cbbba8",
"UseSandbox": false
"UseSandbox": true
},
"TwentyCard": {
"BaseUrl": "https://gateway.20card.ir/ipg",
"TerminalId": "165674",
"TerminalUsername": "ea5y1biehi",
"TerminalPassword": "SaLamAT@1404!",
"CreditPortalUrl": "https://userpanel.20card.ir/",
"DefaultEmail": "info@kbs2.ir",
"Packages": {
"4": {
"GatewayAmountToman": 11200000,
"WalletCreditToman": 12656000
},
"1": {
"GatewayAmountToman": 11200000,
"WalletCreditToman": 12656000
}
}
},
"CmsBaseUrl": "https://localhost:32846",
"FrontOfficeBaseUrl": "http://localhost:5268",
"FMS": {
"Address": "https://dl.afrino.co"
},
"CmsBaseUrl": "https://cms.kbs2.ir",
"FrontOfficeBaseUrl": "https://kbs2.ir",
"JwtSecurityKey": "TvlZVx5TJaHs8e9HgUdGzhGP2CIidoI444nAj+8+g7c=",
"JwtIssuer": "https://localhost",
"JwtAudience": "https://localhost",
"JwtExpiryInDays": 5,
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http1AndHttp2"
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=45.149.79.127,31433;Database=KBS;User Id=sa;Password=YourStrong@Passw0rd;TrustServerCertificate=True;",
"DefaultConnection": "Data Source=185.252.31.44,31433; Initial Catalog=Foursat;User ID=sa;Password=87zH26nbqT;Connection Timeout=300000;MultipleActiveResultSets=True;Encrypt=False",
"providerName": "System.Data.SqlClient"
},
"Otp": {
@@ -19,12 +45,12 @@
},
"Monitoring": {
"SentryEnabled": false,
"SentryDsn": "",
"SentryDsn": "",
"SlackEnabled": false,
"SlackWebhookUrl": "",
"EmailAlertsEnabled": false,
"AdminEmails": [
"admin@example.com"
"admin@example.com"
],
"SmsNotificationsEnabled": false,
"SmsApiKey": "",
@@ -43,7 +69,7 @@
"Sms": {
"Enabled": true,
"Provider": "Kavenegar",
"KavenegarApiKey": "497263626F32626A48685A6137524C4F78575A766E4C74694A556B79317648424964655030682B554545413D",
"KavenegarApiKey": "43676A4E786A6C50452F2F6252507939346A5145764B33566B456454374E657A614468706658656D6534593D",
"Sender": "1000001110100"
},
"DayaPayment": {
@@ -63,7 +89,7 @@
},
"BackgroundJobs": {
"WeeklyCommissionCalculation": {
"Enabled": false,
"Enabled": true,
"CronExpression": "5 0 * * 0"
}
},
@@ -76,23 +102,12 @@
}
},
"AllowedHosts": "*",
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
}
},
"Authentication": {
"Authority": "https://ids.domain.com/",
"Audience": "domain_api"
},
"Seq": {
"ServerUrl": "http://seq-svc:5341",
"ServerUrl": "https://seq.afrino.co",
"ApiKey": "oxpvpUzU1pZxMS4s3Fqq"
},
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft.AspNetCore": "Warning"
}
}
}

Some files were not shown because too many files have changed in this diff Show More