|
|
@@ -24,11 +24,12 @@ local ZhuanpanGift = require("zhuanpan.ZhuanpanGift")
|
|
|
local Log = require("common.Log")
|
|
|
local DB = require("common.DB")
|
|
|
local LuaMongo = _G.lua_mongo
|
|
|
+local MailManager = require("mail.MailManager")
|
|
|
|
|
|
-- 允许的渠道
|
|
|
local ALLOW_CHANNELS = {
|
|
|
[11] = true,
|
|
|
- [16] = true,
|
|
|
+ [17] = true, -- 美团2楼
|
|
|
}
|
|
|
|
|
|
DEFAULT_ZHUANPAN_TYPE_NORMAL = 1 -- 基础转盘
|
|
|
@@ -799,17 +800,17 @@ local function checkAccountDailyFixedReward(account)
|
|
|
if not account then
|
|
|
return false
|
|
|
end
|
|
|
-
|
|
|
+
|
|
|
local QueryByAccount = {account = account}
|
|
|
local fields = {zhuanpan = 1}
|
|
|
LuaMongo.find(DB.db_char, QueryByAccount, fields)
|
|
|
-
|
|
|
+
|
|
|
while true do
|
|
|
local data = {}
|
|
|
if not LuaMongo.next(data) then
|
|
|
break
|
|
|
end
|
|
|
-
|
|
|
+
|
|
|
if data.zhuanpan and data.zhuanpan.dailyFixedReward then
|
|
|
local getTime = data.zhuanpan.dailyFixedReward.getTime
|
|
|
if getTime and Util.isSameDay(getTime) then
|
|
|
@@ -817,10 +818,55 @@ local function checkAccountDailyFixedReward(account)
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
-
|
|
|
+
|
|
|
return false -- 账号下没有角色今日领取过
|
|
|
end
|
|
|
|
|
|
+-- 获取账号下最早创建的角色注册日期(账号级别判断)
|
|
|
+local function getAccountEarliestCreateTime(account)
|
|
|
+ if not account then
|
|
|
+ return nil
|
|
|
+ end
|
|
|
+
|
|
|
+ local QueryByAccount = {account = account}
|
|
|
+ local fields = {createTime = 1}
|
|
|
+ LuaMongo.find(DB.db_char, QueryByAccount, fields)
|
|
|
+
|
|
|
+ local earliestTime = nil
|
|
|
+ while true do
|
|
|
+ local data = {}
|
|
|
+ if not LuaMongo.next(data) then
|
|
|
+ break
|
|
|
+ end
|
|
|
+
|
|
|
+ if data.createTime then
|
|
|
+ if not earliestTime or data.createTime < earliestTime then
|
|
|
+ earliestTime = data.createTime
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ return earliestTime
|
|
|
+end
|
|
|
+
|
|
|
+-- 检查渠道17是否已超过注册后15天(基于当前角色注册时间)
|
|
|
+local function isChannel18Over15Days(human)
|
|
|
+ if not human or not human.db or not human.db.createTime then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local createTime = human.db.createTime
|
|
|
+ local registerDayStart = Util.getDayStartTime(createTime)
|
|
|
+ local now = os.time()
|
|
|
+ local todayDayStart = Util.getDayStartTime(now)
|
|
|
+
|
|
|
+ -- 计算从注册日期到今天已经过了多少天(注册日期是第1天)
|
|
|
+ local daysSinceRegister = math.floor((todayDayStart - registerDayStart) / 86400) + 1
|
|
|
+
|
|
|
+ -- 如果超过15天,则不能领取
|
|
|
+ return daysSinceRegister > 15
|
|
|
+end
|
|
|
+
|
|
|
-- 检查账号下是否有任何角色已领取一次性奖励(账号级别判断)
|
|
|
local function checkAccountOnceReward(account)
|
|
|
if not account then
|
|
|
@@ -848,6 +894,64 @@ local function checkAccountOnceReward(account)
|
|
|
return false -- 账号下没有角色领取过
|
|
|
end
|
|
|
|
|
|
+-- 检查账号下是否有任何角色已领取订阅奖励(账号级别判断)
|
|
|
+local function checkAccountSubscribeReward(account)
|
|
|
+ if not account then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local QueryByAccount = {account = account}
|
|
|
+ local fields = {zhuanpan = 1}
|
|
|
+ LuaMongo.find(DB.db_char, QueryByAccount, fields)
|
|
|
+
|
|
|
+ while true do
|
|
|
+ local data = {}
|
|
|
+ if not LuaMongo.next(data) then
|
|
|
+ break
|
|
|
+ end
|
|
|
+
|
|
|
+ if data.zhuanpan and data.zhuanpan.subscribeReward then
|
|
|
+ local getTime = data.zhuanpan.subscribeReward.getTime
|
|
|
+ if getTime then
|
|
|
+ return true -- 账号下已有角色领取过
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ return false -- 账号下没有角色领取过
|
|
|
+end
|
|
|
+
|
|
|
+-- 从newUniqueTag解析渠道ID (格式: "channelID|serverTag|account")
|
|
|
+local function getChannelIdFromNewUniqueTag(newUniqueTag)
|
|
|
+ if not newUniqueTag then
|
|
|
+ return nil
|
|
|
+ end
|
|
|
+ local parts = {}
|
|
|
+ for part in string.gmatch(newUniqueTag, "([^|]+)") do
|
|
|
+ table.insert(parts, part)
|
|
|
+ end
|
|
|
+ if #parts >= 1 then
|
|
|
+ return tonumber(parts[1])
|
|
|
+ end
|
|
|
+ return nil
|
|
|
+end
|
|
|
+
|
|
|
+-- 获取每日固定奖励配置(根据渠道ID)
|
|
|
+local function getDailyFixedRewardConfig(channelId)
|
|
|
+ if channelId == 17 then
|
|
|
+ -- 渠道17(美图2楼):[[101,20000],[111,5000]]
|
|
|
+ return {
|
|
|
+ {101, 20000},
|
|
|
+ {111, 5000}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ -- 渠道11(默认):[[102, 50]]
|
|
|
+ return {
|
|
|
+ {102, 50}
|
|
|
+ }
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
-- 每日固定奖励查询
|
|
|
function dailyFixedRewardQuery(human)
|
|
|
local msgRet = Msg.gc.GC_ZHUANPAN_DAILY_FIXED_QUERY
|
|
|
@@ -859,31 +963,83 @@ function dailyFixedRewardQuery(human)
|
|
|
-- 每日更新检查
|
|
|
ObjHuman.updateDaily(human)
|
|
|
|
|
|
- -- 初始化数据库
|
|
|
- human.db.zhuanpan = human.db.zhuanpan or {}
|
|
|
- human.db.zhuanpan.dailyFixedReward = human.db.zhuanpan.dailyFixedReward or {}
|
|
|
-
|
|
|
- -- 账号级别判断:先检查当前角色的内存数据,再检查数据库
|
|
|
local account = human.db.account
|
|
|
local isReceived = false
|
|
|
-
|
|
|
- -- 先检查当前角色的内存数据
|
|
|
- local getTime = human.db.zhuanpan.dailyFixedReward.getTime
|
|
|
+ -- 先读取当日是否已领取(必须在 or {} 初始化之前读,否则可能被空表覆盖导致刚写入的 getTime 丢失)
|
|
|
+ local getTime = nil
|
|
|
+ if human.db.zhuanpan and human.db.zhuanpan.dailyFixedReward then
|
|
|
+ getTime = human.db.zhuanpan.dailyFixedReward.getTime
|
|
|
+ end
|
|
|
if getTime and Util.isSameDay(getTime) then
|
|
|
isReceived = true
|
|
|
else
|
|
|
- -- 再检查账号下其他角色(数据库)
|
|
|
isReceived = checkAccountDailyFixedReward(account)
|
|
|
end
|
|
|
-
|
|
|
- if isReceived then
|
|
|
- msgRet.status = 2 -- 已领取(账号级别)
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] getTime=" .. tostring(getTime) .. ", isReceived=" .. tostring(isReceived) .. ", account=" .. tostring(account))
|
|
|
+
|
|
|
+ -- 初始化数据库(放在读取 getTime 之后,避免覆盖已有 dailyFixedReward 导致 isReceived 错误)
|
|
|
+ human.db.zhuanpan = human.db.zhuanpan or {}
|
|
|
+ human.db.zhuanpan.dailyFixedReward = human.db.zhuanpan.dailyFixedReward or {}
|
|
|
+
|
|
|
+ -- 渠道17(美团2楼)需要满足:
|
|
|
+ -- 1) 当日从2楼登录(mtFrom2floor == 1,且 mtFrom2floorDay 是今天)
|
|
|
+ -- 2) 订阅奖励已领取且在15日有效期内
|
|
|
+ local newUniqueTag = human.db.newUniqueTag or human.newUniqueTag
|
|
|
+ local channelId = getChannelIdFromNewUniqueTag(newUniqueTag)
|
|
|
+ if channelId == 17 then
|
|
|
+ -- 2楼登录状态(mtFrom2floor 可能为字符串;Util.isSameDay 同天返回 now 时间戳,否则 nil,转为布尔)
|
|
|
+ local from2floorOk = false
|
|
|
+ if tonumber(human.db.mtFrom2floor) == 1 and human.db.mtFrom2floorDay then
|
|
|
+ from2floorOk = (Util.isSameDay(human.db.mtFrom2floorDay) and true or false)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 订阅相关状态(mtSubscribe 可能为字符串 "1",用 tonumber 统一判断)
|
|
|
+ local isSubscribed = (tonumber(human.db.mtSubscribe) == 1)
|
|
|
+ local zhuanpan = human.db.zhuanpan
|
|
|
+ local hasSubscribeReward = zhuanpan and zhuanpan.subscribeReward and zhuanpan.subscribeReward.getTime
|
|
|
+ local inValidPeriod = hasSubscribeReward and isSubscribeRewardInValidPeriod(human)
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] channelId=17 from2floorOk=" .. tostring(from2floorOk) .. ", mtFrom2floor=" .. tostring(human.db.mtFrom2floor) .. ", mtFrom2floorDay=" .. tostring(human.db.mtFrom2floorDay) .. ", isSubscribed=" .. tostring(isSubscribed) .. ", hasSubscribeReward=" .. tostring(hasSubscribeReward) .. ", inValidPeriod=" .. tostring(inValidPeriod))
|
|
|
+
|
|
|
+ if not isSubscribed then
|
|
|
+ -- 未订阅:不可领取
|
|
|
+ msgRet.status = 3 -- 未激活(未订阅)
|
|
|
+ elseif isReceived then
|
|
|
+ -- 当日已领取:固定为 2,不因 mtFrom2floor 被置 0 而变成 0
|
|
|
+ msgRet.status = 2 -- 已领取(今日已领取)
|
|
|
+ elseif not from2floorOk then
|
|
|
+ -- 当天未从2楼进入:不可领取
|
|
|
+ msgRet.status = 0
|
|
|
+ else
|
|
|
+ if not hasSubscribeReward or not inValidPeriod then
|
|
|
+ -- 已订阅,但订阅奖励尚未领取,或已超过15日有效期
|
|
|
+ msgRet.status = 3 -- 未激活(订阅奖励未领或15天已满)
|
|
|
+ else
|
|
|
+ msgRet.status = 1 -- 可领取(已激活且在15日内,且今日未领)
|
|
|
+ end
|
|
|
+ end
|
|
|
else
|
|
|
- msgRet.status = 1 -- 可领取
|
|
|
+ -- 其他渠道保持原有逻辑
|
|
|
+ if isReceived then
|
|
|
+ msgRet.status = 2 -- 已领取(账号级别)
|
|
|
+ else
|
|
|
+ msgRet.status = 1 -- 可领取
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 根据渠道ID设置奖励物品
|
|
|
+ local newUniqueTag = human.db.newUniqueTag or human.newUniqueTag
|
|
|
+ local channelId = getChannelIdFromNewUniqueTag(newUniqueTag)
|
|
|
+ local rewardConfig = getDailyFixedRewardConfig(channelId or 11) -- 默认渠道11
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] 查询奖励信息: rewardConfig",rewardConfig)
|
|
|
+ -- 循环处理所有奖励物品
|
|
|
+ for i = 1, #rewardConfig do
|
|
|
+ Grid.makeItem(msgRet.reward[i], rewardConfig[i][1], rewardConfig[i][2])
|
|
|
end
|
|
|
+ msgRet.reward[0] = #rewardConfig -- 设置数组长度
|
|
|
|
|
|
- -- 设置奖励物品
|
|
|
- Grid.makeItem(msgRet.reward, 102, 50)
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] channelId=" .. tostring(channelId) .. ", status=" .. tostring(msgRet.status))
|
|
|
|
|
|
if human.fd then
|
|
|
Msg.send(msgRet, human.fd)
|
|
|
@@ -897,7 +1053,7 @@ function dailyFixedRewardGet(human, channelId)
|
|
|
if not ALLOW_CHANNELS[channelId] then
|
|
|
Log.write(
|
|
|
Log.LOGID_DEBUG,
|
|
|
- "[onceRewardGet] 渠道不匹配: channelId=" .. (channelId or "nil") .. ", 允许=11,12"
|
|
|
+ "[dailyFixedRewardGet] 渠道不匹配: channelId=" .. (channelId or "nil") .. ", 允许=11,16,18"
|
|
|
)
|
|
|
return Broadcast.sendErr(human, "渠道不匹配")
|
|
|
end
|
|
|
@@ -926,10 +1082,38 @@ function dailyFixedRewardGet(human, channelId)
|
|
|
Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 账号今日已领取: account="..(account or "nil"))
|
|
|
return Broadcast.sendErr(human, "今日已领取")
|
|
|
end
|
|
|
+
|
|
|
+ -- 渠道17(美团2楼)额外条件:
|
|
|
+ -- 1) 当日从2楼登录(mtFrom2floor == 1 且 mtFrom2floorDay 为今天)
|
|
|
+ -- 2) 订阅奖励已领取且在15日有效期内
|
|
|
+ if channelId == 17 then
|
|
|
+ -- 2楼登录状态(mtFrom2floor 可能为字符串,Util.isSameDay 同天返回时间戳,转为布尔)
|
|
|
+ local from2floorOk = false
|
|
|
+ if tonumber(human.db.mtFrom2floor) == 1 and human.db.mtFrom2floorDay then
|
|
|
+ from2floorOk = (Util.isSameDay(human.db.mtFrom2floorDay) and true or false)
|
|
|
+ end
|
|
|
+
|
|
|
+ if not from2floorOk then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 渠道17当日未从2楼进入,无法领取: account="..(account or "nil"))
|
|
|
+ return Broadcast.sendErr(human, "条件不足,无法领取")
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 订阅有效期检查(mtSubscribe 可能为字符串 "1")
|
|
|
+ if tonumber(human.db.mtSubscribe) ~= 1 or not isSubscribeRewardInValidPeriod(human) then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 渠道17订阅未激活或已过期,无法领取: account="..(account or "nil"))
|
|
|
+ return Broadcast.sendErr(human, "订阅未激活或已过期")
|
|
|
+ end
|
|
|
+ end
|
|
|
|
|
|
BagLogic.cleanMomentItemList()
|
|
|
|
|
|
- BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, 102, 50)
|
|
|
+ -- 根据渠道ID发放不同的奖励(循环处理所有奖励)
|
|
|
+ local rewardConfig = getDailyFixedRewardConfig(channelId)
|
|
|
+ for i = 1, #rewardConfig do
|
|
|
+ BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, rewardConfig[i][1], rewardConfig[i][2])
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 复用已有的日志类型,避免未定义的logType导致断言
|
|
|
local success, err = pcall(function()
|
|
|
BagLogic.addMomentItemList(human, "zhuanpan_once_reward")
|
|
|
end)
|
|
|
@@ -939,7 +1123,15 @@ function dailyFixedRewardGet(human, channelId)
|
|
|
end
|
|
|
|
|
|
-- 记录领取时间
|
|
|
- human.db.zhuanpan.dailyFixedReward.getTime = os.time()
|
|
|
+ local nowTime = os.time()
|
|
|
+ human.db.zhuanpan.dailyFixedReward.getTime = nowTime
|
|
|
+
|
|
|
+ -- 渠道17:领取成功后,消耗当天的2楼登录资格,防止同日重复触发
|
|
|
+ if channelId == 17 then
|
|
|
+ human.db.mtFrom2floor = 0
|
|
|
+ end
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 领取成功 account=" .. tostring(human.db.account) .. " channelId=" .. tostring(channelId) .. " getTime=" .. tostring(nowTime) .. " mtFrom2floor=" .. tostring(human.db.mtFrom2floor))
|
|
|
|
|
|
-- 领取成功后下发查询协议
|
|
|
local querySuccess, queryErr = pcall(function()
|
|
|
@@ -1059,4 +1251,263 @@ function onceRewardGet(human, channelId)
|
|
|
Log.write(Log.LOGID_DEBUG, "[onceRewardGet] 错误: 发送查询协议失败: "..(queryErr or "unknown"))
|
|
|
-- 即使查询协议发送失败,奖励已经发放,所以不返回错误
|
|
|
end
|
|
|
+end
|
|
|
+
|
|
|
+-- 检查当前角色订阅奖励是否在15日有效期内(从订阅奖励领取时间起算)
|
|
|
+function isSubscribeRewardInValidPeriod(human)
|
|
|
+ if not human or not human.db then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+ local zhuanpan = human.db.zhuanpan
|
|
|
+ if not zhuanpan or not zhuanpan.subscribeReward or not zhuanpan.subscribeReward.getTime then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+ local activateTime = zhuanpan.subscribeReward.getTime
|
|
|
+ local activateDayStart = Util.getDayStartTime(activateTime)
|
|
|
+ local nowTs = os.time()
|
|
|
+ local todayDayStart = Util.getDayStartTime(nowTs)
|
|
|
+ -- 激活日为第1天,15日内有效
|
|
|
+ local daysSinceActivate = math.floor((todayDayStart - activateDayStart) / 86400) + 1
|
|
|
+ return daysSinceActivate <= 15
|
|
|
+end
|
|
|
+
|
|
|
+-- 检查美团2楼玩家每日固定奖励领取情况(晚上11点调用)
|
|
|
+function checkMtFrom2floorDailyReward()
|
|
|
+ if _G.is_middle == true then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local QueryMtFrom2floor = {mtFrom2floor = 1}
|
|
|
+ local fields = {_id = 1, zhuanpan = 1, createTime = 1, mtSubscribe = 1, account = 1}
|
|
|
+ LuaMongo.find(DB.db_char, QueryMtFrom2floor, fields)
|
|
|
+
|
|
|
+ local now = os.time()
|
|
|
+ local todayDayStart = Util.getDayStartTime(now)
|
|
|
+ local dailyMailSentCount = 0
|
|
|
+ local subscribeMailSentCount = 0
|
|
|
+
|
|
|
+ while true do
|
|
|
+ local data = {}
|
|
|
+ if not LuaMongo.next(data) then
|
|
|
+ break
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 检查是否在订阅有效期内(如果从未激活订阅奖励,视为未激活,不发每日固定奖励)
|
|
|
+ if data.mtSubscribe ~= 1 then
|
|
|
+ goto continue
|
|
|
+ end
|
|
|
+
|
|
|
+ local inValidPeriod = false
|
|
|
+ if data.zhuanpan and data.zhuanpan.subscribeReward and data.zhuanpan.subscribeReward.getTime then
|
|
|
+ local activateTime = data.zhuanpan.subscribeReward.getTime
|
|
|
+ local activateDayStart = Util.getDayStartTime(activateTime)
|
|
|
+ local daysSinceActivate = math.floor((todayDayStart - activateDayStart) / 86400) + 1
|
|
|
+ inValidPeriod = (daysSinceActivate <= 15)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 订阅奖励未激活或已过期,则不发每日固定奖励
|
|
|
+ if not inValidPeriod then
|
|
|
+ goto continue
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 检查今天是否已领取每日固定奖励
|
|
|
+ local hasReceivedToday = false
|
|
|
+ if data.zhuanpan and data.zhuanpan.dailyFixedReward then
|
|
|
+ local getTime = data.zhuanpan.dailyFixedReward.getTime
|
|
|
+ if getTime and Util.isSameDay(getTime) then
|
|
|
+ hasReceivedToday = true
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 如果今天没领取,发送邮件,并将 mtFrom2floor 置为0,防止当天再次通过登录触发
|
|
|
+ if not hasReceivedToday then
|
|
|
+ local title = "每日固定奖励提醒"
|
|
|
+ local content = "您今日尚未领取每日固定奖励,请及时领取!"
|
|
|
+ local rewardItems = {{101, 20000}, {111, 5000}} -- 渠道17的奖励
|
|
|
+
|
|
|
+ local success, err = pcall(function()
|
|
|
+ MailManager.add(MailManager.SYSTEM, data._id, title, content, rewardItems)
|
|
|
+ -- 更新数据库:标记今日已通过邮件发放,并清除当天的2楼标记
|
|
|
+ local updateFields = {
|
|
|
+ ["zhuanpan.dailyFixedReward.getTime"] = now,
|
|
|
+ ["mtFrom2floor"] = 0,
|
|
|
+ }
|
|
|
+ LuaMongo.update(DB.db_char, {_id = data._id}, updateFields, false, false)
|
|
|
+ end)
|
|
|
+
|
|
|
+ if success then
|
|
|
+ dailyMailSentCount = dailyMailSentCount + 1
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 发送每日固定奖励邮件并更新状态成功: uuid="..data._id)
|
|
|
+ else
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 发送每日固定奖励邮件或更新状态失败: uuid="..data._id..", err="..tostring(err))
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 检查订阅奖励:如果已订阅(mtSubscribe == 1)且未领取,发送邮件
|
|
|
+ if data.mtSubscribe == 1 then
|
|
|
+ -- 检查账号下是否已领取订阅奖励
|
|
|
+ local hasReceivedSubscribe = checkAccountSubscribeReward(data.account)
|
|
|
+
|
|
|
+ if not hasReceivedSubscribe then
|
|
|
+ local title = "订阅奖励提醒"
|
|
|
+ local content = "您已订阅但尚未领取订阅奖励,请及时领取!"
|
|
|
+ local rewardItems = {{101, 50000}, {112, 100}} -- 订阅奖励
|
|
|
+
|
|
|
+ local success, err = pcall(function()
|
|
|
+ MailManager.add(MailManager.SYSTEM, data._id, title, content, rewardItems)
|
|
|
+ end)
|
|
|
+
|
|
|
+ if success then
|
|
|
+ subscribeMailSentCount = subscribeMailSentCount + 1
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 发送订阅奖励邮件成功: uuid="..data._id)
|
|
|
+ else
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 发送订阅奖励邮件失败: uuid="..data._id..", err="..tostring(err))
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ ::continue::
|
|
|
+ end
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 检查完成,每日固定奖励邮件数量: "..dailyMailSentCount..", 订阅奖励邮件数量: "..subscribeMailSentCount)
|
|
|
+end
|
|
|
+
|
|
|
+-- 美团订阅奖励查询(同时接收并存储订阅状态)
|
|
|
+function subscribeRewardQuery(human, msg)
|
|
|
+ local msgRet = Msg.gc.GC_ZHUANPAN_SUBSCRIBE_REWARD_QUERY
|
|
|
+ if not msgRet then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardQuery] 错误: msgRet为nil")
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 如果前端上传了订阅状态,则进行存储
|
|
|
+ if msg and msg.mtSubscribe ~= nil then
|
|
|
+ local val = tonumber(msg.mtSubscribe) or 0
|
|
|
+ -- 只从 0 -> 1,避免重复覆盖或回退
|
|
|
+ if val == 1 and human.db then
|
|
|
+ human.db.mtSubscribe = human.db.mtSubscribe or 0
|
|
|
+ if human.db.mtSubscribe ~= 1 then
|
|
|
+ human.db.mtSubscribe = 1
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardQuery] 更新订阅状态为1, account="..tostring(human.db.account))
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 初始化数据库
|
|
|
+ human.db.zhuanpan = human.db.zhuanpan or {}
|
|
|
+ human.db.zhuanpan.subscribeReward = human.db.zhuanpan.subscribeReward or {}
|
|
|
+
|
|
|
+ -- 检查是否订阅(mtSubscribe == 1)
|
|
|
+ local isSubscribed = (human.db.mtSubscribe == 1)
|
|
|
+
|
|
|
+ -- 账号级别判断:先检查当前角色的内存数据,再检查数据库
|
|
|
+ local account = human.db.account
|
|
|
+ local isReceived = false
|
|
|
+
|
|
|
+ if isSubscribed then
|
|
|
+ -- 先检查当前角色的内存数据
|
|
|
+ local getTime = human.db.zhuanpan.subscribeReward.getTime
|
|
|
+ if getTime then
|
|
|
+ isReceived = true
|
|
|
+ else
|
|
|
+ -- 再检查账号下其他角色(数据库)
|
|
|
+ isReceived = checkAccountSubscribeReward(account)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ if not isSubscribed then
|
|
|
+ msgRet.status = 0 -- 不可领取(未订阅)
|
|
|
+ elseif isReceived then
|
|
|
+ msgRet.status = 2 -- 已领取
|
|
|
+ else
|
|
|
+ msgRet.status = 1 -- 可领取
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 设置奖励物品列表:[[101,50000],[112,100]]
|
|
|
+ local success, err = pcall(function()
|
|
|
+ Grid.makeItem(msgRet.reward[1], 101, 50000)
|
|
|
+ Grid.makeItem(msgRet.reward[2], 112, 100)
|
|
|
+ msgRet.reward[0] = 2 -- 设置数组长度
|
|
|
+ end)
|
|
|
+
|
|
|
+ if not success then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardQuery] 错误: 设置奖励物品失败: "..tostring(err))
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ if human.fd then
|
|
|
+ Msg.send(msgRet, human.fd)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 美团订阅奖励领取
|
|
|
+function subscribeRewardGet(human, channelId)
|
|
|
+ -- 检查渠道,只有渠道ID=17(美团2楼)才能领取
|
|
|
+ if not channelId or channelId ~= 17 then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 渠道不匹配: channelId="..(channelId or "nil")..", 需要=18")
|
|
|
+ return Broadcast.sendErr(human, "渠道不匹配")
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 检查是否订阅(mtSubscribe == 1)
|
|
|
+ if human.db.mtSubscribe ~= 1 then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 未订阅: mtSubscribe="..(human.db.mtSubscribe or "nil"))
|
|
|
+ return Broadcast.sendErr(human, "未订阅,无法领取")
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 初始化数据库
|
|
|
+ human.db.zhuanpan = human.db.zhuanpan or {}
|
|
|
+ human.db.zhuanpan.subscribeReward = human.db.zhuanpan.subscribeReward or {}
|
|
|
+
|
|
|
+ -- 账号级别判断:先检查当前角色的内存数据,再检查数据库
|
|
|
+ local account = human.db.account
|
|
|
+ local isReceived = false
|
|
|
+
|
|
|
+ -- 先检查当前角色的内存数据
|
|
|
+ local getTime = human.db.zhuanpan.subscribeReward.getTime
|
|
|
+ if getTime then
|
|
|
+ isReceived = true
|
|
|
+ else
|
|
|
+ -- 再检查账号下其他角色(数据库)
|
|
|
+ isReceived = checkAccountSubscribeReward(account)
|
|
|
+ end
|
|
|
+
|
|
|
+ if isReceived then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 账号已领取过,无法重复领取: account="..(account or "nil"))
|
|
|
+ return Broadcast.sendErr(human, "已领取过,无法重复领取")
|
|
|
+ end
|
|
|
+
|
|
|
+ BagLogic.cleanMomentItemList()
|
|
|
+
|
|
|
+ -- 发放奖励:[[101,50000],[112,100]]
|
|
|
+ BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, 101, 50000)
|
|
|
+ BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, 112, 100)
|
|
|
+
|
|
|
+ -- 使用已存在的日志类型,避免日志定义缺失导致的断言
|
|
|
+ local success, err = pcall(function()
|
|
|
+ BagLogic.addMomentItemList(human, "zhuanpan_once_reward")
|
|
|
+ end)
|
|
|
+ if not success then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 错误: 添加到背包失败: "..(err or "unknown"))
|
|
|
+ return Broadcast.sendErr(human, "发放奖励失败")
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 记录领取时间(永久记录)
|
|
|
+ human.db.zhuanpan.subscribeReward.getTime = os.time()
|
|
|
+
|
|
|
+ local querySuccess, queryErr = pcall(function()
|
|
|
+ subscribeRewardQuery(human)
|
|
|
+ end)
|
|
|
+ if not querySuccess then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 错误: 发送订阅奖励查询协议失败: "..(queryErr or "unknown"))
|
|
|
+ -- 即使查询协议发送失败,奖励已经发放,所以不返回错误
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 领取订阅奖励后,同时下发每日固定奖励查询协议
|
|
|
+ local dailyQuerySuccess, dailyQueryErr = pcall(function()
|
|
|
+ dailyFixedRewardQuery(human)
|
|
|
+ end)
|
|
|
+ if not dailyQuerySuccess then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 错误: 发送每日固定奖励查询协议失败: "..(dailyQueryErr or "unknown"))
|
|
|
+ -- 即使查询协议发送失败,奖励已经发放,所以不返回错误
|
|
|
+ end
|
|
|
end
|