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:triggerGiftPopUI(actType, actId) UIManager:showUI("app/ui/shop/gift_pop_ui", {type = actType, id = actId}) DataManager.ShopData:removePopUpGift(actType, actId) end -- 触发金币弹窗礼包 function ShopManager:triggerCoinGiftPopUI(actId) self:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.ACT_GIFT, actId) 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 -- 尝试触发金币礼包 if costs.id == GConst.ItemConst.ITEM_ID_GOLD then self:tryTriggerCoinGift() end 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 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 local resetType = result.reqData and result.reqData.reset_type if resetType == 1 then -- 免费的 DataManager.ShopData:addMallDailyAdResetCount() else DataManager.ShopData:addMallDailyDiamondResetCount() end 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) -- 消息无用 仅为了触发推送 end function ShopManager:onMallDailyReset(result) if result.status == 0 then DataManager.ShopData:initMallDaily(result.mall_daily_info) 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 -- 推送助力礼包 function ShopManager:onTriggerLevelUpGift(result) DataManager.ShopData:onTriggerLevelUpGift(result.current_level_up_gift) end -- 尝试触发金币礼包 function ShopManager:tryTriggerCoinGift() local triggerId = DataManager.ShopData:checkAndGetCoinGiftTriggerId() if triggerId then local params = {gold_gift_id = triggerId} local responseData = {} self:sendMessage(ProtoMsgType.FromMsgEnum.TriggerGoldGiftReq, params, responseData, self.tryTriggerCoinGiftFinish) else -- 不满足触发条件 if EDITOR_MODE then Logger.log("不满足金币礼包触发条件") end end end function ShopManager:tryTriggerCoinGiftFinish(result) if result.status == 0 then DataManager.ShopData:onTriggerCoinGift(result.reqData.gold_gift_id) -- 立即触发金币弹窗 self:triggerCoinGiftPopUI(result.reqData.gold_gift_id) end end return ShopManager