TopupLogic.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. -------------------------------------------------
  2. -- 充值
  3. -------------------------------------------------
  4. local BuyExcel = require("excel.buy")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local BuyLogic = require("topup.BuyLogic")
  8. local SceneHandler = require("scene.Handler")
  9. local YunYingLogic = require("yunying.YunYingLogic")
  10. local LeichongHaoli = require("present.LeichongHaoli")
  11. local LeijiChongzhi = require("present.LeijiChongzhi")
  12. local DailyLeichong = require("present.DailyLeichong")
  13. local LoginSignLogic = require("loginSign.LoginSignLogic")
  14. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  15. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  16. local MailExcel = require("excel.mail")
  17. local MailManager = require("mail.MailManager")
  18. local CommonDB = require("common.CommonDB")
  19. local BreakThroughTheme = require("battle.BreakThroughTheme")
  20. local BattleGift = require("battle.BattleGift")
  21. -- 专属客服充值额度
  22. EXCLUSIVE_SERVER_9937 = 1000
  23. TOPUP_LIBAO_ID1 = 1 --盲盒礼包
  24. TOPUP_LIBAO_ID2 = 2 --铂金周卡
  25. TOPUP_LIBAO_ID3 = 3 --365王卡
  26. local MAX_FIREWORKS_DURATION = 43200
  27. local YANHUA_EMAIL = 7012 --烟花邮箱
  28. local ITEMID=1022 --烟花道具ID
  29. --封装直购基本信息
  30. local function wrapTopupItem(net, config, human)
  31. net.id = config.id
  32. BuyLogic.fontBuyItem(human, net.buyItem, config.buyID)
  33. end
  34. -- 充值列表
  35. function query(human)
  36. if SceneHandler.canCharge(human) ~= true then
  37. return
  38. end
  39. local msgRet = Msg.gc.GC_TOPUP_QUERY
  40. msgRet.list[0] = #BuyExcel.topup
  41. for i, config in ipairs(BuyExcel.topup) do
  42. local net = msgRet.list[i]
  43. wrapTopupItem(net, config, human)
  44. end
  45. Msg.send(msgRet,human.fd)
  46. end
  47. -- 直购回调
  48. function clacTopupAcount(human, price, buyID, buyNum)
  49. if price < 0 then return end
  50. if not buyNum then
  51. buyNum = 1
  52. end
  53. ObjHuman.updateDaily(human)
  54. local nAllPrice = price * buyNum
  55. human.db.topupAcountDaily = (human.db.topupAcountDaily or 0) + nAllPrice
  56. human.db.topupAccountMonth = (human.db.topupAccountMonth or 0) + nAllPrice
  57. human.db.topupAcount = (human.db.topupAcount or 0) + nAllPrice
  58. checkKf(human)
  59. YunYingLogic.onCharge(human, nAllPrice, buyID, buyNum)
  60. DailyLeichong.charge(human, nAllPrice)
  61. LeichongHaoli.onAddMoney(human, nAllPrice)
  62. LeijiChongzhi.onAddMoney(human, nAllPrice)
  63. LoginSignLogic.chargeAfter(human)
  64. BreakThroughTheme.charge(human, nAllPrice, buyID)
  65. BattleGift.charge(human, nAllPrice, buyID)
  66. sendFireworksMail(human,nAllPrice)
  67. end
  68. -- 发送烟花邮件
  69. function sendFireworksMail(human, price)
  70. -- if price < 100 then return end -- 如果充值金额小于100,不发送邮件
  71. -- -- 计算烟花数量
  72. -- local nFireWorksCount = math.floor(price / 100)
  73. local amountCond = 1000
  74. if price < amountCond then return end -- 如果充值金额小于100,不发送邮件
  75. -- 计算烟花数量
  76. local nFireWorksCount = math.floor(price / amountCond)
  77. if 0 >= nFireWorksCount then
  78. return
  79. end
  80. local mailCfg = MailExcel.mail[YANHUA_EMAIL]
  81. local title = mailCfg.title
  82. local content = mailCfg.content
  83. local senderName = mailCfg.senderName
  84. local items = {
  85. {ITEMID,nFireWorksCount} -- 1022是烟花的道具ID
  86. }
  87. -- 调用邮件管理器发送邮件
  88. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)
  89. end
  90. function checkKf(human)
  91. -- 激活专属客服
  92. if human.db.topupAcount ~= nil and human.db.topupAcount >= EXCLUSIVE_SERVER_9937 then
  93. Msg.send(Msg.gc.GC_EXCLUSIVE_SERVER,human.fd)
  94. end
  95. end
  96. --给客户端下发结束时间//定义的协议时间 //当客户端有点击请求的时候
  97. function DurationofBonus(human)
  98. local tMsgData = Msg.gc.GC_FIREWORKS_QUERY
  99. local nowBufferDuration = CommonDB.getFireWorksBonusTime()-os.time()
  100. tMsgData.buffDuration = math.max(0,nowBufferDuration)
  101. Msg.send(tMsgData, human.fd)
  102. end
  103. function Addtime(human, fireworksCount)
  104. local nNowTime = os.time()
  105. if not human or fireworksCount <= 0 then
  106. return
  107. end
  108. local currentEndTime = CommonDB.getFireWorksBonusTime()
  109. local baseTime = nNowTime
  110. if currentEndTime > nNowTime then
  111. baseTime = currentEndTime
  112. end
  113. local addedTime = math.max(fireworksCount * 60,60)
  114. local newEndTime = math.min(
  115. baseTime + addedTime,
  116. nNowTime + MAX_FIREWORKS_DURATION
  117. )
  118. local totalDuration = newEndTime-nNowTime
  119. if totalDuration <=0 or totalDuration> MAX_FIREWORKS_DURATION then
  120. return
  121. end
  122. CommonDB.setFireWorkBonusTime(newEndTime)
  123. local tMsgData = Msg.gc.GC_FIREWORKS_SHOW
  124. local nowBuffDuration = CommonDB.getFireWorksBonusTime()-os.time()
  125. tMsgData.buffDuration = math.max(0,nowBuffDuration)
  126. tMsgData.playerName = human.db.name
  127. -- 下发时间和玩家名称
  128. for _, human in pairs(ObjHuman.onlineUuid) do
  129. if human and human.fd then
  130. Msg.send(tMsgData, human.fd)
  131. end
  132. end
  133. end