feat: Add ClearCart command and response, implement CancelOrder command with validation, and enhance DeliveryStatus and User models
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
using CMSMicroservice.Application.DayaLoanCQ.Services;
|
||||
using CMSMicroservice.Domain.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Mock Implementation برای شبیهسازی Daya API
|
||||
/// این کلاس فقط برای تست و توسعه است و باید با Implementation واقعی جایگزین شود
|
||||
/// </summary>
|
||||
public class MockDayaLoanApiService : IDayaLoanApiService
|
||||
{
|
||||
private readonly ILogger<MockDayaLoanApiService> _logger;
|
||||
|
||||
public MockDayaLoanApiService(ILogger<MockDayaLoanApiService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<List<DayaLoanStatusResult>> CheckLoanStatusAsync(
|
||||
List<string> nationalCodes,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
_logger.LogWarning("⚠️ Using MOCK Daya API Service - Replace with real implementation!");
|
||||
|
||||
// شبیهسازی تاخیر شبکه
|
||||
await Task.Delay(100, cancellationToken);
|
||||
|
||||
var results = new List<DayaLoanStatusResult>();
|
||||
|
||||
foreach (var nationalCode in nationalCodes)
|
||||
{
|
||||
// شبیهسازی: کدملیهایی که با 1 شروع میشوند وام گرفتهاند
|
||||
if (nationalCode.StartsWith("1"))
|
||||
{
|
||||
results.Add(new DayaLoanStatusResult
|
||||
{
|
||||
NationalCode = nationalCode,
|
||||
Status = DayaLoanStatus.PendingReceive,
|
||||
ContractNumber = $"MOCK-DAYA-{nationalCode}-{DateTime.Now.Ticks}"
|
||||
});
|
||||
}
|
||||
// شبیهسازی: کدملیهایی که با 2 شروع میشوند رد شدهاند
|
||||
else if (nationalCode.StartsWith("2"))
|
||||
{
|
||||
results.Add(new DayaLoanStatusResult
|
||||
{
|
||||
NationalCode = nationalCode,
|
||||
Status = DayaLoanStatus.Rejected,
|
||||
ContractNumber = null
|
||||
});
|
||||
}
|
||||
// بقیه: هنوز بررسی نشدهاند
|
||||
else
|
||||
{
|
||||
results.Add(new DayaLoanStatusResult
|
||||
{
|
||||
NationalCode = nationalCode,
|
||||
Status = DayaLoanStatus.PendingReceive,
|
||||
ContractNumber = null // هنوز قرارداد صادر نشده
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Mock Daya API returned {Count} results", results.Count);
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Real Implementation برای API واقعی دایا
|
||||
/// TODO: این کلاس باید پیادهسازی شود زمانی که API دایا آماده شد
|
||||
/// </summary>
|
||||
public class DayaLoanApiService : IDayaLoanApiService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<DayaLoanApiService> _logger;
|
||||
|
||||
public DayaLoanApiService(HttpClient httpClient, ILogger<DayaLoanApiService> logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<List<DayaLoanStatusResult>> CheckLoanStatusAsync(
|
||||
List<string> nationalCodes,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
// TODO: پیادهسازی واقعی API دایا
|
||||
// مثال:
|
||||
// var request = new DayaApiRequest { NationalCodes = nationalCodes };
|
||||
// var response = await _httpClient.PostAsJsonAsync("/api/loan/check", request, cancellationToken);
|
||||
// response.EnsureSuccessStatusCode();
|
||||
// var result = await response.Content.ReadFromJsonAsync<DayaApiResponse>(cancellationToken);
|
||||
// return MapToResults(result);
|
||||
|
||||
throw new NotImplementedException("Real Daya API is not implemented yet. Use MockDayaLoanApiService for testing.");
|
||||
}
|
||||
}
|
||||
@@ -70,11 +70,25 @@ public class UserNotificationService : IUserNotificationService
|
||||
|
||||
var formattedAmount = amount.ToString("N0", new System.Globalization.CultureInfo("fa-IR"));
|
||||
|
||||
// Send Email (TODO: User entity needs Email field)
|
||||
// if (_emailSettings.Enabled && !string.IsNullOrEmpty(user.Email))
|
||||
// {
|
||||
// await SendEmailAsync(...);
|
||||
// }
|
||||
// Send Email
|
||||
if (_emailSettings.Enabled && !string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
var emailSubject = $"واریز کمیسیون هفته {weekNumber}";
|
||||
var emailBody = "<div dir='rtl' style='font-family: Tahoma, Arial; text-align: right;'>" +
|
||||
$"<h2>سلام {userFullName}</h2>" +
|
||||
$"<p>کمیسیون هفته {weekNumber} شما به مبلغ <strong>{formattedAmount} ریال</strong> به کیف پول شما واریز شد.</p>" +
|
||||
"<p>از اعتماد شما سپاسگزاریم.</p>" +
|
||||
"<hr/>" +
|
||||
"<p style='color: #666; font-size: 12px;'>FourSat - سیستم مدیریت باشگاه مشتریان</p>" +
|
||||
"</div>";
|
||||
|
||||
await SendEmailAsync(
|
||||
toEmail: user.Email,
|
||||
toName: userFullName,
|
||||
subject: emailSubject,
|
||||
body: emailBody,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
// Send SMS
|
||||
if (_smsSettings.Enabled && !string.IsNullOrEmpty(user.Mobile))
|
||||
@@ -107,11 +121,25 @@ public class UserNotificationService : IUserNotificationService
|
||||
var userFullName = $"{user.FirstName} {user.LastName}".Trim();
|
||||
if (string.IsNullOrEmpty(userFullName)) userFullName = "کاربر عزیز";
|
||||
|
||||
// Send Email (TODO: User entity needs Email field)
|
||||
// if (_emailSettings.Enabled && !string.IsNullOrEmpty(user.Email))
|
||||
// {
|
||||
// await SendEmailAsync(...);
|
||||
// }
|
||||
// Send Email
|
||||
if (_emailSettings.Enabled && !string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
var emailSubject = "فعالسازی باشگاه مشتریان FourSat";
|
||||
var emailBody = "<div dir='rtl' style='font-family: Tahoma, Arial; text-align: right;'>" +
|
||||
$"<h2>تبریک {userFullName}!</h2>" +
|
||||
"<p>عضویت شما در <strong>باشگاه مشتریان FourSat</strong> با موفقیت فعال شد.</p>" +
|
||||
"<p>از این پس میتوانید از مزایای ویژه باشگاه بهرهمند شوید.</p>" +
|
||||
"<hr/>" +
|
||||
"<p style='color: #666; font-size: 12px;'>FourSat - سیستم مدیریت باشگاه مشتریان</p>" +
|
||||
"</div>";
|
||||
|
||||
await SendEmailAsync(
|
||||
toEmail: user.Email,
|
||||
toName: userFullName,
|
||||
subject: emailSubject,
|
||||
body: emailBody,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
// Send SMS
|
||||
if (_smsSettings.Enabled && !string.IsNullOrEmpty(user.Mobile))
|
||||
@@ -145,11 +173,35 @@ public class UserNotificationService : IUserNotificationService
|
||||
var userFullName = $"{user.FirstName} {user.LastName}".Trim();
|
||||
if (string.IsNullOrEmpty(userFullName)) userFullName = "کاربر عزیز";
|
||||
|
||||
// Send Email (TODO: User entity needs Email field)
|
||||
// if (_emailSettings.Enabled && !string.IsNullOrEmpty(user.Email))
|
||||
// {
|
||||
// await SendEmailAsync(...);
|
||||
// }
|
||||
// Send Email
|
||||
if (_emailSettings.Enabled && !string.IsNullOrEmpty(user.Email))
|
||||
{
|
||||
var emailSubject = "خطا در واریز کمیسیون";
|
||||
var emailBody = "<div dir='rtl' style='font-family: Tahoma, Arial; text-align: right;'>" +
|
||||
$"<h2>سلام {userFullName}</h2>" +
|
||||
"<p>متأسفانه در واریز کمیسیون شما خطایی رخ داده است:</p>" +
|
||||
$"<p style='color: red;'><strong>{errorMessage}</strong></p>" +
|
||||
"<p>لطفاً با پشتیبانی تماس بگیرید.</p>" +
|
||||
"<hr/>" +
|
||||
"<p style='color: #666; font-size: 12px;'>FourSat - سیستم مدیریت باشگاه مشتریان</p>" +
|
||||
"</div>";
|
||||
|
||||
await SendEmailAsync(
|
||||
toEmail: user.Email,
|
||||
toName: userFullName,
|
||||
subject: emailSubject,
|
||||
body: emailBody,
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
// Send SMS
|
||||
if (_smsSettings.Enabled && !string.IsNullOrEmpty(user.Mobile))
|
||||
{
|
||||
await SendSmsAsync(
|
||||
phoneNumber: user.Mobile,
|
||||
message: $"خطا در واریز کمیسیون: {errorMessage}\nلطفاً با پشتیبانی تماس بگیرید.",
|
||||
cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user