Special birthday check in tips

This commit is contained in:
2025-11-27 21:49:25 +08:00
parent f51c3c1724
commit a7f4173df7
5 changed files with 332 additions and 116 deletions

View File

@@ -313,12 +313,39 @@ public class AccountEventService(
CultureInfo.CurrentCulture = cultureInfo; CultureInfo.CurrentCulture = cultureInfo;
CultureInfo.CurrentUICulture = cultureInfo; CultureInfo.CurrentUICulture = cultureInfo;
var accountBirthday = await db.AccountProfiles
.Where(x => x.AccountId == user.Id)
.Select(x => x.Birthday)
.FirstOrDefaultAsync();
var now = SystemClock.Instance.GetCurrentInstant().InUtc().Date;
var birthdayDate = accountBirthday?.InUtc().Date;
var isBirthday = birthdayDate.HasValue && birthdayDate.Value.Month == now.Month && birthdayDate.Value.Day == now.Day;
List<CheckInFortuneTip> tips;
CheckInResultLevel checkInLevel;
if (isBirthday)
{
// Skip random logic and tips generation for birthday
checkInLevel = CheckInResultLevel.Special;
tips = [
new CheckInFortuneTip()
{
IsPositive = true,
Title = localizer["FortuneTipSpecialTitle_Birthday"].Value,
Content = localizer["FortuneTipSpecialContent_Birthday", user.Nick].Value,
}
];
}
else
{
// Generate 2 positive tips // Generate 2 positive tips
var positiveIndices = Enumerable.Range(1, FortuneTipCount) var positiveIndices = Enumerable.Range(1, FortuneTipCount)
.OrderBy(_ => Random.Next()) .OrderBy(_ => Random.Next())
.Take(2) .Take(2)
.ToList(); .ToList();
var tips = positiveIndices.Select(index => new CheckInFortuneTip tips = positiveIndices.Select(index => new CheckInFortuneTip
{ {
IsPositive = true, IsPositive = true,
Title = localizer[$"FortuneTipPositiveTitle_{index}"].Value, Title = localizer[$"FortuneTipPositiveTitle_{index}"].Value,
@@ -342,7 +369,7 @@ public class AccountEventService(
// Use weighted random distribution to make all levels reasonably achievable // Use weighted random distribution to make all levels reasonably achievable
// Weights: Worst: 10%, Worse: 20%, Normal: 40%, Better: 20%, Best: 10% // Weights: Worst: 10%, Worse: 20%, Normal: 40%, Better: 20%, Best: 10%
var randomValue = Random.Next(100); var randomValue = Random.Next(100);
var checkInLevel = randomValue switch checkInLevel = randomValue switch
{ {
< 10 => CheckInResultLevel.Worst, // 0-9: 10% chance < 10 => CheckInResultLevel.Worst, // 0-9: 10% chance
< 30 => CheckInResultLevel.Worse, // 10-29: 20% chance < 30 => CheckInResultLevel.Worse, // 10-29: 20% chance
@@ -350,16 +377,7 @@ public class AccountEventService(
< 90 => CheckInResultLevel.Better, // 70-89: 20% chance < 90 => CheckInResultLevel.Better, // 70-89: 20% chance
_ => CheckInResultLevel.Best // 90-99: 10% chance _ => CheckInResultLevel.Best // 90-99: 10% chance
}; };
}
var accountBirthday = await db.AccountProfiles
.Where(x => x.AccountId == user.Id)
.Select(x => x.Birthday)
.FirstOrDefaultAsync();
var now = SystemClock.Instance.GetCurrentInstant().InUtc().Date;
var birthdayDate = accountBirthday?.InUtc().Date;
if (birthdayDate.HasValue && birthdayDate.Value.Month == now.Month && birthdayDate.Value.Day == now.Day)
checkInLevel = CheckInResultLevel.Special;
var result = new SnCheckInResult var result = new SnCheckInResult
{ {

View File

@@ -57,18 +57,6 @@ namespace DysonNetwork.Sphere.Resources {
} }
} }
internal static string FortuneTipNegativeTitle_1 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_1", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_1 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_1", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_2 { internal static string FortuneTipPositiveTitle_2 {
get { get {
return ResourceManager.GetString("FortuneTipPositiveTitle_2", resourceCulture); return ResourceManager.GetString("FortuneTipPositiveTitle_2", resourceCulture);
@@ -81,18 +69,6 @@ namespace DysonNetwork.Sphere.Resources {
} }
} }
internal static string FortuneTipNegativeTitle_2 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_2", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_2 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_2", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_3 { internal static string FortuneTipPositiveTitle_3 {
get { get {
return ResourceManager.GetString("FortuneTipPositiveTitle_3", resourceCulture); return ResourceManager.GetString("FortuneTipPositiveTitle_3", resourceCulture);
@@ -105,18 +81,6 @@ namespace DysonNetwork.Sphere.Resources {
} }
} }
internal static string FortuneTipNegativeTitle_3 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_3", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_3 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_3", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_4 { internal static string FortuneTipPositiveTitle_4 {
get { get {
return ResourceManager.GetString("FortuneTipPositiveTitle_4", resourceCulture); return ResourceManager.GetString("FortuneTipPositiveTitle_4", resourceCulture);
@@ -129,18 +93,6 @@ namespace DysonNetwork.Sphere.Resources {
} }
} }
internal static string FortuneTipNegativeTitle_4 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_4", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_4 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_4", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_5 { internal static string FortuneTipPositiveTitle_5 {
get { get {
return ResourceManager.GetString("FortuneTipPositiveTitle_5", resourceCulture); return ResourceManager.GetString("FortuneTipPositiveTitle_5", resourceCulture);
@@ -153,18 +105,6 @@ namespace DysonNetwork.Sphere.Resources {
} }
} }
internal static string FortuneTipNegativeTitle_5 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_5", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_5 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_5", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_6 { internal static string FortuneTipPositiveTitle_6 {
get { get {
return ResourceManager.GetString("FortuneTipPositiveTitle_6", resourceCulture); return ResourceManager.GetString("FortuneTipPositiveTitle_6", resourceCulture);
@@ -177,18 +117,6 @@ namespace DysonNetwork.Sphere.Resources {
} }
} }
internal static string FortuneTipNegativeTitle_6 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_6", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_6 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_6", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_7 { internal static string FortuneTipPositiveTitle_7 {
get { get {
return ResourceManager.GetString("FortuneTipPositiveTitle_7", resourceCulture); return ResourceManager.GetString("FortuneTipPositiveTitle_7", resourceCulture);
@@ -201,6 +129,162 @@ namespace DysonNetwork.Sphere.Resources {
} }
} }
internal static string FortuneTipPositiveTitle_8 {
get {
return ResourceManager.GetString("FortuneTipPositiveTitle_8", resourceCulture);
}
}
internal static string FortuneTipPositiveContent_8 {
get {
return ResourceManager.GetString("FortuneTipPositiveContent_8", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_9 {
get {
return ResourceManager.GetString("FortuneTipPositiveTitle_9", resourceCulture);
}
}
internal static string FortuneTipPositiveContent_9 {
get {
return ResourceManager.GetString("FortuneTipPositiveContent_9", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_10 {
get {
return ResourceManager.GetString("FortuneTipPositiveTitle_10", resourceCulture);
}
}
internal static string FortuneTipPositiveContent_10 {
get {
return ResourceManager.GetString("FortuneTipPositiveContent_10", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_11 {
get {
return ResourceManager.GetString("FortuneTipPositiveTitle_11", resourceCulture);
}
}
internal static string FortuneTipPositiveContent_11 {
get {
return ResourceManager.GetString("FortuneTipPositiveContent_11", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_12 {
get {
return ResourceManager.GetString("FortuneTipPositiveTitle_12", resourceCulture);
}
}
internal static string FortuneTipPositiveContent_12 {
get {
return ResourceManager.GetString("FortuneTipPositiveContent_12", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_13 {
get {
return ResourceManager.GetString("FortuneTipPositiveTitle_13", resourceCulture);
}
}
internal static string FortuneTipPositiveContent_13 {
get {
return ResourceManager.GetString("FortuneTipPositiveContent_13", resourceCulture);
}
}
internal static string FortuneTipPositiveTitle_14 {
get {
return ResourceManager.GetString("FortuneTipPositiveTitle_14", resourceCulture);
}
}
internal static string FortuneTipPositiveContent_14 {
get {
return ResourceManager.GetString("FortuneTipPositiveContent_14", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_1 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_1", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_1 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_1", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_2 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_2", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_2 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_2", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_3 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_3", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_3 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_3", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_4 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_4", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_4 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_4", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_5 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_5", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_5 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_5", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_6 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_6", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_6 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_6", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_7 { internal static string FortuneTipNegativeTitle_7 {
get { get {
return ResourceManager.GetString("FortuneTipNegativeTitle_7", resourceCulture); return ResourceManager.GetString("FortuneTipNegativeTitle_7", resourceCulture);
@@ -213,15 +297,117 @@ namespace DysonNetwork.Sphere.Resources {
} }
} }
internal static string FortuneTipNegativeTitle_1_ { internal static string FortuneTipNegativeTitle_8 {
get { get {
return ResourceManager.GetString("FortuneTipNegativeTitle_1 ", resourceCulture); return ResourceManager.GetString("FortuneTipNegativeTitle_8", resourceCulture);
} }
} }
internal static string FortuneTipPositiveContent_14 { internal static string FortuneTipNegativeContent_8 {
get { get {
return ResourceManager.GetString("FortuneTipPositiveContent_14", resourceCulture); return ResourceManager.GetString("FortuneTipNegativeContent_8", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_9 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_9", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_9 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_9", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_10 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_10", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_10 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_10", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_11 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_11", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_11 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_11", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_12 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_12", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_12 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_12", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_13 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_13", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_13 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_13", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_14 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_14", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_14 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_14", resourceCulture);
}
}
internal static string FortuneTipNegativeTitle_15 {
get {
return ResourceManager.GetString("FortuneTipNegativeTitle_15", resourceCulture);
}
}
internal static string FortuneTipPositiveContent_15 {
get {
return ResourceManager.GetString("FortuneTipPositiveContent_15", resourceCulture);
}
}
internal static string FortuneTipNegativeContent_15 {
get {
return ResourceManager.GetString("FortuneTipNegativeContent_15", resourceCulture);
}
}
internal static string FortuneTipSpecialTitle_Birthday {
get {
return ResourceManager.GetString("FortuneTipSpecialTitle_Birthday", resourceCulture);
}
}
internal static string FortuneTipSpecialContent_Birthday {
get {
return ResourceManager.GetString("FortuneTipSpecialContent_Birthday", resourceCulture);
} }
} }
} }

View File

@@ -195,4 +195,10 @@
<value>“Why is there still something in the box“</value> <value>“Why is there still something in the box“</value>
<comment/> <comment/>
</data> </data>
<data name="FortuneTipSpecialTitle_Birthday" xml:space="preserve">
<value>Have a Birthday Party</value>
</data>
<data name="FortuneTipSpecialContent_Birthday" xml:space="preserve">
<value>Happy Birthday, {}!</value>
</data>
</root> </root>

View File

@@ -248,4 +248,10 @@
<value>“?暗盒里怎么还有!“</value> <value>“?暗盒里怎么还有!“</value>
<comment/> <comment/>
</data> </data>
<data name="FortuneTipSpecialTitle_Birthday" xml:space="preserve">
<value>过生日</value>
</data>
<data name="FortuneTipSpecialContent_Birthday" xml:space="preserve">
<value>生日快乐,{}</value>
</data>
</root> </root>

View File

@@ -173,7 +173,7 @@
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d3d47f4e_002D5d7b_002D4bb3_002D9fd2_002D0e52828cc908/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt; <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d3d47f4e_002D5d7b_002D4bb3_002D9fd2_002D0e52828cc908/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt; &lt;Solution /&gt;
&lt;/SessionState&gt;</s:String> &lt;/SessionState&gt;</s:String>
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002EPass_002FResources_002FLocalization_002FAccountEventResource/@EntryIndexedValue">False</s:Boolean> <s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002EPass_002FResources_002FLocalization_002FAccountEventResource/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002EPass_002FResources_002FLocalization_002FEmailResource/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002EPass_002FResources_002FLocalization_002FEmailResource/@EntryIndexedValue">True</s:Boolean>