SharePlatformLogic.lua 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. ----------------------------------------
  2. -- 微信小程序分享
  3. -- 微信小程序分享-分享有礼
  4. -- 微信小程序分享-邀请奖励
  5. -- 微信小程序分享-邀请排名
  6. -- db.plShare.shareCnt -- 分享次数
  7. -- db.plShare.shareAccounts -- 分享账号列表
  8. -- db.plShare.firstFlag -- 首次分享状态
  9. -- db.plShare.rewardFlags -- 奖励领取标记
  10. -- db.plShare.groupCnt -- 朋友圈今日分享次数
  11. -- db.plShare.groupTime -- 最近一次朋友圈分享时间
  12. -- db.plShare.groupRewardCnt -- 朋友圈分享可领取奖励次数
  13. -- board.time -- 周一0点
  14. -- board.list -- [uuid] = {uuid, cnt, accounts, time}
  15. ----------------------------------------
  16. local PresentExcel = require("excel.present")
  17. local MailExcel = require("excel.mail")
  18. local Log = require("common.Log")
  19. local Util = require("common.Util")
  20. local CommonDB = require("common.CommonDB")
  21. local Lang = require("common.Lang")
  22. local Timer = require("core.Timer")
  23. local Msg = require("core.Msg")
  24. local ObjHuman = require("core.ObjHuman")
  25. local Grid = require("bag.Grid")
  26. local BagLogic = require("bag.BagLogic")
  27. local Broadcast = require("broadcast.Broadcast")
  28. local PanelDefine = require("broadcast.PanelDefine")
  29. local MailManager = require("mail.MailManager")
  30. local PfLogic = require("platform.PfLogic")
  31. local RoleLogic = require("role.RoleLogic")
  32. local RoleDBLogic = require("role.RoleDBLogic")
  33. local YunYingLogic = require("yunying.YunYingLogic")
  34. local GuideLogic = require("guide.GuideLogic")
  35. BOARD_SHARECNT_MAX = 100 -- 排行榜最高分享次数
  36. FIRST_STATE_NONE = 0 -- 未分享
  37. FIRST_STATE_HAD = 1 -- 已领取
  38. REWARD_STATE_NONE = 0 -- 不可领
  39. REWARD_STATE_GET = 1 -- 可领
  40. REWARD_STATE_HAD = 2 -- 已领取
  41. RANK_2_BOARDRANKDATA = RANK_2_BOARDRANKDATA or nil
  42. -- 是否开启
  43. function isOpen(human, _, funcConfig)
  44. -- 不是以下平台不开放
  45. if not PfLogic.isKunTang() and
  46. not PfLogic.isFKW() then
  47. return
  48. end
  49. -- 完成后活动要消失
  50. if human and funcConfig then
  51. if funcConfig.panelID == PanelDefine.PANEL_ID_148 then
  52. return isOpenFirst(human)
  53. end
  54. if funcConfig.panelID == PanelDefine.PANEL_ID_149 then
  55. return isOpenReward(human)
  56. end
  57. if funcConfig.panelID == PanelDefine.PANEL_ID_151 then
  58. return isOpenGroup(human)
  59. end
  60. end
  61. return true
  62. end
  63. -- 分享有礼
  64. function isOpenFirst(human)
  65. if getFirstState(human) == FIRST_STATE_HAD then
  66. return
  67. end
  68. return true
  69. end
  70. -- 邀请奖励
  71. function isOpenReward(human)
  72. do return true end
  73. for id in ipairs(PresentExcel.sharePFReward) do
  74. if not isGetReward(human, id) then
  75. return true
  76. end
  77. end
  78. end
  79. -- 朋友圈
  80. function isOpenGroup(human)
  81. if human.isIOS == 1 then
  82. return -- ios不显示分享
  83. end
  84. return true
  85. end
  86. -- 红点
  87. function isRed(human, _, funcConfig)
  88. if human and funcConfig then
  89. if funcConfig.panelID == PanelDefine.PANEL_ID_149 then
  90. return isRedReward(human)
  91. end
  92. if funcConfig.panelID == PanelDefine.PANEL_ID_151 then
  93. return isRedGroup(human)
  94. end
  95. end
  96. end
  97. -- 邀请奖励红点
  98. function isRedReward(human)
  99. for id in ipairs(PresentExcel.sharePFReward) do
  100. local state = getRewardState(human, id)
  101. if state == REWARD_STATE_NONE then
  102. break
  103. end
  104. if state == REWARD_STATE_GET then
  105. return true
  106. end
  107. end
  108. end
  109. -- 朋友圈分享红点
  110. function isRedGroup(human)
  111. if not isOpenGroup(human) then
  112. return
  113. end
  114. if getGroupRewardCnt(human) > 0 then
  115. return true
  116. end
  117. end
  118. -- 邀请奖励最大邀请人数
  119. local REWARD_SHARECNT_MAX = nil
  120. function getRewardShareCntMax()
  121. if not REWARD_SHARECNT_MAX then
  122. REWARD_SHARECNT_MAX = 0
  123. for _, cf in ipairs(PresentExcel.sharePFReward) do
  124. if cf.need > REWARD_SHARECNT_MAX then
  125. REWARD_SHARECNT_MAX = cf.need
  126. end
  127. end
  128. end
  129. return REWARD_SHARECNT_MAX
  130. end
  131. -- 获取排行榜刷新时间
  132. function getBoardTime()
  133. return Util.getWeekStartTime(os.time())
  134. end
  135. -- 获取刷新剩余时间
  136. local BOARD_KEEPTIME = 86400 * 7
  137. function getBoardLeftTime()
  138. local startTime = getBoardTime()
  139. return getBoardTime() + BOARD_KEEPTIME - os.time()
  140. end
  141. ------------------------------------ db -------------------------------------------
  142. -- 获取分享有礼状态
  143. function getFirstState(human)
  144. if not human.db.plShare then
  145. return FIRST_STATE_NONE
  146. end
  147. if not human.db.plShare.firstFlag then
  148. return FIRST_STATE_NONE
  149. end
  150. return human.db.plShare.firstFlag
  151. end
  152. -- 设置分享有礼状态
  153. function setFirstState(human, state)
  154. if not human.db.plShare then
  155. human.db.plShare = {}
  156. end
  157. human.db.plShare.firstFlag = state
  158. end
  159. -- 刷新分享人数
  160. function setShareAccount(db, account)
  161. if not account then return end
  162. if account == "" then return end
  163. if not db.plShare then
  164. db.plShare = {}
  165. end
  166. local plShare = db.plShare
  167. plShare.shareAccounts = plShare.shareAccounts or {}
  168. plShare.shareCnt = plShare.shareCnt or 0
  169. if plShare.shareCnt >= getRewardShareCntMax() then
  170. return
  171. end
  172. if plShare.shareAccounts[account] then
  173. return
  174. end
  175. plShare.shareAccounts[account] = true
  176. plShare.shareCnt = plShare.shareCnt + 1
  177. return true
  178. end
  179. -- 获取已分享人数
  180. function getShareCnt(human)
  181. if not human.db.plShare then
  182. return 0
  183. end
  184. return human.db.plShare.shareCnt or 0
  185. end
  186. -- 是否领取邀请奖励
  187. function isGetReward(human, id)
  188. if not human.db.plShare then
  189. return
  190. end
  191. local rewardFlags = human.db.plShare.rewardFlags
  192. if not rewardFlags then return end
  193. return Util.getBit(rewardFlags, id) > 0
  194. end
  195. -- 设置领取邀请奖励
  196. function setGetReward(human, id)
  197. if not human.db.plShare then
  198. human.db.plShare = {}
  199. end
  200. local plShare = human.db.plShare
  201. plShare.rewardFlags = plShare.rewardFlags or 0
  202. plShare.rewardFlags = Util.setBit(plShare.rewardFlags, id)
  203. end
  204. -- 获取奖励状态
  205. function getRewardState(human, id)
  206. local cf = PresentExcel.sharePFReward[id]
  207. if not cf then
  208. return REWARD_STATE_NONE
  209. end
  210. if getShareCnt(human) < cf.need then
  211. return REWARD_STATE_NONE
  212. end
  213. if isGetReward(human, id) then
  214. return REWARD_STATE_HAD
  215. end
  216. return REWARD_STATE_GET
  217. end
  218. --== 下面是排行榜db相关
  219. -- 比较排名
  220. local function cmpRank(a, b)
  221. if a.cnt ~= b.cnt then
  222. return a.cnt > b.cnt
  223. end
  224. if a.time ~= b.time then
  225. return a.time < b.time
  226. end
  227. if a.rank and b.rank then
  228. return a.rank < b.rank
  229. end
  230. if a.rank or not b.rank then
  231. return true
  232. end
  233. return false
  234. end
  235. -- 排序
  236. local function sortBoard(data, noSave)
  237. RANK_2_BOARDRANKDATA = RANK_2_BOARDRANKDATA or {}
  238. Util.cleanTable(RANK_2_BOARDRANKDATA)
  239. for uuid, rankData in pairs(data.list) do
  240. RANK_2_BOARDRANKDATA[#RANK_2_BOARDRANKDATA + 1] = rankData
  241. end
  242. if #RANK_2_BOARDRANKDATA > 1 then
  243. table.sort(RANK_2_BOARDRANKDATA, cmpRank)
  244. end
  245. local isChange = nil
  246. for i = 1, #RANK_2_BOARDRANKDATA do
  247. local rankData = RANK_2_BOARDRANKDATA[i]
  248. if rankData.rank ~= i then
  249. rankData.rank = i
  250. isChange = true
  251. end
  252. end
  253. if isChange and not noSave then
  254. CommonDB.updateValue(CommonDB.KEY_SHARE_PLATFORM_BOARD, data)
  255. end
  256. end
  257. -- 排行榜
  258. function getBoardList()
  259. local data = CommonDB.getValueByKey(CommonDB.KEY_SHARE_PLATFORM_BOARD)
  260. if not data or not data.list then
  261. return
  262. end
  263. if not RANK_2_BOARDRANKDATA then
  264. sortBoard(data)
  265. end
  266. return RANK_2_BOARDRANKDATA
  267. end
  268. -- 根据uuid获取个人数据
  269. function getBoardRankData(uuid)
  270. local data = CommonDB.getValueByKey(CommonDB.KEY_SHARE_PLATFORM_BOARD)
  271. if not data or not data.list then
  272. return
  273. end
  274. return data.list[uuid]
  275. end
  276. -- 重置排行榜
  277. function resetBoard()
  278. local boardList = getBoardList()
  279. -- 先清
  280. local newData = {}
  281. newData.time = getBoardTime()
  282. newData.list = {}
  283. CommonDB.updateValue(CommonDB.KEY_SHARE_PLATFORM_BOARD, newData)
  284. -- 后发之前奖励
  285. local mailConfig = MailExcel.mail[104]
  286. local title = mailConfig.title
  287. local senderName = mailConfig.senderName
  288. for _, config in ipairs(PresentExcel.sharePFBoard) do
  289. for rank = config.minRank, config.maxRank do
  290. local rankData = boardList and boardList[rank]
  291. if not rankData then break end
  292. local content = Util.format(mailConfig.content, rank)
  293. MailManager.add(MailManager.SYSTEM, rankData.uuid, title, content, config.reward, senderName)
  294. end
  295. end
  296. RANK_2_BOARDRANKDATA = nil
  297. return newData
  298. end
  299. -- 初始化上榜数据
  300. local function initBoardRankData(uuid)
  301. local rankData = {}
  302. rankData.uuid = uuid
  303. rankData.cnt = 0
  304. rankData.accounts = {}
  305. rankData.time = nil
  306. rankData.rank = nil
  307. return rankData
  308. end
  309. -- 刷新排行榜
  310. function updateBoard(uuid, account)
  311. if not account or account == "" then return end
  312. local data = CommonDB.getValueByKey(CommonDB.KEY_SHARE_PLATFORM_BOARD)
  313. if not data or data.time ~= getBoardTime() then
  314. data = resetBoard()
  315. end
  316. if not data.list[uuid] then
  317. data.list[uuid] = initBoardRankData(uuid)
  318. end
  319. local rankData = data.list[uuid]
  320. if rankData.accounts[account] then
  321. return -- 分享过了
  322. end
  323. if rankData.cnt >= BOARD_SHARECNT_MAX then
  324. return -- 达到分享上限
  325. end
  326. rankData.time = os.time()
  327. rankData.cnt = rankData.cnt + 1
  328. rankData.accounts[account] = 1
  329. sortBoard(data, true)
  330. CommonDB.updateValue(CommonDB.KEY_SHARE_PLATFORM_BOARD, data)
  331. return true
  332. end
  333. -- 朋友圈已分享次数
  334. function getGroupShareCnt(human)
  335. if not human.db.plShare then
  336. return 0
  337. end
  338. return human.db.plShare.groupCnt or 0
  339. end
  340. -- 朋友圈分享冷却CD
  341. function getGroupCoolTime(human)
  342. if not human.db.plShare then
  343. return 0
  344. end
  345. if not human.db.plShare.groupTime then
  346. return 0
  347. end
  348. local leftTime = human.db.plShare.groupTime - os.time()
  349. return math.max(leftTime, 0)
  350. end
  351. -- 添加分享次数
  352. function addGroupShareCnt(human)
  353. if not human.db.plShare then
  354. human.db.plShare = {}
  355. end
  356. local plShare = human.db.plShare
  357. plShare.groupCnt = (plShare.groupCnt or 0) + 1
  358. plShare.groupRewardCnt = (plShare.groupRewardCnt or 0) + 1
  359. plShare.groupTime = os.time() + PresentExcel.sharePFGroup[1].shareCD
  360. end
  361. -- 朋友圈分享可领取奖励次数
  362. function getGroupRewardCnt(human)
  363. if not human.db.plShare then
  364. return 0
  365. end
  366. return human.db.plShare.groupRewardCnt or 0
  367. end
  368. -- 清空朋友圈可领取次数
  369. function clGroupRewardCnt(human)
  370. if not human.db.plShare then
  371. return
  372. end
  373. human.db.plShare.groupRewardCnt = nil
  374. end
  375. ------------------------------------ msg ------------------------------------------------
  376. -- 查询分享有礼
  377. function sendFirstQuery(human)
  378. if not (isOpen() and isOpenFirst(human)) then
  379. return
  380. end
  381. local config = PresentExcel.sharePFReward[1]
  382. local msgRet = Msg.gc.GC_SHARE_PLATFORM_FIRST_QUERY
  383. msgRet.state = getFirstState(human)
  384. msgRet.rewards[0] = #config.firstReward
  385. for i = 1, msgRet.rewards[0] do
  386. local itemID = config.firstReward[i][1]
  387. local itemCnt = config.firstReward[i][2]
  388. Grid.makeItem(msgRet.rewards[i], itemID, itemCnt)
  389. end
  390. --Msg.trace(msgRet)
  391. Msg.send(msgRet, human.fd)
  392. end
  393. -- 分享弹窗
  394. function sendFirstTip(human)
  395. if not (isOpen() and isOpenFirst(human)) then
  396. return
  397. end
  398. -- 未完全指定指引,不弹出
  399. if not GuideLogic.isFinishGuideID(human, 150) then
  400. return
  401. end
  402. local config = PresentExcel.sharePFReward[1]
  403. local msgRet = Msg.gc.GC_SHARE_PLATFORM_FIRST_TIP
  404. msgRet.rewards[0] = #config.firstReward
  405. for i = 1, msgRet.rewards[0] do
  406. local itemID = config.firstReward[i][1]
  407. local itemCnt = config.firstReward[i][2]
  408. Grid.makeItem(msgRet.rewards[i], itemID, itemCnt)
  409. end
  410. --Msg.trace(msgRet)
  411. Msg.send(msgRet, human.fd)
  412. end
  413. -- 分享完成
  414. function shareInvate(human)
  415. if not isOpen() then return end
  416. local state = getFirstState(human)
  417. if state == FIRST_STATE_HAD then
  418. return
  419. end
  420. setFirstState(human, FIRST_STATE_HAD)
  421. ObjHuman.save(human)
  422. local mailConfig = MailExcel.mail[103]
  423. local title = mailConfig.title
  424. local senderName = mailConfig.senderName
  425. local content= mailConfig.content
  426. local config = PresentExcel.sharePFReward[1]
  427. MailManager.add(MailManager.SYSTEM, human.db._id , title, content, config.firstReward, senderName)
  428. YunYingLogic.sendGroupList(human, PanelDefine.PANEL_ID_147)
  429. sendFirstQuery(human)
  430. Log.writeShareLog(human, 1)
  431. end
  432. -- 邀请奖励查询
  433. function sendRewardQuery(human)
  434. if not (isOpen() and isOpenReward(human)) then
  435. return
  436. end
  437. local msgRet = Msg.gc.GC_SHARE_PLATFORM_REWARDS_QUERY
  438. msgRet.nowValue = getShareCnt(human)
  439. msgRet.list[0] = #PresentExcel.sharePFReward
  440. for i = 1, msgRet.list[0] do
  441. local cf = PresentExcel.sharePFReward[i]
  442. local net = msgRet.list[i]
  443. net.id = i
  444. net.needValue = cf.need
  445. net.state = getRewardState(human, i)
  446. net.rewards[0] = #cf.reward
  447. for j = 1, net.rewards[0] do
  448. local itemID = cf.reward[j][1]
  449. local itemCnt = cf.reward[j][2]
  450. Grid.makeItem(net.rewards[j], itemID, itemCnt)
  451. end
  452. end
  453. --Msg.trace(msgRet)
  454. Msg.send(msgRet, human.fd)
  455. end
  456. -- 领取邀请奖励
  457. function getReward(human, id)
  458. if not isOpen() then return end
  459. local cf = PresentExcel.sharePFReward[id]
  460. if not cf then return end
  461. local state = getRewardState(human, id)
  462. if state == REWARD_STATE_NONE then
  463. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  464. end
  465. if state == REWARD_STATE_HAD then
  466. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  467. end
  468. setGetReward(human, id)
  469. BagLogic.addItemList(human, cf.reward, "share_platform")
  470. if isOpenReward(human) then
  471. sendRewardQuery(human)
  472. for k, v in pairs(funcID) do
  473. YunYingLogic.updateIcon(YYInfo[k], human)
  474. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_149)
  475. break
  476. end
  477. else
  478. for k, v in pairs(funcID) do
  479. YunYingLogic.updateIcon(YYInfo[k], human)
  480. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_147)
  481. break
  482. end
  483. end
  484. end
  485. -- 封装排行榜结构体
  486. local function fontBoardNet(net, uuid, data)
  487. net.rank = data and data.rank or 0
  488. RoleLogic.getRoleBaseByUuid(uuid, net.roleBase)
  489. net.value = data and data.cnt or 0
  490. end
  491. -- 邀请排名查询
  492. function sendBoard(human)
  493. if not isOpen() then return end
  494. local boardList = getBoardList()
  495. local msgRet = Msg.gc.GC_SHARE_PLATFORM_BOARD_QUERY
  496. msgRet.leftTime = getBoardLeftTime()
  497. msgRet.list[0] = math.min(boardList and #boardList or 0, #msgRet.list)
  498. for i = 1, msgRet.list[0] do
  499. local rankData = boardList[i]
  500. fontBoardNet(msgRet.list[i], rankData.uuid, rankData)
  501. end
  502. local myRankData = getBoardRankData(human.db._id)
  503. fontBoardNet(msgRet.myData, human.db._id, myRankData)
  504. --Msg.trace(msgRet)
  505. Msg.send(msgRet, human.fd)
  506. end
  507. -- 邀请排名奖励查询
  508. function sendBoardReward(human)
  509. if not isOpen() then return end
  510. local msgRet = Msg.gc.GC_SHARE_PLATFORM_BOARD_REWARD
  511. msgRet.list[0] = #PresentExcel.sharePFBoard
  512. for i = 1, msgRet.list[0] do
  513. local net = msgRet.list[i]
  514. local cf = PresentExcel.sharePFBoard[i]
  515. net.minRank = cf.minRank
  516. net.maxRank = cf.maxRank
  517. net.rewards[0] = #cf.reward
  518. for j = 1, net.rewards[0] do
  519. local itemID = cf.reward[j][1]
  520. local itemCnt = cf.reward[j][2]
  521. Grid.makeItem(net.rewards[j], itemID, itemCnt)
  522. end
  523. end
  524. --Msg.trace(msgRet)
  525. Msg.send(msgRet, human.fd)
  526. end
  527. -- 朋友圈分享界面查看
  528. function sendGroupQuery(human)
  529. if not isOpen() then return end
  530. ObjHuman.updateDaily(human)
  531. local groupConfig = PresentExcel.sharePFGroup[1]
  532. local msgRet = Msg.gc.GC_SHARE_PLATFORM_GROUP_QUERY
  533. msgRet.rewards[0] = #groupConfig.rewards
  534. for i = 1, msgRet.rewards[0] do
  535. local itemID = groupConfig.rewards[i][1]
  536. local itemCnt = groupConfig.rewards[i][2]
  537. Grid.makeItem(msgRet.rewards[i], itemID, itemCnt)
  538. end
  539. msgRet.maxCnt = groupConfig.dailyCnt
  540. msgRet.nowCnt = getGroupShareCnt(human)
  541. msgRet.leftTime = getGroupCoolTime(human)
  542. msgRet.state = (getGroupRewardCnt(human) > 0) and 1 or 0
  543. --Msg.trace(msgRet)
  544. Msg.send(msgRet, human.fd)
  545. end
  546. -- 领取朋友圈奖励
  547. function getGroupReward(human)
  548. if not isOpen() then return end
  549. local cnt = getGroupRewardCnt(human)
  550. if cnt < 1 then
  551. return Broadcast.sendErr(human, Lang.SHARE_GROUP_GET_ERR_CNT)
  552. end
  553. clGroupRewardCnt(human)
  554. local groupConfig = PresentExcel.sharePFGroup[1]
  555. BagLogic.addItemList(human,groupConfig.rewards, "share_platform")
  556. sendGroupQuery(human)
  557. for k, v in pairs(funcID) do
  558. YunYingLogic.updateIcon(YYInfo[k], human)
  559. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_151)
  560. break
  561. end
  562. end
  563. -- 朋友圈分享成功
  564. function groupShareOK(human)
  565. if not isOpen() then return end
  566. if not isOpenGroup(human) then return end
  567. local groupConfig = PresentExcel.sharePFGroup[1]
  568. if getGroupShareCnt(human) >= groupConfig.dailyCnt then
  569. return -- 每日次数上限
  570. end
  571. if getGroupCoolTime(human) > 0 then
  572. return -- cd中
  573. end
  574. addGroupShareCnt(human)
  575. for k, v in pairs(funcID) do
  576. YunYingLogic.updateIcon(YYInfo[k], human)
  577. break
  578. end
  579. sendGroupQuery(human)
  580. Log.writeShareLog(human, 2)
  581. end
  582. -----------------------------------------------------------------------------------
  583. -- 到点发奖
  584. function onZero()
  585. if _G.is_middle == true then
  586. return
  587. end
  588. if not isOpen() then return end
  589. local data = CommonDB.getValueByKey(CommonDB.KEY_SHARE_PLATFORM_BOARD)
  590. if not data then return end
  591. if data.time == getBoardTime() then
  592. return
  593. end
  594. Timer.addLater(1, resetBoard)
  595. --resetBoard()
  596. end
  597. -- 登陆
  598. function onLogin(human)
  599. sendFirstTip(human)
  600. end
  601. -- 每日刷新
  602. function updateDaily(human)
  603. if not human.db.plShare then
  604. return
  605. end
  606. human.db.plShare.groupCnt = nil
  607. end
  608. -- 分享成功回调 后台
  609. -- accountA是分享
  610. -- accountB是点链接
  611. -- 同一个账号一秒内收到太多回调怀疑是外挂
  612. local ACCOUNT_2_SHARETIME = {}
  613. local ACCOUNT_2_SHARECNT = {}
  614. function onShareOk(accountA, accountB, nocheck)
  615. if not isOpen() then return end
  616. if not accountA or not accountB then
  617. return
  618. end
  619. if accountA == accountB then
  620. return
  621. end
  622. local nowTime = os.time()
  623. if ACCOUNT_2_SHARETIME[accountA] ~= nowTime then
  624. ACCOUNT_2_SHARETIME[accountA] = nowTime
  625. ACCOUNT_2_SHARECNT[accountA] = 0
  626. end
  627. ACCOUNT_2_SHARECNT[accountA] = ACCOUNT_2_SHARECNT[accountA] + 1
  628. if not nocheck and ACCOUNT_2_SHARECNT[accountA] > 5 then
  629. return -- 防刷!!
  630. end
  631. local db = RoleDBLogic.getDbByAccount(accountA)
  632. if not db then return end
  633. -- 个人分享奖励
  634. if setShareAccount(db, accountB) then
  635. RoleDBLogic.saveRole(db)
  636. local human = ObjHuman.onlineAccount[accountA]
  637. if human and human.fd then
  638. for k, v in pairs(funcID) do
  639. YunYingLogic.updateIcon(YYInfo[k], human)
  640. break
  641. end
  642. end
  643. end
  644. -- 分享排行榜
  645. updateBoard(db._id, accountB)
  646. return true
  647. end