activity.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _typeArticle = "12"
  11. )
  12. // LikeSync like sync
  13. func (d *Dao) LikeSync(c context.Context, aid, likes int64) (err error) {
  14. params := url.Values{}
  15. params.Set("oid", strconv.FormatInt(aid, 10))
  16. params.Set("likes", strconv.FormatInt(likes, 10))
  17. params.Set("type", _typeArticle)
  18. resp := struct {
  19. Code int
  20. Data interface{}
  21. }{}
  22. if err = d.httpClient.Get(c, d.c.Job.ActLikeURL, "", params, &resp); err != nil {
  23. log.Error("activity: d.LikeSync.Get(%s) error(%+v)", d.c.Job.ActLikeURL+params.Encode(), err)
  24. PromError("activity:同步点赞数")
  25. return
  26. }
  27. if resp.Code != 0 {
  28. // 未参与活动
  29. if resp.Code == -403 {
  30. return
  31. }
  32. err = ecode.Int(resp.Code)
  33. log.Error("activity: d.LikeSync.Get(%s) error(%+v)", d.c.Job.ActLikeURL+"?"+params.Encode(), resp)
  34. PromError("activity:同步点赞数")
  35. return
  36. }
  37. log.Info("activity: dao.LikeSync success aid: %v count: %v ", aid, likes)
  38. return
  39. }