ServerCommerceManager.lua 28 KB

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