| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- package proto
- import (
- "context"
- "encoding/json"
- "fmt"
- "bet24.com/log"
- utils2 "bet24.com/servers/insecureframe/gate/Utils"
- "bet24.com/servers/micros/common"
- )
- // 金币日志
- func CashLog(userId int, beginTime, endTime string, pageIndex, pageSize int) (int, []*CashInfo) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_CashLog{
- UserId: userId,
- BeginTime: beginTime,
- EndTime: endTime,
- PageIndex: pageIndex,
- PageSize: pageSize,
- }
- reply := &Response_CashLog{}
- err := xclient.Call(context.Background(), "CashLog", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return 0, nil
- }
- return reply.RecordCount, reply.List
- }
- func GetMoney(userId int) (bool, int) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_base{
- UserId: userId,
- }
- reply := &Response_GetMoney{}
- err := xclient.Call(context.Background(), "GetMoney", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return false, 0
- }
- return reply.Success, reply.Gold
- }
- // 获取保险柜金额
- func BankQuery(userId int) (int, int) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_BankInOrOut{
- UserId: userId,
- }
- reply := &Response_BankInOrOut{}
- err := xclient.Call(context.Background(), "BankQuery", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return reply.RetCode, reply.BankAmount
- }
- return reply.RetCode, reply.BankAmount
- }
- func BankIn(userId, amount, gameId int, serverName, ipAddress string) (int, int, int, string) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_BankInOrOut{
- UserId: userId,
- Amount: amount,
- GameID: gameId,
- ServerName: serverName,
- IpAddress: ipAddress,
- }
- reply := &Response_BankInOrOut{}
- err := xclient.Call(context.Background(), "BankIn", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return reply.RetCode, reply.Gold, reply.BankAmount, reply.OutMsg
- }
- return reply.RetCode, reply.Gold, reply.BankAmount, reply.OutMsg
- }
- func BankOut(userId, amount, gameId int, serverName, ipAddress string) (int, int, int, string) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_BankInOrOut{
- UserId: userId,
- Amount: amount,
- GameID: gameId,
- ServerName: serverName,
- IpAddress: ipAddress,
- }
- reply := &Response_BankInOrOut{}
- err := xclient.Call(context.Background(), "BankOut", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return reply.RetCode, reply.Gold, reply.BankAmount, reply.OutMsg
- }
- return reply.RetCode, reply.Gold, reply.BankAmount, reply.OutMsg
- }
- func FinanceLog(userId, pageIndex, pageSize int) (int, []*FinanceInfo) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_CashLog{
- UserId: userId,
- PageIndex: pageIndex,
- PageSize: pageSize,
- }
- reply := &Response_FinanceLog{}
- err := xclient.Call(context.Background(), "FinanceLog", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return reply.RecordCount, reply.List
- }
- return reply.RecordCount, reply.List
- }
- type UserInfoReq struct {
- GameType int `json:"gameType"` //游戏类型: 1.ludo 2.其他
- UserWallets []UserInfo `json:"userWallets"` //结算时的游戏排行
- }
- type UserInfo struct {
- GoldCoins int `json:"goldCoins"` //数量
- Type int `json:"type"` //类型: 1.加 2.减
- UserId int `json:"userId"` // ⽤户ID
- }
- // 加金币
- func GiveMoney(userId, amount, logType int, sourceName, remark, ipAddress string) int {
- // var userInfo = UserInfo{
- // UserId: userId,
- // GoldCoins: amount,
- // Type: 1,
- // }
-
- // var userInfos = []UserInfo{}
- // userInfos = append(userInfos, userInfo)
- // var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
- // jsonData2, _ := json.Marshal(userInfoReq)
- // fmt.Print("私人房增加金币=====", userInfoReq,amount)
- // utils2.PostData(jsonData2)
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GiveReduceMoney{
- UserId: userId,
- Amount: amount,
- LogType: logType,
- SourceName: sourceName,
- Remark: remark,
- IpAddress: ipAddress,
- }
- reply := &Response_GiveReduceMoney{}
- err := xclient.Call(context.Background(), "GiveMoney", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return 0
- }
- return reply.Gold
- }
- // 加金币
- func GiveMoney2(userId, amount, logType int, sourceName, remark, ipAddress string,yyfUid int) int {
- var userInfo = UserInfo{
- UserId: yyfUid,
- GoldCoins: amount,
- Type: 1,
- }
-
- var userInfos = []UserInfo{}
- userInfos = append(userInfos, userInfo)
- var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
- jsonData2, _ := json.Marshal(userInfoReq)
- fmt.Print("私人房增加金币=====", userInfoReq,amount)
- utils2.PostData(jsonData2)
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GiveReduceMoney{
- UserId: userId,
- Amount: amount,
- LogType: logType,
- SourceName: sourceName,
- Remark: remark,
- IpAddress: ipAddress,
- }
- reply := &Response_GiveReduceMoney{}
- err := xclient.Call(context.Background(), "GiveMoney", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return 0
- }
- return reply.Gold
- }
- // 扣减金币
- func ReduceMoney(userId, amount, logType int, sourceName, remark, ipAddress string) bool {
- // var userInfo = UserInfo{
- // UserId: userId,
- // GoldCoins: amount,
- // Type: 2,
- // }
-
- // var userInfos = []UserInfo{}
- // userInfos = append(userInfos, userInfo)
- // var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
- // jsonData2, _ := json.Marshal(userInfoReq)
-
- // fmt.Print("私人房扣减金币=====", userInfoReq,amount)
- // utils2.PostData(jsonData2)
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GiveReduceMoney{
- UserId: userId,
- Amount: amount,
- LogType: logType,
- SourceName: sourceName,
- Remark: remark,
- IpAddress: ipAddress,
- }
- reply := &Response_GiveReduceMoney{}
- err := xclient.Call(context.Background(), "ReduceMoney", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return false
- }
- return reply.Success
- }
- func ReduceMoney2(userId, amount, logType int, sourceName, remark, ipAddress string,yyfUid int) bool {
- var userInfo = UserInfo{
- UserId: yyfUid,
- GoldCoins: amount,
- Type: 2,
- }
-
- var userInfos = []UserInfo{}
- userInfos = append(userInfos, userInfo)
- var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
- jsonData2, _ := json.Marshal(userInfoReq)
-
- fmt.Print("私人房扣减金币=====", userInfoReq,amount)
- utils2.PostData(jsonData2)
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GiveReduceMoney{
- UserId: userId,
- Amount: amount,
- LogType: logType,
- SourceName: sourceName,
- Remark: remark,
- IpAddress: ipAddress,
- }
- reply := &Response_GiveReduceMoney{}
- err := xclient.Call(context.Background(), "ReduceMoney", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return false
- }
- return reply.Success
- }
- func ModifyMoneyWithTax(userId, amount, tax, logType int, sourceName, remark, ipAddress string) int {
- // var userInfo = UserInfo{
- // UserId: userId,
- // //GoldCoins: math.Abs(amount),
- // // Type: 1,
- // }
- // var amount2=amount
- // if amount2 >= 0 {
- // amount2=amount2-tax
- // userInfo.Type = 1
- // } else {
- // amount2=-amount2
- // userInfo.Type = 2
- // }
- // userInfo.GoldCoins=amount2
- // var userInfos = []UserInfo{}
- // userInfos = append(userInfos, userInfo)
- // var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
- // jsonData2, _ := json.Marshal(userInfoReq)
- // fmt.Print("游戏结束操作金币=====", userInfoReq,amount2,tax)
- // utils2.PostData(jsonData2)
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GiveReduceMoney{
- UserId: userId,
- Amount: amount,
- Tax: tax,
- LogType: logType,
- SourceName: sourceName,
- Remark: remark,
- IpAddress: ipAddress,
- }
- reply := &Response_GiveReduceMoney{}
- err := xclient.Call(context.Background(), "ModifyMoneyWithTax", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- return 0
- }
- return reply.Gold
- }
- func ModifyMoneyWithTax2(userId, amount, tax, logType int, sourceName, remark, ipAddress string,yyfUid int) int {
- var userInfo = UserInfo{
- UserId: yyfUid,
- //GoldCoins: math.Abs(amount),
- // Type: 1,
- }
- var amount2=amount
- if amount2 >= 0 {
- amount2=amount2-tax
- userInfo.Type = 1
- } else {
- amount2=-amount2
- userInfo.Type = 2
- }
- userInfo.GoldCoins=amount2
- var userInfos = []UserInfo{}
- userInfos = append(userInfos, userInfo)
- var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
- jsonData2, _ := json.Marshal(userInfoReq)
- fmt.Print("游戏结束操作金币=====", userInfoReq,amount2,tax)
- utils2.PostData(jsonData2)
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GiveReduceMoney{
- UserId: userId,
- Amount: amount,
- Tax: tax,
- LogType: logType,
- SourceName: sourceName,
- Remark: remark,
- IpAddress: ipAddress,
- }
- reply := &Response_GiveReduceMoney{}
- err := xclient.Call(context.Background(), "ModifyMoneyWithTax", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- return 0
- }
- return reply.Gold
- }
- func BankTransfer(userId, toUserId, amount int, ipAddress string) (int, string, int, int) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_Transfer{
- UserId: userId,
- ToUserId: toUserId,
- Amount: amount,
- IpAddress: ipAddress,
- }
- reply := &Response_Transfer{}
- err := xclient.Call(context.Background(), "BankTransfer", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return reply.RetCode, reply.ErrMsg, reply.StillAmount, reply.Refund
- }
- return reply.RetCode, reply.ErrMsg, reply.StillAmount, reply.Refund
- }
- func BankLog(userId int, beginTime, endTime string, pageIndex, pageSize int) *Response_BankLog {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_CashLog{
- UserId: userId,
- BeginTime: beginTime,
- EndTime: endTime,
- PageIndex: pageIndex,
- PageSize: pageSize,
- }
- reply := &Response_BankLog{}
- err := xclient.Call(context.Background(), "BankLog", args, reply)
- if err != nil {
- log.Debug("money failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return nil
- }
- return reply
- }
|