| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- package proto
- import (
- "bet24.com/log"
- "bet24.com/servers/micros/common"
- "context"
- "encoding/json"
- )
- type Request_vip struct {
- ProductId string
- PrivilegeType int
- PurchaseSeconds int
- Point int
- UserId int
- Level int
- Name string
- ToUserId int
- }
- type Reponse_vip struct {
- Value int
- Code int
- Data string
- Success bool
- UserVip *UserVip
- VipList []VipInfo
- VipInfo *VipInfo
- PurchasePackages []PurchasePackage
- }
- // 根据用户ID查询用户vip状态
- func GetUserVip(userId int) string {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetUserVip", args, reply)
- if err != nil {
- log.Debug("vipservice.GetUserVip failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- if reply.UserVip == nil {
- return ""
- }
- d, _ := json.Marshal(reply.UserVip)
- return string(d)
- }
- func GetUserVipInfo(userId int) *UserVip {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetUserVip", args, reply)
- if err != nil {
- log.Debug("vipservice.GetUserVip failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return nil
- }
- return reply.UserVip
- }
- // 获取vip列表,前端展现用
- func GetVipList() string {
- xclient := getClient()
- args := &Request_vip{}
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetVipList", args, reply)
- if err != nil {
- log.Debug("vipservice.GetVipList failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- if reply.VipList == nil {
- return ""
- }
- d, _ := json.Marshal(reply.VipList)
- return string(d)
- }
- // 获取购买礼包列表
- func GetPurchasePackageList(userId int) string {
- xclient := getClient()
- args := &Request_vip{UserId: userId}
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetPurchasePackageList", args, reply)
- if err != nil {
- log.Debug("vipsvc.GetPurchasePackageList failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- if reply.PurchasePackages == nil {
- return ""
- }
- d, _ := json.Marshal(reply.PurchasePackages)
- return string(d)
- }
- // 根据等级获取vip配置信息
- func GetVipByLevel(level int) *VipInfo {
- xclient := getClient()
- args := &Request_vip{
- Level: level,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetVipByLevel", args, reply)
- if err != nil {
- log.Debug("vipservice.GetVipByLevel failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return nil
- }
- log.Debug("GetVipByLevel return %+v", reply.VipInfo)
- return reply.VipInfo
- }
- // 获取额外补助百分比
- func GetExtraBankruptcy(userId int) int {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetExtraBankruptcy", args, reply)
- if err != nil {
- log.Debug("vipservice.GetExtraBankruptcy failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return 0
- }
- return reply.Value
- }
- // 获取额外经验百分比
- func GetExtraExperience(userId int) int {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetExtraExperience", args, reply)
- if err != nil {
- log.Debug("vipservice.GetExtraExperience failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return 0
- }
- return reply.Value
- }
- // 获取额外好友上限数量
- func GetExtraFriendCount(userId int) int {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetExtraFriendCount", args, reply)
- if err != nil {
- log.Debug("vipservice.GetExtraFriendCount failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return 0
- }
- return reply.Value
- }
- func GetUserPrivilegeValue(userId, privilegeType int) int {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- PrivilegeType: privilegeType,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GetUserPrivilegeValue", args, reply)
- if err != nil {
- log.Debug("vipservice.GetUserPrivilegeValue failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return 0
- }
- return reply.Value
- }
- func CanKickPrivateRoomUser(userId, toUserId int) bool {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- ToUserId: toUserId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "CanKickPrivateRoomUser", args, reply)
- if err != nil {
- log.Debug("vipservice.CanKickPrivateRoomUser failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return false
- }
- return reply.Success
- }
- // 判断是否能购买礼包
- func CanBuyPackage(userId int, productId string) bool {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- ProductId: productId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "CanBuyPackage", args, reply)
- if err != nil {
- log.Debug("vipservice.CanBuyPackage failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return false
- }
- return reply.Success
- }
- // 实际购买礼包(已完成支付),发放道具,添加购买历史记录
- func BuyPackage(userId int, productId string) {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- ProductId: productId,
- }
- err := xclient.Call(context.Background(), "BuyPackage", args, nil)
- if err != nil {
- log.Debug("vipservice.BuyPackage failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- }
- }
- // 添加vip点数,可能触发升级,升级如果当前是vip,则需要发放登录道具和升级道具
- func AddVipPoint(userId int, point int) {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- Point: point,
- }
- err := xclient.Call(context.Background(), "AddVipPoint", args, nil)
- if err != nil {
- log.Debug("vipservice.AddVipPoint failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- }
- }
- // 添加vip时长(已完成支付)
- func AddVipSeconds(userId int, purchaseSeconds int) {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- PurchaseSeconds: purchaseSeconds,
- }
- err := xclient.Call(context.Background(), "AddVipSeconds", args, nil)
- if err != nil {
- log.Debug("vipservice.AddVipSeconds failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- }
- }
- // 检查是否能够领取每日礼包
- func CheckDailyAward(userId int) (bool, int) {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "CheckDailyAward", args, reply)
- if err != nil {
- log.Debug("vipservice.CheckDailyAward failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return false, -1
- }
- return reply.Success, reply.Code
- }
- // 领取每日奖励
- func GiftDailyAward(userId int) string {
- xclient := getClient()
- args := &Request_vip{
- UserId: userId,
- }
- reply := &Reponse_vip{}
- err := xclient.Call(context.Background(), "GiftDailyAward", args, reply)
- if err != nil {
- log.Debug("vipservice.GiftDailyAward failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return "fail"
- }
- return "ok"
- }
|