SeckillGiftLogic.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. --[[
  2. absAct[id] = {
  3. gift[id] = state
  4. }
  5. ]]
  6. local AbsActLogic = require("absAct.AbsActLogic")
  7. local AbsActExcel = require("excel.absAct")
  8. local BuyExcel = require("excel.buy")
  9. local Util = require("common.Util")
  10. local Msg = require("core.Msg")
  11. local Grid = require("bag.Grid")
  12. local BagLogic = require("bag.BagLogic")
  13. local BuyLogic = require("topup.BuyLogic")
  14. local ObjHuman = require("core.ObjHuman")
  15. local Lang = require("common.Lang")
  16. local Broadcast = require("broadcast.Broadcast")
  17. local YunYingLogic = require("yunying.YunYingLogic")
  18. function isOpen(human, YYInfo, funcConfig)
  19. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  20. if not state then return end
  21. local absAct = human.db.absAct[funcConfig.funcID]
  22. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  23. return false
  24. end
  25. return true, endTime, startTime
  26. end
  27. function isActive(human, YYInfo, funcConfig)
  28. return not isOpen(human, YYInfo, funcConfig)
  29. end
  30. local function fontSeckillNet(human,net,absAct,i,v)
  31. net.id = i
  32. net.state = 1
  33. if absAct.gift and absAct.gift[i] then
  34. net.state = absAct.gift[i]
  35. end
  36. net.price = v.price
  37. net.name = v.name
  38. BuyLogic.fontBuyItem(human, net.buyItem, v.buyID)
  39. local rewardLen = #v.item
  40. for j = 1,rewardLen do
  41. local itemID = v.item[j][1]
  42. local itemCnt = v.item[j][2]
  43. Grid.makeItem(net.item[j],itemID,itemCnt)
  44. end
  45. net.item[0] = rewardLen
  46. end
  47. function getAndSendMsg(human,id)
  48. -- 判断活动是否开启
  49. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  50. if not state then return end
  51. local absConfig = AbsActExcel.absActivity[id]
  52. if not absConfig then return end
  53. local absAct = human.db.absAct[id]
  54. if not absAct then
  55. return
  56. end
  57. local nowDay = Util.diffDay(starTime) + 1
  58. -- 构造协议
  59. local config = AbsActExcel.seckill
  60. local msgRet = Msg.gc.GC_ABS_HF_SECKILL_GIFT_QUERY
  61. local len = #config
  62. local count = 0
  63. msgRet.oneKeyGift[0] = 0
  64. for i = 1,len do
  65. local v = config[i]
  66. if v.actId == absConfig.actId and v.day == nowDay then
  67. -- v.cont 里面没有配置数据,代表非一键购买配置
  68. if not next(v.cont) then
  69. count = count + 1
  70. local net = msgRet.giftList[count]
  71. fontSeckillNet(human,net,absAct,i,v)
  72. elseif msgRet.oneKeyGift[0] == 0 then
  73. -- 一键购买
  74. local contLen = #v.cont
  75. local continue = false
  76. for s = 1,contLen do
  77. local index = v.cont[s]
  78. -- 配置中的礼包已被购买,跳出,到下一个
  79. if absAct.gift and absAct.gift[index] then
  80. continue = true
  81. break
  82. end
  83. end
  84. if not continue then
  85. local net = msgRet.oneKeyGift[1]
  86. fontSeckillNet(human,net,absAct,i,v)
  87. msgRet.oneKeyGift[0] = 1
  88. end
  89. end
  90. end
  91. end
  92. msgRet.giftList[0] = count
  93. Msg.send(msgRet,human.fd)
  94. end
  95. -- 礼包购买回调
  96. function seckillBuy(human,id,conf)
  97. seckillOnBuy(human,id,conf.args[1])
  98. end
  99. function seckillOnBuy(human,id,giftId)
  100. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  101. if not state then return end
  102. local absConfig = AbsActExcel.absActivity[id]
  103. if not absConfig then return end
  104. local absAct = human.db.absAct[id]
  105. if not absAct then
  106. return
  107. end
  108. local nowDay = Util.diffDay(starTime) + 1
  109. absAct.gift = absAct.gift or {}
  110. local config = AbsActExcel.seckill[giftId]
  111. if nowDay ~= config.day then
  112. return
  113. end
  114. -- 判断是否为一键购买
  115. if next(config.cont) then
  116. local len = #config.cont
  117. -- 一键购买需判断内部所有子礼包是否已被购买,若已被购买,则跳出
  118. for i = 1,len do
  119. if absAct.gift[config.cont[i]] == 2 then
  120. return
  121. end
  122. end
  123. -- 设置每个子礼包状态为已购买
  124. for i = 1,len do
  125. absAct.gift[config.cont[i]] = 2
  126. end
  127. else
  128. -- 判断当前礼包是否已被购买
  129. if absAct.gift[giftId] == 2 then
  130. return
  131. end
  132. -- 设置状态
  133. absAct.gift[giftId] = 2
  134. end
  135. BagLogic.addItemList(human, config.item, "abs_seckill")
  136. getAndSendMsg(human,id)
  137. YunYingLogic.sendBanner(human)
  138. YunYingLogic.updateIcon(YYInfo[id], human)
  139. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  140. end
  141. function isRed(human, YYInfo, funcConfig)
  142. local state,endTime,starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  143. if not state then return end
  144. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  145. local absAct = human.db.absAct[funcConfig.funcID]
  146. if not absAct then return end
  147. local nowDay = Util.diffDay(starTime) + 1
  148. absAct.gift = absAct.gift or {}
  149. local config = AbsActExcel.seckill
  150. local len = #config
  151. for i = 1,len do
  152. if config[i].actId == absConfig.actId and nowDay == config[i].day then
  153. if not next(config[i].cont) then
  154. if absAct.gift[i] ~= 2 then
  155. return true
  156. end
  157. end
  158. end
  159. end
  160. return false
  161. end