income_main.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package income
  2. import (
  3. "bet24.com/log"
  4. pb "bet24.com/servers/micros/audioroom/proto"
  5. "encoding/json"
  6. "fmt"
  7. )
  8. func Run() {
  9. getIncomeManager()
  10. }
  11. // 触发游戏收益(仅房主)
  12. func TriggerGameIncome(userId int, data pb.TriggerData) {
  13. getIncomeManager().triggerGameIncome(userId, data)
  14. }
  15. // 触发礼物收益(接收者、房主)
  16. func TriggerGiftIncome(userId int, data pb.TriggerData) {
  17. getIncomeManager().triggerGiftIncome(userId, data)
  18. }
  19. // 获取收益信息
  20. func GetIncomeInfo(userId int, data string) string {
  21. var req pb.Request
  22. if err := json.Unmarshal([]byte(data), &req); err != nil {
  23. retData := fmt.Sprintf("user_audioroom.GetIncomeInfo unmarshal fail %v", err)
  24. log.Release(retData)
  25. return retData
  26. }
  27. // 房间信息无效
  28. if r := getIncomeManager().getRoomInfo(req.RoomId); r == nil {
  29. return ""
  30. }
  31. var ret pb.Response_GetIncomeInfo
  32. ret.IncomeLevel, ret.GoldIncomeRatio, ret.ChipIncomeRatio = getIncomeManager().getIncomeInfo(userId, req.GameId)
  33. buf, _ := json.Marshal(ret)
  34. return string(buf)
  35. }
  36. // 获取收益记录
  37. func GetIncomeLog(userId int, data string) string {
  38. retData := "false"
  39. var req pb.Request_IncomeList
  40. if err := json.Unmarshal([]byte(data), &req); err != nil {
  41. retData = fmt.Sprintf("user_audioroom.GetIncomeLog unmarshal fail %v", err)
  42. log.Release(retData)
  43. return retData
  44. }
  45. var ret pb.Response_IncomeList
  46. ret.RecordCount, ret.List = getIncomeManager().getIncomeLog(req.RoomId, userId, req.FromUserId, req.ItemType,
  47. req.BeginTime, req.EndTime, req.PageIndex, req.PageSize)
  48. buf, _ := json.Marshal(ret)
  49. return string(buf)
  50. }
  51. // 获取用户收益统计
  52. func GetUserIncomeStat(userId int, data string) string {
  53. retData := "false"
  54. var req pb.Request_IncomeList
  55. if err := json.Unmarshal([]byte(data), &req); err != nil {
  56. retData = fmt.Sprintf("user_audioroom.GetUserIncomeStat unmarshal fail %v", err)
  57. log.Release(retData)
  58. return retData
  59. }
  60. var ret pb.Response_IncomeList
  61. ret.RecordCount, ret.TotalGameProfit, ret.TotalGiftProfit, ret.List = getIncomeManager().getUserIncomeStat(req.RoomId, userId,
  62. req.FromUserId, req.ItemType, req.SortType, req.BeginTime, req.EndTime, req.PageIndex, req.PageSize)
  63. buf, _ := json.Marshal(ret)
  64. return string(buf)
  65. }
  66. // 获取游戏收益统计
  67. func GetGameIncomeStat(userId int, data string) string {
  68. retData := "false"
  69. var req pb.Request_IncomeList
  70. if err := json.Unmarshal([]byte(data), &req); err != nil {
  71. retData = fmt.Sprintf("user_audioroom.GetGameIncomeStat unmarshal fail %v", err)
  72. log.Release(retData)
  73. return retData
  74. }
  75. var ret pb.Response_IncomeList
  76. ret.RecordCount, ret.List = getIncomeManager().getGameIncomeStat(req.RoomId, userId, req.ItemType, req.SortType, req.BeginTime, req.EndTime, req.PageIndex, req.PageSize)
  77. buf, _ := json.Marshal(ret)
  78. return string(buf)
  79. }
  80. // 订阅房间信息
  81. func SubscribeRoomInfo(onRoomInfo func(roomId int) *pb.RoomInfo) {
  82. getIncomeManager().setRoomInfoSubscriber(onRoomInfo)
  83. }
  84. // 打印用户
  85. func Dump(param1, param2 string) {
  86. getIncomeManager().dumpUser(param1)
  87. }