local Email = class("Email", require("shared.ModelBase")) function Email:ctor(properties) Email.super.ctor(self, properties) end Email.schema = { key = {"string"}, -- redis key id = {"number", 0}, -- 数据库ID emailId = {"number", 0}, -- 邮件csv ID title = {"string", ""}, -- 邮件标题 stitle = {"string", ""}, -- 小标题 content = {"string", ""}, -- 邮件正文 attachments = {"string", ""}, status = {"number", 0}, -- 邮件状态: 未读, 已读, 已领取 createtime = {"number", skynet.timex()}, contentPms = {"table", {}}, rewardPms = {"table", {}}, } function Email:data() local emailId = self:getProperty("emailId") local title = self:getProperty("title") local stitle = self:getProperty("stitle") local content = self:getProperty("content") local attachments = self:getProperty("attachments") local contentPms = self:getProperty("contentPms") local rewardPms = self:getProperty("rewardPms") local emailData = csvdb["emailCsv"][emailId] if emailData then -- 如果内容是直接插入到数据库 if content == "" and emailData.body ~= "" then content = io.readfile("src/" .. emailData.body) content = content:format(table.unpack(contentPms)) end if title == "" and emailData.title ~= "" then title = emailData.title end if stitle == "" and emailData.subtitle ~= "" then stitle = emailData.subtitle end if attachments == "" and emailData.attachment ~= "" then attachments = emailData.attachment:format(table.unpack(rewardPms)) end end return { id = self:getProperty("id"), status = self:getProperty("status"), createtime = self:getProperty("createtime"), title = title, stitle = stitle, content = content, attachments = attachments, } end return Email