match.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package like
  2. import (
  3. "context"
  4. "database/sql"
  5. "fmt"
  6. "go-common/app/job/main/activity/model/match"
  7. "go-common/library/log"
  8. "go-common/library/xstr"
  9. )
  10. const (
  11. _unDoMatchSQL = "SELECT mid,stake,result FROM act_match_user_log WHERE m_o_id = ? AND status = 0 LIMIT ?"
  12. _upMatchUserSQL = "UPDATE act_match_user_log SET status = 1 WHERE m_o_id = ? AND mid IN (%s)"
  13. _matchObjSQL = "SELECT id,match_id,sid,result FROM act_matchs_object WHERE status = 0 AND id = ?"
  14. )
  15. // UnDoMatchUsers un finish users.
  16. func (d *Dao) UnDoMatchUsers(c context.Context, matchObjID int64, limit int) (list []*match.ActMatchUser, err error) {
  17. rows, err := d.db.Query(c, _unDoMatchSQL, matchObjID, limit)
  18. if err != nil {
  19. log.Error("UnDoMatchUsers.Query error(%v)", err)
  20. return
  21. }
  22. defer rows.Close()
  23. for rows.Next() {
  24. user := new(match.ActMatchUser)
  25. if err = rows.Scan(&user.Mid, &user.Stake, &user.Result); err != nil {
  26. log.Error("UnDoMatchUsers row.Scan error(%v)", err)
  27. return
  28. }
  29. list = append(list, user)
  30. }
  31. return
  32. }
  33. // UpMatchUserResult update match user result.
  34. func (d *Dao) UpMatchUserResult(c context.Context, matchObjID int64, mids []int64) (err error) {
  35. if _, err = d.db.Exec(c, fmt.Sprintf(_upMatchUserSQL, xstr.JoinInts(mids)), matchObjID); err != nil {
  36. log.Error("UpMatchUserResult d.db.Exec mids(%v) error(%v)", mids, err)
  37. }
  38. return
  39. }
  40. // MatchObjInfo get match object info from db.
  41. func (d *Dao) MatchObjInfo(c context.Context, matchObjID int64) (data *match.ActMatchObj, err error) {
  42. row := d.db.QueryRow(c, _matchObjSQL, matchObjID)
  43. data = new(match.ActMatchObj)
  44. if err = row.Scan(&data.ID, &data.MatchID, &data.SID, &data.Result); err != nil {
  45. if err == sql.ErrNoRows {
  46. err = nil
  47. } else {
  48. log.Error("MatchObjInfo row.Scan() error(%v)", err)
  49. }
  50. }
  51. return
  52. }