🐛 Fix daily sign random panic

This commit is contained in:
LittleSheep 2024-09-08 10:39:08 +08:00
parent d4ed047ed7
commit 582e6cdb61
2 changed files with 6 additions and 5 deletions

View File

@ -4,9 +4,9 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix date formatting issue on daily signing"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix daily sign batch list query issue">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/sign_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/sign_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/services/sign.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/sign.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -153,7 +153,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value=":bug: Fix internal token audience update isn't fully applied" />
<MESSAGE value=":arrow_up: Implement list user relative grpc function" /> <MESSAGE value=":arrow_up: Implement list user relative grpc function" />
<MESSAGE value=":alien: Change avatar and banner id to string" /> <MESSAGE value=":alien: Change avatar and banner id to string" />
<MESSAGE value=":card_file_box: Update modeling" /> <MESSAGE value=":card_file_box: Update modeling" />
@ -178,7 +177,8 @@
<MESSAGE value=":sparkles: Can get today's daily sign record" /> <MESSAGE value=":sparkles: Can get today's daily sign record" />
<MESSAGE value=":bug: Fix auto maintain range missing models" /> <MESSAGE value=":bug: Fix auto maintain range missing models" />
<MESSAGE value=":bug: Fix date formatting issue on daily signing" /> <MESSAGE value=":bug: Fix date formatting issue on daily signing" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix date formatting issue on daily signing" /> <MESSAGE value=":bug: Fix daily sign batch list query issue" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix daily sign batch list query issue" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

View File

@ -6,6 +6,7 @@ import (
"git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models" "git.solsynth.dev/hydrogen/passport/pkg/internal/models"
"gorm.io/gorm" "gorm.io/gorm"
"math"
"math/rand" "math/rand"
"time" "time"
) )
@ -37,7 +38,7 @@ func DailySign(user models.Account) (models.SignRecord, error) {
tier := rand.Intn(5) tier := rand.Intn(5)
record := models.SignRecord{ record := models.SignRecord{
ResultTier: tier, ResultTier: tier,
ResultExperience: rand.Intn(tier*100) + 100, ResultExperience: rand.Intn(int(math.Max(float64(tier), 1)*100)+1-100) + 100,
AccountID: user.ID, AccountID: user.ID,
} }