jypoints.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package middleground
  2. import (
  3. "app.yhyue.com/moapp/jyPoints/rpc/integral"
  4. "app.yhyue.com/moapp/jyPoints/rpc/integralclient"
  5. "context"
  6. "fmt"
  7. "github.com/zeromicro/go-zero/core/discov"
  8. "github.com/zeromicro/go-zero/zrpc"
  9. "log"
  10. )
  11. type jyPoints struct {
  12. hosts []string
  13. key string
  14. client zrpc.Client
  15. }
  16. func newJyPoints(hosts []string, key string) *jyPoints {
  17. r := &jyPoints{
  18. hosts: hosts,
  19. key: key,
  20. }
  21. r.client = r.NewClient()
  22. return r
  23. }
  24. func (r *jyPoints) NewClient() zrpc.Client {
  25. if r.client != nil && r.client.Conn() != nil {
  26. return r.client
  27. }
  28. client, err := zrpc.NewClient(zrpc.RpcClientConf{
  29. Etcd: discov.EtcdConf{
  30. Hosts: r.hosts,
  31. Key: r.key,
  32. },
  33. })
  34. if err != nil {
  35. log.Println(err)
  36. return nil
  37. }
  38. r.client = client
  39. return client
  40. }
  41. // 积分消费2008
  42. func (r *jyPoints) PointConsume(userId, appId, endDate, sourceType, abstract string, point, pointType int64, operationType bool) (resp *integral.Resp, err error) {
  43. client := r.NewClient()
  44. if client == nil {
  45. err = fmt.Errorf("jyPoint client err 01")
  46. return
  47. }
  48. resp, err = integralclient.NewIntegral(client).IntegralConsume(context.Background(), &integral.Req{
  49. UserId: userId,
  50. AppId: appId,
  51. EndDate: endDate,
  52. SourceType: sourceType,
  53. Point: point,
  54. PointType: pointType,
  55. Abstract: abstract,
  56. OperationType: operationType,
  57. })
  58. log.Println("消费剑鱼币 请求积分rpc 返回内容:", resp)
  59. return
  60. }
  61. // 积分新增
  62. func (r *jyPoints) PointHarvest(userId, appId, endDate, sourceType, abstract string, point, pointType int64, operationType bool) (resp *integral.Resp, err error) {
  63. client := r.NewClient()
  64. if client == nil {
  65. err = fmt.Errorf("jyPoint client err 02")
  66. return
  67. }
  68. var (
  69. ctx = context.Background()
  70. )
  71. resp, err = integralclient.NewIntegral(client).IntegralHarvest(ctx, &integral.Req{
  72. UserId: userId,
  73. AppId: appId,
  74. EndDate: endDate,
  75. SourceType: sourceType,
  76. Point: point,
  77. PointType: pointType,
  78. Abstract: abstract,
  79. OperationType: operationType,
  80. })
  81. log.Println("奖励剑鱼币 请求积分rpc 返回内容:", resp)
  82. return
  83. }
  84. // 积分查询
  85. func (r *jyPoints) PointIntegralBalance(userId, appId string) (resp *integral.Resp, err error) {
  86. client := r.NewClient()
  87. if client == nil {
  88. err = fmt.Errorf("jyPoint client err 03")
  89. return
  90. }
  91. var (
  92. ctx = context.Background()
  93. )
  94. resp, err = integralclient.NewIntegral(client).IntegralBalanceCheck(ctx, &integral.Req{
  95. UserId: userId,
  96. AppId: appId,
  97. })
  98. log.Println("奖励剑鱼币 请求积分rpc 返回内容:", resp)
  99. return
  100. }