ServerCommerceManager.lua 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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 = false,
  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 = bLater == true and false or true
  233. tCommerceActInfo.nOpen = nOpen
  234. tCommerceActInfo.nBatchID = tCommerceInfo.nBatchID
  235. print("[CommerceAct_CreateCacheInfo] 创建缓存数据 nStartTime = "..tCommerceActInfo.nStartTime.." nEendTime = "..tCommerceActInfo.nEendTime
  236. .." nOpen = "..tCommerceActInfo.nOpen.." nBatchID = "
  237. ..tCommerceActInfo.nBatchID.." isRun = "..(tCommerceActInfo.isRun == true and 1 or 0))
  238. if bLater == true then
  239. Timer.addLater(ServerCommerceActDefine.COMMERCEACT_BEGINDELATTIME, CommerceAct_LaterBeginAct)
  240. else
  241. for uuid, human in pairs(ObjHuman.onlineUuid) do
  242. ServerCommerceTask.CommerceActTask_HumanSubEvent(human)
  243. CommerceAct_SendActInfo(human)
  244. end
  245. end
  246. end
  247. -- 清理排行榜数据
  248. local function CommerceAct_ClearRankInfo()
  249. ServerCommerceMiddle.CommerceMiddle_ClearRank()
  250. end
  251. -- 起服初始化数据
  252. local function CommerceAct_ActCheckOpen_InitServer(nOpen, nOperate, nServerKey)
  253. if ServerCommerceActDefine.COMMERCEACT_NOOPEN ~= nOpen then
  254. local tCommerceInfo = CommonDB.GetCommerceActInfo()
  255. local bIsCreateCache = true
  256. -- 不存在数据
  257. if not tCommerceInfo or nil == _G.next(tCommerceInfo) then
  258. print("[CommerceAct_ActCheckOpen_InitServer] 不存在commonDB数据开始创建")
  259. CommerceAct_CreateCommonDB()
  260. -- 清理排行榜数据
  261. CommerceAct_ClearRankInfo()
  262. else
  263. table.print_lua_table(tCommerceInfo)
  264. -- 存在数据检查是否结束
  265. if true == CommerceAct_CheckActIsOverTime() then
  266. print("[CommerceAct_ActCheckOpen_InitServer] 存在commonDB数据开始进入判断")
  267. local bOpenNext = CommerceAct_CanOpenNext()
  268. if true == bOpenNext then
  269. print("[CommerceAct_ActCheckOpen_InitServer] 开启下一轮")
  270. -- 开启下一轮
  271. if tCommerceInfo.nBatchID < ServerCommerceActDefine.COMMERCEACT_ENDBATCH then
  272. CommerveManager_WriteLog("[CommerveManager-onZeroAll] 当前条件满足开启下一轮活动")
  273. CommerceAct_CreateCommonDB()
  274. -- 清理排行榜数据
  275. CommerceAct_ClearRankInfo()
  276. end
  277. else
  278. bIsCreateCache = false
  279. end
  280. end
  281. end
  282. local bLater = nOperate == ServerCommerceActDefine.COMMERCEACT_ZERO and true or false
  283. if true == bIsCreateCache then
  284. CommerceAct_CreateCacheInfo(nOpen, bLater)
  285. ServerCommerceActRank.CommercerActRank_GetRankServerKey(nServerKey)
  286. ServerCommerceActRank.CommercerActRank_InitServerQueryRank()
  287. print("[CommerceAct_ActCheckOpen_InitServer] 起服初始化完成")
  288. else
  289. tCommerceInfo = CommonDB.GetCommerceActInfo()
  290. tCommerceActInfo = {}
  291. tCommerceActInfo.nStartTime = tCommerceInfo.nBeginTime
  292. tCommerceActInfo.nEendTime = tCommerceInfo.nEndTime
  293. tCommerceActInfo.isRun = false
  294. tCommerceActInfo.nOpen = 0
  295. tCommerceActInfo.nBatchID = tCommerceInfo.nBatchID
  296. print("[CommerceAct_ActCheckOpen_InitServer] 活动不在开放时间")
  297. end
  298. end
  299. end
  300. -- 获取玩家当前点数
  301. function CommerceAct_GetHumanPoint(human)
  302. return human.db.ServerCommerce.nPoint
  303. end
  304. -- 设置玩家当前点数
  305. local function CommerceAct_SetHumanPoint(human, nValue)
  306. human.db.ServerCommerce.nPoint = nValue
  307. end
  308. -- 获取开始时间
  309. function CommerceAct_GetOpenAndEndTime()
  310. if not tCommerceActInfo or not tCommerceActInfo.nStartTime or not tCommerceActInfo.nEendTime then
  311. return 0, 0
  312. end
  313. return tCommerceActInfo.nStartTime, tCommerceActInfo.nEendTime
  314. end
  315. ----------------------------------------- 外部调用开始 -------------------------------------
  316. function onZeroAll(funcID)
  317. local nNowTime = os.time()
  318. local tDate = os.date("*t",nNowTime)
  319. -- 活动未开启
  320. if tDate.hour == ServerCommerceActDefine.COMMERCEACT_BEGINTIME then
  321. -- 获取DB数据
  322. local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
  323. if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) then
  324. CommerceAct_LaterTimeQuery(ServerCommerceActDefine.COMMERCEACT_ZERO)
  325. return
  326. end
  327. -- 存在DB数据说明已经满足条件了
  328. if true == CommerceAct_CheckActIsOverTime() then
  329. local bOpenNext = CommerceAct_CanOpenNext()
  330. if false == bOpenNext then
  331. return
  332. end
  333. -- 开启下一轮
  334. if tCommerceDBInfo.nBatchID < ServerCommerceActDefine.COMMERCEACT_ENDBATCH then
  335. CommerveManager_WriteLog("[CommerveManager-onZeroAll] 当前条件满足开启下一轮活动 nOldBatchID = "..tCommerceDBInfo.nBatchID.." nNewBatchID = "..tCommerceDBInfo.nBatchID+1)
  336. CommerceAct_CreateCommonDB()
  337. -- 存在数据说明时间是满足的
  338. CommerceAct_CreateCacheInfo(ServerCommerceActDefine.COMMERCEACT_OPEN, true)
  339. -- 遍历在线玩家
  340. for uuid, human in pairs(ObjHuman.onlineUuid) do
  341. CommerceAct_BeginAllAct(human)
  342. end
  343. -- 清理排行榜数据
  344. CommerceAct_ClearRankInfo()
  345. -- 重新请求排行榜数据
  346. ServerCommerceActRank.CommercerActRank_InitServerQueryRank()
  347. end
  348. end
  349. end
  350. end
  351. function onHour(hour)
  352. local nNowTime = os.time()
  353. local tDate = os.date("*t",nNowTime)
  354. print("[CommerceAct_onHour] 进入整点时间判断 hour = "..hour.." nNowTime = "..nNowTime)
  355. if tDate.hour == ServerCommerceActDefine.COMMERCEACT_ENDTIME then
  356. if not tCommerceActInfo then
  357. print("[CommerceAct_onHour] 不存在对应的数据 ")
  358. return
  359. end
  360. print("[CommerceAct_onHour] 进入结束时间判断 hour = "..hour.." nNowTime = "..nNowTime)
  361. local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
  362. if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) then
  363. print("[CommerceAct_onHour] 存在缓存数据, 但是获取不到DB数据")
  364. return
  365. end
  366. local nEndTime = tCommerceDBInfo.nEndTime
  367. print("[CommerceAct_onHour] nNowTime = "..nNowTime.." nEndTime = "..nEndTime)
  368. if nEndTime <= nNowTime then
  369. print("[CommerceAct_onHour] 活动结束 开始处理活动结束流程 ")
  370. -- 活动结束处理
  371. CommerceAct_End()
  372. tCommerceActInfo.nSendRankMail = true
  373. tCommerceActInfo.isRun = false
  374. -- 关闭活动入口
  375. for uuid, human in pairs(ObjHuman.onlineUuid) do
  376. YunYingLogic.sendBanner(human)
  377. end
  378. end
  379. end
  380. end
  381. -- 请求活动打开信息
  382. function CommerceAct_GetActOpen(nOperate)
  383. print("[CommerceAct_GetActOpen] 开始向中心服请求活动数据")
  384. ServerCommerceMiddle.CommerceMiddle_IsActOpen(nOperate)
  385. end
  386. -- 中心服回复活动信息
  387. function CommerceAct_ActCheckOpen(nOpen, nOperate, nServerKey)
  388. print("[CommerceAct_ActCheckOpen] 收到活动信息开始处理 nOpen = "..nOpen.." nOperate ="..nOperate)
  389. CommerceAct_ActCheckOpen_InitServer(nOpen, nOperate, nServerKey)
  390. end
  391. -- 起服初始化
  392. function CommerceAct_Init()
  393. if _G.is_middle == true then
  394. -- 中心服起服获取信息
  395. print("[CommerceAct_Init] 中心服起服请求数据开始")
  396. ServerCommerceMiddle.CommerceMiddle_InitServer()
  397. return
  398. end
  399. local nNowTime = os.time()
  400. for nID, v in pairs(ServerCommerceCof.CommerceAct) do
  401. if v.moduleFn then
  402. local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
  403. if moduleFn then
  404. tCommerceActModuel[nID] = moduleFn
  405. if moduleFn.Init then
  406. local bRet = moduleFn.Init()
  407. if false == bRet then
  408. print("[CommerceAct_Init] 初始化模块数据失败 nID ".. nID)
  409. end
  410. end
  411. print("[CommerceAct_Init] 加载模块成功 name = "..v.name)
  412. else
  413. print("[CommerceAct_Init] 加载模块失败 nID ".. nID)
  414. end
  415. else
  416. print("[CommerceAct_Init] 未配置 name = "..v.name)
  417. end
  418. end
  419. print("[CommerceAct_Init] 延迟进行请求数据操作")
  420. -- 延迟向中心服请求数据
  421. CommerceAct_LaterTimeQuery(ServerCommerceActDefine.COMMERCEACT_SERVEROPEN)
  422. end
  423. -- 是否还在活动期间
  424. function CommerceAct_IsRun()
  425. if not tCommerceActInfo then
  426. return false
  427. end
  428. if false == CommerceAct_CheckOpenDay() then
  429. print("[CommerceAct_IsRun] 开服时间不符合条件 nNowOpenDay = ", CommonDB.getServerOpenDay())
  430. return false
  431. end
  432. return tCommerceActInfo.isRun
  433. end
  434. -- 玩家登录
  435. function onLogin(human, funcID)
  436. if not human then
  437. return
  438. end
  439. -- 下发活动基础数据
  440. if true == CommerceAct_IsRun() then
  441. print("[CommerceManger_onLogin] 玩家进入进行注册")
  442. local tCommonDBData = CommonDB.GetCommerceActInfo()
  443. if not tCommonDBData or nil == _G.next(tCommonDBData) then
  444. print("[CommerceManger_onLogin] 玩家登录不存在对应的数据通用DB数据!!!!")
  445. return
  446. end
  447. -- 不存在数据直接创建
  448. if not human.db.ServerCommerce then
  449. CommerceAct_CreateHumanDB(human)
  450. else
  451. -- 用记在玩家身上的批次 和 CommonDB 中的数据比较
  452. local nOldBatchID = human.db.ServerCommerce.nBatchID
  453. local nNowBatchID = tCommonDBData.nBatchID
  454. if nNowBatchID ~= nOldBatchID then
  455. CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家登录 记录的批次不一致 nOldBatchID = "..nOldBatchID.." nNowBatchID = "..nNowBatchID, human)
  456. print("[CommerceManger_onLogin] 玩家登录批次不一致, 重置玩家数据 name = "..human.db.name)
  457. CommerceAct_CreateHumanDB(human)
  458. end
  459. end
  460. CommerceAct_SendActInfo(human)
  461. for _, module in pairs(tCommerceActModuel) do
  462. if module and module.onLogin then
  463. module.onLogin(human)
  464. end
  465. end
  466. else
  467. print("[CommerceManger_onLogin] 111111111")
  468. -- 不在活动中
  469. local tCommonDBData = CommonDB.GetCommerceActInfo()
  470. if not tCommonDBData or nil == _G.next(tCommonDBData) then
  471. print("[CommerceManger_onLogin] 玩家登录不存在对应的数据通用DB数据!!!!")
  472. return
  473. end
  474. if false == CommerceAct_CheckActIsOverTime() then
  475. print("[CommerceManger_onLogin] 当前还在活动时间内,返回")
  476. return
  477. end
  478. print("[CommerceManger_onLogin] 222222222222")
  479. -- 不存在对应DB数据
  480. if not human.db.ServerCommerce then
  481. return
  482. end
  483. print("[CommerceManger_onLogin] 33333333333")
  484. -- 未发送个人邮件都是未上榜的
  485. local bSendPlayerMail = CommerveManager_GetHumanSendPlayerMail(human)
  486. if false == bSendPlayerMail then
  487. print("[CommerceManger_onLogin] 发送个人奖励 name = "..human.db.name)
  488. CommerveManager_SetHumanSendPlayerMail(human, true)
  489. ServerCommerceActRank.CommercerActRank_SendHumanMailHumanLogin(human)
  490. else
  491. print("[CommerceManger_onLogin] 个人奖励 已经发送过了 name = "..human.db.name)
  492. end
  493. -- 全服邮件
  494. local bSendServerMail = CommerveManager_GetHumanSendServerMail(human)
  495. if false == bSendServerMail and true == tCommonDBData.nSendRankMail then
  496. print("[CommerceManger_onLogin] 全服邮件奖励开始发送 name = "..human.db.name)
  497. CommerveManager_SetHumanSendServerMail(human, true)
  498. ServerCommerceActRank.CommercerActRank_SendServerMailHumanLogin(human)
  499. else
  500. print("[CommerceManger_onLogin] 全服邮件奖励 已经发送过了 name = "..human.db.name)
  501. end
  502. end
  503. end
  504. -- 是否开启
  505. function isOpen(human, YYInfo, funcConfig)
  506. local bRet = CommerceAct_IsRun()
  507. local nRet = bRet and 1 or 0
  508. print("CommerceAct_isOpen 结束 开启为1, 未开启为0 nRet = "..nRet)
  509. return bRet
  510. end
  511. --
  512. function isActive(human, YYInfo, funcConfig)
  513. return not isOpen(human, YYInfo, funcConfig)
  514. end
  515. function isRed(human, YYInfo, funcConfig)
  516. if false == CommerceAct_IsRun() then
  517. return
  518. end
  519. if false == CommerceAct_CheckOpenDay() then
  520. return
  521. end
  522. if not human.db.ServerCommerce then
  523. CommerceAct_CreateHumanDB(human)
  524. end
  525. local bRet
  526. for _, module in pairs(tCommerceActModuel) do
  527. if module and module.isRed then
  528. bRet = module.isRed(human)
  529. if true == bRet then
  530. break
  531. end
  532. end
  533. end
  534. return bRet
  535. end
  536. function onCharge(human, price, funcID, buyID)
  537. if not human then
  538. return
  539. end
  540. if false == CommerceAct_IsRun() then
  541. return
  542. end
  543. if not human.db.ServerCommerce then
  544. CommerceAct_CreateHumanDB(human)
  545. end
  546. print("[onCharge] 跨服商业活动 玩家充值回调开始 name = "..human.db.name.." price = "..price)
  547. for _, module in pairs(tCommerceActModuel) do
  548. if module and module.onCharge then
  549. module.onCharge(human, price, funcID, buyID)
  550. end
  551. end
  552. local tBuyCfg = BuyConf.buy[buyID]
  553. if tBuyCfg then
  554. local region = human.region or "CN"
  555. local nPoint = tBuyCfg[region]
  556. CommerveManager_AddServerPoint(nPoint)
  557. CommerveManager_AddHumanPint(human, nPoint)
  558. end
  559. end
  560. -- 增加整个服务器的点数
  561. function CommerveManager_AddServerPoint(nAddPoint)
  562. if false == CommerceAct_IsRun() then
  563. return
  564. end
  565. local tCommonDBData = CommonDB.GetCommerceActInfo()
  566. local nNewPoint = tCommonDBData.nPoint + nAddPoint
  567. CommonDB.SetCommerceActInfo_Point(nNewPoint)
  568. print("[CommerveManager_AddServerPoint] 增加整个服务器的点数 nAddPoint = "..nAddPoint.." nNewPoint = "..nNewPoint)
  569. for _, module in pairs(tCommerceActModuel) do
  570. if module and module.onAllPointChange then
  571. module.onAllPointChange()
  572. end
  573. end
  574. local szText = "[CommerveManager_AddServerPoint] 增加了整个服务器的积分 nAddPoint = "..nAddPoint.." nNewPoint = "..nNewPoint.." 寻宝"..Config.NEW_SVR_INDEX.."区"
  575. CommerveManager_WriteLog(szText)
  576. end
  577. -- 增加个人积分
  578. function CommerveManager_AddHumanPint(human, nPoint)
  579. if false == CommerceAct_IsRun() then
  580. return
  581. end
  582. local nNowPoint = CommerceAct_GetHumanPoint(human)
  583. local nNewPoint = nNowPoint + nPoint
  584. CommerceAct_SetHumanPoint(human ,nNewPoint)
  585. print("[CommerveManager_AddHumanPint] 增加个人积分 nAddPoint = "..nPoint.." nNewPoint = "..nNewPoint.." name = "..human.db.name)
  586. ServerCommerceActRank.CommercerActRank_HumanPointChange(human, nNewPoint)
  587. local szText = "[CommerveManager_AddHumanPint] 增加了个人积分 nAddPoint = "..nPoint.." nNewPoint = "..nNewPoint
  588. CommerveManager_WriteLog(szText, human)
  589. end
  590. -- 写日志
  591. function CommerveManager_WriteLog(szLogText, human)
  592. if human then
  593. szLogText = szLogText.." name = "..human.db.name.." id = "..human.db._id
  594. end
  595. Log.write(Log.LOGID_OSS_COMMON_ACT, szLogText)
  596. end
  597. -- 设置全服发送邮件奖励
  598. function CommerveManager_SetCommDBSendMail(nValue)
  599. local tCommonDBData = CommonDB.GetCommerceActInfo()
  600. local tNewDBData =
  601. {
  602. nBeginTime = tCommonDBData.nBeginTime,
  603. nEndTime = tCommonDBData.nEndTime,
  604. nPoint = tCommonDBData.nPoint,
  605. nSendRankMail = nValue,
  606. nBatchID = tCommonDBData.nBatchID
  607. }
  608. CommonDB.SetCommerceActInfo(tNewDBData)
  609. end
  610. -- 获取全服发送邮件标识
  611. function CommerveManager_GetCommDBSendMail()
  612. return CommonDB.GetCommerceActInfo_SendServerMail()
  613. end
  614. -- 设置玩家已经获取了全服奖励邮件
  615. function CommerveManager_SetHumanSendServerMail(human, nValue)
  616. human.db.ServerCommerce.bSendServerMail = nValue
  617. end
  618. -- 获取玩家全服奖励邮件状态
  619. function CommerveManager_GetHumanSendServerMail(human)
  620. return human.db.ServerCommerce.bSendServerMail
  621. end
  622. -- 设置玩家已经获取了个人奖励邮件
  623. function CommerveManager_SetHumanSendPlayerMail(human, nValue)
  624. human.db.ServerCommerce.bSendPlayerMail = nValue
  625. end
  626. -- 获取玩家全服奖励邮件状态
  627. function CommerveManager_GetHumanSendPlayerMail(human)
  628. return human.db.ServerCommerce.bSendPlayerMail
  629. end
  630. -- GM 清理数据
  631. function CommerveManager_GMClear(human)
  632. human.db.ServerCommerce =
  633. {
  634. nPoint = 0, -- 当前玩家个人积分
  635. Task = {}, -- 任务信息
  636. Charge = {}, -- 连充豪礼
  637. Shop = {}, -- 战区钜惠
  638. nBatchID = 1, -- 批次
  639. bSendPlayerMail = false, -- 是否发送个人邮件
  640. bSendServerMail = false, -- 是否发送全服邮件
  641. }
  642. for nID, module in pairs(tCommerceActModuel) do
  643. if module and module.CreatDB then
  644. local bRet = module.CreatDB(human)
  645. if false == bRet then
  646. print("[CommerceAct_CreateHumanDB] nID 初始化DB 数据失败 nID = "..nID)
  647. end
  648. end
  649. end
  650. table.print_lua_table(human.db.ServerCommerce)
  651. print("[CommerveManager_GMClear] 玩家重置数据完成 name = "..human.db.name)
  652. end
  653. -- GM 增加个人积分
  654. function CommerveManager_GMAddHumanPoint(human, nNum)
  655. CommerveManager_AddHumanPint(human, nNum)
  656. end
  657. -- GM 增加服务器积分
  658. function CommerveManager_GMAddServerPoint(nNum)
  659. CommerveManager_AddServerPoint(nNum)
  660. end
  661. -- GM 发送邮件
  662. function CommerveManager_SendMail()
  663. CommerveManager_SetCommDBSendMail(false)
  664. CommerceAct_End()
  665. end
  666. function CommerceMiddle_AddTaskPoint(human, nNum)
  667. ServerCommerceTask.CommerceTask_AddPoint(human, nNum)
  668. end
  669. function CommerveManager_GMRest(human)
  670. CommerceAct_End()
  671. print("[CommerveManager_GMRest] 发送邮件处理完成")
  672. CommonDB.SetCommerceActInfo({})
  673. print("[CommerveManager_GMRest] 处理公共DB数据结束")
  674. CommerceAct_ClearRankInfo()
  675. print("[CommerveManager_GMRest] 发送清理排行榜命令完成")
  676. CommerceAct_GetActOpen(ServerCommerceActDefine.COMMERCEACT_SERVEROPEN)
  677. print("[CommerveManager_GMRest] 重新请求数据")
  678. end
  679. function CommerveManager_GMRestCommonDB()
  680. CommerceAct_CreateCommonDB()
  681. print("[CommerveManager_GMRestCommonDB] 重置通用DB数据完成")
  682. end