prize_log.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/live/xlottery/model"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _addPrizeData = "INSERT INTO capsule_prize_log (prize_id,uid,day,timestamp) VALUES (?,?,?,?)"
  10. _getUserPrizeData = "SELECT prize_id,uid,day,`timestamp` from capsule_prize_log where prize_id = ? and uid = ? order by id desc"
  11. _getPrizeDayData = "SELECT prize_id,uid,day,`timestamp` from capsule_prize_log where prize_id = ? and day = ? order by id desc"
  12. )
  13. // AddPrizeData 添加特殊奖品获奖记录
  14. func (d *Dao) AddPrizeData(ctx context.Context, prizeId, uid int64, day string, timestamp int64) (status bool, err error) {
  15. res, err := d.db.Exec(ctx, _addPrizeData, prizeId, uid, day, timestamp)
  16. if err != nil {
  17. log.Error("[dao.prize_extra | AddWhiteUser] add(%s) error (%v)", _addPrizeData, err)
  18. return
  19. }
  20. rows, _ := res.RowsAffected()
  21. status = rows > 0
  22. return
  23. }
  24. // GetUserPrizeLog 获取特殊奖品记录
  25. func (d *Dao) GetUserPrizeLog(ctx context.Context, prizeId int64, uid int64) (prizeLog *model.PrizeLog, err error) {
  26. row := d.db.QueryRow(ctx, _getUserPrizeData, prizeId, uid)
  27. prizeLog = &model.PrizeLog{}
  28. err = row.Scan(&prizeLog.PrizeId, &prizeLog.Uid, &prizeLog.Day, &prizeLog.Timestamp)
  29. if err == sql.ErrNoRows {
  30. return nil, nil
  31. }
  32. if err != nil {
  33. log.Error("[dao.pool_prize | GetUserPrizeLog]query(%s) error(%v)", _getUserPrizeData, err)
  34. return
  35. }
  36. return prizeLog, nil
  37. }
  38. // GetPrizeDayLog 获取特殊奖品记录
  39. func (d *Dao) GetPrizeDayLog(ctx context.Context, prizeId int64, day string) (prizeLog *model.PrizeLog, err error) {
  40. row := d.db.QueryRow(ctx, _getPrizeDayData, prizeId, day)
  41. prizeLog = &model.PrizeLog{}
  42. err = row.Scan(&prizeLog.PrizeId, &prizeLog.Uid, &prizeLog.Day, &prizeLog.Timestamp)
  43. if err == sql.ErrNoRows {
  44. return nil, nil
  45. }
  46. if err != nil {
  47. log.Error("[dao.pool_prize | GetPrizeDayLog]query(%s) error(%v)", _getPrizeDayData, err)
  48. return
  49. }
  50. return
  51. }