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. "fmt"
  8. "github.com/gogf/gf/v2/os/gcfg"
  9. "github.com/gogf/gf/v2/os/gctx"
  10. "github.com/tal-tech/go-zero/core/discov"
  11. "github.com/tal-tech/go-zero/zrpc"
  12. "log"
  13. "time"
  14. )
  15. var zrpcClient zrpc.Client
  16. func init() {
  17. var err error
  18. zrpcClient, err = zrpc.NewClient(zrpc.RpcClientConf{
  19. Etcd: discov.EtcdConf{
  20. Hosts: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.address", nil).Strings(),
  21. Key: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.key", nil).String(),
  22. },
  23. })
  24. if err != nil {
  25. log.Fatalln(err)
  26. }
  27. }
  28. // IntegralHarvest 积分奖励发放
  29. func IntegralHarvest(userId string, pNum, pType, dateStamp int64) error {
  30. t := time.Unix(dateStamp, 0).AddDate(1, 0, 0)
  31. req := &integral.Req{
  32. UserId: userId,
  33. AppId: gcfg.Instance().MustGet(gctx.New(), "docPoints.appId", "10000").String(),
  34. PointType: pType,
  35. Point: pNum,
  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", req), "IntegralHarvest Resp error", err)
  42. }
  43. if resp.Code == 1 {
  44. logger.Info(fmt.Sprintf("%+v", req), "已成功增加", pNum, "积分")
  45. return nil
  46. } else {
  47. return fmt.Errorf(fmt.Sprintf("%+v", req), "增加", pNum, "积分失败", "Code", resp.Code, "Message", resp.Message)
  48. }
  49. }