feat: publish sanitized custom.97 source
This commit is contained in:
1022 files changed
+69903
-19207
No files matched your search
+6
-7
@@ -1,7 +1,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
@@ -55,7 +54,7 @@ func HasCheckedInToday(userId int) (bool, error) {
|
||||
func UserCheckin(userId int) (*Checkin, error) {
|
||||
setting := operation_setting.GetCheckinSetting()
|
||||
if !setting.Enabled {
|
||||
return nil, errors.New("签到功能未启用")
|
||||
return nil, common.NewMessage("Check-in feature is not enabled")
|
||||
}
|
||||
|
||||
// 检查今天是否已签到
|
||||
@@ -64,7 +63,7 @@ func UserCheckin(userId int) (*Checkin, error) {
|
||||
return nil, err
|
||||
}
|
||||
if hasChecked {
|
||||
return nil, errors.New("今日已签到")
|
||||
return nil, common.NewMessage("Already checked in today")
|
||||
}
|
||||
|
||||
// 计算随机额度奖励
|
||||
@@ -97,13 +96,13 @@ func userCheckinWithTransaction(checkin *Checkin, userId int, quotaAwarded int)
|
||||
// 步骤1: 创建签到记录
|
||||
// 数据库有唯一约束 (user_id, checkin_date),可以防止并发重复签到
|
||||
if err := tx.Create(checkin).Error; err != nil {
|
||||
return errors.New("签到失败,请稍后重试")
|
||||
return common.NewMessage("Check-in failed, please try again later")
|
||||
}
|
||||
|
||||
// 步骤2: 在事务中增加用户额度
|
||||
if err := tx.Model(&User{}).Where("id = ?", userId).
|
||||
Update("quota", gorm.Expr("quota + ?", quotaAwarded)).Error; err != nil {
|
||||
return errors.New("签到失败:更新额度出错")
|
||||
return common.NewMessage("Check-in failed: quota update error")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -126,7 +125,7 @@ func userCheckinWithoutTransaction(checkin *Checkin, userId int, quotaAwarded in
|
||||
// 步骤1: 创建签到记录
|
||||
// 数据库有唯一约束 (user_id, checkin_date),可以防止并发重复签到
|
||||
if err := DB.Create(checkin).Error; err != nil {
|
||||
return nil, errors.New("签到失败,请稍后重试")
|
||||
return nil, common.NewMessage("Check-in failed, please try again later")
|
||||
}
|
||||
|
||||
// 步骤2: 增加用户额度
|
||||
@@ -134,7 +133,7 @@ func userCheckinWithoutTransaction(checkin *Checkin, userId int, quotaAwarded in
|
||||
if err := IncreaseUserQuota(userId, quotaAwarded, true); err != nil {
|
||||
// 如果增加额度失败,需要回滚签到记录
|
||||
DB.Delete(checkin)
|
||||
return nil, errors.New("签到失败:更新额度出错")
|
||||
return nil, common.NewMessage("Check-in failed: quota update error")
|
||||
}
|
||||
|
||||
return checkin, nil
|
||||
|
||||
Reference in new issue
Block a user