achievements.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package like
  2. import (
  3. "context"
  4. likemdl "go-common/app/interface/main/activity/model/like"
  5. xsql "go-common/library/database/sql"
  6. "github.com/pkg/errors"
  7. )
  8. const (
  9. _achievesSQL = "select `id`,`name`,`icon`,`dic`,`unlock`,`ctime`,`mtime`,`del`,`sid`,`image`,`award` from act_like_achievements where sid = ? and del = 0 order by `unlock` limit 100"
  10. // HaveAward award state
  11. HaveAward = 1
  12. )
  13. // RawActLikeAchieves .
  14. func (d *Dao) RawActLikeAchieves(c context.Context, sid int64) (res *likemdl.Achievements, err error) {
  15. var rows *xsql.Rows
  16. if rows, err = d.db.Query(c, _achievesSQL, sid); err != nil {
  17. if err == xsql.ErrNoRows {
  18. err = nil
  19. } else {
  20. err = errors.Wrapf(err, "RawActLikeAchieves:Query(%s)", _achievesSQL)
  21. return
  22. }
  23. }
  24. defer rows.Close()
  25. list := make([]*likemdl.ActLikeAchievement, 0, 100)
  26. for rows.Next() {
  27. a := &likemdl.ActLikeAchievement{}
  28. if err = rows.Scan(&a.ID, &a.Name, &a.Icon, &a.Dic, &a.Unlock, &a.Ctime, &a.Mtime, &a.Del, &a.Sid, &a.Image, &a.Award); err != nil {
  29. err = errors.Wrap(err, "RawActLikeAchieves:scan()")
  30. return
  31. }
  32. list = append(list, a)
  33. }
  34. res = &likemdl.Achievements{Achievements: list}
  35. if err = rows.Err(); err != nil {
  36. err = errors.Wrap(err, "RawActLikeAchieves:rows.Err()")
  37. }
  38. return
  39. }