| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- local GoodsData = class('GoodsData')
- function GoodsData:ctor()
- self.count = 0
- self.buyNum = 0
- end
- function GoodsData:Dispose()
- self.id = nil
- self.price = nil
- self.curPrice = nil
- self.disPercent = nil
- self.hot = nil
- self.limitType = nil
- self.count = nil
- self.startTime = nil
- self.endTime = nil
- self.buyNum = nil
- self.buyLastTime = nil
- self.cfgData = nil
- end
- function GoodsData:SetBaseData(data, cfgData, refreshTime, dayEndTime, weekEndTime)
- self.id = data.goods_id
- self.price = data.price
- self.curPrice = data.cur_price
- self.disPercent = data.dispercent
- self.hot = data.hot
- self.limitType = data.limit_type
- self.count = data.count or 0
- self.startTime = data.start_time
- self.endTime = data.end_time
- self.cfgData = cfgData
- if not self:IsDiscount() then
- self.curPrice = self.price
- end
- if self.limitType == Enum.LimitBuyType.Forever then
- self.endTime = dayEndTime
- elseif self.limitType == Enum.LimitBuyType.Daily then
- self.endTime = dayEndTime
- elseif self.limitType == Enum.LimitBuyType.Week then
- self.endTime = weekEndTime
- elseif self.limitType == Enum.LimitBuyType.Special then
- self.endTime = refreshTime
- end
- self.buyNum = 0
- self.buyLastTime = nil
- end
- function GoodsData:SetBuyData(data)
- self.buyNum = data.buy_num or 0
- self.buyLastTime = data.buy_time
- end
- function GoodsData:GetCurTime()
- return ManagerContainer.LuaTimerMgr:GetTimeSecond()
- end
- function GoodsData:IsValidTime()
- if self.limitType == Enum.LimitBuyType.NoLimit then
- return true
- end
- if self.limitType == Enum.LimitBuyType.Forever then
- return true
- elseif self.limitType == Enum.LimitBuyType.Daily then
- local curTime = self:GetCurTime()
- return (curTime <= self.endTime)
- elseif self.limitType == Enum.LimitBuyType.Week then
- local curTime = self:GetCurTime()
- return (curTime <= self.endTime)
- elseif self.limitType == Enum.LimitBuyType.Time then
- local curTime = self:GetCurTime()
- return (curTime >= self.startTime and curTime <= self.endTime)
- elseif self.limitType == Enum.LimitBuyType.Special then
- local curTime = self:GetCurTime()
- return (curTime <= self.endTime)
- end
- return true
- end
- function GoodsData:IsCanBuy()
- if self.limitType == Enum.LimitBuyType.NoLimit then
- return true
- end
- if self:GetRemainBuyNumInternal() <= 0 then
- return false
- end
- if self.limitType == Enum.LimitBuyType.Forever then
- return true
- elseif self.limitType == Enum.LimitBuyType.Daily then
- local curTime = self:GetCurTime()
- return (curTime <= self.endTime)
- elseif self.limitType == Enum.LimitBuyType.Week then
- local curTime = self:GetCurTime()
- return (curTime <= self.endTime)
- elseif self.limitType == Enum.LimitBuyType.Time then
- local curTime = self:GetCurTime()
- return (curTime >= self.startTime and curTime <= self.endTime)
- elseif self.limitType == Enum.LimitBuyType.Special then
- local curTime = self:GetCurTime()
- return (curTime <= self.endTime)
- end
- return true
- end
- function GoodsData:GetRemainBuyNumInternal()
- if not self.count or self.count <= 0 then
- return 0
- end
- if self.buyNum then
- return (self.count - self.buyNum)
- else
- return self.count
- end
- end
- --- 返回剩余可购买次数
- ---@return integer -1时为无限次
- function GoodsData:GetRemainBuyNum()
- if self.limitType == Enum.LimitBuyType.NoLimit then
- return -1
- end
- local remainNum = self:GetRemainBuyNumInternal()
- if remainNum <= 0 then
- return 0
- end
- return remainNum
- -- if self.limitType == Enum.LimitBuyType.Forever then
- -- return remainNum
- -- elseif self.limitType == Enum.LimitBuyType.Daily then
- -- local curTime = self:GetCurTime()
- -- if curTime <= self.endTime then
- -- return remainNum
- -- else
- -- return 0
- -- end
- -- elseif self.limitType == Enum.LimitBuyType.Week then
- -- local curTime = self:GetCurTime()
- -- if curTime <= self.endTime then
- -- return remainNum
- -- else
- -- return 0
- -- end
- -- elseif self.limitType == Enum.LimitBuyType.Time then
- -- local curTime = self:GetCurTime()
- -- if (curTime >= self.startTime and curTime <= self.endTime) then
- -- return remainNum
- -- else
- -- return 0
- -- end
- -- elseif self.limitType == Enum.LimitBuyType.Special then
- -- local curTime = self:GetCurTime()
- -- if curTime <= self.endTime then
- -- return remainNum
- -- else
- -- return 0
- -- end
- -- end
- -- return 0
- end
- --- 是否卖光了
- function GoodsData:IsSoldout()
- if self.limitType == Enum.LimitBuyType.NoLimit then
- return false
- end
- if self.limitType == Enum.LimitBuyType.Forever
- or self.limitType == Enum.LimitBuyType.Daily
- or self.limitType == Enum.LimitBuyType.Week
- or self.limitType == Enum.LimitBuyType.Time
- or self.limitType == Enum.LimitBuyType.Special then
- if self:GetRemainBuyNumInternal() <= 0 then
- return true
- end
- return false
- end
- return true
- end
- --- 获得商品的显示规则数据
- ---@return boolean,int64,int64 是否显示,显示需要刷新的时间,数据需要刷新的时间
- function GoodsData:GetShowInfo()
- if self.limitType == Enum.LimitBuyType.NoLimit then
- return true, nil, nil
- elseif self.limitType == Enum.LimitBuyType.Forever then
- -- if self:GetRemainBuyNumInternal() > 0 then
- return true, nil, nil
- -- else
- -- if self.buyLastTime then
- -- if (self.endTime - self.buyLastTime) > ManagerContainer.LuaTimerMgr:GetOneDaySeconds() then
- -- return false, nil, nil
- -- else
- -- return true, self.endTime, self.endTime
- -- end
- -- else
- -- return true, self.endTime, self.endTime
- -- end
- -- end
- elseif self.limitType == Enum.LimitBuyType.Daily then
- return true, nil, self.endTime
- elseif self.limitType == Enum.LimitBuyType.Week then
- return true, nil, self.endTime
- elseif self.limitType == Enum.LimitBuyType.Time then
- local curTime = self:GetCurTime()
- if curTime < self.startTime then
- return false, self.startTime, self.endTime
- elseif curTime > self.endTime then
- return false, nil, nil
- else
- return true, self.endTime, self.endTime
- end
- elseif self.limitType == Enum.LimitBuyType.Special then
- return true, nil, self.endTime
- end
- return false, nil, nil
- end
- function GoodsData:IsDiscount()
- return self.disPercent and self.disPercent > 0 and self.disPercent < 100
- end
- function GoodsData:GetSortId()
- return self.cfgData.SortId
- end
- function GoodsData:GetGoodsCfgData()
- return self.cfgData
- end
- function GoodsData:CalculateLimitTime()
- local time = ManagerContainer.LuaTimerMgr:GetRemainSeconds(self.endTime)
- local timerStr, outTime = CommonUtil.FormatTimeDMS(time)
- return timerStr, outTime
- end
- return GoodsData
|