| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- local ShopData = class('ShopData')
- local GoodsData = require('Shop/GoodsData')
- local function CompValidTimeData(a, b)
- if a and a > 0 then
- if not b or b > a then
- b = a
- end
- end
- return b
- end
- function ShopData:ctor()
- end
- function ShopData:Dispose()
- self.shopId = nil
- self.refreshTime = nil
- self.refreshCount = nil
- self.dayEndTime = nil
- self.weekEndTime = nil
- self.goodsDataMap = nil
- self.needRefreshTime = nil
- self.needRefreshDataTime = nil
- self.showGoodsDatas = nil
- end
- function ShopData:SetData(data,isBoliShop)
- local shopId = data.goods_type
- local refreshTime = data.refresh_time
- local refreshCount = data.refresh_count
- local dayEndTime = data.day_end
- local weekEndTime = data.week_end
- --- 初始化数据
- local goodsDataMap = {}
- local itemInfos = data.item_info
- if itemInfos then
- for i = 1, #itemInfos do
- local itemInfo = itemInfos[i]
- if itemInfo then
- local id = itemInfo.goods_id
- local cfgData = ManagerContainer.CfgMgr:GetShopCfgByGoodsId(id)
- if isBoliShop then
- cfgData = ManagerContainer.CfgMgr:GetBoliShopCfgById(id)
- end
- if cfgData then
- local goodsData = nil
- if self.goodsDataMap then
- goodsData = self.goodsDataMap[id]
- end
- if not goodsData then
- goodsData = GoodsData:new()
- goodsData:SetBaseData(itemInfo, cfgData, refreshTime, dayEndTime, weekEndTime)
- else
- goodsData:SetBaseData(itemInfo, cfgData, refreshTime, dayEndTime, weekEndTime)
- end
- if goodsDataMap[id] then
- LogWarning('[wboy] Find Same Goods Info !!! id = ' .. tostring(id))
- end
- goodsDataMap[id] = goodsData
- else
- LogError('[wboy] Config Not Find Goods Info !!! id = ' .. tostring(id))
- end
- end
- end
- end
- -- 记录购买过的数据
- local buyInfos = data.buy_info
- if buyInfos then
- for i = 1, #buyInfos do
- local buyInfo = buyInfos[i]
- if buyInfo then
- local id = buyInfo.goods_id
- local goodsData = goodsDataMap[id]
- if goodsData then
- goodsData:SetBuyData(buyInfo)
- else
- LogWarning('[wboy] buy_info has not exist goods, id = ' .. tostring(id))
- end
- end
- end
- end
- self.shopId = shopId
- self.refreshTime = refreshTime
- self.refreshCount = refreshCount
- self.dayEndTime = dayEndTime
- self.weekEndTime = weekEndTime
- self.goodsDataMap = goodsDataMap
- self:RefreshShowGoodsDatas()
- end
- function ShopData:RefreshBuyInfoData(data)
- local id = data.goods_id
- local goodsData = self.goodsDataMap[id]
- if goodsData then
- local isShow, refreshTime, refreshDataTime = goodsData:GetShowInfo()
- goodsData.buyNum = data.cur_num
- goodsData.buyLastTime = data.cur_buy_time
- local isShowNew, refreshTimeNew, refreshDataTimeNew = goodsData:GetShowInfo()
- if isShow ~= isShowNew or refreshTime ~= refreshTimeNew or refreshDataTime ~= refreshDataTimeNew then
- self:RefreshShowGoodsDatas()
- end
- end
- end
- --- 整理数据,获得需要显示的商品,下次商店需要刷新界面的时间, 下次商店需要刷新数据的时间
- function ShopData:RefreshShowGoodsDatas()
- local needRefreshTime = nil
- local needRefreshDataTime = nil
- local showGoodsDatas = {}
- for _, goodsData in pairs(self.goodsDataMap) do
- local isShow, refreshTime, refreshDataTime = goodsData:GetShowInfo()
- if isShow then
- showGoodsDatas[#showGoodsDatas+1] = goodsData
- end
- needRefreshTime = CompValidTimeData(refreshTime, needRefreshTime)
- needRefreshDataTime = CompValidTimeData(refreshDataTime, needRefreshDataTime)
- end
- needRefreshTime = CompValidTimeData(self.refreshTime, needRefreshTime)
- needRefreshDataTime = CompValidTimeData(self.refreshTime, needRefreshDataTime)
- needRefreshTime = CompValidTimeData(self.dayEndTime, needRefreshTime)
- needRefreshDataTime = CompValidTimeData(self.dayEndTime, needRefreshDataTime)
- needRefreshTime = CompValidTimeData(self.weekEndTime, needRefreshTime)
- needRefreshDataTime = CompValidTimeData(self.weekEndTime, needRefreshDataTime)
- self.needRefreshTime = needRefreshTime
- self.needRefreshDataTime = needRefreshDataTime
- self.showGoodsDatas = showGoodsDatas
- self:SortShowData()
- end
- function ShopData:SortShowData()
- if not self.showGoodsDatas then return end
- table.sort(self.showGoodsDatas, function (a, b)
- local isSoldOutA = a:IsSoldout()
- local isSoldOutB = b:IsSoldout()
- if isSoldOutA == isSoldOutB then
- return a:GetSortId() < b:GetSortId()
- else
- return not isSoldOutA
- end
- end)
- end
- function ShopData:GetGoodsDataById(id)
- return self.goodsDataMap[id]
- end
- function ShopData:GetShowGoodsDatas()
- return self.showGoodsDatas
- end
- function ShopData:GetNeedRefreshTime()
- return self.needRefreshTime
- end
- function ShopData:GetNeedRefreshDataTime()
- return self.needRefreshDataTime
- end
- function ShopData:GetRefreshTime()
- return self.refreshTime
- end
- function ShopData:GetRefreshCount()
- return self.refreshCount
- end
- return ShopData
|