SuperFundLogic.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. --------------------------------------------------
  2. -- 超值基金
  3. -- db.superFund[type] = {ts, loginDay, sendDay}
  4. --------------------------------------------------
  5. local PresentExcel = require("excel.present")
  6. local MailExcel = require("excel.mail")
  7. local DB = require("common.DB")
  8. local Util = require("common.Util")
  9. local Lang = require("common.Lang")
  10. local Msg = require("core.Msg")
  11. local ObjHuman = require("core.ObjHuman")
  12. local Grid = require("bag.Grid")
  13. local MailManager = require("mail.MailManager")
  14. local ItemDefine = require("bag.ItemDefine")
  15. local BuyLogic = require("topup.BuyLogic")
  16. local Broadcast = require("broadcast.Broadcast")
  17. local BagLogic = require("bag.BagLogic")
  18. local PanelDefine = require("broadcast.PanelDefine")
  19. local YunYingLogic = require("yunying.YunYingLogic")
  20. local SceneHandler = require("scene.Handler")
  21. -- 超值基金类型
  22. local TYPE_SMALL = 1
  23. local TYPE_BIG = 2
  24. -- 状态
  25. local STATE_CANT_BUY = 0
  26. local STATE_CAN_BUY = 1
  27. local STATE_HAD_BUY = 2
  28. local MAILID_LIST = {61, 60}
  29. -- 获取状态
  30. local function getBuyState(human, fundType)
  31. if human.db.superFund and
  32. human.db.superFund[fundType] then
  33. return STATE_HAD_BUY
  34. end
  35. if not human.db.bigPrivFlag then
  36. return STATE_CANT_BUY
  37. end
  38. return STATE_CAN_BUY
  39. end
  40. -- 获取配置
  41. local function getConfig(fundType)
  42. if fundType == TYPE_BIG then
  43. return PresentExcel.superBigFund
  44. end
  45. if fundType == TYPE_SMALL then
  46. return PresentExcel.superSmallFund
  47. end
  48. end
  49. -- 已发送天数 0-30
  50. local function getSendDay(human, fundType)
  51. if not human.db.superFund or
  52. not human.db.superFund[fundType] then
  53. return 0
  54. end
  55. local fundData = human.db.superFund[fundType]
  56. return fundData.sendDay
  57. end
  58. -- 封装奖励结构体
  59. local function fontRewardNet(net, day, rcf, sendDay)
  60. net.day = day
  61. Grid.makeItem(net.reward, rcf.reward[1][1], rcf.reward[1][2])
  62. net.isGet = (sendDay >= day) and 1 or 0
  63. end
  64. -- 查询
  65. function superFundQuery(human, fundType)
  66. local config = getConfig(fundType)
  67. if not config then return end
  68. local fdefine = config[1]
  69. local msgRet = Msg.gc.GC_SUPER_FUND_QUERY
  70. local net = msgRet.data
  71. net.type = fundType
  72. net.canBuy = getBuyState(human, fundType)
  73. local sendDay = getSendDay(human, fundType)
  74. net.list[0] = 0
  75. for i = 1, #config do
  76. local rcf = config[i]
  77. if rcf.preview == 1 then
  78. net.list[0] = net.list[0] + 1
  79. fontRewardNet(net.list[net.list[0]], i, rcf, sendDay)
  80. end
  81. end
  82. net.vipexp = fdefine.vipexp
  83. net.zuanshi = fdefine.zuanshi
  84. BuyLogic.fontBuyItem(human, net.buyItem, fdefine.buyID)
  85. --Msg.trace(msgRet)
  86. Msg.send(msgRet, human.fd)
  87. end
  88. -- 奖励查看
  89. function rewardQuery(human, fundType)
  90. local config = getConfig(fundType)
  91. if not config then return end
  92. local msgRet = Msg.gc.GC_SUPER_FUND_REWARD_QUERY
  93. msgRet.type = fundType
  94. local sendDay = getSendDay(human, fundType)
  95. msgRet.reward[0] = #config
  96. for i = 1, msgRet.reward[0] do
  97. fontRewardNet(msgRet.reward[i], i, config[i], sendDay)
  98. end
  99. --Msg.trace(msgRet)
  100. Msg.send(msgRet,human.fd)
  101. end
  102. -- 购买
  103. function buySuperFund(human, fundType)
  104. local config = getConfig(fundType)
  105. if not config then return end
  106. local fdefine = config[1]
  107. local fundData = {}
  108. fundData.ts = os.time()
  109. fundData.loginDay = 1
  110. fundData.sendDay = 0
  111. human.db.superFund = human.db.superFund or {}
  112. human.db.superFund[fundType] = fundData
  113. sendReward(human)
  114. BagLogic.cleanMomentItemList()
  115. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, ItemDefine.ITEM_ZUANSHI_ID, fdefine.zuanshi)
  116. BagLogic.addMomentItemList(human, "superFund")
  117. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  118. for k, v in pairs(funcID) do
  119. YunYingLogic.updateIcon(YYInfo[k], human)
  120. break
  121. end
  122. superFundQuery(human, fundType)
  123. end
  124. -- 发送奖励
  125. function sendReward(human)
  126. if not human.db.superFund then return end
  127. local delList = nil
  128. local isChange = nil
  129. for fundType, fundData in pairs(human.db.superFund) do
  130. local config = getConfig(fundType)
  131. local sendDay = fundData.sendDay
  132. for day = sendDay + 1, fundData.loginDay do
  133. local rcf = config and config[day]
  134. if not rcf then break end
  135. fundData.sendDay = day
  136. local mailID = MAILID_LIST[fundType]
  137. local mailConfig = MailExcel.mail[mailID]
  138. local title = mailConfig.title
  139. local content = Util.format(mailConfig.content, day)
  140. local senderName = mailConfig.senderName
  141. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, rcf.reward, senderName)
  142. isChange = true
  143. end
  144. if not (config and config[fundData.loginDay]) then
  145. delList = delList or {}
  146. delList[#delList + 1] = fundType
  147. end
  148. end
  149. if delList then
  150. for _, fundType in ipairs(delList) do
  151. human.db.superFund[fundType] = nil
  152. end
  153. if not next(human.db.superFund) then
  154. human.db.superFund = nil
  155. end
  156. end
  157. -- 发完就存DB,保险
  158. if isChange or delList then
  159. ObjHuman.save(human)
  160. end
  161. end
  162. -- 登录
  163. function onLogin(human)
  164. updateDaily(human)
  165. sendReward(human)
  166. end
  167. -- 0点刷新
  168. function updateDaily(human)
  169. if not human.db.superFund then return end
  170. local isChange = nil
  171. for fundType, fundData in pairs(human.db.superFund) do
  172. if not Util.isSameDay(fundData.ts) then
  173. fundData.ts = os.time()
  174. fundData.loginDay = fundData.loginDay + 1
  175. isChange = true
  176. end
  177. end
  178. if isChange then
  179. sendReward(human)
  180. end
  181. end
  182. function isOpen(human)
  183. if not SceneHandler.canCharge(human) then
  184. return
  185. end
  186. return true
  187. end
  188. -- 没购买就红点??
  189. function isRed(human, YYInfo, funcConfig)
  190. if funcConfig.panelID == PanelDefine.PANEL_ID_67 then -- 128
  191. if getBuyState(human, TYPE_SMALL) ~= STATE_HAD_BUY then
  192. return true
  193. end
  194. elseif funcConfig.panelID == PanelDefine.PANEL_ID_68 then --328
  195. if getBuyState(human, TYPE_BIG) ~= STATE_HAD_BUY then
  196. return true
  197. end
  198. end
  199. end