gm.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. local code = require "code"
  2. local timeUtil = require "utils.timeUtil"
  3. local util_user = require("utils.util_user")
  4. local util_mail = require("utils.util_mail")
  5. local gameConst = require("const.gameConst")
  6. local baseAdapt = require("base.baseAdapt")
  7. local resAdapt = require("adapt.resAdapt")
  8. local moduleData = require("data.module")
  9. local payData = require("data.pay")
  10. local userData = require("data.user")
  11. local bagData = require("data.bag")
  12. local root = {}
  13. -- 获取玩家信息
  14. function root.gm_get_player_info(msg)
  15. local uid = tonumber(msg.uid)
  16. log.info("gm_get_player_info msg[%s]", tostring(msg))
  17. --.玩家id .玩家昵称 .国王等级 .竞技场等级 .玩家密码 -是否在线 .渠道号 .版本号 -账号状态 .注册时间 .最近登录时间 -状态
  18. --.战斗局数 .广告次数 。金币 。钻石 .充值金额 -充值次数 .当前城市 .UUID .UDID
  19. local _, items = root.getBagInfo({uid = uid})
  20. local userInfo = userData:user_get_info(uid)
  21. userInfo.status = ""
  22. userInfo.gold = bagData:get_item_count(uid, gameConst.ITEM_ID.GOLD) -- 金币
  23. userInfo.diamond = bagData:get_item_count(uid, gameConst.ITEM_ID.DIAMOND) -- 钻石
  24. userInfo.RechargeAmount = payData:user_get_total_pay_count(uid) -- 充值总额 integer
  25. userInfo.RechargeCount = 0 -- 充值次数 integer
  26. return code.OK, {user = userInfo, bag = {items = items}}
  27. end
  28. -- 背包信息
  29. function root.gm_get_player_bag_info(msg)
  30. local uid = tonumber(msg.uid)
  31. local itemList = {}
  32. local itemInfo = moduleData:hget_json(uid, "bag", "itemInfo")
  33. for k, v in ipairs(itemInfo) do
  34. if v.count > 0 then
  35. table.insert(itemList, {id = v.id, count = v.count, endTime = v.endTime})
  36. end
  37. end
  38. for i, v in pairs(itemList) do
  39. v.name = resAdapt:get_item_name(v.id)
  40. if v.sceneLv then
  41. v.name = string.format("%s-%s", v.name, v.sceneLv)
  42. v.sceneLv = nil
  43. elseif v.endTime then
  44. v.name = string.format("%s(%s)", v.name, timeUtil.toString(v.endTime))
  45. v.endTime = nil
  46. end
  47. end
  48. return code.OK, itemList
  49. end
  50. -- 获取道具配置
  51. function root.gm_get_conf_items(msg)
  52. local items = {}
  53. local conf = resAdapt:get_item_conf_list()
  54. for _, v in ipairs(conf) do
  55. table.insert(items, {id = v.id, ty = v.type, name = v.name, price = v.price})
  56. end
  57. log.info("gm_get_conf_items items[%s]", tostring(items))
  58. return code.OK, {items = items}
  59. end
  60. -- 获取商品配置
  61. function root.gm_get_conf_goods(msg)
  62. local list = {}
  63. local shConf = baseAdapt:getConfig("GoodsConfig")
  64. for k, v in ipairs(shConf) do
  65. table.insert(list, {id = v.id, name = v.name, rmb = v.rmb})
  66. end
  67. return code.OK, {goodsList = list}
  68. end
  69. -- 对某个玩家发送邮件
  70. function root.send_mail(msg)
  71. local uid = tonumber(msg.uid)
  72. for i, v in pairs(msg.items) do
  73. if not resAdapt:get_item_conf(v.id) then
  74. return code.RES.ID_ERROR
  75. end
  76. end
  77. local ok = util_mail:add_mail(uid, 0, msg.title, msg.message, msg.items, msg.type, nil, nil, "GM后台")
  78. do
  79. -- 埋点
  80. local keyEvent = "message"
  81. for _, value in ipairs(msg.items or {}) do
  82. local text = string.format("%s,%s,%s", tostring(1), tostring(value.id), tostring(value.count))
  83. util_user:log_event(uid, keyEvent, text)
  84. end
  85. end
  86. if not ok then
  87. return code.UNKNOWN
  88. end
  89. return code.OK, {}
  90. end
  91. -- 玩家状态
  92. function root.update_player_status(msg)
  93. log.info("update_player_status msg[%s]", tostring(msg))
  94. if msg == nil then
  95. return code.PARAMTER_ERROR
  96. end
  97. local uid = tonumber(msg.uid)
  98. local status = msg.status
  99. if uid == nil or status == nil then
  100. return code.PARAMTER_ERROR
  101. end
  102. if util_user:user_is_online_game(uid) then
  103. util_user:user_call_game_agent(uid, "user.updateStatus", msg)
  104. else
  105. moduleData:hset(uid, "user", "status", status)
  106. end
  107. return code.OK
  108. end
  109. return root