up_info_video.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. )
  9. const (
  10. // select
  11. _upInfoNicknameSQL = "SELECT mid, nickname FROM up_info_video WHERE mid in (%s)"
  12. _upInfoNicknameByMIDSQL = "SELECT nickname FROM %s WHERE mid = ? AND account_state = 3 AND is_deleted = 0"
  13. // update
  14. _updateUpInfoScoreSQL = "UPDATE %s set credit_score = credit_score + ? WHERE mid = ? AND is_deleted = 0"
  15. )
  16. // GetUpInfoNickname get nickname
  17. func (d *Dao) GetUpInfoNickname(c context.Context, mids []int64) (upInfo map[int64]string, err error) {
  18. upInfo = make(map[int64]string)
  19. if len(mids) == 0 {
  20. return
  21. }
  22. rows, err := d.db.Query(c, fmt.Sprintf(_upInfoNicknameSQL, xstr.JoinInts(mids)))
  23. if err != nil {
  24. log.Error("GetUpInfoNickname d.db.Query error(%v)", err)
  25. return
  26. }
  27. defer rows.Close()
  28. for rows.Next() {
  29. var mid int64
  30. var nickname string
  31. err = rows.Scan(&mid, &nickname)
  32. if err != nil {
  33. log.Error("GetUpInfoNickname rows scan error(%v)", err)
  34. return
  35. }
  36. upInfo[mid] = nickname
  37. }
  38. err = rows.Err()
  39. return
  40. }
  41. // GetUpInfoNicknameByMID get nickname by mid
  42. func (d *Dao) GetUpInfoNicknameByMID(c context.Context, mid int64, table string) (nickname string, err error) {
  43. err = d.db.QueryRow(c, fmt.Sprintf(_upInfoNicknameByMIDSQL, table), mid).Scan(&nickname)
  44. if err == sql.ErrNoRows {
  45. return "", nil
  46. }
  47. return
  48. }
  49. // TxUpdateUpInfoScore update up_info_video credit score
  50. func (d *Dao) TxUpdateUpInfoScore(tx *sql.Tx, table string, score int, mid int64) (rows int64, err error) {
  51. res, err := tx.Exec(fmt.Sprintf(_updateUpInfoScoreSQL, table), score, mid)
  52. if err != nil {
  53. return
  54. }
  55. return res.RowsAffected()
  56. }