ServerCommerceManager.lua 30 KB

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