OverflowFundLogic.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. --------------------------------------
  2. -- 数据库设计
  3. --[[
  4. 1 超值基金
  5. 2 奢华基金
  6. human.db.overflow = {}
  7. human.db.overflow.state = {}
  8. human.db.overflow.state[1] = time
  9. human.db.overflow.state[2] = time
  10. human.db.overflow.get = {}
  11. human.db.overflow.get[1] = val
  12. human.db.overflow.get[2] = val
  13. ]]
  14. -----------------------------------------
  15. -- 引用文件
  16. local PresentExcel = require("excel.present")
  17. local Msg = require("core.Msg")
  18. local Util = require("common.Util")
  19. local BuyLogic = require("topup.BuyLogic")
  20. local BagLogic = require("bag.BagLogic")
  21. local Grid = require("bag.Grid")
  22. local PanelDefine = require("broadcast.PanelDefine")
  23. local YunYingLogic = require("yunying.YunYingLogic")
  24. -----------------------------------------
  25. -- 宏定义
  26. OVERFLOW_TYPE_1 = 1 -- 超值基金
  27. OVERFLOW_TYPE_2 = 2 -- 奢华基金
  28. -----------------------------------------
  29. -- 逻辑接口
  30. -- 是否开启
  31. function isOpen(human,YYInfo,funcConfig)
  32. if not human.db.nFirstBuy or 1 ~= human.db.nFirstBuy then
  33. return false
  34. end
  35. return true
  36. end
  37. -- 获取当前基金状态
  38. --return 状态,下次领取天数 状态 0 未购买 1 领取 2 已领取
  39. local function getState(human,type)
  40. -- 有数据
  41. if human.db.overflow and human.db.overflow.state and human.db.overflow.state[type] then
  42. local day = Util.diffDay(human.db.overflow.state[type]) + 1
  43. human.db.overflow.get = human.db.overflow.get or {}
  44. human.db.overflow.get[type] = human.db.overflow.get[type] or 0
  45. local nextDay = human.db.overflow.get[type]
  46. if nextDay < day then
  47. return 1,nextDay + 1
  48. else
  49. return 2,nextDay + 1
  50. end
  51. end
  52. return 0,0
  53. end
  54. -- 基金信息查询
  55. function overflowQuery(human,type)
  56. -- 根据类型获得配置
  57. local config = nil
  58. if type == OVERFLOW_TYPE_1 then
  59. config = PresentExcel.overflowFund
  60. elseif type == OVERFLOW_TYPE_2 then
  61. config = PresentExcel.luxuryFund
  62. end
  63. if not config then
  64. return
  65. end
  66. local msgRet = Msg.gc.GC_OVERFLOW_FUND_QUERY
  67. msgRet.type = type
  68. BuyLogic.fontBuyItem(human, msgRet.buyMsg, config[1].buyID)
  69. msgRet.state,msgRet.nextGet = getState(human,type)
  70. local len = #config
  71. local count = 0
  72. for i = 1,len do
  73. Grid.makeItem(msgRet.item[i],config[i].item[1][1],config[i].item[1][2])
  74. if config[i].part == 1 then
  75. count = count + 1
  76. msgRet.partItem[count] = i
  77. end
  78. end
  79. msgRet.partItem[0] = count
  80. msgRet.item[0] = len
  81. msgRet.worth[1] = PresentExcel.overflowFund[1].worth
  82. msgRet.worth[2] = PresentExcel.luxuryFund[1].worth
  83. msgRet.worth[0] = 2
  84. Msg.send(msgRet,human.fd)
  85. end
  86. function onBuy(human,type)
  87. -- 已购买,不可重复购买
  88. if human.db.overflow and human.db.overflow.state and human.db.overflow.state[type] then
  89. return
  90. end
  91. human.db.overflow = human.db.overflow or {}
  92. human.db.overflow.state = human.db.overflow.state or {}
  93. human.db.overflow.get = human.db.overflow.get or {}
  94. human.db.overflow.state[type] = os.time()
  95. human.db.overflow.get[type] = 0
  96. overflowQuery(human,type)
  97. for k, v in pairs(funcID) do
  98. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3310)
  99. break
  100. end
  101. end
  102. function getFundReward(human,type)
  103. -- 根据类型获得配置
  104. local config = nil
  105. if type == OVERFLOW_TYPE_1 then
  106. config = PresentExcel.overflowFund
  107. elseif type == OVERFLOW_TYPE_2 then
  108. config = PresentExcel.luxuryFund
  109. end
  110. if not config then
  111. return
  112. end
  113. local state = getState(human,type)
  114. if state == 0 then
  115. return
  116. end
  117. local day = Util.diffDay(human.db.overflow.state[type]) + 1
  118. human.db.overflow.get = human.db.overflow.get or {}
  119. human.db.overflow.get[type] = human.db.overflow.get[type] or 0
  120. local nextDay = human.db.overflow.get[type] + 1
  121. local item = {}
  122. local len = #config
  123. for i = nextDay,day do
  124. if not config[i] then
  125. break
  126. end
  127. human.db.overflow.get[type] = human.db.overflow.get[type] + 1
  128. item[#item + 1] = {config[i].item[1][1],config[i].item[1][2]}
  129. end
  130. BagLogic.addItemList(human, item, "overflow_fund")
  131. -- 领取完最后一天
  132. if day >= len then
  133. human.db.overflow.state[type] = nil
  134. human.db.overflow.get[type] = nil
  135. end
  136. overflowQuery(human,type)
  137. for k, v in pairs(funcID) do
  138. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3310)
  139. break
  140. end
  141. end
  142. function isRed(human)
  143. for i = 1,2 do
  144. local state = getState(human,i)
  145. -- 已购买
  146. if state ~= 0 then
  147. local day = Util.diffDay(human.db.overflow.state[i]) + 1
  148. human.db.overflow.get = human.db.overflow.get or {}
  149. human.db.overflow.get[i] = human.db.overflow.get[i] or 0
  150. local nextDay = human.db.overflow.get[i] + 1
  151. if day >= nextDay then
  152. return true
  153. end
  154. end
  155. end
  156. return false
  157. end