sk-client/Assets/ManagedResources/~Lua/Modules/FirstRecharge/FirstRechargeManager.lua

358 lines
12 KiB
Lua

--[[
* @ClassName FirstRechargeManager
* @Description 首充管理
* @Date 2019/7/4 19:11
* @Author MagicianJoker, fengliudianshao@outlook.com
* @Copyright Copyright (c) 2019, MagicianJoker
--]]
FirstRechargeManager = {}
local this = FirstRechargeManager
local activityRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)
local AccumRechargeValue
--充值
local rechargeTime
local welfareCurrencyRechargeTime
function this.Initialize()
end
function this.GetFirstRechargeRedPointStatus()
local redPoint = false
if ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FirstRecharge) then
if ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FirstRecharge) then
redPoint = redPoint or this.GetSixMoneyTabRedPointStatus()
redPoint = redPoint or this.GetHundredTabRedPointStatus()
end
end
return redPoint
end
function this.GetSixMoneyTabRedPointStatus()
local shift = this.GetRechargeShift()
local redPoint = false
for _, rewardInfo in ConfigPairs(activityRewardConfig) do
if rewardInfo.ActivityId == ActivityTypeDef.FirstRecharge and rewardInfo.Values[1][2] == shift[1] then
redPoint = redPoint or this.GetDayItemRedPoint(rewardInfo)
end
end
return redPoint
end
function this.GetHundredTabRedPointStatus()
local shift = this.GetRechargeShift()
local redPoint = false
for _, rewardInfo in ConfigPairs(activityRewardConfig) do
if rewardInfo.ActivityId == ActivityTypeDef.FirstRecharge and rewardInfo.Values[1][2] == shift[2] then
local activityInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.FirstRecharge)
local AccumRecharge = 0
for _, missInfo in pairs(activityInfo.mission) do
if missInfo and missInfo.progress then
AccumRecharge = missInfo.progress
end
end
if AccumRecharge == 0 then
redPoint = false
else
if AccumRecharge/100 >= rewardInfo.Values[1][2]*10 then
if this.isFirstRecharge == 0 then
-- Log("______________________1111")
-- this.SetRechargeTime(math.floor(GetTimeStamp()))
this.isFirstRecharge = 1
end
local day = GetTimePass(this.GetRechargeTime(rewardInfo.Values[1][1]))
if rewardInfo.Values[1][3] <= day then
if not ActivityGiftManager.GetActivityInfo(ActivityTypeDef.FirstRecharge, rewardInfo.Id) then
redPoint = false
end
local state = ActivityGiftManager.GetActivityInfo(ActivityTypeDef.FirstRecharge, rewardInfo.Id).state
return state == 0
else
redPoint = false
end
else
redPoint = false
end
end
end
end
return redPoint
end
function this.GetRechargeShift()
local shift = {}
for _, rewardInfo in ConfigPairs(activityRewardConfig) do
if rewardInfo.ActivityId == ActivityTypeDef.FirstRecharge then
local state = true
for i = 1, #shift do
if shift[i] == rewardInfo.Values[1][2] then
state = false
end
end
if state then
table.insert(shift, rewardInfo.Values[1][2])
end
end
end
table.sort(shift, function (a, b)
return a < b
end)
return shift
end
function this.GetDayItemRedPoint(context)
local activityInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.FirstRecharge)
local AccumRecharge = 0
for _, missInfo in pairs(activityInfo.mission) do
if missInfo and missInfo.progress then
AccumRecharge = missInfo.progress
end
end
if AccumRecharge == 0 then
return false
else
if AccumRecharge >= context.Values[1][2] then
if this.isFirstRecharge == 0 then
-- this.SetRechargeTime(math.floor(GetTimeStamp()))
this.isFirstRecharge = 1
end
local day = GetTimePass(this.GetRechargeTime(context.Values[1][1]))
if context.Values[1][3] <= day then
if not ActivityGiftManager.GetActivityInfo(ActivityTypeDef.FirstRecharge, context.Id) then
return false
end
local state = ActivityGiftManager.GetActivityInfo(ActivityTypeDef.FirstRecharge, context.Id).state
return state ~= 1
else
return false
end
else
return false
end
end
return false
end
function this.GetReceiveAll()
local condition = true
local activityInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.FirstRecharge)
if activityInfo then
for i = 1, #activityInfo.mission do
local rechargeInfo = activityInfo.mission[i]
condition = condition and rechargeInfo.state == 1
end
end
return condition
end
function this.GetFirstRechargeExist()
if this.GetReceiveAll() or ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FirstRecharge) == nil then
return false
end
return true
end
-----------首充,累充相关----------------------
this.isFirstRecharge = 0
--刷新累计充值金额
function this.RefreshAccumRechargeValue(goodsId)
if this.isFirstRecharge == 0 then
--this.SetRechargeTime(math.floor(GetTimeStamp()))
this.isFirstRecharge = 1
end
if LuckyCatManager.isOpenLuckyCat then
LuckyCatManager.SetAccumRechargeValue()
end
end
function this.SetAccumRechargeValue(value, flag)
if flag then
AccumRechargeValue = AccumRechargeValue + value
CheckRedPointStatus(RedPointType.FirstRecharge)
else
AccumRechargeValue = value
end
end
function this.GetAccumRechargeValue()
return AccumRechargeValue
end
function this.SetRechargeTime(value)
rechargeTime = value
end
function this.GetRechargeTime(type)
-- 0 真充 +假充 1真充 2假充
if type == 0 then
if rechargeTime ~= 0 then
if welfareCurrencyRechargeTime~=0 then
if rechargeTime <= welfareCurrencyRechargeTime then
return rechargeTime
else
return welfareCurrencyRechargeTime
end
else
return rechargeTime
end
end
if welfareCurrencyRechargeTime ~=0 then
if rechargeTime ~=0 then
if welfareCurrencyRechargeTime <= rechargeTime then
return welfareCurrencyRechargeTime
else
return rechargeTime
end
else
return welfareCurrencyRechargeTime
end
end
return rechargeTime
elseif type == 1 then
return rechargeTime
elseif type == 2 then
return welfareCurrencyRechargeTime
end
end
function this.SetWelfareCurrencyRechargeTime(value)
welfareCurrencyRechargeTime = value
end
-- function this.GetWelfareCurrencyRechargeTime(type)
-- return welfareCurrencyRechargeTime
-- end
--设置红点存储本地
function this.PlayerPrefsSetStrItemId(val)
PlayerPrefs.SetInt(PlayerManager.uid.."FirstRechatgePace", val)
end
--获得红点信息
function this.PlayerPrefsGetStrItemId()
return PlayerPrefs.GetInt(PlayerManager.uid.."FirstRechatgePace", 0)--1 已经查看过不需要显示新红点 0 显示红点
end
function this.IsShowFirstChatge()
if FirstRechargeManager.isFirstRecharge == 1 and FirstRechargeManager.PlayerPrefsGetStrItemId() == 0 and ActTimeCtrlManager.IsQualifiled(38) and FirstRechargeManager.GetFirstRechargeExist() then
return true
else
return false
end
end
function this.GetFirstRewardState()
local tempData = {}
local index = 0
for _, rewardInfo in ConfigPairs(activityRewardConfig) do
if rewardInfo.ActivityId == ActivityTypeDef.FirstRecharge and
rewardInfo.Values[1][2] == IndexValueDef[1] then
table.insert(tempData, rewardInfo)
end
end
if #tempData > 0 then
for i = 1, #tempData do
local data = tempData[i]
if ActivityGiftManager.GetActivityInfo(data.ActivityId, data.Id) then
local state = ActivityGiftManager.GetActivityInfo(data.ActivityId, data.Id).state
if data.Values[1][3] == 1 then
if state == 1 then
index = index + 1
break
end
end
end
end
end
local tempData2 = {}
for _, rewardInfo in ConfigPairs(activityRewardConfig) do
if rewardInfo.ActivityId == ActivityTypeDef.FirstRecharge and
rewardInfo.Values[1][2] == IndexValueDef[2] then
table.insert(tempData2, rewardInfo)
end
end
if #tempData2 > 0 then
for i = 1, #tempData2 do
local data = tempData2[i]
if ActivityGiftManager.GetActivityInfo(data.ActivityId, data.Id) then
local state = ActivityGiftManager.GetActivityInfo(data.ActivityId, data.Id).state
if data.Values[1][3] == 1 then
if state == 1 then
index = index +1
break
end
end
end
end
end
if index >=2 then
return true
end
return false
end
function this.AgainRechargeRedPot()
local tempData = {}
for _, rewardInfo in ConfigPairs(activityRewardConfig) do
if rewardInfo.ActivityId == ActivityTypeDef.AgainRecharge then
table.insert(tempData, rewardInfo)
end
end
local activityInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.AgainRecharge)
if not activityInfo then
return false
end
for i = 1, 3 do
local data = tempData[i]
local AccumRecharge = 0
for _, missInfo in pairs(activityInfo.mission) do
if missInfo and missInfo.progress then
AccumRecharge = missInfo.progress
end
end
if AccumRecharge/1000 >= data.Values[1][2] then
local day = GetTimePass(FirstRechargeManager.GetRechargeTime(data.Values[1][1]))--FirstRechargeManager.GetRechargeTime()
if data.Values[1][3] <= day then
local state = ActivityGiftManager.GetActivityInfo(data.ActivityId, data.Id).state
if state == 0 then
return true
end
end
end
end
return false
end
function this.GetAgainReceiveAll()
local tempData = {}
for _, rewardInfo in ConfigPairs(activityRewardConfig) do
if rewardInfo.ActivityId == ActivityTypeDef.AgainRecharge then
table.insert(tempData, rewardInfo)
end
end
local condition = 0
local activityInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.AgainRecharge)
if activityInfo == nil then
return true
end
for i = 1, 3 do
local data = tempData[i]
local state = ActivityGiftManager.GetActivityInfo(data.ActivityId, data.Id).state
if state == 1 then
condition = condition + 1
end
end
if condition >= 3 then
return true
end
return false
end
return this