dao.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package coin
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-view/conf"
  5. coinrpc "go-common/app/service/main/coin/api/gorpc"
  6. "go-common/app/service/main/coin/model"
  7. "go-common/library/net/metadata"
  8. "github.com/pkg/errors"
  9. )
  10. // Dao is coin dao
  11. type Dao struct {
  12. coinRPC *coinrpc.Service
  13. }
  14. // New initial coin dao
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. coinRPC: coinrpc.New(c.CoinRPC),
  18. }
  19. return
  20. }
  21. // AddCoins add coin to upper.
  22. func (d *Dao) AddCoins(c context.Context, aid, mid, upID, maxCoin, avtype, multiply int64, typeID int16, pubTime int64) (err error) {
  23. ip := metadata.String(c, metadata.RemoteIP)
  24. arg := &model.ArgAddCoin{Mid: mid, UpMid: upID, MaxCoin: maxCoin, Aid: aid, AvType: avtype, Multiply: multiply, RealIP: ip, TypeID: typeID, PubTime: pubTime}
  25. return d.coinRPC.AddCoins(c, arg)
  26. }
  27. // ArchiveUserCoins .
  28. func (d *Dao) ArchiveUserCoins(c context.Context, aid, mid, avType int64) (res *model.ArchiveUserCoins, err error) {
  29. ip := metadata.String(c, metadata.RemoteIP)
  30. arg := &model.ArgCoinInfo{Mid: mid, Aid: aid, AvType: avType, RealIP: ip}
  31. if res, err = d.coinRPC.ArchiveUserCoins(c, arg); err != nil {
  32. err = errors.Wrapf(err, "%v", arg)
  33. }
  34. return
  35. }
  36. // UserCoins get user coins
  37. func (d *Dao) UserCoins(c context.Context, mid int64) (count float64, err error) {
  38. ip := metadata.String(c, metadata.RemoteIP)
  39. arg := &model.ArgCoinInfo{Mid: mid, RealIP: ip}
  40. if count, err = d.coinRPC.UserCoins(c, arg); err != nil {
  41. err = errors.Wrapf(err, "%v", arg)
  42. }
  43. return
  44. }