| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- package proto
- import (
- "context"
- "encoding/json"
- "bet24.com/log"
- "bet24.com/servers/micros/common"
- "github.com/smallnest/rpcx/client"
- )
- const ServiceName = "userlabel"
- var consulAddr = common.Default_Consul_Addr
- func getClient() client.XClient {
- return common.GetClientPool().GetClient(ServiceName, consulAddr)
- }
- type Request struct {
- UserId int `json:",omitempty"`
- Name string `json:",omitempty"`
- IpAddress string `json:",omitempty"`
- }
- type Response struct {
- RetCode int
- Data string
- }
- 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("userLabel failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- log.Debug("userLabel return %s", reply.Data)
- return reply.Data
- }
- type Request_GetLabel struct {
- UserId int // 用户id
- TypeId int // 类型id
- }
- type Response_GetLabel struct {
- Labels []LabelColor
- }
- type LabelColor struct {
- TypeId int // 类型id
- TypeName string // 类型名称
- LabelId string // 标签ID
- LabelName string // 标签名称
- Color string // 色值
- PoolValue int // 奖池金额
- }
- type Request_TriggerEvent struct {
- UserId int // 用户ID
- TypeId int // 类型ID
- Scope // 范围
- }
- // 用户标签触发事件
- func TriggerEvent(userId, typeId int, scope Scope) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_TriggerEvent{
- UserId: userId,
- TypeId: typeId,
- Scope: scope,
- }
- err := xclient.Call(context.Background(), "TriggerEvent", args, nil)
- if err != nil {
- common.GetClientPool().RemoveClient(ServiceName)
- log.Debug("userLabel failed to call: %v", err)
- }
- return
- }
- // 获取标签列表
- func GetLabel(userId, typeId int) []LabelColor {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GetLabel{
- UserId: userId,
- TypeId: typeId,
- }
- reply := &Response_GetLabel{}
- err := xclient.Call(context.Background(), "GetLabel", args, reply)
- if err != nil {
- common.GetClientPool().RemoveClient(ServiceName)
- log.Debug("userLabel failed to call: %v", err)
- }
- return reply.Labels
- }
- type LabelUser struct {
- UserId int // 用户id
- NickName string // 昵称
- TypeId int // 类型id
- TypeName string // 类型名称
- LabelId string // 标签ID
- LabelName string // 标签名称
- UpdateTime string // 更新时间
- }
- type Request_GetListByLabelId struct {
- LabelId int
- PageIndex int
- PageSize int
- }
- type Response_GetListByLabelId struct {
- RecordCount int
- List []LabelUser
- }
- // 获取标签列表
- func GetListByLabelId(labelId, pageIndex, pageSize int) string {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GetListByLabelId{
- LabelId: labelId,
- PageIndex: pageIndex,
- PageSize: pageSize,
- }
- reply := &Response_GetListByLabelId{}
- err := xclient.Call(context.Background(), "GetListByLabelId", args, reply)
- if err != nil {
- common.GetClientPool().RemoveClient(ServiceName)
- log.Debug("userLabel failed to call: %v", err)
- }
- buf, _ := json.Marshal(reply)
- return string(buf)
- }
- type Response_GetConfigSimpleInfo struct {
- List []ConfigSimpleInfo
- }
- // 获取标签配置简单信息
- func GetConfigSimpleInfo() []ConfigSimpleInfo {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request{}
- reply := &Response_GetConfigSimpleInfo{}
- err := xclient.Call(context.Background(), "GetConfigSimpleInfo", args, reply)
- if err != nil {
- common.GetClientPool().RemoveClient(ServiceName)
- log.Debug("userLabel failed to call: %v", err)
- }
- return reply.List
- }
|