local Shop_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local purchase_pb = require("Proto/purchase_pb") local exchange_pb = require('Proto/exchange_pb') local TriggerType = LuaConst.UnlockConditionType Shop_Model.TriggerSort = { TopShow = 0, --商店排序最高优先级(未解锁 + MaxSpecialSortID标识) OnSell = 1, SoldOut = 2, GuildBuildLevel = 3, TeamLevel = 4, StoreCoinCost = 5, SyncSoloRank = 6, ClimbTowerLevel = 7, NationClimbTowerAllLevel = 8, } local ItemState = { [TriggerType.StoreCoinCost] = Shop_Model.TriggerSort.StoreCoinCost, [TriggerType.GuildBuildLevelByType] = Shop_Model.TriggerSort.GuildBuildLevel, [TriggerType.TeamLevel] = Shop_Model.TriggerSort.TeamLevel, [TriggerType.SyncSolo_Rank] = Shop_Model.TriggerSort.SyncSoloRank, [TriggerType.ClimbTowerLevel] = Shop_Model.TriggerSort.ClimbTowerLevel, [LuaConst.TriggerType.NationClimbTowerAllLevel] = Shop_Model.TriggerSort.NationClimbTowerAllLevel, } private.isShowPayForTest=false local ShowGoodsInfo = {} function Shop_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageExchange, private.ExchangeResp) private.isRequest = false end -- ---------------商店配置信息---------------------------- function Shop_Model.GetItemIndexInStore(itemId, itemSourceId) local tabId = Shop_Model.GetTabIDByItemId(itemId, itemSourceId) local goods = Shop_Model.GetShopGoodsCfgByTypeID(tabId) for i, v in ipairs(goods) do if v.OriData.ItemID == itemId then return i - 1 end end return nil end function Shop_Model.GetTabIDByItemId(itemId, itemSourceId) for i, v in MDL.OperationActivity.StoreGoodsData:GetEnumerator() do if v.ItemID == itemId and v.ItemSourceID == itemSourceId then return v.TabID end end logging.error(LTAG.ERROR, "没有找到该物品ID:", itemId) end function Shop_Model.GetShopTypeIDArray() local idList = {} for i, v in MDL.OperationActivity.StoreTypeData:GetEnumerator() do if v.TypeID == 1 and Shop_Model.GetShopTypeInfoByTabID(v.TabID) then table.insert(idList, v.TabID) end end return idList end function Shop_Model.GetStoreTypeTabName(tabId) local nameCfg = DataSheetManager.StoreTypeDataName:GetDataByTabID(tabId) if nameCfg then return nameCfg.TabName end logging.error(LTAG.ERROR, "商城数据缺少对应IDS", tabId) return nil end --商店类型是否开启 function Shop_Model.GetShopTypeInfoByTabID(_tabID) local storeTypeData = MDL.OperationActivity.StoreTypeData:GetDataByTabID(_tabID) if storeTypeData then for i, v in ipairs(storeTypeData.Show_Table) do if not MDL.Unlock.IsComplete(v.ShowCondition, v.ShowConditionParam) then return false end end else logging.error(LTAG.ERROR, "商店TypeID不存在, ID:", _tabID ,"如果是活动相关请检查AMS数据,否则请联系数值策划") end return true end --商店物品信息 function Shop_Model.GetShopGoodsCfgByTypeID(_tabID) ShowGoodsInfo = {} local lockedtype local triggerparam for i, v in MDL.OperationActivity.StoreGoodsData:GetEnumerator() do if v.TabID == _tabID then local condition = v.Show_Table local ShowCondition = 0 local ShowConditionParam = 0 for i, v in ipairs(condition) do ShowCondition = v.ShowCondition ShowConditionParam = v.ShowConditionParam end local isOpen = MDL.Unlock.IsComplete(ShowCondition, ShowConditionParam) if isOpen then lockedtype = Shop_Model.TriggerSort.OnSell triggerparam = nil local conditions = v.UnlockTigger_Table if CTL.PayMall.IsSoldOut(v) or private.NotActiveHeroPriority(v) then lockedtype = Shop_Model.TriggerSort.SoldOut end if #conditions ~= 0 then for i = 1 ,#conditions do triggerparam = string.split(conditions[i].TriggerParam,";") if not MDL.Unlock.IsComplete(conditions[i].TriggerType, conditions[i].TriggerParam) then if v.MaxSpecialSortID then lockedtype = Shop_Model.TriggerSort.TopShow else lockedtype = ItemState[conditions[i].TriggerType]-- 单字字符串d end break end end end table.insert(ShowGoodsInfo,{OriData = v,LockType = lockedtype,TriggerParam = triggerparam}) end end end table.sort(ShowGoodsInfo,private.SortItemOrder) return ShowGoodsInfo end function private.NotActiveHeroPriority(goodData) local heroId local itemData = DataSheetManager.ItemData:GetDataByID(goodData.ItemID) if goodData.IsActiveHero and itemData.FirstType == LuaConst.ItemType.WeaponFragment and itemData.SecondType == LuaConst.ItemWeaponType.WeaponFragment then -- 神兵碎片 heroId = itemData.BelongerID elseif goodData.IsActiveHero and itemData.FirstType == LuaConst.ItemType.HeroFragment and (itemData.SecondType == LuaConst.ItemHeroType.HeroFragment or itemData.SecondType == LuaConst.ItemHeroType.Hero) then heroId = itemData.SecondType == LuaConst.ItemHeroType.HeroFragment and itemData.BelongerID or itemData.BelongToHero end if heroId and not MDL.HeroSelect.IsHasHero(heroId) then return true end return false end function Shop_Model.CheckCost(data) local d = string.split(data,";") local limit = tonumber(d[3]) return limit <= MDL.PayMall.GetCostItemCount(tonumber(d[1]), tonumber(d[2])) end function Shop_Model.IsHeroFragmentByID(itemId) local goodsItem = DataSheetManager.ItemData:GetDataByID(itemId) if goodsItem.FirstType == 5 and goodsItem.SecondType == 1 then return true else return false end end -- ---------------通信信息---------------------------- function Shop_Model.IsFirstPay(index) local IAPIndexArray = MDL.Currency.GetFirstIAPIndexArray() if IAPIndexArray == nil then return true end for i=1,#IAPIndexArray do if IAPIndexArray[i] == index then return false end end return true end function Shop_Model.GetMaxCountBuyGoods() local value = DataSheetManager.ConstData:GetDataByID("SigleBuyMax") if value == nil then return 99 end return value.IntValue end --兑换逻辑 function Shop_Model.Exchange(cfgId, count) logging.log(LTAG.LOG,"-----------cfgId------------- ", cfgId) logging.log(LTAG.LOG,"-----------count------------- ", count) local msg = exchange_pb.ExchangeReq() msg.currencyId = cfgId msg.nums = count NetManager.SendMessage(MessageEnums.MessageExchange, msg) end --新的兑换逻辑 function private.ExchangeResp(msgResp) logging.log(LTAG.LOG, "ExchangeResp",msgResp) if msgResp.Resp.Code == 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Store_CoinExchange_Success) EventSystem.Dispatch(EventID.UI_Shop_Close_Exchange) logging.log(LTAG.LOG,"-----------兑换成功-------------") end end function Shop_Model.GetIapPriceByIndex(index) local iapData = DataSheetManager.IAP:GetDataByIndex(index) if(iapData ~=nil) then return tonumber(iapData.Price) else return -1 end end function Shop_Model.GetIapIDByIndex(index) local iapData = DataSheetManager.IAP:GetDataByIndex(index) if iapData ~= nil then return iapData.IapID else return "nil" end end function Shop_Model.GetIapNameByIndex(index) local iapData = DataSheetManager.IAP:GetDataByIndex(index) if iapData ~= nil then return iapData.IapName else return "nil" end end -- local purchase_item_pb = require('Proto/purchase_item_pb') -- local test = {} -- local msg1 = purchase_item_pb.PurchaseGoodsInfos() -- msg1.goodsId = 101 -- msg1.purchasedNums = 1 -- table.insert(test, msg1) -- local msg2 = purchase_item_pb.PurchaseGoodsInfos() -- msg2.goodsId = 102 -- msg2.purchasedNums = 1 -- table.insert(test, msg2) -- MDL.Shop.RefreshBuyGoodsInfo(test) function Shop_Model.GetIsShowPayForTest() return private.isShowPayForTest end function Shop_Model.SetIsShowPayForTest(isShow) private.isShowPayForTest=isShow end function private.SortItemOrder(a,b) local aSoldState = a.LockType local bSoldState = b.LockType if aSoldState ~= bSoldState then return aSoldState < bSoldState else return a.OriData.SortID > b.OriData.SortID end end --增加支持渠道的显示 function Shop_Model.IsShowIapConfigByChannel(iapConfig) local sdkChannelId = SDKUtil.ChannelID --只要是配了显示的渠道,那么就只有配置的渠道才显示 if #iapConfig.ChannelShow>0 then for __, channelId in ipairs(iapConfig.ChannelShow) do if sdkChannelId == channelId then return true end end return false end for __, channelId in ipairs(iapConfig.ChannelHide) do if sdkChannelId == channelId then return false end end return true end return Shop_Model