ServerCommerceManager.lua 31 KB

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