141 lines
4.5 KiB
Lua
141 lines
4.5 KiB
Lua
local ShopManager = class("ShopManager", BaseModule)
|
|
|
|
function ShopManager:showBoxHeroUI(type)
|
|
UIManager:showUI("app/ui/shop/box_hero_ui", {type = type})
|
|
end
|
|
|
|
function ShopManager:showBoxLevelUI()
|
|
UIManager:showUI("app/ui/shop/box_level_ui")
|
|
end
|
|
|
|
function ShopManager:showBoxOpenUI(params)
|
|
UIManager:showUI("app/ui/shop/box_open_ui", params)
|
|
end
|
|
|
|
-- 商店宝箱奖励展示界面
|
|
function ShopManager:showBoxRewardUI(params)
|
|
UIManager:showUI("app/ui/shop/box_reward_ui", params)
|
|
end
|
|
|
|
function ShopManager:showBoxLevelUpUI(params)
|
|
UIManager:showUI("app/ui/shop/box_level_up_ui", params)
|
|
end
|
|
|
|
-- 购买每日特惠商品
|
|
function ShopManager:buyMallDailyGift(id, isAd)
|
|
if not DataManager.ShopData:getMallDailyIsOpen() then
|
|
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_DESC))
|
|
return
|
|
end
|
|
|
|
local params = {id = id}
|
|
local rewards, costs = DataManager.ShopData:getMallDailyRewardAndCost(id)
|
|
|
|
if costs then
|
|
if not GFunc.checkCost(costs.id, costs.num, true) then
|
|
return
|
|
end
|
|
end
|
|
|
|
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)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
local id = result.reqData and result.reqData.id
|
|
if id then
|
|
if id == 1 then -- 免费的
|
|
DataManager.ShopData:addMallDailyAdResetCount()
|
|
else
|
|
DataManager.ShopData:addMallDailyDiamondResetCount()
|
|
end
|
|
end
|
|
GFunc.showRewardBox(result.rewards)
|
|
DataManager.ShopData:updateMallDailyGoods(result.good_info)
|
|
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.ItemConst.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 = GConst.REWARD_TYPE.ITEM, 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
|
|
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
|
|
|
|
function ShopManager:onMallDailyReset(result)
|
|
if result.status == 0 then
|
|
DataManager.ShopData:initMallDaily(result.mall_daily_info)
|
|
end
|
|
end
|
|
|
|
-- 常规钻石
|
|
function ShopManager:buyMallTreasure(id, isAd)
|
|
PayManager:purchasePackage(id, PayManager.PURCHARSE_TYPE.MALL_TREASURE)
|
|
end
|
|
|
|
function ShopManager:buyMallTreasureFinish(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
GFunc.showRewardBox(result.rewards)
|
|
-- TODOJ
|
|
end
|
|
end
|
|
|
|
-- 常规金币
|
|
function ShopManager:buyMallIdleCoin(id, isAd)
|
|
local params = {id = id, ad = isAd}
|
|
local rewardNum, costs = DataManager.ShopData:getCommonDailyCoinDataById(id)
|
|
|
|
local responseData = {
|
|
rewards = {type = GConst.REWARD_TYPE.ITEM, id = GConst.ITEM_ID_GOLD, num = rewardNum},
|
|
costs = costs
|
|
}
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.BuyMallIdleReq, params, responseData, self.buyMallIdleCoinFinish, BIReport.ITEM_GET_TYPE.MALL_IDLE)
|
|
end
|
|
|
|
function ShopManager:buyMallIdleCoinFinish(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
GFunc.showRewardBox(result.rewards)
|
|
DataManager.ShopData:initCommonDailyGoldGift(result.ad_count)
|
|
end
|
|
end
|
|
|
|
return ShopManager |