Store.lua 4.02 KB
-- 商店数据

local Store = class("Store", require("shared.ModelBase"))

function Store:ctor(properties)
	Store.super.ctor(self, properties)
end

Store.schema = {
	Store_buyRecord		= {"table", {}},		-- 购买商品记录 {id=count}
	Store_rechargeRecord	= {"table", {}},		-- 充值记录 {id=count}
	Store_growFund		= {"number", 0},		-- 成长基金
	Store_growFundRecord  = {"table", {}},        -- 成长基金领取记录
	Store_monthCardExTs	= {"number", 0},		-- 月卡过期时间戳
	Store_smonthCardExTs	= {"number", 0},		-- 超级月卡过期时间戳
	Store_battleCardExTs	= {"number", 0},		-- 赛季卡过期时间戳
	Store_battleCardRecord = {"table", {}},		-- 赛季卡领取记录
}

function Store:updateProperty(params)
	local type, default = table.unpack(self.schema[params.field])

	if params.delta then
		self:incrProperty(params.field, params.delta)
		if not params.notNotify then
			self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
		end
		return true
	end
	if params.value then
		self:setProperty(params.field, params.value)
		if not params.notNotify then
			self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
		end
		return true
	end
	return false
end

function Store:refreshData(notify, refreshType)
    local buyRecord = self:getProperty("Store_buyRecord")
    local result = {}
	for id, data in pairs(csvdb["shop_normalCsv"]) do
        if data.shop == 1 and refreshType == RefreshType.RefreshType_Daily then
            buyRecord[id] = nil
		end
        if data.shop == 2 and refreshType == RefreshType.RefreshType_Weekly then
            buyRecord[id] = nil
		end
	end
    self:setProperty("Store_buyRecord", buyRecord)
	if notify then
        --self.owner:notifyUpdateProperties(self:data())
        self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord})
	end
end

function Store:refreshPvpBuyRecord(notify)
    local buyRecord = self:getProperty("Store_buyRecord")
	for id, data in pairs(csvdb["shop_normalCsv"]) do
        if data.shop == 3 then
            buyRecord[id] = nil
		end
    end
    self:setProperty("Store_buyRecord", buyRecord)
	if notify then
        self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord})
	end
end

-- 发送月卡邮件
function Store:sendMonthCardEmail()
end

-- 购买通行证
function onBuyCard(type, duration)
    local timeNow = skynet.timex()
    if rechargeData.type == CardType.NormalMonthCard then
        self:updateProperty({field = "Store_monthCardExTs", value = timeNow + duration})
    elseif rechargeData.type == CardType.SuperMonthCard then
        self:updateProperty({field = "Store_smonthCardExTs", value = timeNow + duration})
    elseif rechargeData.type == CardType.PrivilegeCard then
    elseif rechargeData.type == CardType.GrowFund then
        self:updateProperty({field = "Store_growFundRecord", 1})
    elseif rechargeData.type == CardType.BattleCard then
        self:updateProperty({field = "Store_battleCardRecord", 1})
    end
end

function checkRechargeRecord(limit, id)
    local rechargeRecord = self:getProperty("Store_rechargeRecord")
    if limit ~= 0 and limit <= (rechargeRecord[id] or 0) then
        skynet.error(string.format("recharge id:%d count over limit, user id:%d", id, self.owner:getProperty("id")))
        return false
    end
    rechargeRecord[id] = rechargeRecord[id] + 1
    self:updateProperty({field = "Store_rechargeRecord", value = rechargeRecord[id]})
    return true
end

function Store:data()
	return {
        Store_buyRecord		= self:getProperty("Store_buyRecord"),
        Store_rechargeRecord	= self:getProperty("Store_rechargeRecord"),
        Store_growFund		= self:getProperty("Store_growFund"),
        Store_growFundRecord  = self:getProperty("Store_growFundRecord"),
        Store_monthCardExTs  = self:getProperty("Store_monthCardExTs"),
        Store_smonthCardExTs  = self:getProperty("Store_smonthCardExTs"),
        Store_battleCardExTs  = self:getProperty("Store_battleCardExTs"),
        Store_battleCardRecord  = self:getProperty("Store_battleCardRecord"),
	}
end

return Store