Email.lua
1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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", ""}, -- 邮件标题
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 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 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,
content = content,
attachments = attachments,
}
end
return Email