RebateLogic.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. --渠道返利逻辑
  2. local Config = require("Config")
  3. local InnerMsg = require("core.InnerMsg")
  4. local ObjHuman = require("core.ObjHuman")
  5. local RebateCfg = require("excel.rebate")
  6. local CommonDB = require("common.CommonDB")
  7. local Util = require("common.Util")
  8. local MiddleManager = require("middle.MiddleManager")
  9. local RoleDBLogic = require("role.RoleDBLogic")
  10. local MailManager = require("mail.MailManager")
  11. local MailExcel = require("excel.mail")
  12. local Log = require("common.Log")
  13. -- 返利邮件ID
  14. local REBATE_MAIL_ID = 7016
  15. -- 获取玩家总充值金额
  16. local function getRoleTotalRecharge(account)
  17. account = tostring(account)
  18. for _, v in ipairs(RebateCfg.rebate) do
  19. if v.account == account then
  20. return v.totalRecharge
  21. end
  22. end
  23. end
  24. -- 检查玩家是否符合返利条件
  25. local function check(channelId, account)
  26. local mainCfg = RebateCfg.main[1]
  27. if channelId ~= mainCfg.channelId then
  28. return false
  29. end
  30. if getRoleTotalRecharge(account) then
  31. return true
  32. end
  33. return false
  34. end
  35. ----------------------------------------------------普通服-----------------------------------------------------
  36. local function calcRebateItemCnt(account)
  37. local roleTotalRecharge = getRoleTotalRecharge(account)
  38. local rebateDays = RebateCfg.main[1].rebateDays
  39. return math.ceil(roleTotalRecharge / rebateDays)
  40. end
  41. --玩家登录时
  42. function NS_RebateQuery(channelId, serverId, account)
  43. if not check(channelId, account) then
  44. return
  45. end
  46. -- 向跨服查询是否返利
  47. local tMsgData = InnerMsg.lw.LW_UPDATE_BAN_INFO --待改
  48. tMsgData.nSrcServerID = Config.SVR_INDEX
  49. tMsgData.channelId = channelId
  50. tMsgData.serverId = serverId
  51. tMsgData.account = account
  52. -- InnerMsg.sendMsg(0, tMsgData)
  53. end
  54. --收到跨服通知给玩家返利
  55. function NS_Rebate_Do(channelId, serverId, account)
  56. local uTag = RoleDBLogic.Generateuuid(channelId, account, serverId)
  57. local human = ObjHuman.onlineNewUniqueTag[uTag]
  58. if not human or not human.db or not human.db._id then
  59. local logInfo = string.format("channelId: %s, serverId: %s, account: %s, result: %s, time: %s",
  60. channelId, serverId, account, "defeat", os.time())
  61. Log.write(Log.LOGID_OSS_REBATE, logInfo)
  62. return
  63. end
  64. -- 发邮件
  65. local mailCfg = MailExcel.mail[REBATE_MAIL_ID]
  66. local itemId = RebateCfg.main[1].rebateItemId
  67. local itemCnt = calcRebateItemCnt(account)
  68. local itemList = { {itemId, itemCnt } }
  69. MailManager.add(MailManager.SYSTEM, human.db._id, mailCfg.title, mailCfg.content, itemList, mailCfg.senderName or "GM")
  70. end
  71. ----------------------------------------------------------------------------------------------------------------
  72. ----------------------------------------------------跨服-----------------------------------------------------
  73. local function getRebateData()
  74. return CommonDB.getValueByKey(CommonDB.KEY_REBATE_DATA)
  75. end
  76. local function updateRebateData(newData)
  77. CommonDB.updateValue(CommonDB.KEY_REBATE_DATA, newData)
  78. end
  79. -- 收到普通服查询是否给玩家返利
  80. function CS_RebateQuery(msg)
  81. local channelId = msg.channelId
  82. local serverId = msg.serverId
  83. local account = msg.account
  84. if not check(channelId, account) then
  85. return
  86. end
  87. local now = os.time()
  88. local rebateData = getRebateData()
  89. local mainCfg = RebateCfg.main[1]
  90. if rebateData and rebateData[account] then
  91. local roleRebateData = rebateData[account]
  92. --同账号值返一个区
  93. if roleRebateData.serverId ~= serverId then
  94. return
  95. end
  96. if roleRebateData.rebateDays >= mainCfg.rebateDays then
  97. return
  98. end
  99. -- 一天返一次
  100. if Util.isSameDayByTimes(roleRebateData.lastRebateTime, now) then
  101. return
  102. end
  103. end
  104. rebateData = rebateData or {}
  105. rebateData[account] = rebateData[account] or {}
  106. local roleRebateData = rebateData[account]
  107. roleRebateData.serverId = serverId
  108. roleRebateData.rebateDays = (roleRebateData.rebateDays or 0) + 1
  109. roleRebateData.lastRebateTime = now
  110. -- 更新数据库
  111. updateRebateData(rebateData)
  112. -- 通知游戏服当天可以返利
  113. local tMsgData = InnerMsg.wl.WL_UPDATE_BAN_INFO --待改
  114. tMsgData.channelId = channelId
  115. tMsgData.serverId = serverId
  116. tMsgData.account = account
  117. local fd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
  118. InnerMsg.sendMsg(fd, tMsgData)
  119. end
  120. ----------------------------------------------------------------------------------------------------------------