user_cash.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package gatesink
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "bet24.com/log"
  6. "bet24.com/servers/common"
  7. "bet24.com/servers/fishhall/protocol"
  8. "bet24.com/servers/insecureframe/gate"
  9. cash "bet24.com/servers/micros/money/proto"
  10. )
  11. // 金币日志
  12. func (this *user) cashLog(msg, data string) {
  13. retData := ""
  14. var req protocol.CashList_req
  15. if err := json.Unmarshal([]byte(data), &req); err != nil {
  16. retData = fmt.Sprintf("cashLog unmarshal fail %v", err)
  17. log.Release(retData)
  18. this.WriteMsg(msg, retData)
  19. return
  20. }
  21. // 查询时间段
  22. if len(req.BeginTime) <= 0 || len(req.EndTime) <= 0 {
  23. req.BeginTime = common.GetNowTime().Format(common.Layout)
  24. req.EndTime = common.GetNowTime().Format(common.Layout)
  25. }
  26. // 页索引
  27. if req.PageIndex <= 0 {
  28. req.PageIndex = 1
  29. }
  30. // 每页显示50条记录
  31. if req.PageSize <= 0 {
  32. req.PageSize = 50
  33. }
  34. recordCount, logs := cash.CashLog(this.getUserId(), req.BeginTime, req.EndTime, req.PageIndex, req.PageSize)
  35. d, _ := json.Marshal(struct {
  36. RecordCount int
  37. List []*cash.CashInfo
  38. }{
  39. RecordCount: recordCount,
  40. List: logs,
  41. })
  42. this.WriteMsg(msg, string(d))
  43. }
  44. // 保险柜存款
  45. func (this *user) bankIn(msg, data string) {
  46. var req protocol.BankInOrOut_req
  47. if err := json.Unmarshal([]byte(data), &req); err != nil {
  48. retData := fmt.Sprintf("BankInAndOut_req Unmarshal data failed %v", data)
  49. log.Release(retData)
  50. this.WriteMsg(msg, retData)
  51. return
  52. }
  53. var resp protocol.BankInOrOut_resp
  54. resp.RetCode, resp.Gold, resp.BankAmount, resp.OutMsg = cash.BankIn(this.getUserId(), req.Amount, req.GameID, "", "")
  55. if resp.RetCode != 1 {
  56. log.Debug("user.bankIn failed %v", resp)
  57. }
  58. //刷新金币
  59. u := gate.GetUserInfo(this.UserIndex)
  60. u.SetUserGold(resp.Gold)
  61. u.SetUserBankamount(resp.BankAmount)
  62. d, _ := json.Marshal(resp)
  63. this.WriteMsg(msg, string(d))
  64. }
  65. // 保险柜取款
  66. func (this *user) bankOut(msg, data string) {
  67. var req protocol.BankInOrOut_req
  68. if err := json.Unmarshal([]byte(data), &req); err != nil {
  69. retData := fmt.Sprintf("BankInAndOut_req Unmarshal data failed %v", data)
  70. log.Release(retData)
  71. this.WriteMsg(msg, retData)
  72. return
  73. }
  74. var resp protocol.BankInOrOut_resp
  75. resp.RetCode, resp.Gold, resp.BankAmount, resp.OutMsg = cash.BankOut(this.getUserId(), req.Amount, req.GameID, "", "")
  76. if resp.RetCode != 1 {
  77. log.Debug("user.bankOut failed %v", resp)
  78. }
  79. //刷新金币
  80. u := gate.GetUserInfo(this.UserIndex)
  81. u.SetUserGold(resp.Gold)
  82. u.SetUserBankamount(resp.BankAmount)
  83. d, _ := json.Marshal(resp)
  84. this.WriteMsg(msg, string(d))
  85. }
  86. // 保险柜查询
  87. func (this *user) bankQuery(msg, data string) {
  88. var resp protocol.BankInOrOut_resp
  89. resp.RetCode, resp.BankAmount = cash.BankQuery(this.getUserId())
  90. if resp.RetCode != 1 {
  91. log.Debug("user.bankQuery failed %v", resp)
  92. }
  93. d, _ := json.Marshal(resp)
  94. this.WriteMsg(msg, string(d))
  95. }
  96. func (this *user) financeLog(msg, data string) {
  97. retData := ""
  98. var req protocol.CashList_req
  99. if err := json.Unmarshal([]byte(data), &req); err != nil {
  100. retData = fmt.Sprintf("financeLog unmarshal fail %v", err)
  101. log.Release(retData)
  102. this.WriteMsg(msg, retData)
  103. return
  104. }
  105. // 页索引
  106. if req.PageIndex <= 0 {
  107. req.PageIndex = 1
  108. }
  109. // 每页显示50条记录
  110. if req.PageSize <= 0 {
  111. req.PageSize = 50
  112. }
  113. recordCount, list := cash.FinanceLog(this.getUserId(), req.PageIndex, req.PageSize)
  114. d, _ := json.Marshal(struct {
  115. RecordCount int
  116. List []*cash.FinanceInfo
  117. }{
  118. RecordCount: recordCount,
  119. List: list,
  120. })
  121. this.WriteMsg(msg, string(d))
  122. }
  123. // 赠送
  124. func (this *user) transferGold(msg, data string) {
  125. retData := ""
  126. var req protocol.Transfer_req
  127. if err := json.Unmarshal([]byte(data), &req); err != nil {
  128. retData = fmt.Sprintf("transfer unmarshal fail %v", err)
  129. log.Release(retData)
  130. this.WriteMsg(msg, retData)
  131. return
  132. }
  133. var resp protocol.Transfer_resp
  134. resp.Success, resp.ErrMsg =
  135. cash.GoldTransfer(this.getUserId(), req.ToUserID, req.Amount, this.GetIP())
  136. if !resp.Success {
  137. log.Debug("user.transfer failed %s", resp.ErrMsg)
  138. } else {
  139. // 是否自动刷新金币?
  140. // ...
  141. }
  142. d, _ := json.Marshal(resp)
  143. this.WriteMsg(msg, string(d))
  144. }
  145. func (this *user) goldTransferLog(msg, data string) {
  146. this.WriteMsg(msg, cash.GetGoldTransferLog(this.getUserId()))
  147. }
  148. func (this *user) goldTransferCfg(msg, data string) {
  149. this.WriteMsg(msg, cash.GetGoldTransferConfig(this.getUserId()))
  150. }