package rpc import ( "fmt" "log" "time" "app.yhyue.com/moapp/jyPoints/rpc/integral" "app.yhyue.com/moapp/jyPoints/rpc/integralclient" "app.yhyue.com/moapp/jybase/date" "app.yhyue.com/moapp/jybase/go-logger/logger" "github.com/gogf/gf/v2/os/gcfg" "github.com/gogf/gf/v2/os/gctx" "github.com/zeromicro/go-zero/core/discov" "github.com/zeromicro/go-zero/zrpc" ) var zrpcClient zrpc.Client func init() { var err error zrpcClient, err = zrpc.NewClient(zrpc.RpcClientConf{ Etcd: discov.EtcdConf{ Hosts: gcfg.Instance().MustGet(gctx.New(), "etcd.address", nil).Strings(), Key: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.integral.key", nil).String(), }, }) if err != nil { log.Fatalln(err) } } // IntegralHarvest 积分奖励发放 func IntegralHarvest(userId string, pNum, pType, dateStamp int64) error { t := time.Unix(dateStamp, 0).AddDate(1, 0, 0) req := &integral.Req{ UserId: userId, AppId: gcfg.Instance().MustGet(gctx.New(), "docPoints.appId", "10000").String(), PointType: pType, Point: pNum, EndDate: date.FormatDate(&t, date.Date_Full_Layout), OperationType: false, } resp, err := integralclient.NewIntegral(zrpcClient).IntegralHarvest(gctx.New(), req) if err != nil { return fmt.Errorf(fmt.Sprintf("%+v", req), "IntegralHarvest Resp error", err) } if resp.Code == 1 { logger.Info(fmt.Sprintf("%+v", req), "已成功增加", pNum, "积分") return nil } else { return fmt.Errorf(fmt.Sprintf("%+v", req), "增加", pNum, "积分失败", "Code", resp.Code, "Message", resp.Message) } }