ServerCommerceManager.lua 32 KB

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