ugift_day.go 1.2 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. _getBagStatus = "SELECT id,uid,day,day_info FROM ugift_day_status WHERE uid = ? AND day = ? LIMIT 1"
  11. _addDayBag = "INSERT INTO ugift_day_status (uid,day,day_info) VALUES (?,?,?)"
  12. )
  13. // GetDayBagStatus GetDayBagStatus
  14. func (d *Dao) GetDayBagStatus(ctx context.Context, uid int64, date string) (res *model.DayGiftInfo, err error) {
  15. log.Info("GetDayBagStatus,%d,%s", uid, date)
  16. row := d.db.QueryRow(ctx, _getBagStatus, uid, date)
  17. res = &model.DayGiftInfo{}
  18. if err = row.Scan(&res.ID, &res.UID, &res.Day, &res.DayInfo); err != nil {
  19. if err == sql.ErrNoRows {
  20. err = nil
  21. return
  22. }
  23. log.Error("GetUserGiftBagStatus row.Scan error(%v)", err)
  24. }
  25. return
  26. }
  27. // AddDayBag AddDayBag
  28. func (d *Dao) AddDayBag(ctx context.Context, uid int64, date string, dayInfo *model.BagGiftStatus) (affected int64, err error) {
  29. log.Info("AddDayBag,%d,%s,%v", uid, date, dayInfo)
  30. di, err := json.Marshal(dayInfo)
  31. if err != nil {
  32. return
  33. }
  34. res, err := d.db.Exec(ctx, _addDayBag, uid, date, di)
  35. if err != nil {
  36. log.Error("AddUserGiftBag error(%v)", err)
  37. return
  38. }
  39. return res.LastInsertId()
  40. }