123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package middleground
- import (
- "app.yhyue.com/moapp/jyPoints/rpc/integral"
- "app.yhyue.com/moapp/jyPoints/rpc/integralclient"
- "context"
- "fmt"
- "github.com/zeromicro/go-zero/core/discov"
- "github.com/zeromicro/go-zero/zrpc"
- "log"
- )
- type jyPoints struct {
- hosts []string
- key string
- client zrpc.Client
- }
- func newJyPoints(hosts []string, key string) *jyPoints {
- r := &jyPoints{
- hosts: hosts,
- key: key,
- }
- r.client = r.NewClient()
- return r
- }
- func (r *jyPoints) NewClient() zrpc.Client {
- if r.client != nil && r.client.Conn() != nil {
- return r.client
- }
- client, err := zrpc.NewClient(zrpc.RpcClientConf{
- Etcd: discov.EtcdConf{
- Hosts: r.hosts,
- Key: r.key,
- },
- })
- if err != nil {
- log.Println(err)
- return nil
- }
- r.client = client
- return client
- }
- // 积分消费2008
- func (r *jyPoints) PointConsume(userId, appId, endDate, sourceType, abstract string, point, pointType int64, operationType bool) (resp *integral.Resp, err error) {
- client := r.NewClient()
- if client == nil {
- err = fmt.Errorf("jyPoint client err 01")
- return
- }
- resp, err = integralclient.NewIntegral(client).IntegralConsume(context.Background(), &integral.Req{
- UserId: userId,
- AppId: appId,
- EndDate: endDate,
- SourceType: sourceType,
- Point: point,
- PointType: pointType,
- Abstract: abstract,
- OperationType: operationType,
- })
- log.Println("消费剑鱼币 请求积分rpc 返回内容:", resp)
- return
- }
- // 积分新增
- func (r *jyPoints) PointHarvest(userId, appId, endDate, sourceType, abstract string, point, pointType int64, operationType bool) (resp *integral.Resp, err error) {
- client := r.NewClient()
- if client == nil {
- err = fmt.Errorf("jyPoint client err 02")
- return
- }
- var (
- ctx = context.Background()
- )
- resp, err = integralclient.NewIntegral(client).IntegralHarvest(ctx, &integral.Req{
- UserId: userId,
- AppId: appId,
- EndDate: endDate,
- SourceType: sourceType,
- Point: point,
- PointType: pointType,
- Abstract: abstract,
- OperationType: operationType,
- })
- log.Println("奖励剑鱼币 请求积分rpc 返回内容:", resp)
- return
- }
- // 积分查询
- func (r *jyPoints) PointIntegralBalance(userId, appId string) (resp *integral.Resp, err error) {
- client := r.NewClient()
- if client == nil {
- err = fmt.Errorf("jyPoint client err 03")
- return
- }
- var (
- ctx = context.Background()
- )
- resp, err = integralclient.NewIntegral(client).IntegralBalanceCheck(ctx, &integral.Req{
- UserId: userId,
- AppId: appId,
- })
- log.Println("奖励剑鱼币 请求积分rpc 返回内容:", resp)
- return
- }
|