ugift_week.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "go-common/app/service/live/gift/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. var (
  10. _getWeekBagStatus = "SELECT id,uid,week,level,week_info FROM ugift_week_status WHERE uid = ? AND week = ? AND level =? ORDER BY ctime DESC LIMIT 1"
  11. _addWeekBag = "INSERT INTO ugift_week_status (uid,week,level,week_info) VALUES (?,?,?,?)"
  12. )
  13. // GetWeekBagStatus GetWeekBagStatus
  14. func (d *Dao) GetWeekBagStatus(ctx context.Context, uid int64, week int, level int64) (res *model.WeekGiftInfo, err error) {
  15. log.Info("GetWeekBagStatus,uid:%d,week:%d,level:%d", uid, week, level)
  16. row := d.db.QueryRow(ctx, _getWeekBagStatus, uid, week, level)
  17. res = &model.WeekGiftInfo{}
  18. if err = row.Scan(&res.ID, &res.UID, &res.Week, &res.Level, &res.WeekInfo); err != nil {
  19. if err == sql.ErrNoRows {
  20. err = nil
  21. return
  22. }
  23. log.Error("GetWeekBagStatus row.Scan error(%v)", err)
  24. }
  25. return
  26. }
  27. // AddWeekBag AddWeekBag
  28. func (d *Dao) AddWeekBag(ctx context.Context, uid int64, week int, level int64, weekInfo *model.BagGiftStatus) (affected int64, err error) {
  29. log.Info("AddWeekBag,uid:%d,week:%d,level:%d,weekInfo:%v", uid, week, level, weekInfo)
  30. wi, err := json.Marshal(weekInfo)
  31. if err != nil {
  32. return
  33. }
  34. res, err := d.db.Exec(ctx, _addWeekBag, uid, week, level, wi)
  35. if err != nil {
  36. log.Error("AddUserGiftBag error(%v)", err)
  37. return
  38. }
  39. return res.LastInsertId()
  40. }