cashmgr.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package handler
  2. import (
  3. "encoding/json"
  4. "bet24.com/log"
  5. "bet24.com/redis"
  6. pb "bet24.com/servers/micros/money/proto"
  7. notification "bet24.com/servers/micros/notification/proto"
  8. )
  9. type cashmgr struct {
  10. }
  11. func newCashMgr() *cashmgr {
  12. log.Debug("cash manager running")
  13. return &cashmgr{}
  14. }
  15. // 金币日志
  16. func (bm *cashmgr) cashLog(userId int, beginTime, endTime string, pageIndex, pageSize int) (int, []*pb.CashInfo) {
  17. return cashLog(userId, beginTime, endTime, pageIndex, pageSize)
  18. }
  19. // 获取金币
  20. func (bm *cashmgr) getMoney(userId int) (bool, int, int) {
  21. return getMoney(userId)
  22. }
  23. // 加金币并通知客户端
  24. func (bm *cashmgr) giveMoney(userId, amount, logType int, sourceName, remark, ipAddress string) int {
  25. retCode := giveMoney(userId, amount, logType, sourceName, remark, ipAddress)
  26. if retCode != 1 {
  27. log.Debug("cash.giveMoney fail userId=%d amount=%d logType=%d sourceName=%s remark=%s",
  28. userId, amount, logType, sourceName, remark)
  29. return retCode
  30. }
  31. //通知客户端
  32. notification.AddNotification(userId, notification.Notification_Gold, "")
  33. go bm.notifyGoldChanged(userId)
  34. return retCode
  35. }
  36. // 加金币并通知客户端
  37. func (bm *cashmgr) modifyMoneyWithTax(userId, amount, tax, logType int, sourceName, remark, ipAddress string) int {
  38. retCode := modifyMoneyWithTax(userId, amount, tax, logType, sourceName, remark, ipAddress)
  39. if retCode != 1 {
  40. log.Debug("cash.modifyMoneyWithTax fail userId=%d amount=%d logType=%d sourceName=%s remark=%s",
  41. userId, amount, logType, sourceName, remark)
  42. return retCode
  43. }
  44. //通知客户端
  45. notification.AddNotification(userId, notification.Notification_Gold, "")
  46. go bm.notifyGoldChanged(userId)
  47. return retCode
  48. }
  49. // 减金币并通知客户端
  50. func (bm *cashmgr) reduceMoney(userId, amount, logType int, sourceName, remark, ipAddress string) int {
  51. retCode := reduceMoney(userId, amount, logType, sourceName, remark, ipAddress)
  52. if retCode != 1 {
  53. log.Debug("cash.reduceMoney fail userId=%d amount=%d logType=%d sourceName=%s remark=%s",
  54. userId, amount, logType, sourceName, remark)
  55. return retCode
  56. }
  57. //通知客户端
  58. go notification.AddNotification(userId, notification.Notification_Gold, "")
  59. go bm.notifyGoldChanged(userId)
  60. return retCode
  61. }
  62. func (bm *cashmgr) notifyGoldChanged(userId int) {
  63. var d redis.Channel_msg
  64. d.Message = "RefreshGold"
  65. d.UserID = userId
  66. js, _ := json.Marshal(d)
  67. redis.Publish(string(js))
  68. }
  69. // 保险柜存入并通知客户端
  70. func (bm *cashmgr) BankIn(userId, amount, gameId int, serverName, ipAddress string) (int, int, int, string) {
  71. retCode, cash, bank, outMsg := bankIn(userId, amount, gameId, serverName, ipAddress)
  72. if retCode != 1 {
  73. log.Debug("cash.BankIn fail userId=%d amount=%d gameId=%d serverName=%s ipAddress=%s",
  74. userId, amount, gameId, serverName, ipAddress)
  75. return retCode, cash, bank, outMsg
  76. }
  77. //通知客户端
  78. go notification.AddNotification(userId, notification.Notification_Gold, "")
  79. go bm.notifyGoldChanged(userId)
  80. return retCode, cash, bank, outMsg
  81. }
  82. // 保险柜取出并通知客户端
  83. func (bm *cashmgr) BankOut(userId, amount, gameId int, serverName, ipAddress string) (int, int, int, string) {
  84. retCode, cash, bank, outMsg := bankOut(userId, amount, gameId, serverName, ipAddress)
  85. if retCode != 1 {
  86. log.Debug("cash.BankOut fail userId=%d amount=%d serverName=%s ipAddress=%s",
  87. userId, amount, serverName, ipAddress)
  88. return retCode, cash, bank, outMsg
  89. }
  90. //通知客户端
  91. go notification.AddNotification(userId, notification.Notification_Gold, "")
  92. go bm.notifyGoldChanged(userId)
  93. return retCode, cash, bank, outMsg
  94. }
  95. // 保险柜查询
  96. func (bm *cashmgr) BankQuery(userId int) (int, int) {
  97. return bankQuery(userId)
  98. }
  99. // 保险柜转账
  100. func (bm *cashmgr) BankTransfer(userId, toUserId, amount int, ipAddress string) (int, int, string) {
  101. retCode, stillAmount, outMsg := bankTransfer(userId, toUserId, amount, ipAddress)
  102. if retCode != 1 {
  103. log.Debug("cash.BankTransfer fail userId=%d toUserId=%d amount=%d ipAddress=%s",
  104. userId, toUserId, amount, ipAddress)
  105. return retCode, stillAmount, outMsg
  106. }
  107. go bm.notifyGoldChanged(userId)
  108. return retCode, stillAmount, outMsg
  109. }
  110. // 转账(操作结果/操作描述/剩余金额/返还金额)
  111. func (bm *cashmgr) Transfer(userId, toUserId, amount int, ipAddress string) (int, string, int, int) {
  112. retCode, outMsg, stillAmount, refund := cashTransfer(userId, toUserId, amount, ipAddress)
  113. if retCode != 1 {
  114. log.Debug("cash.Transfer fail userId=%d toUserId=%d amount=%d ipAddress=%s",
  115. userId, toUserId, amount, ipAddress)
  116. return retCode, outMsg, stillAmount, refund
  117. }
  118. go bm.notifyGoldChanged(userId)
  119. go notification.AddNotification(toUserId, notification.Notification_Gold, "")
  120. go notification.AddNotification(userId, notification.Notification_Gold, "")
  121. return retCode, outMsg, stillAmount, refund
  122. }
  123. // 赠送记录
  124. func (this *cashmgr) getTransferLog(userId, days int) []*pb.TransferInfo {
  125. return cashTransferLog(userId, days)
  126. }
  127. // 添加赠送记录
  128. func (this *cashmgr) addTransferLog(userId int, nickName string, toUserId int, toNickName string, wantAmount, taxAmount int, ipAddress string) {
  129. addCashTransferLog(userId, nickName, toUserId, toNickName, wantAmount, taxAmount, ipAddress)
  130. }
  131. // 保险柜记录
  132. func (bm *cashmgr) BankLog(userId int, beginTime, endTime string, pageIndex, pageSize int) (int, []*pb.BankLogInfo) {
  133. return bankLog(userId, beginTime, endTime, pageIndex, pageSize)
  134. }
  135. // 充值、提现记录
  136. func (bm *cashmgr) FinanceLog(userId int, pageIndex, pageSize int) (int, []*pb.FinanceInfo) {
  137. return financeLog(userId, pageIndex, pageSize)
  138. }