ServerCommerceManager.lua 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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. 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. local nDelayTime = math.random(5, 30)
  377. Timer.addLater(nDelayTime, CommerceAct_End)
  378. -- 活动结束处理
  379. tCommerceActInfo.nSendRankMail = true
  380. tCommerceActInfo.isRun = false
  381. -- 关闭活动入口
  382. for uuid, human in pairs(ObjHuman.onlineUuid) do
  383. YunYingLogic.sendBanner(human)
  384. end
  385. end
  386. end
  387. end
  388. -- 请求活动打开信息
  389. function CommerceAct_GetActOpen(nOperate)
  390. print("[CommerceAct_GetActOpen] 开始向中心服请求活动数据")
  391. ServerCommerceMiddle.CommerceMiddle_IsActOpen(nOperate)
  392. end
  393. -- 中心服回复活动信息
  394. function CommerceAct_ActCheckOpen(nOpen, nOperate, nServerKey)
  395. print("[CommerceAct_ActCheckOpen] 收到活动信息开始处理 nOpen = "..nOpen.." nOperate ="..nOperate)
  396. CommerceAct_ActCheckOpen_InitServer(nOpen, nOperate, nServerKey)
  397. end
  398. -- 起服初始化
  399. function CommerceAct_Init()
  400. if _G.is_middle == true then
  401. -- 中心服起服获取信息
  402. print("[CommerceAct_Init] 中心服起服请求数据开始")
  403. ServerCommerceMiddle.CommerceMiddle_InitServer()
  404. return
  405. end
  406. local nNowTime = os.time()
  407. for nID, v in pairs(ServerCommerceCof.CommerceAct) do
  408. if v.moduleFn then
  409. local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
  410. if moduleFn then
  411. tCommerceActModuel[nID] = moduleFn
  412. if moduleFn.Init then
  413. local bRet = moduleFn.Init()
  414. if false == bRet then
  415. print("[CommerceAct_Init] 初始化模块数据失败 nID ".. nID)
  416. end
  417. end
  418. print("[CommerceAct_Init] 加载模块成功 name = "..v.name)
  419. else
  420. print("[CommerceAct_Init] 加载模块失败 nID ".. nID)
  421. end
  422. else
  423. print("[CommerceAct_Init] 未配置 name = "..v.name)
  424. end
  425. end
  426. print("[CommerceAct_Init] 延迟进行请求数据操作")
  427. -- 延迟向中心服请求数据
  428. CommerceAct_LaterTimeQuery(ServerCommerceActDefine.COMMERCEACT_SERVEROPEN)
  429. end
  430. -- 是否还在活动期间
  431. function CommerceAct_IsRun()
  432. if not tCommerceActInfo then
  433. return false
  434. end
  435. if false == CommerceAct_CheckOpenDay() then
  436. print("[CommerceAct_IsRun] 开服时间不符合条件 nNowOpenDay = ", CommonDB.getServerOpenDay())
  437. return false
  438. end
  439. return tCommerceActInfo.isRun
  440. end
  441. -- 玩家登录
  442. function onLogin(human, funcID)
  443. if not human then
  444. return
  445. end
  446. -- 下发活动基础数据
  447. if true == CommerceAct_IsRun() then
  448. print("[CommerceManger_onLogin] 玩家进入进行注册")
  449. local tCommonDBData = CommonDB.GetCommerceActInfo()
  450. if not tCommonDBData or nil == _G.next(tCommonDBData) then
  451. print("[CommerceManger_onLogin] 玩家登录不存在对应的数据通用DB数据!!!!")
  452. return
  453. end
  454. -- 不存在数据直接创建
  455. if not human.db.ServerCommerce then
  456. CommerceAct_CreateHumanDB(human)
  457. else
  458. -- 用记在玩家身上的批次 和 CommonDB 中的数据比较
  459. local nOldBatchID = human.db.ServerCommerce.nBatchID
  460. local nNowBatchID = tCommonDBData.nBatchID
  461. if nNowBatchID ~= nOldBatchID then
  462. CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家登录 记录的批次不一致 nOldBatchID = "..nOldBatchID.." nNowBatchID = "..nNowBatchID, human)
  463. print("[CommerceManger_onLogin] 玩家登录批次不一致, 重置玩家数据 name = "..human.db.name)
  464. CommerceAct_CreateHumanDB(human)
  465. end
  466. end
  467. CommerceAct_SendActInfo(human)
  468. for _, module in pairs(tCommerceActModuel) do
  469. if module and module.onLogin then
  470. module.onLogin(human)
  471. end
  472. end
  473. else
  474. -- 不在活动中
  475. local tCommonDBData = CommonDB.GetCommerceActInfo()
  476. if not tCommonDBData or nil == _G.next(tCommonDBData) then
  477. print("[CommerceManger_onLogin] 玩家登录不存在对应的数据通用DB数据!!!!")
  478. return
  479. end
  480. if false == CommerceAct_CheckActIsOverTime() then
  481. print("[CommerceManger_onLogin] 当前还在活动时间内,返回")
  482. return
  483. end
  484. -- 不存在对应DB数据
  485. if not human.db.ServerCommerce then
  486. return
  487. end
  488. -- 未发送个人邮件都是未上榜的
  489. local bSendPlayerMail = CommerveManager_GetHumanSendPlayerMail(human)
  490. local nHumanPoint = CommerceAct_GetHumanPoint(human)
  491. if false == bSendPlayerMail and nHumanPoint >= 1 then
  492. print("[CommerceManger_onLogin] 发送个人奖励 name = "..human.db.name)
  493. CommerveManager_SetHumanSendPlayerMail(human, true)
  494. ServerCommerceActRank.CommercerActRank_SendHumanMailHumanLogin(human)
  495. else
  496. --CommerveManager_SetHumanSendPlayerMail(human, true)
  497. CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家条件不满足发送个人奖励邮件 nSendServer = "..(bSendPlayerMail == true and 1 or 0).." nHumanPoint = "
  498. ..nHumanPoint, human)
  499. end
  500. -- 全服邮件
  501. local bSendServerMail = CommerveManager_GetHumanSendServerMail(human)
  502. local nSendServer = true == bSendServerMail and 1 or 0
  503. if false == bSendServerMail and 1 == tCommonDBData.nSendRankMail and CommerceAct_GetHumanPoint(human) >= 1 then
  504. print("[CommerceManger_onLogin] 全服邮件奖励开始发送 name = "..human.db.name)
  505. CommerveManager_SetHumanSendServerMail(human, true)
  506. ServerCommerceActRank.CommercerActRank_SendServerMailHumanLogin(human)
  507. else
  508. CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家条件不满足 nSendServer = "..nSendServer.." nHumanPoint = "
  509. ..nHumanPoint.." tCommonDBData.nSendRankMail = "..tCommonDBData.nSendRankMail, human)
  510. --CommerveManager_SetHumanSendServerMail(human, true)
  511. print("[CommerceManger_onLogin] 全服邮件奖励 已经发送过了或积分不满足条件 name = "..human.db.name)
  512. end
  513. end
  514. end
  515. -- 是否开启
  516. function isOpen(human, YYInfo, funcConfig)
  517. local bRet = CommerceAct_IsRun()
  518. local nRet = bRet and 1 or 0
  519. print("CommerceAct_isOpen 结束 开启为1, 未开启为0 nRet = "..nRet)
  520. return bRet
  521. end
  522. --
  523. function isActive(human, YYInfo, funcConfig)
  524. return not isOpen(human, YYInfo, funcConfig)
  525. end
  526. function isRed(human, YYInfo, funcConfig)
  527. if false == CommerceAct_IsRun() then
  528. return
  529. end
  530. if false == CommerceAct_CheckOpenDay() then
  531. return
  532. end
  533. if not human.db.ServerCommerce then
  534. CommerceAct_CreateHumanDB(human)
  535. end
  536. local bRet
  537. for _, module in pairs(tCommerceActModuel) do
  538. if module and module.isRed then
  539. bRet = module.isRed(human)
  540. if true == bRet then
  541. break
  542. end
  543. end
  544. end
  545. return bRet
  546. end
  547. function onCharge(human, price, funcID, buyID)
  548. if not human then
  549. return
  550. end
  551. if false == CommerceAct_IsRun() then
  552. return
  553. end
  554. if not human.db.ServerCommerce then
  555. CommerceAct_CreateHumanDB(human)
  556. end
  557. print("[onCharge] 跨服商业活动 玩家充值回调开始 name = "..human.db.name.." price = "..price)
  558. for _, module in pairs(tCommerceActModuel) do
  559. if module and module.onCharge then
  560. module.onCharge(human, price, funcID, buyID)
  561. end
  562. end
  563. local tBuyCfg = BuyConf.buy[buyID]
  564. if tBuyCfg then
  565. local region = human.region or "CN"
  566. local nPoint = tBuyCfg[region]
  567. CommerveManager_AddServerPoint(nPoint)
  568. CommerveManager_AddHumanPint(human, nPoint)
  569. end
  570. end
  571. -- 增加整个服务器的点数
  572. function CommerveManager_AddServerPoint(nAddPoint)
  573. if false == CommerceAct_IsRun() then
  574. return
  575. end
  576. local tCommonDBData = CommonDB.GetCommerceActInfo()
  577. local nNewPoint = tCommonDBData.nPoint + nAddPoint
  578. CommonDB.SetCommerceActInfo_Point(nNewPoint)
  579. print("[CommerveManager_AddServerPoint] 增加整个服务器的点数 nAddPoint = "..nAddPoint.." nNewPoint = "..nNewPoint)
  580. for _, module in pairs(tCommerceActModuel) do
  581. if module and module.onAllPointChange then
  582. module.onAllPointChange()
  583. end
  584. end
  585. local szText = "[CommerveManager_AddServerPoint] 增加了整个服务器的积分 nAddPoint = "..nAddPoint.." nNewPoint = "..nNewPoint.." 寻宝"..Config.NEW_SVR_INDEX.."区"
  586. CommerveManager_WriteLog(szText)
  587. end
  588. -- 增加个人积分
  589. function CommerveManager_AddHumanPint(human, nPoint)
  590. if false == CommerceAct_IsRun() then
  591. return
  592. end
  593. local nNowPoint = CommerceAct_GetHumanPoint(human)
  594. local nNewPoint = nNowPoint + nPoint
  595. CommerceAct_SetHumanPoint(human ,nNewPoint)
  596. print("[CommerveManager_AddHumanPint] 增加个人积分 nAddPoint = "..nPoint.." nNewPoint = "..nNewPoint.." name = "..human.db.name)
  597. ServerCommerceActRank.CommercerActRank_HumanPointChange(human, nNewPoint)
  598. local szText = "[CommerveManager_AddHumanPint] 增加了个人积分 nAddPoint = "..nPoint.." nNewPoint = "..nNewPoint
  599. CommerveManager_WriteLog(szText, human)
  600. end
  601. -- 写日志
  602. function CommerveManager_WriteLog(szLogText, human)
  603. if human then
  604. szLogText = szLogText.." name = "..human.db.name.." id = "..human.db._id
  605. end
  606. Log.write(Log.LOGID_OSS_COMMON_ACT, szLogText)
  607. end
  608. -- 设置全服发送邮件奖励
  609. function CommerveManager_SetCommDBSendMail(nValue)
  610. local tCommonDBData = CommonDB.GetCommerceActInfo()
  611. if not tCommonDBData then
  612. print("[CommerveManager_SetCommDBSendMail] 居然不存在对应的数据")
  613. return
  614. end
  615. local tNewDBData =
  616. {
  617. nBeginTime = tCommonDBData.nBeginTime,
  618. nEndTime = tCommonDBData.nEndTime,
  619. nPoint = tCommonDBData.nPoint,
  620. nSendRankMail = nValue,
  621. nBatchID = tCommonDBData.nBatchID
  622. }
  623. CommonDB.SetCommerceActInfo(tNewDBData)
  624. print("[CommerveManager_SetCommDBSendMail] 设置全服邮件奖信息结束")
  625. table.print_lua_table(tNewDBData)
  626. end
  627. -- 获取全服发送邮件标识
  628. function CommerveManager_GetCommDBSendMail()
  629. return CommonDB.GetCommerceActInfo_SendServerMail()
  630. end
  631. -- 设置玩家已经获取了全服奖励邮件
  632. function CommerveManager_SetHumanSendServerMail(human, nValue)
  633. human.db.ServerCommerce.bSendServerMail = nValue
  634. end
  635. -- 获取玩家全服奖励邮件状态
  636. function CommerveManager_GetHumanSendServerMail(human)
  637. return human.db.ServerCommerce.bSendServerMail
  638. end
  639. -- 设置玩家已经获取了个人奖励邮件
  640. function CommerveManager_SetHumanSendPlayerMail(human, nValue)
  641. human.db.ServerCommerce.bSendPlayerMail = nValue
  642. end
  643. -- 获取玩家全服奖励邮件状态
  644. function CommerveManager_GetHumanSendPlayerMail(human)
  645. return human.db.ServerCommerce.bSendPlayerMail
  646. end
  647. -- GM 清理数据
  648. function CommerveManager_GMClear(human)
  649. human.db.ServerCommerce =
  650. {
  651. nPoint = 0, -- 当前玩家个人积分
  652. Task = {}, -- 任务信息
  653. Charge = {}, -- 连充豪礼
  654. Shop = {}, -- 战区钜惠
  655. nBatchID = 1, -- 批次
  656. bSendPlayerMail = false, -- 是否发送个人邮件
  657. bSendServerMail = false, -- 是否发送全服邮件
  658. }
  659. for nID, module in pairs(tCommerceActModuel) do
  660. if module and module.CreatDB then
  661. local bRet = module.CreatDB(human)
  662. if false == bRet then
  663. print("[CommerceAct_CreateHumanDB] nID 初始化DB 数据失败 nID = "..nID)
  664. end
  665. end
  666. end
  667. table.print_lua_table(human.db.ServerCommerce)
  668. print("[CommerveManager_GMClear] 玩家重置数据完成 name = "..human.db.name)
  669. end
  670. -- GM 增加个人积分
  671. function CommerveManager_GMAddHumanPoint(human, nNum)
  672. CommerveManager_AddHumanPint(human, nNum)
  673. end
  674. -- GM 增加服务器积分
  675. function CommerveManager_GMAddServerPoint(nNum)
  676. CommerveManager_AddServerPoint(nNum)
  677. end
  678. -- GM 发送邮件
  679. function CommerveManager_SendMail()
  680. CommerveManager_SetCommDBSendMail(0)
  681. CommerceAct_End()
  682. end
  683. function CommerceMiddle_AddTaskPoint(human, nNum)
  684. ServerCommerceTask.CommerceTask_AddPoint(human, nNum)
  685. end
  686. function CommerveManager_GMRest(human)
  687. CommerceAct_End()
  688. print("[CommerveManager_GMRest] 发送邮件处理完成")
  689. local nNowTime = os.time()
  690. local nEndTime = nNowTime + (ServerCommerceActDefine.COMMERCEACT_LASTDAY - 1)* 86400
  691. local tEndDate = os.date("*t",nEndTime)
  692. tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
  693. tEndDate.min = 0
  694. tEndDate.sec = 0
  695. nEndTime = os.time(tEndDate)
  696. local tDBData = {
  697. nBeginTime = nNowTime,
  698. nEndTime = nEndTime,
  699. nPoint = 0,
  700. nSendRankMail = 0,
  701. nBatchID = 1,
  702. }
  703. CommonDB.SetCommerceActInfo(tDBData)
  704. print("[CommerveManager_GMRest] 重新设置公共DB数据结束")
  705. CommerceAct_ClearRankInfo()
  706. print("[CommerveManager_GMRest] 发送清理排行榜命令完成")
  707. CommerceAct_GetActOpen(ServerCommerceActDefine.COMMERCEACT_SERVEROPEN)
  708. print("[CommerveManager_GMRest] 重新请求数据")
  709. end
  710. function CommerveManager_GMRestCommonDB()
  711. local nNowTime = os.time()
  712. local tCommerceInfo = CommonDB.GetCommerceActInfo()
  713. local nEndTime = nNowTime + (ServerCommerceActDefine.COMMERCEACT_LASTDAY - 1)* 86400
  714. local tEndDate = os.date("*t",nEndTime)
  715. tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
  716. tEndDate.min = 0
  717. tEndDate.sec = 0
  718. nEndTime = os.time(tEndDate)
  719. local tDBData = {
  720. nBeginTime = nNowTime,
  721. nEndTime = nEndTime,
  722. nPoint = 0,
  723. nSendRankMail = 0,
  724. nBatchID = 1,
  725. }
  726. CommonDB.SetCommerceActInfo(tDBData)
  727. print("[CommerveManager_GMRestCommonDB] 重置通用DB数据完成")
  728. end
  729. function CommerveManager_GMClearMiddleMail()
  730. ServerCommerceMiddle.CommerceMiddle_GMClearMiddleMail()
  731. end
  732. function CommerveManager_GMSendHumanMail(human)
  733. ServerCommerceActRank.CommercerActRank_SendHumanMailHumanLogin(human)
  734. end