coin.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package coin
  2. import (
  3. "context"
  4. "go-common/app/service/main/coin/model"
  5. "go-common/library/net/rpc"
  6. )
  7. const (
  8. _addCoins = "RPC.AddCoins"
  9. _archiveUserCoins = "RPC.ArchiveUserCoins"
  10. _userCoins = "RPC.UserCoins"
  11. _modifyCoin = "RPC.ModifyCoin"
  12. _list = "RPC.List"
  13. _userLog = "RPC.UserLog"
  14. _addUserCoinExp = "RPC.AddUserCoinExp"
  15. _updateAddCoin = "RPC.UpdateAddCoin"
  16. _todayExp = "RPC.TodayExp"
  17. )
  18. const (
  19. _appid = "community.service.coin"
  20. )
  21. var (
  22. _noRes = &struct{}{}
  23. )
  24. // Service rpc service.
  25. type Service struct {
  26. client *rpc.Client2
  27. }
  28. //go:generate mockgen -source coin.go -destination mock.go -package coin
  29. // RPC coin rpc
  30. type RPC interface {
  31. AddCoins(c context.Context, arg *model.ArgAddCoin) (err error)
  32. ArchiveUserCoins(c context.Context, arg *model.ArgCoinInfo) (res *model.ArchiveUserCoins, err error)
  33. UserCoins(c context.Context, arg *model.ArgCoinInfo) (count float64, err error)
  34. }
  35. // New new service.
  36. func New(c *rpc.ClientConfig) (s *Service) {
  37. s = &Service{}
  38. s.client = rpc.NewDiscoveryCli(_appid, c)
  39. return
  40. }
  41. // AddCoins coin to archive.
  42. func (s *Service) AddCoins(c context.Context, arg *model.ArgAddCoin) (err error) {
  43. err = s.client.Call(c, _addCoins, arg, _noRes)
  44. return
  45. }
  46. // ArchiveUserCoins get archive User added coins.
  47. func (s *Service) ArchiveUserCoins(c context.Context, arg *model.ArgCoinInfo) (res *model.ArchiveUserCoins, err error) {
  48. res = &model.ArchiveUserCoins{}
  49. err = s.client.Call(c, _archiveUserCoins, arg, res)
  50. return
  51. }
  52. // UserCoins get user coins.
  53. func (s *Service) UserCoins(c context.Context, arg *model.ArgCoinInfo) (count float64, err error) {
  54. err = s.client.Call(c, _userCoins, arg, &count)
  55. return
  56. }
  57. // ModifyCoin modify user coin.
  58. func (s *Service) ModifyCoin(c context.Context, arg *model.ArgModifyCoin) (count float64, err error) {
  59. err = s.client.Call(c, _modifyCoin, arg, &count)
  60. return
  61. }
  62. // List coin added list.
  63. func (s *Service) List(c context.Context, arg *model.ArgList) (list []*model.List, err error) {
  64. err = s.client.Call(c, _list, arg, &list)
  65. return
  66. }
  67. // UserLog user log
  68. func (s *Service) UserLog(c context.Context, arg *model.ArgLog) (logs []*model.Log, err error) {
  69. err = s.client.Call(c, _userLog, arg, &logs)
  70. return
  71. }
  72. // AddUserCoinExp add user coin exp
  73. func (s *Service) AddUserCoinExp(c context.Context, arg *model.ArgAddUserCoinExp) (err error) {
  74. err = s.client.Call(c, _addUserCoinExp, arg, _noRes)
  75. return
  76. }
  77. // UpdateAddCoin update db after add coin for job.
  78. func (s *Service) UpdateAddCoin(c context.Context, arg *model.Record) (err error) {
  79. err = s.client.Call(c, _updateAddCoin, arg, _noRes)
  80. return
  81. }
  82. // TodayExp get today exp
  83. func (s *Service) TodayExp(c context.Context, arg *model.ArgMid) (number int64, err error) {
  84. err = s.client.Call(c, _todayExp, arg, &number)
  85. return
  86. }