每日特惠
This commit is contained in:
parent
aec28d95e8
commit
58de179979
@ -69,7 +69,10 @@ BIReport.ITEM_GET_TYPE = {
|
||||
BOUNTY = "Bounty",
|
||||
IDLE_DROP = "IdleDrop",
|
||||
IDLE_QUICK_DROP = "IdleQuickDrop",
|
||||
MAIL = "Mail"
|
||||
MAIL = "Mail",
|
||||
MALL = "Mall",
|
||||
MALL_DAILY = "MallDaily", -- 每日特惠
|
||||
MALL_DAILY_RESET = "MallDailyReset",
|
||||
}
|
||||
|
||||
BIReport.ADS_CLICK_TYPE = {
|
||||
|
||||
@ -20,7 +20,7 @@ function DataManager:init()
|
||||
self:initManager("DailyTaskData", "app/userdata/task/daily_task_data")
|
||||
self:initManager("IdleData", "app/userdata/idle/idle_data")
|
||||
-- self:initManager("SevenDayData", "app/userdata/activity/seven_day/seven_day_data")
|
||||
self:initManager("ShopData", "app/userdata/idle/shop_data")
|
||||
self:initManager("ShopData", "app/userdata/shop/shop_data")
|
||||
end
|
||||
|
||||
function DataManager:initManager(name, path)
|
||||
@ -122,6 +122,7 @@ function DataManager:initWithServerData(data)
|
||||
self.DailyTaskData:init(data.task_daily)
|
||||
self.IdleData:init(data.idle)
|
||||
-- self.SevenDayData:init(data.SevenDayData)
|
||||
self.ShopData:initCrossDay()
|
||||
self.ShopData:initActGift(data.act) -- 礼包购买信息
|
||||
self.ShopData:initMallDaily(data.mall_daily) -- 每日特惠
|
||||
self.ShopData:initCommonDailyGoldGift(data.mall_idle) -- 常驻金币礼包
|
||||
|
||||
@ -49,6 +49,8 @@ ModuleManager.MODULE_KEY = {
|
||||
STORE_BOX_3_OPEN = "store_box_3_open",
|
||||
BOUNTY_OPEN = "bounty_open",
|
||||
IDLE_DROP = "idle_drop",
|
||||
MALL = "mall", -- 商城
|
||||
MALL_DAILY = "mall_daily", -- 每日商城
|
||||
}
|
||||
|
||||
local _moduleMgrs = {}
|
||||
|
||||
@ -6,32 +6,68 @@ end
|
||||
|
||||
-- 购买每日特惠商品
|
||||
function ShopManager:buyMallDailyGift(id)
|
||||
-- TODOJ
|
||||
-- if not DataManager.SevenDayData:getIsOpen() then
|
||||
-- GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_DESC))
|
||||
-- return
|
||||
-- end
|
||||
if not DataManager.ShopData:getMallDailyIsOpen() then
|
||||
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_DESC))
|
||||
return
|
||||
end
|
||||
|
||||
-- if DataManager.SevenDayData:getStepCollected(id) then
|
||||
-- return
|
||||
-- end
|
||||
|
||||
-- if not DataManager.SevenDayData:canClaimStepTask(id) then
|
||||
-- return
|
||||
-- end
|
||||
|
||||
-- local params = {id = id}
|
||||
-- local responseData = {
|
||||
-- rewards = {GFunc.getRewardTableByReward(DataManager.SevenDayData:getStepReward(id))},
|
||||
-- Claimed = {
|
||||
-- [id] = true
|
||||
-- }
|
||||
-- }
|
||||
-- self:sendMessage(ProtoMsgType.FromMsgEnum.SevenDayRewardReq, params, responseData, self.claimStepRewardFinish, BIReport.ITEM_GET_TYPE.SEVEN_DAY_STEP_REWARD)
|
||||
local params = {id = id}
|
||||
local rewards, costs = DataManager.ShopData:getMallDailyRewardAndCost(id)
|
||||
local responseData = {
|
||||
rewards = rewards,
|
||||
costs = costs
|
||||
}
|
||||
self:sendMessage(ProtoMsgType.FromMsgEnum.BuyMallDailyReq, params, responseData, self.buyMallDailyGiftFinish, BIReport.ITEM_GET_TYPE.MALL_DAILY)
|
||||
end
|
||||
|
||||
function ShopManager:buyMallDailyGiftFinish(result)
|
||||
-- TODOJ
|
||||
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||
GFunc.addRewards(result.rewards)
|
||||
GFunc.addCosts(result.costs)
|
||||
GFunc.showRewardBox(result.rewards)
|
||||
end
|
||||
end
|
||||
|
||||
-- 重置每日特惠商品(type 1广告 2钻石)
|
||||
function ShopManager:resetMallDailyGift(type)
|
||||
if not DataManager.ShopData:getMallDailyIsOpen() then
|
||||
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_DESC))
|
||||
return
|
||||
end
|
||||
|
||||
if type == 2 then -- 钻石刷新
|
||||
if not GFunc.checkCost(GConst.ITEM_ID_GEM, DataManager.ShopData:getMallDailyDiamondResetCost(), true) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local params = {reset_type = type}
|
||||
local responseData = {}
|
||||
if type == 2 then
|
||||
local costs = {type = 1, id = GConst.ITEM_ID_GEM, num = DataManager.ShopData:getMallDailyDiamondResetCost()}
|
||||
responseData.costs = costs
|
||||
end
|
||||
self:sendMessage(ProtoMsgType.FromMsgEnum.MallDailyResetReq, params, responseData, self.resetMallDailyGiftFinish, BIReport.ITEM_GET_TYPE.MALL_DAILY_RESET)
|
||||
end
|
||||
|
||||
function ShopManager:resetMallDailyGiftFinish(result)
|
||||
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||
GFunc.addCosts(result.costs)
|
||||
DataManager.ShopData:initMallDaily(result.mall_daily_info)
|
||||
end
|
||||
end
|
||||
|
||||
-- 跨天刷新每日商店数据
|
||||
function ShopManager:mallDailyGiftOverDay()
|
||||
local params = {}
|
||||
local responseData = {}
|
||||
self:sendMessage(ProtoMsgType.FromMsgEnum.MallDailyOverDayReq, params, responseData, self.mallDailyGiftOverDayFinish)
|
||||
end
|
||||
|
||||
function ShopManager:mallDailyGiftOverDayFinish(result)
|
||||
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||
DataManager.ShopData:initMallDaily(result.mall_daily_info)
|
||||
end
|
||||
end
|
||||
|
||||
return ShopManager
|
||||
@ -167,6 +167,14 @@ function MainCityUI:_bind()
|
||||
self:bind(DataManager.MailData, "redPoint", function()
|
||||
self:refreshSettingBtn()
|
||||
end)
|
||||
|
||||
self:bind(DataManager.ShopData, "dirty", function()
|
||||
if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.SHOP and self.subComps[self.selectedIndex] then
|
||||
if self.subComps[self.selectedIndex] then
|
||||
self.subComps[self.selectedIndex]:refresh()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function MainCityUI:initBottomUI()
|
||||
|
||||
@ -19,12 +19,12 @@ function HotCell:init()
|
||||
self.sellOutText:setText("已购买TD") -- TODOJ
|
||||
end
|
||||
|
||||
function HotCell:refresh(data, clickCallback)
|
||||
function HotCell:refresh(data)
|
||||
local id = data.id
|
||||
local index = data.good_index
|
||||
local bought = data.bought
|
||||
|
||||
local cfgInfo = ConfigManager:getConfig("mall_daily")[id]
|
||||
local cfgInfo = DataManager.ShopData:getMallDailyConfig()[id]
|
||||
local reward = cfgInfo.good[index]
|
||||
local cost = cfgInfo.cost[index]
|
||||
|
||||
@ -79,11 +79,13 @@ function HotCell:refresh(data, clickCallback)
|
||||
end
|
||||
end
|
||||
|
||||
if clickCallback then
|
||||
self:addClickListener(function()
|
||||
clickCallback(cfgInfo.id)
|
||||
end)
|
||||
end
|
||||
self:addClickListener(function()
|
||||
self:onClickGift(cfgInfo.id)
|
||||
end)
|
||||
end
|
||||
|
||||
function HotCell:onClickGift(id)
|
||||
ModuleManager.ShopManager:buyMallDailyGift(id)
|
||||
end
|
||||
|
||||
function HotCell:setVisible(visible)
|
||||
|
||||
@ -53,9 +53,7 @@ function HotSellCell:refresh()
|
||||
for i = 1, CELL_COUNT do
|
||||
if i <= goodsCount then
|
||||
self.cells[i]:setVisible(true)
|
||||
self.cells[i]:refresh(goods[i], function(id)
|
||||
self:onClickGift(id)
|
||||
end)
|
||||
self.cells[i]:refresh(goods[i])
|
||||
else
|
||||
self.cells[i]:setVisible(false)
|
||||
end
|
||||
@ -74,20 +72,16 @@ function HotSellCell:setVisible(visible)
|
||||
self.baseObject:setVisible(visible)
|
||||
end
|
||||
|
||||
function HotSellCell:onClickGift(id)
|
||||
Logger.logHighlight("Click id:%s", id) -- TODOJ
|
||||
end
|
||||
|
||||
function HotSellCell:onClickRefresh()
|
||||
local freeRefreshCount = DataManager.ShopData:getMallDailyAdLeftCount() -- 免费刷新次数
|
||||
local gemRefreshCount = DataManager.ShopData:getMallDailyDiamondLeftCount() -- 钻石刷新次数
|
||||
local gemRefreshCost = DataManager.ShopData:getMallDailyDiamondResetCost() -- 钻石刷新消耗
|
||||
|
||||
if freeRefreshCount > 0 then
|
||||
-- TODOJ
|
||||
ModuleManager.ShopData:resetMallDailyGift(1)
|
||||
elseif gemRefreshCount > 0 then
|
||||
if GFunc.checkCost(GConst.ItemConst.ITEM_ID_GEM, gemRefreshCost, true) then
|
||||
-- TODOJ
|
||||
ModuleManager.ShopData:resetMallDailyGift(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -124,6 +124,12 @@ function ShopComp:refresh()
|
||||
self:refreshTitle()
|
||||
self:refreshDiscountPage()
|
||||
self:refreshMainPage()
|
||||
|
||||
-- 如果已经跨天了 需要重新请求每日礼包数据
|
||||
if DataManager.ShopData:getMallDailyDirty() then
|
||||
DataManager.ShopData:markMallDailyDirty(false)
|
||||
ModuleManager.ShopManager:mallDailyGiftOverDay()
|
||||
end
|
||||
end
|
||||
|
||||
function ShopComp:refreshDiscountPage()
|
||||
|
||||
@ -5,6 +5,19 @@ function ShopData:ctor()
|
||||
end
|
||||
|
||||
function ShopData:clear()
|
||||
|
||||
DataManager:unregisterCrossDayFunc("ShopData")
|
||||
end
|
||||
|
||||
function ShopData:setDirty()
|
||||
self.data.isDirty = not self.data.isDirty
|
||||
end
|
||||
|
||||
function ShopData:initCrossDay()
|
||||
DataManager:registerCrossDayFunc("ShopData", function()
|
||||
self:resetMallDaily()
|
||||
self:setDirty()
|
||||
end)
|
||||
end
|
||||
|
||||
-- 通用礼包部分 **********************************************************************************************
|
||||
@ -17,7 +30,7 @@ function ShopData:initActGift(act)
|
||||
for _, gift in ipairs(self.gifts) do
|
||||
local giftType = gift.act_type
|
||||
local giftId = gift.id
|
||||
local buyCount = gift.buy_count
|
||||
local buyCount = gift.buy_count -- 已购次数
|
||||
local latestBuyTime = gift.latest_buy_at -- 最后一次购买时间
|
||||
local latestOrderUuid = gift.latest_order_uuid -- 正在支付的订单ID
|
||||
if not self.giftMap then
|
||||
@ -28,6 +41,8 @@ function ShopData:initActGift(act)
|
||||
end
|
||||
self.giftMap[giftType][giftId] = gift
|
||||
end
|
||||
|
||||
self:setDirty()
|
||||
end
|
||||
|
||||
-- 已购买的礼包
|
||||
@ -65,12 +80,34 @@ end
|
||||
|
||||
-- 每日特惠部分 **********************************************************************************************
|
||||
|
||||
function ShopData:getMallDailyConfig()
|
||||
return ConfigManager:getConfig("mall_daily")
|
||||
end
|
||||
|
||||
-- 初始化每日特惠
|
||||
function ShopData:initMallDaily(mallDaily)
|
||||
mallDaily = mallDaily or {}
|
||||
self.mallDailyAdResetCount = mallDaily.ad_reset_Count or 0
|
||||
self.mallDailyDiamondResetCount = mallDaily.diamond_reset_Count or 0
|
||||
self.mallDailyGoods = mallDaily.goods or {} -- {id,good_index,bought}
|
||||
|
||||
self:markMallDailyDirty(false)
|
||||
self:setDirty()
|
||||
end
|
||||
|
||||
-- 每日特惠跨天重置
|
||||
function ShopData:resetMallDaily()
|
||||
self.mallDailyAdResetCount = 0
|
||||
self.mallDailyDiamondResetCount = 0
|
||||
self:markMallDailyDirty(true) -- 标记需要重新请求数据,在界面/下次打开界面时请求
|
||||
end
|
||||
|
||||
function ShopData:getMallDailyDirty()
|
||||
return self.data.mallDailyDirty
|
||||
end
|
||||
|
||||
function ShopData:markMallDailyDirty(isDirty)
|
||||
self.data.mallDailyDirty = isDirty
|
||||
end
|
||||
|
||||
function ShopData:getMallDailyAdResetCount()
|
||||
@ -107,6 +144,26 @@ function ShopData:getMallDailyGoodsMaxCount()
|
||||
return 1 -- TODOJ 目前无配置表
|
||||
end
|
||||
|
||||
-- 每日特惠 是否开启
|
||||
function ShopData:getMallDailyIsOpen()
|
||||
return ModuleManager:getIsOpen()
|
||||
end
|
||||
|
||||
-- 根据商品id获取本日的随机商品数据
|
||||
function ShopData:getMallDailyRewardAndCost(id)
|
||||
local cfg = self:getMallDailyConfig()
|
||||
local index
|
||||
for _, info in ipairs(self:getMallDailyGoods()) do
|
||||
if info.id == id then
|
||||
index = info.good_index
|
||||
break
|
||||
end
|
||||
end
|
||||
if index then
|
||||
return cfg[id].good[index], cfg[id].cost[index]
|
||||
end
|
||||
end
|
||||
|
||||
-- 每日特惠结束 ----------------------------------------------------------------------------------------------
|
||||
|
||||
-- 常驻金币礼包 **********************************************************************************************
|
||||
@ -114,6 +171,8 @@ end
|
||||
function ShopData:initCommonDailyGoldGift(mallIdle)
|
||||
mallIdle = mallIdle or {}
|
||||
self.commonDailyGoldBuyCount = mallIdle[1] or 0 -- 已购的金币广告礼包次数
|
||||
|
||||
self:setDirty()
|
||||
end
|
||||
|
||||
function ShopData:getCommonDailyCoinAdBuyCount()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user