FestivalSevenDayCardLogic.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. --[[
  2. absAct ={
  3. [id] = {
  4. time = os.time()
  5. day = 1
  6. }
  7. }
  8. ]]
  9. local AbsActLogic = require("absAct.AbsActLogic")
  10. local AbsActExcel = require("excel.absAct")
  11. local BuyExcel = require("excel.buy")
  12. local Util = require("common.Util")
  13. local Msg = require("core.Msg")
  14. local Grid = require("bag.Grid")
  15. local BagLogic = require("bag.BagLogic")
  16. local BuyLogic = require("topup.BuyLogic")
  17. local ObjHuman = require("core.ObjHuman")
  18. local Lang = require("common.Lang")
  19. local Broadcast = require("broadcast.Broadcast")
  20. local MailManager = require("mail.MailManager")
  21. local MailExcel = require("excel.mail")
  22. local YunYingLogic = require("yunying.YunYingLogic")
  23. function isOpen(human, YYInfo, funcConfig)
  24. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  25. if not state then return end
  26. local absAct = human.db.absAct[funcConfig.funcID]
  27. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  28. return false
  29. end
  30. return true, endTime, startTime
  31. end
  32. function isActive(human, YYInfo, funcConfig)
  33. return not isOpen(human, YYInfo, funcConfig)
  34. end
  35. function fontFestvialSevenDayCard(human,config,net,id,giftId)
  36. local len = #config.item
  37. for i = 1,len do
  38. local jLen = #config.item[i]
  39. for j = 1,jLen do
  40. Grid.makeItem(net.dayItem[i].item[j],config.item[i][j][1],config.item[i][j][2])
  41. end
  42. net.dayItem[i].item[0] = jLen
  43. end
  44. net.dayItem[0] = len
  45. BuyLogic.fontBuyItem(human, net.buyItem, config.buyID)
  46. net.state = human.db.absAct[id].card and (human.db.absAct[id].card[giftId] and 1 or 0) or 0
  47. end
  48. function getAndSendMsg(human,id)
  49. -- 判断活动是否开启
  50. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  51. print("festvialCard",state, endTime, starTime)
  52. if not state then return end
  53. local absConfig = AbsActExcel.absActivity[id]
  54. if not absConfig then return end
  55. local absAct = human.db.absAct[id]
  56. if not absAct then
  57. return
  58. end
  59. local msgRet = Msg.gc.GC_ABS_FESTVIAL_SEVENDAY_CARD_QUERY
  60. local config = AbsActExcel.festvialSevenDayCard
  61. local len = 0
  62. for infoId,info in pairs(config) do
  63. if info.actId == absConfig.actId then
  64. len = len + 1
  65. fontFestvialSevenDayCard(human,info,msgRet.netList[len],id,infoId)
  66. end
  67. end
  68. msgRet.netList[0] = len
  69. Msg.send(msgRet,human.fd)
  70. end
  71. function festvialCard(human,id,conf)
  72. local giftId = conf.args[1]
  73. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  74. if not state then return end
  75. local absConfig = AbsActExcel.absActivity[id]
  76. if not absConfig then return end
  77. local absAct = human.db.absAct[id]
  78. if not absAct then
  79. return
  80. end
  81. absAct.card = absAct.card or {}
  82. if absAct.card and absAct.card[giftId] then
  83. return
  84. end
  85. absAct.card[giftId] = {}
  86. absAct.card[giftId].day = 1
  87. local dayIndex = absAct.card[giftId].day
  88. local cardConfig = AbsActExcel.festvialSevenDayCard[giftId]
  89. BagLogic.addItemList(human, cardConfig.zuanshi, "festival_seven_day_card")
  90. if cardConfig then
  91. -- 减去一天
  92. local mailId = cardConfig.mailId
  93. local mailConfig = MailExcel.mail[mailId]
  94. local title = mailConfig.title
  95. local senderName = mailConfig.senderName
  96. local content = Util.format(mailConfig.content, 7, dayIndex)
  97. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, cardConfig.item[dayIndex], senderName)
  98. end
  99. getAndSendMsg(human, id)
  100. YunYingLogic.sendBanner(human)
  101. YunYingLogic.updateIcon(YYInfo[id], human)
  102. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  103. end
  104. function updateDaily(human,id)
  105. local config = AbsActExcel.absActivity[id]
  106. if not config then return end
  107. AbsActLogic.checkAbsActClean(human, id)
  108. -- 有无激活记录
  109. local absAct = human.db.absAct[id]
  110. if not absAct then return end
  111. if not absAct.card then
  112. return
  113. end
  114. -- 发放奖励
  115. for giftId, v in pairs(absAct.card) do
  116. if type(v) == "table" and v.day and v.day < 7 then
  117. v.day = v.day + 1
  118. local dayIndex = v.day
  119. local cardConfig = AbsActExcel.festvialSevenDayCard[giftId]
  120. if cardConfig then
  121. -- 减去一天
  122. local mailId = cardConfig.mailId
  123. local mailConfig = MailExcel.mail[mailId]
  124. local title = mailConfig.title
  125. local senderName = mailConfig.senderName
  126. local content = Util.format(mailConfig.content, 7, dayIndex)
  127. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, cardConfig.item[dayIndex], senderName)
  128. end
  129. clean = true
  130. -- 有数据就 跳出重置流程
  131. if v.day <= 7 then
  132. clean = false
  133. else
  134. -- 小于0的 清除掉
  135. absAct.card[giftId] = nil
  136. end
  137. end
  138. end
  139. if clean and not next(absAct.card) then
  140. human.db.absAct[id] = { endTime = config.realEndTime }
  141. end
  142. end
  143. function isRed(human, YYInfo, funcConfig)
  144. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  145. if not state then return end
  146. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  147. local absAct = human.db.absAct[funcConfig.funcID]
  148. if not absAct then return end
  149. if not absAct.card then
  150. return true
  151. end
  152. local config = AbsActExcel.festvialSevenDayCard
  153. local len = #config
  154. for i = 1,len do
  155. if not absAct.card[i] then
  156. return true
  157. end
  158. end
  159. return false
  160. end