admin/src/Oms.Application/Shared/MarketingCouponScope.cs
zzh f972a28d79
All checks were successful
Build and Deploy / deploy (push) Successful in 3m50s
feat: 落地滚动会员、券发放与邀请分成奖励
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-06 17:40:24 +08:00

53 lines
1.3 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace Oms.Application.Shared;
public class CouponApplyScope
{
[JsonPropertyName("countryCodes")]
public List<string>? CountryCodes { get; set; }
}
public static class MarketingCouponScope
{
public static bool Matches(string? applyScopeJson, string? destinationCountry)
{
var codes = ParseCountryCodes(applyScopeJson);
if (codes.Count == 0)
{
return true;
}
if (string.IsNullOrWhiteSpace(destinationCountry))
{
return false;
}
var dest = destinationCountry.Trim();
return codes.Any(x => string.Equals(x, dest, StringComparison.OrdinalIgnoreCase));
}
public static IReadOnlyList<string> ParseCountryCodes(string? applyScopeJson)
{
if (string.IsNullOrWhiteSpace(applyScopeJson))
{
return [];
}
try
{
var scope = JsonSerializer.Deserialize<CouponApplyScope>(applyScopeJson);
return (scope?.CountryCodes ?? [])
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(x => x.Trim())
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
catch (JsonException)
{
return [];
}
}
}