Skip to content

Commit

Permalink
fix: 修正GroupInfo取RowsAffected逻辑错误导致部分group_player_info读取失败的问题 (#1188)
Browse files Browse the repository at this point in the history
Co-authored-by: bugtower100 <2889352839@qq.com>
  • Loading branch information
PaienNate and bugtower100 authored Jan 9, 2025
1 parent a46aa98 commit 23b8ab8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions dice/model/group_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,18 @@ func GroupPlayerInfoGet(db *gorm.DB, groupID string, playerID string) *GroupPlay

// 使用 GORM 查询数据并绑定到结构体中
// db.Table("表名").Where("条件").First(&ret) 查询一条数据并映射到结构体
err := db.Model(&GroupPlayerInfoBase{}).
result := db.Model(&GroupPlayerInfoBase{}).
Where("group_id = ? AND user_id = ?", groupID, playerID).
Select("name, last_command_time, auto_set_name_template, dice_side_num").
Scan(&ret).Error

First(&ret)
err := result.Error
// 如果查询发生错误,打印错误并返回 nil
if err != nil {
log.Errorf("error getting group player info: %s", err.Error())
return nil
}

// 如果查询到的数据为空,返回 nil
if db.RowsAffected == 0 {
if result.RowsAffected == 0 {
return nil
}

Expand Down

0 comments on commit 23b8ab8

Please sign in to comment.