1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package rpc
- import (
- "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"
- "fmt"
- "github.com/gogf/gf/v2/os/gcfg"
- "github.com/gogf/gf/v2/os/gctx"
- "github.com/tal-tech/go-zero/core/discov"
- "github.com/tal-tech/go-zero/zrpc"
- "log"
- "time"
- )
- 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.baseserver.integral.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)
- }
- }
|