-- 商店数据 local Store = class("Store", require("shared.ModelBase")) function Store:ctor(properties) Store.super.ctor(self, properties) end Store.schema = { buyR = {"table", {}}, -- 购买商品记录 {id=count} payR = {"table", {}}, -- 充值记录 {id=count} growFund = {"number", 0}, -- 成长基金 growFundR = {"string", ""}, -- 成长基金领取记录 monthCardEx = {"number", 0}, -- 月卡过期时间戳 smonthCardEx = {"number", 0}, -- 超级月卡过期时间戳 battleCardEx = {"number", 0}, -- 赛季卡过期时间戳 battleFR = {"string", ""}, -- 免费赛季卡领取记录 battleLR = {"string", ""}, -- 付费赛季卡领取记录 limitTPack = {"table", {}} -- 限时礼包 {id=expire_ts} } function Store:updateProperty(params) params = params or {} if not self.schema[params.field] then return end local oldValue = self:getProperty(params.field) if params.value then self:setProperty(params.field, params.value) elseif params.delta then self:incrProperty(params.field, params.delta) else return end local newValue = self:getProperty(params.field) if not params.notNotify then self:notifyUpdateProperty(params.field, newValue, oldValue) end end function Store:refreshData(notify, refreshType) local buyRecord = self:getProperty("buyR") 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("buyR", buyRecord) if notify then self:notifyUpdateProperty({field="buyR", value=buyRecord}) end end function Store:refreshPvpBuyRecord(notify) local buyRecord = self:getProperty("buyR") for id, data in pairs(csvdb["shop_normalCsv"]) do if data.shop == 3 then buyRecord[id] = nil end end self:setProperty("buyR", buyRecord) if notify then self:notifyUpdateProperty({field="buyR", value=buyRecord}) end end -- 发送月卡邮件 function Store:sendMonthCardEmail() local monthCardEx = self:getProperty("monthCardEx") local smonthCardEx = self:getProperty("smonthCardEx") local timeNow = skynet.timex() if monthCardEx < timeNow then redisproxy:insertEmail({roleId = self.owner:getProperty("id"), emailId = 19}) end if smonthCardEx < timeNow then redisproxy:insertEmail({roleId = self.owner:getProperty("id"), emailId = 20}) end end -- 购买通行证 function Store:onBuyCard(type, duration) duration = duration == "" and 0 or tonumber(duration) local timeNow = skynet.timex() if type == CardType.NormalMonthCard then self:updateProperty({field = "monthCardEx", value = timeNow + duration}) elseif type == CardType.SuperMonthCard then self:updateProperty({field = "smonthCardEx", value = timeNow + duration}) elseif type == CardType.PrivilegeCard then elseif type == CardType.GrowFund then self:updateProperty({field = "growFund", value = 1}) elseif type == CardType.BattleCard then self:updateProperty({field = "battleCardEx", value = timeNow + duration}) end end function Store:checkRechargeRecord(limit, id) local rechargeRecord = self:getProperty("payR") 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] or 0) + 1 self:updateProperty({field = "payR", value = rechargeRecord}) return true end function Store:notifyUpdateProperty(field, newValue, oldValue) local datas = { key = field, newValue = newValue, oldValue = oldValue, } SendPacket(actionCodes.Store_updateproperty, MsgPack.pack(datas)) end function Store:data() return { buyR = self:getProperty("buyR"), payR = self:getProperty("payR"), growFund = self:getProperty("growFund"), growFundR = self:getProperty("growFundR"), monthCardEx = self:getProperty("monthCardEx"), smonthCardEx = self:getProperty("smonthCardEx"), battleCardEx = self:getProperty("battleCardEx"), battleCardR = self:getProperty("battleCardR"), limitTPack = self:getProperty("limitTPack"), } end return Store