cash.pb.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. package proto
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "bet24.com/log"
  7. utils2 "bet24.com/servers/insecureframe/gate/Utils"
  8. "bet24.com/servers/micros/common"
  9. )
  10. // 金币日志
  11. func CashLog(userId int, beginTime, endTime string, pageIndex, pageSize int) (int, []*CashInfo) {
  12. xclient := getClient()
  13. //defer xclient.Close()
  14. args := &Request_CashLog{
  15. UserId: userId,
  16. BeginTime: beginTime,
  17. EndTime: endTime,
  18. PageIndex: pageIndex,
  19. PageSize: pageSize,
  20. }
  21. reply := &Response_CashLog{}
  22. err := xclient.Call(context.Background(), "CashLog", args, reply)
  23. if err != nil {
  24. log.Debug("money failed to call: %v", err)
  25. common.GetClientPool().RemoveClient(ServiceName)
  26. return 0, nil
  27. }
  28. return reply.RecordCount, reply.List
  29. }
  30. func GetMoney(userId int) (bool, int) {
  31. xclient := getClient()
  32. //defer xclient.Close()
  33. args := &Request_base{
  34. UserId: userId,
  35. }
  36. reply := &Response_GetMoney{}
  37. err := xclient.Call(context.Background(), "GetMoney", args, reply)
  38. if err != nil {
  39. log.Debug("money failed to call: %v", err)
  40. common.GetClientPool().RemoveClient(ServiceName)
  41. return false, 0
  42. }
  43. return reply.Success, reply.Gold
  44. }
  45. // 获取保险柜金额
  46. func BankQuery(userId int) (int, int) {
  47. xclient := getClient()
  48. //defer xclient.Close()
  49. args := &Request_BankInOrOut{
  50. UserId: userId,
  51. }
  52. reply := &Response_BankInOrOut{}
  53. err := xclient.Call(context.Background(), "BankQuery", args, reply)
  54. if err != nil {
  55. log.Debug("money failed to call: %v", err)
  56. common.GetClientPool().RemoveClient(ServiceName)
  57. return reply.RetCode, reply.BankAmount
  58. }
  59. return reply.RetCode, reply.BankAmount
  60. }
  61. func BankIn(userId, amount, gameId int, serverName, ipAddress string) (int, int, int, string) {
  62. xclient := getClient()
  63. //defer xclient.Close()
  64. args := &Request_BankInOrOut{
  65. UserId: userId,
  66. Amount: amount,
  67. GameID: gameId,
  68. ServerName: serverName,
  69. IpAddress: ipAddress,
  70. }
  71. reply := &Response_BankInOrOut{}
  72. err := xclient.Call(context.Background(), "BankIn", args, reply)
  73. if err != nil {
  74. log.Debug("money failed to call: %v", err)
  75. common.GetClientPool().RemoveClient(ServiceName)
  76. return reply.RetCode, reply.Gold, reply.BankAmount, reply.OutMsg
  77. }
  78. return reply.RetCode, reply.Gold, reply.BankAmount, reply.OutMsg
  79. }
  80. func BankOut(userId, amount, gameId int, serverName, ipAddress string) (int, int, int, string) {
  81. xclient := getClient()
  82. //defer xclient.Close()
  83. args := &Request_BankInOrOut{
  84. UserId: userId,
  85. Amount: amount,
  86. GameID: gameId,
  87. ServerName: serverName,
  88. IpAddress: ipAddress,
  89. }
  90. reply := &Response_BankInOrOut{}
  91. err := xclient.Call(context.Background(), "BankOut", args, reply)
  92. if err != nil {
  93. log.Debug("money failed to call: %v", err)
  94. common.GetClientPool().RemoveClient(ServiceName)
  95. return reply.RetCode, reply.Gold, reply.BankAmount, reply.OutMsg
  96. }
  97. return reply.RetCode, reply.Gold, reply.BankAmount, reply.OutMsg
  98. }
  99. func FinanceLog(userId, pageIndex, pageSize int) (int, []*FinanceInfo) {
  100. xclient := getClient()
  101. //defer xclient.Close()
  102. args := &Request_CashLog{
  103. UserId: userId,
  104. PageIndex: pageIndex,
  105. PageSize: pageSize,
  106. }
  107. reply := &Response_FinanceLog{}
  108. err := xclient.Call(context.Background(), "FinanceLog", args, reply)
  109. if err != nil {
  110. log.Debug("money failed to call: %v", err)
  111. common.GetClientPool().RemoveClient(ServiceName)
  112. return reply.RecordCount, reply.List
  113. }
  114. return reply.RecordCount, reply.List
  115. }
  116. type UserInfoReq struct {
  117. GameType int `json:"gameType"` //游戏类型: 1.ludo 2.其他
  118. UserWallets []UserInfo `json:"userWallets"` //结算时的游戏排行
  119. }
  120. type UserInfo struct {
  121. GoldCoins int `json:"goldCoins"` //数量
  122. Type int `json:"type"` //类型: 1.加 2.减
  123. UserId int `json:"userId"` // ⽤户ID
  124. }
  125. // 加金币
  126. func GiveMoney(userId, amount, logType int, sourceName, remark, ipAddress string) int {
  127. // var userInfo = UserInfo{
  128. // UserId: userId,
  129. // GoldCoins: amount,
  130. // Type: 1,
  131. // }
  132. // var userInfos = []UserInfo{}
  133. // userInfos = append(userInfos, userInfo)
  134. // var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
  135. // jsonData2, _ := json.Marshal(userInfoReq)
  136. // fmt.Print("私人房增加金币=====", userInfoReq,amount)
  137. // utils2.PostData(jsonData2)
  138. xclient := getClient()
  139. //defer xclient.Close()
  140. args := &Request_GiveReduceMoney{
  141. UserId: userId,
  142. Amount: amount,
  143. LogType: logType,
  144. SourceName: sourceName,
  145. Remark: remark,
  146. IpAddress: ipAddress,
  147. }
  148. reply := &Response_GiveReduceMoney{}
  149. err := xclient.Call(context.Background(), "GiveMoney", args, reply)
  150. if err != nil {
  151. log.Debug("money failed to call: %v", err)
  152. common.GetClientPool().RemoveClient(ServiceName)
  153. return 0
  154. }
  155. return reply.Gold
  156. }
  157. // 加金币
  158. func GiveMoney2(userId, amount, logType int, sourceName, remark, ipAddress string,yyfUid int) int {
  159. var userInfo = UserInfo{
  160. UserId: yyfUid,
  161. GoldCoins: amount,
  162. Type: 1,
  163. }
  164. var userInfos = []UserInfo{}
  165. userInfos = append(userInfos, userInfo)
  166. var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
  167. jsonData2, _ := json.Marshal(userInfoReq)
  168. fmt.Print("私人房增加金币=====", userInfoReq,amount)
  169. utils2.PostData(jsonData2)
  170. xclient := getClient()
  171. //defer xclient.Close()
  172. args := &Request_GiveReduceMoney{
  173. UserId: userId,
  174. Amount: amount,
  175. LogType: logType,
  176. SourceName: sourceName,
  177. Remark: remark,
  178. IpAddress: ipAddress,
  179. }
  180. reply := &Response_GiveReduceMoney{}
  181. err := xclient.Call(context.Background(), "GiveMoney", args, reply)
  182. if err != nil {
  183. log.Debug("money failed to call: %v", err)
  184. common.GetClientPool().RemoveClient(ServiceName)
  185. return 0
  186. }
  187. return reply.Gold
  188. }
  189. // 扣减金币
  190. func ReduceMoney(userId, amount, logType int, sourceName, remark, ipAddress string) bool {
  191. // var userInfo = UserInfo{
  192. // UserId: userId,
  193. // GoldCoins: amount,
  194. // Type: 2,
  195. // }
  196. // var userInfos = []UserInfo{}
  197. // userInfos = append(userInfos, userInfo)
  198. // var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
  199. // jsonData2, _ := json.Marshal(userInfoReq)
  200. // fmt.Print("私人房扣减金币=====", userInfoReq,amount)
  201. // utils2.PostData(jsonData2)
  202. xclient := getClient()
  203. //defer xclient.Close()
  204. args := &Request_GiveReduceMoney{
  205. UserId: userId,
  206. Amount: amount,
  207. LogType: logType,
  208. SourceName: sourceName,
  209. Remark: remark,
  210. IpAddress: ipAddress,
  211. }
  212. reply := &Response_GiveReduceMoney{}
  213. err := xclient.Call(context.Background(), "ReduceMoney", args, reply)
  214. if err != nil {
  215. log.Debug("money failed to call: %v", err)
  216. common.GetClientPool().RemoveClient(ServiceName)
  217. return false
  218. }
  219. return reply.Success
  220. }
  221. func ReduceMoney2(userId, amount, logType int, sourceName, remark, ipAddress string,yyfUid int) bool {
  222. var userInfo = UserInfo{
  223. UserId: yyfUid,
  224. GoldCoins: amount,
  225. Type: 2,
  226. }
  227. var userInfos = []UserInfo{}
  228. userInfos = append(userInfos, userInfo)
  229. var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
  230. jsonData2, _ := json.Marshal(userInfoReq)
  231. fmt.Print("私人房扣减金币=====", userInfoReq,amount)
  232. utils2.PostData(jsonData2)
  233. xclient := getClient()
  234. //defer xclient.Close()
  235. args := &Request_GiveReduceMoney{
  236. UserId: userId,
  237. Amount: amount,
  238. LogType: logType,
  239. SourceName: sourceName,
  240. Remark: remark,
  241. IpAddress: ipAddress,
  242. }
  243. reply := &Response_GiveReduceMoney{}
  244. err := xclient.Call(context.Background(), "ReduceMoney", args, reply)
  245. if err != nil {
  246. log.Debug("money failed to call: %v", err)
  247. common.GetClientPool().RemoveClient(ServiceName)
  248. return false
  249. }
  250. return reply.Success
  251. }
  252. func ModifyMoneyWithTax(userId, amount, tax, logType int, sourceName, remark, ipAddress string) int {
  253. // var userInfo = UserInfo{
  254. // UserId: userId,
  255. // //GoldCoins: math.Abs(amount),
  256. // // Type: 1,
  257. // }
  258. // var amount2=amount
  259. // if amount2 >= 0 {
  260. // amount2=amount2-tax
  261. // userInfo.Type = 1
  262. // } else {
  263. // amount2=-amount2
  264. // userInfo.Type = 2
  265. // }
  266. // userInfo.GoldCoins=amount2
  267. // var userInfos = []UserInfo{}
  268. // userInfos = append(userInfos, userInfo)
  269. // var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
  270. // jsonData2, _ := json.Marshal(userInfoReq)
  271. // fmt.Print("游戏结束操作金币=====", userInfoReq,amount2,tax)
  272. // utils2.PostData(jsonData2)
  273. xclient := getClient()
  274. //defer xclient.Close()
  275. args := &Request_GiveReduceMoney{
  276. UserId: userId,
  277. Amount: amount,
  278. Tax: tax,
  279. LogType: logType,
  280. SourceName: sourceName,
  281. Remark: remark,
  282. IpAddress: ipAddress,
  283. }
  284. reply := &Response_GiveReduceMoney{}
  285. err := xclient.Call(context.Background(), "ModifyMoneyWithTax", args, reply)
  286. if err != nil {
  287. log.Debug("money failed to call: %v", err)
  288. return 0
  289. }
  290. return reply.Gold
  291. }
  292. func ModifyMoneyWithTax2(userId, amount, tax, logType int, sourceName, remark, ipAddress string,yyfUid int) int {
  293. var userInfo = UserInfo{
  294. UserId: yyfUid,
  295. //GoldCoins: math.Abs(amount),
  296. // Type: 1,
  297. }
  298. var amount2=amount
  299. if amount2 >= 0 {
  300. amount2=amount2-tax
  301. userInfo.Type = 1
  302. } else {
  303. amount2=-amount2
  304. userInfo.Type = 2
  305. }
  306. userInfo.GoldCoins=amount2
  307. var userInfos = []UserInfo{}
  308. userInfos = append(userInfos, userInfo)
  309. var userInfoReq = UserInfoReq{GameType: 1, UserWallets: userInfos}
  310. jsonData2, _ := json.Marshal(userInfoReq)
  311. fmt.Print("游戏结束操作金币=====", userInfoReq,amount2,tax)
  312. utils2.PostData(jsonData2)
  313. xclient := getClient()
  314. //defer xclient.Close()
  315. args := &Request_GiveReduceMoney{
  316. UserId: userId,
  317. Amount: amount,
  318. Tax: tax,
  319. LogType: logType,
  320. SourceName: sourceName,
  321. Remark: remark,
  322. IpAddress: ipAddress,
  323. }
  324. reply := &Response_GiveReduceMoney{}
  325. err := xclient.Call(context.Background(), "ModifyMoneyWithTax", args, reply)
  326. if err != nil {
  327. log.Debug("money failed to call: %v", err)
  328. return 0
  329. }
  330. return reply.Gold
  331. }
  332. func BankTransfer(userId, toUserId, amount int, ipAddress string) (int, string, int, int) {
  333. xclient := getClient()
  334. //defer xclient.Close()
  335. args := &Request_Transfer{
  336. UserId: userId,
  337. ToUserId: toUserId,
  338. Amount: amount,
  339. IpAddress: ipAddress,
  340. }
  341. reply := &Response_Transfer{}
  342. err := xclient.Call(context.Background(), "BankTransfer", args, reply)
  343. if err != nil {
  344. log.Debug("money failed to call: %v", err)
  345. common.GetClientPool().RemoveClient(ServiceName)
  346. return reply.RetCode, reply.ErrMsg, reply.StillAmount, reply.Refund
  347. }
  348. return reply.RetCode, reply.ErrMsg, reply.StillAmount, reply.Refund
  349. }
  350. func BankLog(userId int, beginTime, endTime string, pageIndex, pageSize int) *Response_BankLog {
  351. xclient := getClient()
  352. //defer xclient.Close()
  353. args := &Request_CashLog{
  354. UserId: userId,
  355. BeginTime: beginTime,
  356. EndTime: endTime,
  357. PageIndex: pageIndex,
  358. PageSize: pageSize,
  359. }
  360. reply := &Response_BankLog{}
  361. err := xclient.Call(context.Background(), "BankLog", args, reply)
  362. if err != nil {
  363. log.Debug("money failed to call: %v", err)
  364. common.GetClientPool().RemoveClient(ServiceName)
  365. return nil
  366. }
  367. return reply
  368. }