OverflowFundLogic.lua 5.5 KB

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