OverflowFundLogic.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. -- 检查是否可以一键扫荡:购买项207(奢华基金)购买后开启一键扫荡权限
  86. -- 购买项207对应的是奢华基金(OVERFLOW_TYPE_2)
  87. -- local canOneClickSaodang = 0
  88. -- if type == OVERFLOW_TYPE_2 then
  89. -- -- 检查是否购买了奢华基金
  90. -- if human.db.overflow and human.db.overflow.state and human.db.overflow.state[OVERFLOW_TYPE_2] then
  91. -- canOneClickSaodang = 1
  92. -- end
  93. -- end
  94. -- msgRet.canOneClickSaodang = canOneClickSaodang
  95. Msg.send(msgRet,human.fd)
  96. end
  97. function onBuy(human,type)
  98. -- 已购买,不可重复购买
  99. if human.db.overflow and human.db.overflow.state and human.db.overflow.state[type] then
  100. return
  101. end
  102. human.db.overflow = human.db.overflow or {}
  103. human.db.overflow.state = human.db.overflow.state or {}
  104. human.db.overflow.get = human.db.overflow.get or {}
  105. human.db.overflow.state[type] = os.time()
  106. human.db.overflow.get[type] = 0
  107. overflowQuery(human,type)
  108. for k, v in pairs(funcID) do
  109. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3310)
  110. break
  111. end
  112. end
  113. function getFundReward(human,type)
  114. -- 根据类型获得配置
  115. local config = nil
  116. if type == OVERFLOW_TYPE_1 then
  117. config = PresentExcel.overflowFund
  118. elseif type == OVERFLOW_TYPE_2 then
  119. config = PresentExcel.luxuryFund
  120. end
  121. if not config then
  122. return
  123. end
  124. local state = getState(human,type)
  125. if state == 0 then
  126. return
  127. end
  128. local day = Util.diffDay(human.db.overflow.state[type]) + 1
  129. human.db.overflow.get = human.db.overflow.get or {}
  130. human.db.overflow.get[type] = human.db.overflow.get[type] or 0
  131. local nextDay = human.db.overflow.get[type] + 1
  132. local item = {}
  133. local len = #config
  134. for i = nextDay,day do
  135. if not config[i] then
  136. break
  137. end
  138. human.db.overflow.get[type] = human.db.overflow.get[type] + 1
  139. item[#item + 1] = {config[i].item[1][1],config[i].item[1][2]}
  140. end
  141. BagLogic.addItemList(human, item, "overflow_fund")
  142. -- 领取完最后一天
  143. if day >= len then
  144. human.db.overflow.state[type] = nil
  145. human.db.overflow.get[type] = nil
  146. end
  147. overflowQuery(human,type)
  148. for k, v in pairs(funcID) do
  149. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3310)
  150. break
  151. end
  152. end
  153. function isRed(human)
  154. for i = 1,2 do
  155. local state = getState(human,i)
  156. -- 已购买
  157. if state ~= 0 then
  158. local day = Util.diffDay(human.db.overflow.state[i]) + 1
  159. human.db.overflow.get = human.db.overflow.get or {}
  160. human.db.overflow.get[i] = human.db.overflow.get[i] or 0
  161. local nextDay = human.db.overflow.get[i] + 1
  162. if day >= nextDay then
  163. return true
  164. end
  165. end
  166. end
  167. return false
  168. end
  169. -- function GetRemainNum(human, nBuyID)
  170. -- local tBuyConf = BuyExcel.buy[nBuyID]
  171. -- if not tBuyConf then
  172. -- return 0
  173. -- end
  174. -- local bType = tBuyConf.args[1]
  175. -- local state = getState(human, bType)
  176. -- return (0 == state) and 1 or 0
  177. -- end