activity.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/main/growup/model"
  5. "go-common/library/log"
  6. // "go-common/library/database/sql"
  7. )
  8. const (
  9. _activitySQL = "SELECT id,name,signed_start,signed_end,sign_up_start,sign_up_end,sign_up,win_type,progress_start,progress_end,progress_sync,update_page,bonus_query,bonus_query_start,bonus_query_end,background,win_desc,unwin_desc,details FROM creative_activity WHERE id = ?"
  10. _upActivitySQL = "SELECT mid,nickname,ranking,state FROM up_activity WHERE activity_id = ? AND is_deleted = 0"
  11. _inUpActivitySQL = "INSERT INTO up_activity(mid,nickname,activity_id,state,sign_up_time) VALUES(?,?,?,?,?)"
  12. )
  13. // GetActivity get activity by query
  14. func (d *Dao) GetActivity(c context.Context, id int64) (ac *model.CActivity, err error) {
  15. ac = &model.CActivity{}
  16. err = d.db.QueryRow(c, _activitySQL, id).Scan(&ac.ID, &ac.Name, &ac.SignedStart, &ac.SignedEnd, &ac.SignUpStart, &ac.SignUpEnd, &ac.SignUp, &ac.WinType, &ac.ProgressStart, &ac.ProgressEnd, &ac.ProgressSync, &ac.UpdatePage, &ac.BonusQuery, &ac.BonusQueryStart, &ac.BonusQueryEnd, &ac.Background, &ac.WinDesc, &ac.UnwinDesc, &ac.Details)
  17. return
  18. }
  19. // ListUpActivity get up from up_activity
  20. func (d *Dao) ListUpActivity(c context.Context, id int64) (ups []*model.UpBonus, err error) {
  21. ups = make([]*model.UpBonus, 0)
  22. rows, err := d.db.Query(c, _upActivitySQL, id)
  23. if err != nil {
  24. log.Error("ListUpActivity d.db.Query error(%v)", err)
  25. return
  26. }
  27. defer rows.Close()
  28. for rows.Next() {
  29. up := &model.UpBonus{}
  30. err = rows.Scan(&up.MID, &up.Nickname, &up.Rank, &up.State)
  31. if err != nil {
  32. log.Error("ListUpActivity rows.Scan error(%v)", err)
  33. return
  34. }
  35. ups = append(ups, up)
  36. }
  37. err = rows.Err()
  38. return
  39. }
  40. // SignUpActivity up sign up activity
  41. func (d *Dao) SignUpActivity(c context.Context, up *model.UpBonus) (rows int64, err error) {
  42. res, err := d.db.Exec(c, _inUpActivitySQL, up.MID, up.Nickname, up.ActivityID, up.State, up.SignUpTime)
  43. if err != nil {
  44. log.Error("SignUpActivity.Exec(%s) error(%v)", _inUpActivitySQL, err)
  45. return
  46. }
  47. return res.RowsAffected()
  48. }