ServerCommerceManager.lua 30 KB

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