feat: update admin

This commit is contained in:
yanghao05
2025-04-28 19:12:31 +08:00
parent 82c112b1eb
commit 685c87207f
12 changed files with 251 additions and 238 deletions

View File

@@ -310,3 +310,24 @@ func (m *usersModel) HasBought(ctx context.Context, userID, postID int64) (bool,
return userPost.ID > 0, nil
}
// Count
func (m *usersModel) Count(ctx context.Context, cond BoolExpression) (int64, error) {
tbl := table.Users
stmt := tbl.
SELECT(COUNT(tbl.ID).AS("cnt")).
WHERE(cond)
m.log.Infof("sql: %s", stmt.DebugSql())
var cnt struct {
Cnt int64
}
if err := stmt.QueryContext(ctx, db, &cnt); err != nil {
m.log.Errorf("error counting users: %v", err)
return 0, err
}
return cnt.Cnt, nil
}