item_mysql.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/job/openplatform/open-sug/model"
  6. "go-common/library/log"
  7. )
  8. // WishCount ...
  9. func (d *Dao) WishCount(c context.Context, item *model.Item) (wishCount int, err error) {
  10. row := d.ugcDB.QueryRow(c, fmt.Sprintf(_getWishCount, item.ID%16), item.ID)
  11. if err = row.Scan(&item.WishCount); err != nil {
  12. item.WishCount = 0
  13. }
  14. return item.WishCount, err
  15. }
  16. // CommentCount ...
  17. func (d *Dao) CommentCount(c context.Context, item *model.Item) (commentCount int, err error) {
  18. row := d.ugcDB.QueryRow(c, fmt.Sprintf(_getCommentCount, item.ID%128), item.ID)
  19. if err = row.Scan(&item.CommentCount); err != nil {
  20. item.CommentCount = 0
  21. }
  22. return item.CommentCount, err
  23. }
  24. // SalesCount ...
  25. func (d *Dao) SalesCount(c context.Context, item *model.Item) (salesCount int, err error) {
  26. row := d.ugcDB.QueryRow(c, _getSaleCount, item.ID)
  27. if err = row.Scan(&item.CommentCount); err != nil {
  28. item.CommentCount = 0
  29. }
  30. return item.CommentCount, err
  31. }
  32. // InsertMatch ...
  33. func (d *Dao) InsertMatch(c context.Context, item *model.Item, season model.Score) (affect int64, err error) {
  34. score := int(season.Score * 1000)
  35. res, err := d.ticketDB.Exec(c, _insertMatch, item.ID, season.SeasonID, season.SeasonName, score, item.Name, item.HeadImg, item.SugImg, item.Name, season.SeasonName, score, item.HeadImg, item.SugImg)
  36. if err != nil {
  37. log.Error("(%v)", err)
  38. return
  39. }
  40. affect, err = res.RowsAffected()
  41. return
  42. }
  43. // UpdatePic ...
  44. func (d *Dao) UpdatePic(c context.Context, sug *model.Sug) (affect int64, err error) {
  45. res, err := d.ticketDB.Exec(c, _updatePic, sug.Item.SugImg, sug.Item.Name, sug.Item.HeadImg, sug.Item.ID, sug.SeasonID)
  46. if err != nil {
  47. log.Error("(%v)", err)
  48. return
  49. }
  50. affect, err = res.RowsAffected()
  51. return
  52. }