| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- package proto
- import (
- "context"
- "bet24.com/log"
- "bet24.com/servers/micros/common"
- "github.com/smallnest/rpcx/client"
- )
- const ServiceName = "badgeservice"
- var consulAddr = common.Default_Consul_Addr
- func getClient() client.XClient {
- return common.GetClientPool().GetClient(ServiceName, consulAddr)
- }
- type Request struct {
- UserId int `json:",omitempty"`
- Model int `json:",omitempty"`
- BadgeId int `json:",omitempty"`
- Position int `json:",omitempty"`
- Name string `json:",omitempty"`
- IpAddress string `json:",omitempty"`
- Action int `json:",omitempty"`
- Progress int `json:",omitempty"`
- Param Scope `json:",omitempty"`
- }
- type Response struct {
- RetCode int
- Data string
- Badges []BadgePosition
- }
- func SetConsulAddr(addr string) {
- consulAddr = addr
- }
- func SayHello(name string) string {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request{
- Name: name,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "SayHello", args, reply)
- if err != nil {
- log.Debug("%s failed to call: %v", ServiceName, err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- log.Debug("userLabel return %s", reply.Data)
- return reply.Data
- }
- // 获取系统成就的徽章列表
- func GetSysBadgeList() string {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request{}
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetSysBadgeList", args, reply)
- if err != nil {
- log.Debug("%s failed to call: %v", ServiceName, err)
- common.GetClientPool().RemoveClient(ServiceName)
- return "[]"
- }
- return reply.Data
- }
- // 获取用户徽章佩戴与展示
- func GetBadgeWearAndShow(userId int) []BadgePosition {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request{
- UserId: userId,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetBadgeWearAndShow", args, reply)
- if err != nil {
- log.Debug("%s failed to call: %v", ServiceName, err)
- common.GetClientPool().RemoveClient(ServiceName)
- return nil
- }
- return reply.Badges
- }
- // 获取用户徽章列表
- func GetUserBadgeList(userId int) string {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request{
- UserId: userId,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetUserBadgeList", args, reply)
- if err != nil {
- log.Debug("%s failed to call: %v", ServiceName, err)
- common.GetClientPool().RemoveClient(ServiceName)
- return "[]"
- }
- if reply.Data == "" {
- return "[]"
- }
- return reply.Data
- }
- // 佩戴成就徽章
- func WearBadge(userId, badgeId, position int) string {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request{
- UserId: userId,
- BadgeId: badgeId,
- Position: position,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "WearBadge", args, reply)
- if err != nil {
- log.Debug("%s failed to call: %v", ServiceName, err)
- common.GetClientPool().RemoveClient(ServiceName)
- return "[]"
- }
- if reply.Data == "" {
- return "[]"
- }
- return reply.Data
- }
- // 触发动作(徽章进度)
- func DoAction(userId, action, progress int, param Scope) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request{
- UserId: userId,
- Action: action,
- Progress: progress,
- Param: param,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "DoAction", args, reply)
- if err != nil {
- log.Debug("%s failed to call: %v", ServiceName, err)
- common.GetClientPool().RemoveClient(ServiceName)
- }
- return
- }
|