miduo_client/Assets/ManagedResources/~Lua/Modules/Operating/OperatingManager.lua

651 lines
20 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

--[[
* @ClassName OperatingManager
* @Description 运营活动管理
* @Date 2019/6/6 10:29
* @Author MagicianJoker, fengliudianshao@outlook.com
* @Copyright Copyright (c) 2019, MagicianJoker
--]]
OperatingManager = {}
local this = OperatingManager
local giftGoodsInfoList = {}
--- 新的数据列表按照ID存取
local newGoodsList = {}
local hadBuyGoodsList = {}
local rechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
local luxuryConfig = ConfigManager.GetConfig(ConfigName.LuxuryFundConfig)
--初始化
function this.Initialize()
Game.GlobalEvent:AddEvent(GameEvent.Player.OnLevelChange, function()
RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift)
end)
Game.GlobalEvent:AddEvent(GameEvent.PatFace.PatFaceHaveGrowGift, this.NewHeroGift)
end
---------------------------局限性----------------------------
function this.SetBasicValues(giftGoodsList)
for _, v in pairs(GoodsTypeDef) do
giftGoodsInfoList[v] = {}
end
for _, giftGoodsInfo in ipairs(giftGoodsList) do
local rechargeConfig = ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig, giftGoodsInfo.goodsId)
--Log("------充值活动-----------".. rechargeConfig.Type .." ".. giftGoodsInfo.goodsId .." "
--..giftGoodsInfo.buyTimes.." "..giftGoodsInfo.startTime.." "
--..giftGoodsInfo.endTime .. " 可购买次数" .. giftGoodsInfo.dynamicBuyTimes)
if giftGoodsInfoList[rechargeConfig.Type] then
table.insert(giftGoodsInfoList[rechargeConfig.Type], giftGoodsInfo)
end
end
Game.GlobalEvent:DispatchEvent(GameEvent.FindFairy.RefreshBuyOpenState)
end
-- 判断商品数据是否在可用时间范围内
local function _IsGiftGoodsAvailable(gift)
-- body
if not gift then return false end
if gift.startTime == 0 and gift.endTime == 0 then return true end
local curTime = GetTimeStamp()
local isAvailable = curTime > gift.startTime and curTime <= gift.endTime
return isAvailable
end
function this.RemoveGiftInfoList(goodsType)
giftGoodsInfoList[goodsType] = nil
end
--- 删除某一类型的某一条商品数据
function this.RemoveItemInfoByType(type, goodsId)
if not giftGoodsInfoList[type] then
Log("此类商品不存在")
return
end
for k,v in pairs(giftGoodsInfoList[type]) do
if v then
if v.goodsId == goodsId then
table.remove(giftGoodsInfoList[type], k)
end
end
end
end
function this.IsRechargeable(goodsType)
return giftGoodsInfoList[goodsType]
end
--- 获取激活后的商品数据
function this.GetGiftGoodsInfo(goodsType, Id)
if not giftGoodsInfoList[goodsType] then
return nil
end
for _, giftGoodsInfo in pairs(giftGoodsInfoList[goodsType]) do
if Id then
if giftGoodsInfo.goodsId == Id then
return giftGoodsInfo
end
else
-- 判断是否可用
if _IsGiftGoodsAvailable(giftGoodsInfo) then
return giftGoodsInfo
end
end
end
return nil
end
function this.GetGiftGoodsInfoList(type)
return giftGoodsInfoList[type] and giftGoodsInfoList[type] or {}
end
function this.RefreshGiftGoodsBuyTimes(goodsType, goodsId, buyTimes)
if not giftGoodsInfoList[goodsType] then
return
end
for _, giftGoodsInfo in ipairs(giftGoodsInfoList[goodsType]) do
if giftGoodsInfo.goodsId == goodsId then
giftGoodsInfo.buyTimes = giftGoodsInfo.buyTimes + (buyTimes and buyTimes or 1)
end
end
end
--- 获取商品的剩余购买次数
--- 0 不可买 1: 剩余1次-1不限次数
function this.GetLeftBuyTime(type, goodsId)
if not giftGoodsInfoList[type] then
Log("此类基金尚未激活!, 商品ID是 -- " .. goodsId)
return
end
--- 此类商品的购买次数限制
local limitTime = rechargeConfig[goodsId].Limit
if limitTime == 0 then --- 不限购
return -1
else
local boughtTime = this.GetGoodsBuyTime(type, goodsId)
return limitTime - boughtTime
end
end
--- 获取商品已经购买次数
function this.GetGoodsBuyTime(type, goodsId)
if not giftGoodsInfoList[type] then
return
end
for k,v in pairs(giftGoodsInfoList[type]) do
if v.goodsId == goodsId then
return v.buyTimes
end
end
end
--------------------------------------------------------------
function this.SetHadBuyGoodsId(BuyGoodsList)
for i = 1, #BuyGoodsList do
table.insert(hadBuyGoodsList, BuyGoodsList[i])
end
end
function this.GetHadBuyGoodsTypeId(type)
for _, goodsId in ipairs(hadBuyGoodsList) do
if rechargeConfig[goodsId].Type == type then
return goodsId
end
end
end
function this.GetGrowthRedPointState()
local redPoint = false
local openStatus = ActivityGiftManager.GetActivityOpenStatus(ActivityTypeDef.GrowthReward)
if openStatus then
local actRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)
for _, configInfo in ConfigPairs(actRewardConfig) do
if configInfo.ActivityId == ActivityTypeDef.GrowthReward then
local activityInfo = ActivityGiftManager.GetActivityInfo(ActivityTypeDef.GrowthReward, configInfo.Id)
if activityInfo and activityInfo.state == 0 then
if configInfo.Values[1][1] == ConditionType.Level then
redPoint = redPoint or PlayerManager.level >= configInfo.Values[1][2]
else
redPoint = redPoint or FightPointPassManager.IsFightPointPass(configInfo.Values[1][2])
end
end
end
end
end
return redPoint
end
-- 商品时间数据
local _GoodsDurationData = {}
function this.SetGoodsDurationData(dataList)
if not dataList then
return
end
for _, data in ipairs(dataList) do
-- 这里协议字段为goodsType其实数据为ID
_GoodsDurationData[data.goodsType] = data.endTime
--Log("商品类型 = "..data.goodsType..", 剩余时间 = "..data.endTime)
end
end
-- 根据类型判断相应的物品是否开启并返回相应的ID
function this.GetActiveGoodsIDByType(goodsType)
for goodsId, endTime in pairs(_GoodsDurationData) do
if rechargeConfig[goodsId].Type == goodsType and endTime > GetTimeStamp() then
return goodsId, endTime
end
end
end
function this.GetGoodsEndTime(goodsType)
local goodsId, endTime = this.GetActiveGoodsIDByType(goodsType)
return endTime
end
function this.RemoveEndTime(goodsId)
_GoodsDurationData[goodsId] = nil
end
function this.SetGoodsEndTime(goodsId, endTime)
_GoodsDurationData[goodsId] = endTime
end
-- 直购活动是否还在
function this.IsGoodsExit(type, id)
local isOpen = false
local data = this.GetGiftGoodsInfo(type, id)
if data then
-- 有数据,但是活动结束
local time = data.endTime - PlayerManager.serverTime
isOpen = time > 0
else
isOpen = false
end
return isOpen
end
-- 五星成长礼红点
function this.GetRedState()
local isRed = false
local redValue = PlayerPrefs.GetInt(PlayerManager.uid .. "BlaBlaBla")
local openState = this.IsGoodsExit(GoodsTypeDef.DirectPurchaseGift, 21)
if openState and redValue == 0 then
isRed = true
else
isRed = false
end
return isRed
end
---------------------------------------累计签到--------------------------------
local _SignInData
function this.SetSignInData(signIn)
_SignInData = signIn
CheckRedPointStatus(RedPointType.CumulativeSignIn)
end
function this.GetSignInData()
return _SignInData
end
--红点检测方法
function this.GetSignInRedPointStatus()
local receiveNum=PrivilegeManager.GetPrivilegeRemainValue(PRIVILEGE_TYPE.DAY_SIGN_IN)--本地标记可领取次数
local rechargeNum=PrivilegeManager.GetPrivilegeNumber(PRIVILEGE_TYPE.DAY_SIGN_IN)--充值标记 1未充值 2已充值
return _SignInData.state == 0 or receiveNum>0--(_SignInData.state==1 and ((receiveNum==0 and rechargeNum==1) or (receiveNum==1 and rechargeNum==2)))
end
---------------------------------- 什么什么什么新鸡成长礼包 ------------------------------------------
--- 新增一个礼包
function this.NewHeroGift()
this.SetHeroRedState(1)
CheckRedPointStatus(RedPointType.HERO_STAR_GIFT)
end
--- 获取那个的显示数据
function this.GetStarGiftData()
local data = {}
for k, v in ConfigPairs(rechargeConfig) do
if v.ShowType == 8 then
local t = {}
t.data = v -- 数据结构
t.Id = v.Id -- 商品ID
data[#data + 1] = t
end
end
return data
end
function this.IsHeroGiftActive()
local activeNum = 0
if not giftGoodsInfoList[GoodsTypeDef.DirectPurchaseGift] then
return false
else
for i = 1, #giftGoodsInfoList[GoodsTypeDef.DirectPurchaseGift] do
local data =giftGoodsInfoList[GoodsTypeDef.DirectPurchaseGift][i]
if data then
local id = data.goodsId
if rechargeConfig[id].ShowType == 8 then --- 只有前端显示的商品类型
activeNum = activeNum + 1
end
end
end
end
return activeNum > 0
end
--- 获取礼包的显示数据
function this.GetGiftShowData()
local staticData = this.GetStarGiftData()
local newData = {}
for i = 1, #staticData do
local goodsId = staticData[i].Id
local data = {}
data.rewardData = staticData[i].data.RewardShow
data.price = staticData[i].data.Price
data.id = goodsId
data.name = staticData[i].data.Name
local serData = this.GetGiftGoodsInfo(GoodsTypeDef.DirectPurchaseGift, goodsId)
if serData and serData.endTime > 0 then --- 商品激活可购买
data.endTime = serData.endTime
data.startTime = serData.startTime
data.leftBuyTime = serData.dynamicBuyTimes
data.isActive = 1
else --- 未激活只是显示而已
data.endTime = 0
data.startTime = 0
data.leftBuyTime = 0
data.isActive = 0
end
newData[#newData + 1] = data
end
---排序
if #newData > 1 then
table.sort(newData, function(a, b)
if a.isActive == b.isActive then
return a.id > b.id
else
return a.isActive > b.isActive
end
end)
end
return newData
end
--- 礼包红点
function this.IsHeroStarGiftActive()
local clickedState = this.GetHeroRedState()
local isActive = this.IsHeroGiftActive()
local hasRed = clickedState == 1 and isActive
return hasRed
end
function this.SetHeroRedState(value)
PlayerPrefs.SetInt(PlayerManager.uid .. "hero_star_gift", value)
end
function this.GetHeroRedState()
return PlayerPrefs.GetInt(PlayerManager.uid .. "hero_star_gift")
end
----------------------------------------------------------------------------------------------
--- 获取鸡精面版的显示信息
--- 传进来的参数值是 33或者是34基金类型
function this.GetPanelShowReward(type, isAll)
local data = {}
for k, v in ConfigPairs(luxuryConfig) do
if not isAll then
if v.Type == type and v.ShowReward == 1 then
data[#data + 1] = v
end
else
if v.Type == type then
data[#data + 1] = v
end
end
end
return data
end
--- 某一个鸡精活动是否开启
function this.IsBaseOpen(type, id)
local isOpen = false
local data = this.GetGiftGoodsInfo(type, id)
if data then
--- 常驻
if tonumber(data.endTime) == 0 then
isOpen = true
else
local time = data.endTime - PlayerManager.serverTime
local isBuy = this.IsBaseBuy(type)
isOpen = time > 0
-- 如果购买了结束也没有用
if isBuy then
isOpen = true
end
end
else
isOpen = false
-- 如果购买了结束也没有用
if this.IsBaseBuy(type) then
isOpen = true
end
end
return isOpen
end
--- 判断某一个鸡精是否购买
function this.IsBaseBuy(type)
local leftTime = this.GetGoodsEndTime(type)
local isBuy = false
if not leftTime then
isBuy = false
else
if leftTime <= 0 then
isBuy = false
else
isBuy = true
end
end
return isBuy
end
---- 界面打开时设置一下服务器数据
function this.SetSerData(goodsType)
local endTime = this.GetGoodsEndTime(goodsType)
if not endTime then return end
local startTime = endTime - 24 * 30 * 60 * 60
local passSecond = GetTimeStamp() - startTime
-- Log("结束时间" .. os.date("%Y年%m月%d", endTime))
-- Log("起点时间" .. os.date("%Y年%m月%d", startTime))
-- Log("服务器时间".. os.date("%Y年%m月%d", GetTimeStamp()))
-- Log("经历时间 --- " .. PlayerManager.serverTime)
this.SetSignRewarDay(goodsType, passSecond)
end
local getDay = {}
local oneDaySeconds = 24 * 60 * 60
-- 累计领取天数
function this.GetRewardDay(goodType)
-- Log("天数 " .. getDay[goodType])
-- 未激活时没有天数
if not this.IsBaseBuy(goodType) then return 0 end
return getDay[goodType]
end
--- 设置累计天数
function this.SetSignRewarDay(goodType, second)
if not getDay[goodType] then getDay[goodType] = {} end
-- 小于24小时按一天
if second <= oneDaySeconds * 1 then
getDay[goodType] = 1
elseif second >= oneDaySeconds * 30 then
getDay[goodType] = 30
else
local hour = math.ceil(math.ceil(second / 60) / 60)
getDay[goodType] = math.ceil(hour / 24)
-- Log("累计" .. hour .. "小时")
getDay[goodType] = getDay[goodType] >= 30 and 30 or getDay[goodType]
end
end
-- 显示数据
function this.GetShowTime(endTime)
local duration = 30 * 24 * 60 * 60
local endStr = os.date("%Y年%m月%d日", endTime)
local startStr = os.date("%Y年%m月%d日", endTime - duration + 1)
return startStr, endStr
end
--月卡开始
--初始化月卡数据
local monthSaveAmt = 0--月卡累计总额
local smonthSaveAmt = 0--豪华月卡累计总额
local monthCardData = {}
function this.InitMonthCardData(data)
monthCardData = {}
--LogError("月卡信息初始化 "..#data)
for i = 1, #data do
--LogError("月卡信息初始化 "..data[i].id.." "..data[i].endingTime.." "..data[i].state)
local singleMonthCard = {}
singleMonthCard.id = data[i].id
singleMonthCard.endingTime = data[i].endingTime
singleMonthCard.state = data[i].state
if i == MONTH_CARD_TYPE.MONTHCARD then
--LogError("月卡信息初始化 月卡累计充值 "..data[i].totleAmt)
monthSaveAmt = data[i].totleAmt
elseif i == MONTH_CARD_TYPE.LUXURYMONTHCARD then
--LogError("月卡信息初始化 豪华月卡累计充值 "..data[i].totleAmt)
smonthSaveAmt = data[i].totleAmt
end
table.insert(monthCardData,singleMonthCard)
end
CheckRedPointStatus(RedPointType.MonthCard)
end
--推送更新月卡数据
function this.UpdateMonthCardData(msg)
--LogError("月卡信息推送 "..#msg.monthinfos)
--当我数据没有 后端推过来的有数据 此时需要弹窗
local showStr = ""
for i = 1, #msg.monthinfos do
if monthCardData[i].endingTime <= 0 then
showStr = "恭喜您成功开通月卡/豪华月卡,是否立即前往月卡界面领取奖励。"
end
end
monthCardData = {}
for i = 1, #msg.monthinfos do
--LogError("月卡信息推送 "..msg.monthinfos[i].id.." "..msg.monthinfos[i].endingTime.." "..msg.monthinfos[i].state)
local singleMonthCard = {}
singleMonthCard.id = msg.monthinfos[i].id
singleMonthCard.endingTime = msg.monthinfos[i].endingTime
singleMonthCard.state = msg.monthinfos[i].state--0 未领取 1 已领取
if i == MONTH_CARD_TYPE.MONTHCARD then
monthSaveAmt = msg.monthinfos[i].totleAmt
elseif i == MONTH_CARD_TYPE.LUXURYMONTHCARD then
smonthSaveAmt = msg.monthinfos[i].totleAmt
end
table.insert(monthCardData,singleMonthCard)
end
CheckRedPointStatus(RedPointType.MonthCard)
if showStr ~= "" then
if ActTimeCtrlManager.SingleFuncState(JumpType.Welfare) then
MsgPanel.ShowOne(showStr, function()
JumpManager.GoJump(36004)
end,"立即前往")
end
end
end
function this.RefreshMonthCardChargeMoney(msg)
--LogError("月卡金额信息推送 "..msg.monthSaveAmt.." "..msg.smonthSaveAmt)
monthSaveAmt = msg.monthSaveAmt--月卡累计总额
smonthSaveAmt = msg.smonthSaveAmt--豪华月卡累计总额
end
-- 月卡累计总额
function this.GetmonthSaveAmt()
return monthSaveAmt
end
-- 豪华月卡累计总额
function this.GetsmonthSaveAmt()
return smonthSaveAmt
end
--前端设置月卡领取状态数据
function this.SetMonthCardGetStateData(type,state)
if monthCardData[type] then
monthCardData[type].state = state--0 未领取 1 已领取
end
CheckRedPointStatus(RedPointType.MonthCard)
end
--后端设置月卡领取状态数据 datas已领取的月卡id 五点刷新
function this.BackSetMonthCardGetStateData(datas)
for i = 1, #monthCardData do
if monthCardData[i] then--0 未领取 1 已领取
if datas[i] then
monthCardData[i].state = 1
else
monthCardData[i].state = 0
end
end
end
--事件
CheckRedPointStatus(RedPointType.MonthCard)
Game.GlobalEvent:DispatchEvent(GameEvent.MonthCard.OnMonthCardUpdate)
end
--获取月卡数据
function this.GetMonthCardData()
if monthCardData then
return monthCardData
else
return nil
end
end
--月卡到期
local addTimeNum = 30 * 24 * 60 * 60
function this.RefreshMonthCardEnd()
for i = 1, #monthCardData do
if monthCardData[i] and monthCardData[i].endingTime > 0 then--0 未领取 1 已领取
local dayLuxuryNum = math.floor((monthCardData[i].endingTime + addTimeNum - GetTimeStamp()) / (24 * 3600))
if dayLuxuryNum < 0 then
monthCardData[i].endingTime = 0
monthCardData[i].state = 0--0 未领取 1 已领取
if i == MONTH_CARD_TYPE.MONTHCARD then
monthSaveAmt = 0--月卡累计总额
else
smonthSaveAmt = 0--豪华月卡累计总额
end
end
end
end
CheckRedPointStatus(RedPointType.MonthCard)
end
--单种月卡红点检测
function this.RefreshMonthCardRedPoint(type)
if monthCardData[type] then
if monthCardData[type].endingTime ~= 0 and monthCardData[type].state == 0 then
return true
end
end
return false
end
--所有月卡红点检测
function this.AllRefreshMonthCardRedPoint()
for i = 1, #monthCardData do
if monthCardData[i].endingTime ~= 0 and monthCardData[i].state == 0 then
return true
end
end
return false
end
--所有月卡激活状态
function this.GetMonthCardIsOpen(type)
if monthCardData[type] then
if monthCardData[type].endingTime ~= 0 then
return true
end
end
return false
end
--月卡结束
return this