ServerCommerceManager.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. --------------------------------
  2. -- 文件名 : ServerCommerceActManger.lua
  3. -- 文件说明 : 跨服商业-活动模板管理
  4. -- 创建时间 : 2025/03/26
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local Lang = require("common.Lang")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local MailExcel = require("excel.mail")
  11. local Msg = require("core.Msg")
  12. local ObjHuman = require("core.ObjHuman")
  13. local CommonDB = require("common.CommonDB")
  14. local Log = require("common.Log")
  15. local YunYingLogic = require("yunying.YunYingLogic")
  16. local ServerCommerceCof = require("excel.ServerCommerce")
  17. local ServerCommerceActDefine = require("serverCommerce.ServerCommerceActDefine")
  18. local Timer = require("core.Timer")
  19. local BuyConf = require("excel.buy")
  20. local ServerCommerceMiddle = require("serverCommerce.ServerCommerceMiddle")
  21. local ServerCommerceActCharge = require("serverCommerce.ServerCommerceActCharge")
  22. local ServerCommerceActRank = require("serverCommerce.ServerCommerceActRank")
  23. local ServerCommerceTask = require("serverCommerce.ServerCommerceActTask")
  24. local Config = require("Config")
  25. -- 活动信息
  26. tCommerceActInfo = nil
  27. -- {
  28. -- nStartTime = nil, -- 开始时间
  29. -- nEendTime = nil, -- 结束时间
  30. -- isRun = nil, -- 是否在活动中
  31. -- nOpen = nil, -- 是否打开
  32. -- nBatchID = nil, -- 批次
  33. -- }
  34. -- 加载的模块
  35. tCommerceActModuel = {}
  36. -- 当前的操作类型
  37. local nQueryOperate = nil
  38. ----------------------------------------- 内部处理开始 -------------------------------------
  39. -- 下发数据
  40. local function CommerceAct_SendData(tMsgData, fd)
  41. Msg.send(tMsgData, fd)
  42. end
  43. local function CommerceAct_CheckOpenDay()
  44. local nNowOpenDay = CommonDB.getServerOpenDay()
  45. return nNowOpenDay >= ServerCommerceActDefine.COMMERCEACT_SHOW_OPENDAY
  46. end
  47. -- 创建玩家DB数据
  48. function CommerceAct_CreateHumanDB(human)
  49. local nBatchID = 1
  50. local tCommonDBData = CommonDB.GetCommerceActInfo()
  51. if tCommonDBData and nil ~= _G.next(tCommonDBData) then
  52. nBatchID = tCommonDBData.nBatchID
  53. end
  54. human.db.ServerCommerce =
  55. {
  56. nPoint = 0, -- 当前玩家个人积分
  57. Task = {}, -- 任务信息
  58. Charge = {}, -- 连充豪礼
  59. Shop = {}, -- 战区钜惠
  60. nBatchID = nBatchID, -- 批次
  61. bSendPlayerMail = false, -- 是否发送个人邮件
  62. bSendServerMail = false, -- 是否发送全服邮件
  63. battleGround = {
  64. freeChallengeCnt = ServerCommerceActDefine.COMMERCEACT_DAILY_FREECHALLENGETIMES,
  65. resetTime = os.time(),
  66. },
  67. }
  68. for nID, module in pairs(tCommerceActModuel) do
  69. if module and module.CreatDB then
  70. local bRet = module.CreatDB(human)
  71. if false == bRet then
  72. print("[CommerceAct_CreateHumanDB] nID 初始化DB 数据失败 nID = "..nID)
  73. end
  74. end
  75. end
  76. end
  77. -- 下发活动数据
  78. function CommerceAct_SendActInfo(human)
  79. if not human or not tCommerceActInfo then
  80. return
  81. end
  82. if false == CommerceAct_CheckOpenDay() then
  83. return
  84. end
  85. print("[CommerceAct_SendActInfo] 下发活动数据 开始 ")
  86. local tMsgData = Msg.gc.GC_SERVEERCOMMERCE_ACT_ALLINFO
  87. tMsgData.nStartTime = tCommerceActInfo.nStartTime
  88. tMsgData.nEendTime = tCommerceActInfo.nEendTime
  89. tMsgData.tActID[0] = #ServerCommerceCof.CommerceAct
  90. local nIndex = 1
  91. for id, v in pairs(ServerCommerceCof.CommerceAct) do
  92. local tActData = tMsgData.tActID[nIndex]
  93. nIndex = nIndex + 1
  94. tActData.ID = id
  95. tActData.name = v.name
  96. tActData.nSortID = v.sortID
  97. tActData.nIcon = v.icon
  98. tActData.nPanelID = v.panelID
  99. local bRed = false
  100. if tCommerceActModuel[id] and tCommerceActModuel[id].isRed then
  101. bRed = tCommerceActModuel[id].isRed(human)
  102. end
  103. print("[CommerceAct_SendActInfo] name = "..tActData.name)
  104. tActData.nRed = (bRed == true) and 1 or 0
  105. end
  106. YunYingLogic.sendBanner(human)
  107. CommerceAct_SendData(tMsgData, human.fd)
  108. print("[CommerceAct_SendActInfo] 下发活动数据 结束 ")
  109. end
  110. -- 各个子活动重置活动数据
  111. local function CommerceAct_ResetData(human)
  112. if not human then
  113. return
  114. end
  115. end
  116. -- 各个子活动处理结束数据
  117. local function CommerceAct_HandleEndData(human)
  118. if not human then
  119. return
  120. end
  121. end
  122. -- 所有活动初始化数据开始
  123. local function CommerceAct_BeginAllAct(human)
  124. if not human or not tCommerceActInfo then
  125. return
  126. end
  127. CommerceAct_CreateHumanDB(human)
  128. print("[CommerceAct_BeginAllAct] 所有活动初始化数据开始 ")
  129. end
  130. -- 结束所有活动
  131. local function CommerceAct_EndAllAct(human)
  132. -- 各个子活动处理数据
  133. CommerceAct_HandleEndData(human)
  134. end
  135. -- 活动开始
  136. local function CommerceAct_Begin()
  137. if not tCommerceActInfo then
  138. return
  139. end
  140. for nID, module in pairs(tCommerceActModuel) do
  141. if module and module.ClearCache then
  142. module.ClearCache()
  143. end
  144. end
  145. -- 遍历在线玩家
  146. for uuid, human in pairs(ObjHuman.onlineUuid) do
  147. CommerceAct_BeginAllAct(human)
  148. CommerceAct_SendActInfo(human)
  149. end
  150. end
  151. -- 活动结束
  152. function CommerceAct_End()
  153. -- 排行榜结束
  154. ServerCommerceMiddle.CommerceMiddle_QueryServerRank(ServerCommerceActDefine.COMMERCEACT_SENDSERVERMAIL)
  155. -- 处理巅峰战场活动
  156. local ServerCommerceActBattleGroundNS = require("serverCommerce.ServerCommerceActBattleGroundNS")
  157. ServerCommerceActBattleGroundNS.Act_End()
  158. end
  159. -- 延迟向中心服请求数据
  160. local function CommerceAct_LaterTimeQuery(nOperate)
  161. print("[CommerceAct_LaterTimeQuery] 延迟向中心服请求数据开始")
  162. Timer.addLater(ServerCommerceActDefine.COMMERCEACT_INITSERVERTIME, CommerceAct_GetActOpen, nOperate)
  163. end
  164. -- 延迟10分钟开始
  165. local function CommerceAct_LaterBeginAct()
  166. if not tCommerceActInfo then
  167. return
  168. end
  169. tCommerceActInfo.isRun = true
  170. CommerceAct_Begin()
  171. end
  172. -- 检查活动是否过期
  173. local function CommerceAct_CheckActIsOverTime()
  174. local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
  175. if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) then
  176. return true
  177. end
  178. local nEndTime = tCommerceDBInfo.nEndTime
  179. local nNowTime = os.time()
  180. return nNowTime >= nEndTime
  181. end
  182. -- 检查是否开启下一轮活动
  183. local function CommerceAct_CanOpenNext()
  184. local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
  185. if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) or not tCommerceDBInfo.nEndTime then
  186. print("[CommerceAct_CanOpenNext] 不存在对应的DB数据")
  187. return true
  188. end
  189. local nDiffDay = Util.diffDay(tCommerceDBInfo.nEndTime)
  190. if nDiffDay > ServerCommerceActDefine.COMMERCEACT_NEXTDAY then
  191. print("[CommerceAct_CanOpenNext] 间隔天数已经满足条件 nDiffDay = "..nDiffDay)
  192. return true
  193. end
  194. return false
  195. end
  196. -- 创建通用DB数据
  197. local function CommerceAct_CreateCommonDB()
  198. local nNowTime = os.time()
  199. local tCommerceInfo = CommonDB.GetCommerceActInfo()
  200. local nEndTime = nNowTime + (ServerCommerceActDefine.COMMERCEACT_LASTDAY - 1)* 86400
  201. local tEndDate = os.date("*t",nEndTime)
  202. tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
  203. tEndDate.min = 0
  204. tEndDate.sec = 0
  205. nEndTime = os.time(tEndDate)
  206. local tDBData = {
  207. nBeginTime = nNowTime,
  208. nEndTime = nEndTime,
  209. nPoint = 0,
  210. nSendRankMail = 0,
  211. }
  212. if not tCommerceInfo or nil == _G.next(tCommerceInfo) then
  213. print("[CommerceAct_CreateCommonDB] 不存在DB数据 批次为1")
  214. tDBData.nBatchID = 1
  215. else
  216. if tCommerceInfo.nBatchID then
  217. tDBData.nBatchID = tCommerceInfo.nBatchID + 1
  218. print("[CommerceAct_CreateCommonDB] 存在DB数据 批次为加1 nOldBatchID = "..tCommerceInfo.nBatchID.." nNewBatchID = "..tDBData.nBatchID)
  219. else
  220. tDBData.nBatchID = 1
  221. end
  222. end
  223. CommonDB.SetCommerceActInfo(tDBData)
  224. end
  225. -- 创建缓存数据
  226. local function CommerceAct_CreateCacheInfo(nOpen, bLater)
  227. local tCommerceInfo = CommonDB.GetCommerceActInfo()
  228. if not tCommerceInfo or nil == _G.next(tCommerceInfo) then
  229. print("[CommerceAct_CreateCacheInfo] 为什么会不存在数据\n")
  230. return
  231. end
  232. tCommerceActInfo = {}
  233. tCommerceActInfo.nStartTime = tCommerceInfo.nBeginTime
  234. tCommerceActInfo.nEendTime = tCommerceInfo.nEndTime
  235. tCommerceActInfo.isRun = true
  236. if true == bLater then
  237. tCommerceActInfo.isRun = false
  238. end
  239. tCommerceActInfo.nOpen = nOpen
  240. tCommerceActInfo.nBatchID = tCommerceInfo.nBatchID
  241. print("[CommerceAct_CreateCacheInfo] 创建缓存数据 nStartTime = "..tCommerceActInfo.nStartTime.." nEendTime = "..tCommerceActInfo.nEendTime
  242. .." nOpen = "..tCommerceActInfo.nOpen.." nBatchID = "
  243. ..tCommerceActInfo.nBatchID.." isRun = "..(tCommerceActInfo.isRun == true and 1 or 0))
  244. if bLater == true then
  245. Timer.addLater(ServerCommerceActDefine.COMMERCEACT_BEGINDELATTIME, CommerceAct_LaterBeginAct)
  246. else
  247. for uuid, human in pairs(ObjHuman.onlineUuid) do
  248. if not human.db.ServerCommerce then
  249. CommerceAct_CreateHumanDB(human)
  250. end
  251. ServerCommerceTask.CommerceActTask_HumanSubEvent(human)
  252. CommerceAct_SendActInfo(human)
  253. end
  254. end
  255. end
  256. -- 清理排行榜数据
  257. local function CommerceAct_ClearRankInfo()
  258. ServerCommerceMiddle.CommerceMiddle_ClearRank()
  259. end
  260. -- 请求中心服活动时间和批次数据
  261. local function CommerceAct_QueryActOpenTime()
  262. ServerCommerceMiddle.CommerceMiddle_QueryActOpenTime()
  263. end
  264. -- 起服初始化数据
  265. local function CommerceAct_ActCheckOpen_InitServer(nOpen, nOperate, nServerKey)
  266. if ServerCommerceActDefine.COMMERCEACT_NOOPEN ~= nOpen then
  267. nQueryOperate = nOperate
  268. ServerCommerceActRank.CommercerActRank_GetRankServerKey(nServerKey)
  269. -- 活动开启去请求时间数据
  270. CommerceAct_QueryActOpenTime()
  271. end
  272. end
  273. -- 获取玩家当前点数
  274. function CommerceAct_GetHumanPoint(human)
  275. return human.db.ServerCommerce.nPoint
  276. end
  277. -- 设置玩家当前点数
  278. local function CommerceAct_SetHumanPoint(human, nValue)
  279. human.db.ServerCommerce.nPoint = nValue
  280. end
  281. -- 获取开始时间
  282. function CommerceAct_GetOpenAndEndTime()
  283. if not tCommerceActInfo or not tCommerceActInfo.nStartTime or not tCommerceActInfo.nEendTime then
  284. return 0, 0
  285. end
  286. return tCommerceActInfo.nStartTime, tCommerceActInfo.nEendTime
  287. end
  288. ----------------------------------------- 外部调用开始 -------------------------------------
  289. function onZeroAll(funcID)
  290. local nNowTime = os.time()
  291. local tDate = os.date("*t",nNowTime)
  292. -- 活动未开启
  293. if tDate.hour == ServerCommerceActDefine.COMMERCEACT_BEGINTIME then
  294. -- 获取DB数据
  295. local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
  296. if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) then
  297. CommerceAct_LaterTimeQuery(ServerCommerceActDefine.COMMERCEACT_ZERO)
  298. return
  299. end
  300. -- 存在DB数据说明已经满足条件了
  301. if true == CommerceAct_CheckActIsOverTime() then
  302. local bOpenNext = CommerceAct_CanOpenNext()
  303. if false == bOpenNext then
  304. return
  305. end
  306. -- 开启下一轮
  307. if tCommerceDBInfo.nBatchID < ServerCommerceActDefine.COMMERCEACT_ENDBATCH then
  308. CommerveManager_WriteLog("[CommerveManager-onZeroAll] 当前条件满足开启下一轮活动 nOldBatchID = "..tCommerceDBInfo.nBatchID.." nNewBatchID = "..tCommerceDBInfo.nBatchID+1)
  309. -- 清理排行榜数据
  310. CommerceAct_ClearRankInfo()
  311. -- 重新请求活动时间数据
  312. CommerceAct_QueryActOpenTime()
  313. nQueryOperate = ServerCommerceActDefine.COMMERCEACT_ZERO
  314. -- CommerceAct_CreateCommonDB()
  315. -- -- 存在数据说明时间是满足的
  316. -- CommerceAct_CreateCacheInfo(ServerCommerceActDefine.COMMERCEACT_OPEN, true)
  317. -- -- 遍历在线玩家
  318. -- for uuid, human in pairs(ObjHuman.onlineUuid) do
  319. -- CommerceAct_BeginAllAct(human)
  320. -- end
  321. -- -- 重新请求排行榜数据
  322. -- ServerCommerceActRank.CommercerActRank_InitServerQueryRank()
  323. end
  324. end
  325. end
  326. end
  327. function onHour(hour)
  328. local nNowTime = os.time()
  329. local tDate = os.date("*t",nNowTime)
  330. print("[CommerceAct_onHour] 进入整点时间判断 hour = "..hour.." nNowTime = "..nNowTime)
  331. if tDate.hour == ServerCommerceActDefine.COMMERCEACT_ENDTIME then
  332. if not tCommerceActInfo then
  333. print("[CommerceAct_onHour] 不存在对应的数据 ")
  334. return
  335. end
  336. print("[CommerceAct_onHour] 进入结束时间判断 hour = "..hour.." nNowTime = "..nNowTime)
  337. local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
  338. if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) then
  339. print("[CommerceAct_onHour] 存在缓存数据, 但是获取不到DB数据")
  340. return
  341. end
  342. local nEndTime = tCommerceDBInfo.nEndTime
  343. print("[CommerceAct_onHour] nNowTime = "..nNowTime.." nEndTime = "..nEndTime)
  344. if nEndTime <= nNowTime then
  345. print("[CommerceAct_onHour] 活动结束 开始处理活动结束流程 ")
  346. local nDelayTime = math.random(5, 30)
  347. Timer.addLater(nDelayTime, CommerceAct_End)
  348. -- 活动结束处理
  349. tCommerceActInfo.nSendRankMail = true
  350. tCommerceActInfo.isRun = false
  351. -- 关闭活动入口
  352. for uuid, human in pairs(ObjHuman.onlineUuid) do
  353. YunYingLogic.sendBanner(human)
  354. end
  355. end
  356. end
  357. end
  358. -- 请求活动打开信息
  359. function CommerceAct_GetActOpen(nOperate)
  360. print("[CommerceAct_GetActOpen] 开始向中心服请求活动数据")
  361. ServerCommerceMiddle.CommerceMiddle_IsActOpen(nOperate)
  362. end
  363. -- 中心服回复活动信息
  364. function CommerceAct_ActCheckOpen(nOpen, nOperate, nServerKey)
  365. print("[CommerceAct_ActCheckOpen] 收到活动信息开始处理 nOpen = "..nOpen.." nOperate ="..nOperate)
  366. CommerceAct_ActCheckOpen_InitServer(nOpen, nOperate, nServerKey)
  367. end
  368. -- 起服初始化
  369. function CommerceAct_Init()
  370. if _G.is_middle == true then
  371. -- 中心服起服获取信息
  372. print("[CommerceAct_Init] 中心服起服请求数据开始")
  373. ServerCommerceMiddle.CommerceMiddle_InitServer()
  374. return
  375. end
  376. local nNowTime = os.time()
  377. for nID, v in pairs(ServerCommerceCof.CommerceAct) do
  378. if v.moduleFn then
  379. local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
  380. if moduleFn then
  381. tCommerceActModuel[nID] = moduleFn
  382. if moduleFn.Init then
  383. local bRet = moduleFn.Init()
  384. if false == bRet then
  385. print("[CommerceAct_Init] 初始化模块数据失败 nID ".. nID)
  386. end
  387. end
  388. print("[CommerceAct_Init] 加载模块成功 name = "..v.name)
  389. else
  390. print("[CommerceAct_Init] 加载模块失败 nID ".. nID)
  391. end
  392. else
  393. print("[CommerceAct_Init] 未配置 name = "..v.name)
  394. end
  395. end
  396. print("[CommerceAct_Init] 延迟进行请求数据操作")
  397. -- 延迟向中心服请求数据
  398. CommerceAct_LaterTimeQuery(ServerCommerceActDefine.COMMERCEACT_SERVEROPEN)
  399. end
  400. -- 是否还在活动期间
  401. function CommerceAct_IsRun()
  402. if not tCommerceActInfo then
  403. return false
  404. end
  405. if false == CommerceAct_CheckOpenDay() then
  406. print("[CommerceAct_IsRun] 开服时间不符合条件 nNowOpenDay = ", CommonDB.getServerOpenDay())
  407. return false
  408. end
  409. return tCommerceActInfo.isRun
  410. end
  411. -- 获取到中心服活动时间数据
  412. function CommerceAct_GetActTime(tData)
  413. local tOldDBData = CommonDB.GetCommerceActInfo()
  414. local tNewDBData = nil
  415. local szText = "[CommerceAct_GetActTime] 获取到对应的中心服时间数据 nBatchID = "..tData.nBatchID.." nBeginTime = "..tData.nBeginTime.." nEndTime = ".. tData.nEndTime
  416. print(szText)
  417. if tOldDBData and nil ~= _G.next(tOldDBData) then
  418. if tOldDBData.nBatchID ~= tData.nBatchID or tOldDBData.nBeginTime ~= tData.nBeginTime
  419. or tOldDBData.nEndTime ~= tOldDBData.nEndTime then
  420. -- szText = szText .."当前服务器数据和获取到的中心服数据不一致进行了重置 旧的DB数据 nOldBatchID = "..tOldDBData.nBatchID
  421. -- .." nOldBeginTime = "..tOldDBData.nBeginTime.." nOldEndTime = ".. tOldDBData.nEndTime
  422. -- print(szText)
  423. tNewDBData = {}
  424. tNewDBData.nBatchID = tData.nBatchID
  425. tNewDBData.nBeginTime = tData.nBeginTime
  426. tNewDBData.nEndTime = tData.nEndTime
  427. CommerveManager_WriteLog(szText)
  428. -- 存在旧数据,看看需要重置数据
  429. if tData.nBeginTime > tOldDBData.nEndTime then
  430. tNewDBData.nPoint = 0
  431. tNewDBData.nSendRankMail = 0
  432. CommerveManager_WriteLog("[CommerceAct_GetActTime] 存在旧的数据,当前批次开启时间大于上一次结束时间, 重置点数和发送邮件数据")
  433. else
  434. tNewDBData.nPoint = tOldDBData.nPoint
  435. tNewDBData.nSendRankMail = tOldDBData.nSendRankMail
  436. end
  437. else
  438. print("[CommerceAct_GetActTime] 当前时间相同")
  439. end
  440. else
  441. tNewDBData = {}
  442. tNewDBData.nBatchID = tData.nBatchID
  443. tNewDBData.nBeginTime = tData.nBeginTime
  444. tNewDBData.nEndTime = tData.nEndTime
  445. tNewDBData.nPoint = 0
  446. tNewDBData.nSendRankMail = 0
  447. szText = szText.." 当前服务器不存在数据直接创建"
  448. CommerveManager_WriteLog(szText)
  449. end
  450. if nil ~= tNewDBData then
  451. CommonDB.SetCommerceActInfo(tNewDBData)
  452. end
  453. local tCommerceInfo = CommonDB.GetCommerceActInfo()
  454. local nNowTime = os.time()
  455. if nNowTime < tCommerceInfo.nEndTime then
  456. local bLater = nQueryOperate == ServerCommerceActDefine.COMMERCEACT_ZERO and true or false
  457. CommerceAct_CreateCacheInfo(1, bLater)
  458. ServerCommerceActRank.CommercerActRank_InitServerQueryRank()
  459. else
  460. tCommerceActInfo = {}
  461. tCommerceActInfo.nStartTime = tCommerceInfo.nBeginTime
  462. tCommerceActInfo.nEendTime = tCommerceInfo.nEndTime
  463. tCommerceActInfo.isRun = false
  464. tCommerceActInfo.nOpen = 0
  465. tCommerceActInfo.nBatchID = tCommerceInfo.nBatchID
  466. print("[CommerceAct_ActCheckOpen_InitServer] 活动不在开放时间")
  467. end
  468. end
  469. -- 跨天
  470. function updateDaily(human, funcID)
  471. if not human then
  472. return
  473. end
  474. if true == CommerceAct_IsRun() then
  475. for _, module in pairs(tCommerceActModuel) do
  476. if module and module.updateDaily then
  477. module.updateDaily(human)
  478. end
  479. end
  480. end
  481. end
  482. -- 玩家登录
  483. function onLogin(human, funcID)
  484. if not human then
  485. return
  486. end
  487. -- 下发活动基础数据
  488. if true == CommerceAct_IsRun() then
  489. print("[CommerceManger_onLogin] 玩家进入进行注册")
  490. local tCommonDBData = CommonDB.GetCommerceActInfo()
  491. if not tCommonDBData or nil == _G.next(tCommonDBData) then
  492. print("[CommerceManger_onLogin] 玩家登录不存在对应的数据通用DB数据!!!!")
  493. return
  494. end
  495. -- 不存在数据直接创建
  496. if not human.db.ServerCommerce then
  497. CommerceAct_CreateHumanDB(human)
  498. else
  499. -- 用记在玩家身上的批次 和 CommonDB 中的数据比较
  500. local nOldBatchID = human.db.ServerCommerce.nBatchID
  501. local nNowBatchID = tCommonDBData.nBatchID
  502. if nNowBatchID ~= nOldBatchID then
  503. CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家登录 记录的批次不一致 nOldBatchID = "..nOldBatchID.." nNowBatchID = "..nNowBatchID, human)
  504. print("[CommerceManger_onLogin] 玩家登录批次不一致, 重置玩家数据 name = "..human.db.name)
  505. CommerceAct_CreateHumanDB(human)
  506. end
  507. end
  508. CommerceAct_SendActInfo(human)
  509. for _, module in pairs(tCommerceActModuel) do
  510. if module and module.onLogin then
  511. module.onLogin(human)
  512. end
  513. end
  514. else
  515. -- 不在活动中
  516. local tCommonDBData = CommonDB.GetCommerceActInfo()
  517. if not tCommonDBData or nil == _G.next(tCommonDBData) then
  518. print("[CommerceManger_onLogin] 玩家登录不存在对应的数据通用DB数据!!!!")
  519. return
  520. end
  521. if false == CommerceAct_CheckActIsOverTime() then
  522. print("[CommerceManger_onLogin] 当前还在活动时间内,返回")
  523. return
  524. end
  525. -- 不存在对应DB数据
  526. if not human.db.ServerCommerce then
  527. return
  528. end
  529. -- 未发送个人邮件都是未上榜的
  530. local bSendPlayerMail = CommerveManager_GetHumanSendPlayerMail(human)
  531. local nHumanPoint = CommerceAct_GetHumanPoint(human)
  532. if false == bSendPlayerMail and nHumanPoint >= 1 then
  533. print("[CommerceManger_onLogin] 发送个人奖励 name = "..human.db.name)
  534. CommerveManager_SetHumanSendPlayerMail(human, true)
  535. ServerCommerceActRank.CommercerActRank_SendHumanMailHumanLogin(human)
  536. else
  537. --CommerveManager_SetHumanSendPlayerMail(human, true)
  538. CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家条件不满足发送个人奖励邮件 nSendServer = "..(bSendPlayerMail == true and 1 or 0).." nHumanPoint = "
  539. ..nHumanPoint, human)
  540. end
  541. -- 全服邮件
  542. local bSendServerMail = CommerveManager_GetHumanSendServerMail(human)
  543. local nSendServer = true == bSendServerMail and 1 or 0
  544. if false == bSendServerMail and 1 == tCommonDBData.nSendRankMail and CommerceAct_GetHumanPoint(human) >= 1 then
  545. print("[CommerceManger_onLogin] 全服邮件奖励开始发送 name = "..human.db.name)
  546. CommerveManager_SetHumanSendServerMail(human, true)
  547. ServerCommerceActRank.CommercerActRank_SendServerMailHumanLogin(human)
  548. else
  549. CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家条件不满足 nSendServer = "..nSendServer.." nHumanPoint = "
  550. ..nHumanPoint.." tCommonDBData.nSendRankMail = "..tCommonDBData.nSendRankMail, human)
  551. --CommerveManager_SetHumanSendServerMail(human, true)
  552. print("[CommerceManger_onLogin] 全服邮件奖励 已经发送过了或积分不满足条件 name = "..human.db.name)
  553. end
  554. end
  555. end
  556. -- 是否开启
  557. function isOpen(human, YYInfo, funcConfig)
  558. local bRet = CommerceAct_IsRun()
  559. local nRet = bRet and 1 or 0
  560. print("CommerceAct_isOpen 结束 开启为1, 未开启为0 nRet = "..nRet)
  561. return bRet
  562. end
  563. --
  564. function isActive(human, YYInfo, funcConfig)
  565. return not isOpen(human, YYInfo, funcConfig)
  566. end
  567. function isRed(human, YYInfo, funcConfig)
  568. if false == CommerceAct_IsRun() then
  569. return
  570. end
  571. if false == CommerceAct_CheckOpenDay() then
  572. return
  573. end
  574. if not human.db.ServerCommerce then
  575. CommerceAct_CreateHumanDB(human)
  576. end
  577. local bRet
  578. for _, module in pairs(tCommerceActModuel) do
  579. if module and module.isRed then
  580. bRet = module.isRed(human)
  581. if true == bRet then
  582. break
  583. end
  584. end
  585. end
  586. return bRet
  587. end
  588. function onCharge(human, price, funcID, buyID)
  589. if not human then
  590. return
  591. end
  592. if false == CommerceAct_IsRun() then
  593. return
  594. end
  595. if not human.db.ServerCommerce then
  596. CommerceAct_CreateHumanDB(human)
  597. end
  598. print("[onCharge] 跨服商业活动 玩家充值回调开始 name = "..human.db.name.." price = "..price)
  599. for _, module in pairs(tCommerceActModuel) do
  600. if module and module.onCharge then
  601. module.onCharge(human, price, funcID, buyID)
  602. end
  603. end
  604. local tBuyCfg = BuyConf.buy[buyID]
  605. if tBuyCfg then
  606. local region = human.region or "CN"
  607. local nPoint = tBuyCfg[region]
  608. CommerveManager_AddServerPoint(nPoint)
  609. CommerveManager_AddHumanPint(human, nPoint)
  610. end
  611. end
  612. -- 增加整个服务器的点数
  613. function CommerveManager_AddServerPoint(nAddPoint)
  614. if false == CommerceAct_IsRun() then
  615. return
  616. end
  617. local tCommonDBData = CommonDB.GetCommerceActInfo()
  618. local nNewPoint = tCommonDBData.nPoint + nAddPoint
  619. CommonDB.SetCommerceActInfo_Point(nNewPoint)
  620. print("[CommerveManager_AddServerPoint] 增加整个服务器的点数 nAddPoint = "..nAddPoint.." nNewPoint = "..nNewPoint)
  621. for _, module in pairs(tCommerceActModuel) do
  622. if module and module.onAllPointChange then
  623. module.onAllPointChange()
  624. end
  625. end
  626. local szText = "[CommerveManager_AddServerPoint] 增加了整个服务器的积分 nAddPoint = "..nAddPoint.." nNewPoint = "..nNewPoint.." 寻宝"..Config.NEW_SVR_INDEX.."区"
  627. CommerveManager_WriteLog(szText)
  628. end
  629. -- 增加个人积分
  630. function CommerveManager_AddHumanPint(human, nPoint)
  631. if false == CommerceAct_IsRun() then
  632. return
  633. end
  634. local nNowPoint = CommerceAct_GetHumanPoint(human)
  635. local nNewPoint = nNowPoint + nPoint
  636. CommerceAct_SetHumanPoint(human ,nNewPoint)
  637. print("[CommerveManager_AddHumanPint] 增加个人积分 nAddPoint = "..nPoint.." nNewPoint = "..nNewPoint.." name = "..human.db.name)
  638. ServerCommerceActRank.CommercerActRank_HumanPointChange(human, nNewPoint)
  639. local szText = "[CommerveManager_AddHumanPint] 增加了个人积分 nAddPoint = "..nPoint.." nNewPoint = "..nNewPoint
  640. CommerveManager_WriteLog(szText, human)
  641. end
  642. -- 写日志
  643. function CommerveManager_WriteLog(szLogText, human)
  644. if human then
  645. szLogText = szLogText.." name = "..human.db.name.." id = "..human.db._id
  646. end
  647. Log.write(Log.LOGID_OSS_COMMON_ACT, szLogText)
  648. end
  649. -- 设置全服发送邮件奖励
  650. function CommerveManager_SetCommDBSendMail(nValue)
  651. local tCommonDBData = CommonDB.GetCommerceActInfo()
  652. if not tCommonDBData then
  653. print("[CommerveManager_SetCommDBSendMail] 居然不存在对应的数据")
  654. return
  655. end
  656. local tNewDBData =
  657. {
  658. nBeginTime = tCommonDBData.nBeginTime,
  659. nEndTime = tCommonDBData.nEndTime,
  660. nPoint = tCommonDBData.nPoint,
  661. nSendRankMail = nValue,
  662. nBatchID = tCommonDBData.nBatchID
  663. }
  664. CommonDB.SetCommerceActInfo(tNewDBData)
  665. print("[CommerveManager_SetCommDBSendMail] 设置全服邮件奖信息结束")
  666. -- table.print_lua_table(tNewDBData)
  667. end
  668. -- 获取全服发送邮件标识
  669. function CommerveManager_GetCommDBSendMail()
  670. return CommonDB.GetCommerceActInfo_SendServerMail()
  671. end
  672. -- 设置玩家已经获取了全服奖励邮件
  673. function CommerveManager_SetHumanSendServerMail(human, nValue)
  674. human.db.ServerCommerce.bSendServerMail = nValue
  675. end
  676. -- 获取玩家全服奖励邮件状态
  677. function CommerveManager_GetHumanSendServerMail(human)
  678. return human.db.ServerCommerce.bSendServerMail
  679. end
  680. -- 设置玩家已经获取了个人奖励邮件
  681. function CommerveManager_SetHumanSendPlayerMail(human, nValue)
  682. human.db.ServerCommerce.bSendPlayerMail = nValue
  683. end
  684. -- 获取玩家全服奖励邮件状态
  685. function CommerveManager_GetHumanSendPlayerMail(human)
  686. return human.db.ServerCommerce.bSendPlayerMail
  687. end
  688. -- GM 清理数据
  689. function CommerveManager_GMClear(human)
  690. human.db.ServerCommerce =
  691. {
  692. nPoint = 0, -- 当前玩家个人积分
  693. Task = {}, -- 任务信息
  694. Charge = {}, -- 连充豪礼
  695. Shop = {}, -- 战区钜惠
  696. nBatchID = 1, -- 批次
  697. bSendPlayerMail = false, -- 是否发送个人邮件
  698. bSendServerMail = false, -- 是否发送全服邮件
  699. battleGround = {
  700. freeChallengeCnt = ServerCommerceActDefine.COMMERCEACT_DAILY_FREECHALLENGETIMES,
  701. resetTime = os.time(),
  702. },
  703. }
  704. for nID, module in pairs(tCommerceActModuel) do
  705. if module and module.CreatDB then
  706. local bRet = module.CreatDB(human)
  707. if false == bRet then
  708. print("[CommerceAct_CreateHumanDB] nID 初始化DB 数据失败 nID = "..nID)
  709. end
  710. end
  711. end
  712. -- table.print_lua_table(human.db.ServerCommerce)
  713. print("[CommerveManager_GMClear] 玩家重置数据完成 name = "..human.db.name)
  714. end
  715. -- GM 增加个人积分
  716. function CommerveManager_GMAddHumanPoint(human, nNum)
  717. CommerveManager_AddHumanPint(human, nNum)
  718. end
  719. -- GM 增加服务器积分
  720. function CommerveManager_GMAddServerPoint(nNum)
  721. CommerveManager_AddServerPoint(nNum)
  722. end
  723. -- GM 发送邮件
  724. function CommerveManager_SendMail()
  725. CommerveManager_SetCommDBSendMail(0)
  726. CommerceAct_End()
  727. end
  728. function CommerceMiddle_AddTaskPoint(human, nNum)
  729. ServerCommerceTask.CommerceTask_AddPoint(human, nNum)
  730. end
  731. function CommerveManager_GMRest(human)
  732. ServerCommerceMiddle.CommerceMiddle_GMClearMiddleMail()
  733. end
  734. function CommerveManager_GMRestCommonDB()
  735. local nNowTime = os.time()
  736. local tCommerceInfo = CommonDB.GetCommerceActInfo()
  737. local nEndTime = nNowTime + (ServerCommerceActDefine.COMMERCEACT_LASTDAY - 1)* 86400
  738. local tEndDate = os.date("*t",nEndTime)
  739. tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
  740. tEndDate.min = 0
  741. tEndDate.sec = 0
  742. nEndTime = os.time(tEndDate)
  743. local tDBData = {
  744. nBeginTime = nNowTime,
  745. nEndTime = nEndTime,
  746. nPoint = 0,
  747. nSendRankMail = 0,
  748. nBatchID = 1,
  749. }
  750. CommonDB.SetCommerceActInfo(tDBData)
  751. print("[CommerveManager_GMRestCommonDB] 重置通用DB数据完成")
  752. end
  753. function CommerveManager_GMClearMiddleMail()
  754. ServerCommerceMiddle.CommerceMiddle_GMClearMiddleMail()
  755. end
  756. function CommerveManager_GMSendHumanMail(human)
  757. ServerCommerceActRank.CommercerActRank_SendHumanMailHumanLogin(human)
  758. end
  759. -- function GetRemainNum(human, nBuyID)
  760. -- for _, module in pairs(tCommerceActModuel) do
  761. -- if module and module.onCharge then
  762. -- if module.IsHaveBuyID and module.IsHaveBuyID(nBuyID) then
  763. -- return module.GetRemainNum(human, nBuyID)
  764. -- end
  765. -- end
  766. -- end
  767. -- return 0
  768. -- end