ServerCommerceManager.lua 24 KB

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