Email.lua 2.71 KB
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:log(role, action)
	role:log("onMail", {
		mail_action_type = action, -- 操作(1=收,2=领,3=删)
		mail_receivetime = self:getProperty("createtime"), -- 收件时间
		mail_textid = self:getProperty("emailId"), -- 邮件文本ID
		mial_title = self:getProperty("title"), -- 邮件标题参数
		mail_content = json.encode(self:getProperty("contentPms")), -- 邮件内容参数
		mail_attach = self:getProperty("attachments"), -- 邮件附件
		mail_reason = self:getProperty("stitle"), -- 原因
		mail_readstatus = self:getProperty("status") >= 1 and 1 or 0, -- 邮件读取状态
		mail_attachstatus = self:getProperty("status") >= 2 and 1 or 0, -- 邮件附件状态
		mail_timeout = 0, -- 邮件超时时间
		mail_friend_id = 0, -- 收件方账号id
		mail_friend_roleid = 0, -- 收件方角色id
	})
end

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) or ""
		--	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
			if next(rewardPms) then
				attachments = emailData.attachment:format(table.unpack(rewardPms))
			else
				attachments = emailData.attachment
			end
		end
	end

	return {
		cfgId = emailId,
		id = self:getProperty("id"),
		status = self:getProperty("status"),
		createtime = self:getProperty("createtime"),
		title = title,
		stitle = stitle,
		content = content,
		contentPms = contentPms,
		attachments = attachments,
	}
end

return Email