integral.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package rpc
  2. import (
  3. "app.yhyue.com/moapp/jyPoints/rpc/integral"
  4. "app.yhyue.com/moapp/jyPoints/rpc/integralclient"
  5. "app.yhyue.com/moapp/jybase/date"
  6. "app.yhyue.com/moapp/jybase/go-logger/logger"
  7. "app.yhyue.com/moapp/message/model"
  8. "fmt"
  9. "github.com/gogf/gf/v2/os/gcfg"
  10. "github.com/gogf/gf/v2/os/gctx"
  11. "github.com/tal-tech/go-zero/core/discov"
  12. "github.com/tal-tech/go-zero/zrpc"
  13. "log"
  14. "time"
  15. )
  16. var zrpcClient zrpc.Client
  17. func init() {
  18. var err error
  19. zrpcClient, err = zrpc.NewClient(zrpc.RpcClientConf{
  20. Etcd: discov.EtcdConf{
  21. Hosts: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.address", nil).Strings(),
  22. Key: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.key", nil).String(),
  23. },
  24. })
  25. if err != nil {
  26. log.Fatalln(err)
  27. }
  28. }
  29. func IntegralHarvest(msg *model.Message, point, pointType int64) error {
  30. t := time.Unix(msg.E_time, 0).AddDate(1, 0, 0)
  31. req := &integral.Req{
  32. UserId: msg.E_userId,
  33. AppId: gcfg.Instance().MustGet(gctx.New(), "docPoints.appId", "10000").String(),
  34. PointType: pointType,
  35. Point: point,
  36. EndDate: date.FormatDate(&t, date.Date_Full_Layout),
  37. OperationType: false,
  38. }
  39. resp, err := integralclient.NewIntegral(zrpcClient).IntegralHarvest(gctx.New(), req)
  40. if err != nil {
  41. return fmt.Errorf(fmt.Sprintf("%+v", msg), "IntegralHarvest Resp error", err)
  42. }
  43. if resp.Code == 1 {
  44. logger.Info(fmt.Sprintf("%+v", msg), "已成功增加", point, "积分")
  45. return nil
  46. } else {
  47. return fmt.Errorf(fmt.Sprintf("%+v", msg), "增加", point, "积分失败", "Code", resp.Code, "Message", resp.Message)
  48. }
  49. }