service.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dynamic
  2. import (
  3. "context"
  4. "go-common/app/interface/main/creative/conf"
  5. "go-common/app/interface/main/creative/dao/lottery"
  6. lMdl "go-common/app/interface/main/creative/model/lottery"
  7. "go-common/app/interface/main/creative/service"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. )
  11. //Service struct
  12. type Service struct {
  13. c *conf.Config
  14. lottery *lottery.Dao
  15. }
  16. //New get service
  17. func New(c *conf.Config, rpcdaos *service.RPCDaos) *Service {
  18. s := &Service{
  19. c: c,
  20. lottery: lottery.New(c),
  21. }
  22. return s
  23. }
  24. // LotteryUserCheck fn
  25. func (s *Service) LotteryUserCheck(c context.Context, mid int64) (check bool, err error) {
  26. var (
  27. ret int
  28. ip = metadata.String(c, metadata.RemoteIP)
  29. )
  30. if ret, err = s.lottery.UserCheck(c, mid, ip); err != nil {
  31. log.Error("s.lottery.UserCheck err(%v) | mid(%d), ip(%s)", err, mid, ip)
  32. return
  33. }
  34. if ret == 1 {
  35. check = true
  36. }
  37. return
  38. }
  39. // LotteryNotice fn
  40. func (s *Service) LotteryNotice(c context.Context, aid, mid int64) (bind bool, err error) {
  41. var ret *lMdl.Notice
  42. if ret, err = s.lottery.Notice(c, aid, mid, metadata.String(c, metadata.RemoteIP)); err != nil {
  43. log.Error("s.lottery.Notice err(%v) |aid(%d)|mid(%d)", err, aid, mid)
  44. return
  45. }
  46. if ret != nil && ret.BizID > 0 {
  47. bind = true
  48. }
  49. return
  50. }