|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+--[[
|
|
|
2
|
+Descripttion:邮件
|
|
|
3
|
+version:
|
|
|
4
|
+Author: Neo,Huang
|
|
|
5
|
+Date: 2022-08-17 16:04:20
|
|
|
6
|
+LastEditors: Neo,Huang
|
|
|
7
|
+LastEditTime: 2022-08-19 20:12:34
|
|
|
8
|
+--]]
|
|
|
9
|
+local code = require("code")
|
|
|
10
|
+local util_mail = require("utils.util_mail")
|
|
|
11
|
+local timeUtil = require("utils.timeUtil")
|
|
|
12
|
+local itemUtil = require("utils.itemUtil")
|
|
|
13
|
+
|
|
|
14
|
+local bagData = require("data.bag")
|
|
|
15
|
+
|
|
|
16
|
+local root = class("mailSelf", require("base.baseModule"))
|
|
|
17
|
+
|
|
|
18
|
+function root:ctor(uid)
|
|
|
19
|
+ root.super.ctor(self, "tb_mail_self", "uid", true, nil, nil)
|
|
|
20
|
+
|
|
|
21
|
+ self.uid = uid
|
|
|
22
|
+end
|
|
|
23
|
+
|
|
|
24
|
+function root:getInitColumnNameOptions()
|
|
|
25
|
+ return {
|
|
|
26
|
+ uid = "bigint(20) unsigned NOT NULL COMMENT '用户ID'",
|
|
|
27
|
+ readIdList = "JSON COMMENT '已读邮件ID列表'",
|
|
|
28
|
+ delIdList = "JSON COMMENT '已删邮件ID列表'",
|
|
|
29
|
+ awardIdList = "JSON COMMENT '已领取奖励邮件ID列表'"
|
|
|
30
|
+ }
|
|
|
31
|
+end
|
|
|
32
|
+
|
|
|
33
|
+-- 读邮件 - 新增
|
|
|
34
|
+function root:add_read_mail(id)
|
|
|
35
|
+ if is_empty(id) then
|
|
|
36
|
+ return false
|
|
|
37
|
+ end
|
|
|
38
|
+ local readIdList = self:redis_get_key_info("readIdList")
|
|
|
39
|
+ if table.include(readIdList, id) then
|
|
|
40
|
+ return false
|
|
|
41
|
+ end
|
|
|
42
|
+ table.insetr(readIdList, id)
|
|
|
43
|
+ self:redis_update_key_info("readIdList", readIdList)
|
|
|
44
|
+end
|
|
|
45
|
+-- 是否已读
|
|
|
46
|
+function root:is_read(id)
|
|
|
47
|
+ if is_empty(id) then
|
|
|
48
|
+ return false
|
|
|
49
|
+ end
|
|
|
50
|
+ local readIdList = self:redis_get_key_info("readIdList")
|
|
|
51
|
+ if table.include(readIdList, id) then
|
|
|
52
|
+ return true
|
|
|
53
|
+ end
|
|
|
54
|
+ return false
|
|
|
55
|
+end
|
|
|
56
|
+
|
|
|
57
|
+-- 读邮件 - 新增
|
|
|
58
|
+function root:add_del_mail(id)
|
|
|
59
|
+ if is_empty(id) then
|
|
|
60
|
+ return false
|
|
|
61
|
+ end
|
|
|
62
|
+ local delIdList = self:redis_get_key_info("delIdList")
|
|
|
63
|
+ if table.include(delIdList, id) then
|
|
|
64
|
+ return false
|
|
|
65
|
+ end
|
|
|
66
|
+ table.insetr(delIdList, id)
|
|
|
67
|
+ self:redis_update_key_info("delIdList", delIdList)
|
|
|
68
|
+end
|
|
|
69
|
+-- 是否已读
|
|
|
70
|
+function root:is_del(id)
|
|
|
71
|
+ if is_empty(id) then
|
|
|
72
|
+ return false
|
|
|
73
|
+ end
|
|
|
74
|
+ local delIdList = self:redis_get_key_info("delIdList")
|
|
|
75
|
+ if table.include(delIdList, id) then
|
|
|
76
|
+ return true
|
|
|
77
|
+ end
|
|
|
78
|
+ return false
|
|
|
79
|
+end
|
|
|
80
|
+
|
|
|
81
|
+-- 奖励 - 新增
|
|
|
82
|
+function root:add_award_mail(id)
|
|
|
83
|
+ if is_empty(id) then
|
|
|
84
|
+ return false
|
|
|
85
|
+ end
|
|
|
86
|
+ local awardIdList = self:redis_get_key_info("awardIdList")
|
|
|
87
|
+ if table.include(awardIdList, id) then
|
|
|
88
|
+ return false
|
|
|
89
|
+ end
|
|
|
90
|
+ table.insetr(awardIdList, id)
|
|
|
91
|
+ self:redis_update_key_info("awardIdList", awardIdList)
|
|
|
92
|
+ return true
|
|
|
93
|
+end
|
|
|
94
|
+-- 是否已读
|
|
|
95
|
+function root:is_awarded(id)
|
|
|
96
|
+ if is_empty(id) then
|
|
|
97
|
+ return false
|
|
|
98
|
+ end
|
|
|
99
|
+ local awardIdList = self:redis_get_key_info("awardIdList")
|
|
|
100
|
+ if table.include(awardIdList, id) then
|
|
|
101
|
+ return true
|
|
|
102
|
+ end
|
|
|
103
|
+ return false
|
|
|
104
|
+end
|
|
|
105
|
+
|
|
|
106
|
+----------------------------------------
|
|
|
107
|
+-- 接口
|
|
|
108
|
+----------------------------------------
|
|
|
109
|
+-- 模块信息
|
|
|
110
|
+function root:itf_get_info(msg)
|
|
|
111
|
+ local lastTime = msg.lastTime or 0
|
|
|
112
|
+ local list = util_mail:user_get_mail_info_list(self.uid, lastTime)
|
|
|
113
|
+ local mailList = {}
|
|
|
114
|
+ if not is_empty(list) then
|
|
|
115
|
+ for _, v in ipairs(list) do
|
|
|
116
|
+ if not self:is_del(v.id) then
|
|
|
117
|
+ local info = {
|
|
|
118
|
+ id = v.id,
|
|
|
119
|
+ title = v.title,
|
|
|
120
|
+ cnt = v.cnt,
|
|
|
121
|
+ ty = v.ty,
|
|
|
122
|
+ createTime = v.createTime,
|
|
|
123
|
+ expireTime = v.expireTime,
|
|
|
124
|
+ status = v.status,
|
|
|
125
|
+ statusItems = self:is_awarded(v.id) and 1 or 0
|
|
|
126
|
+ }
|
|
|
127
|
+ if not is_empty(v.items) then
|
|
|
128
|
+ info.items = cjson_decode(v.items)
|
|
|
129
|
+ end
|
|
|
130
|
+ info.status = self:is_read(v.id) and 1 or 0
|
|
|
131
|
+ table.insert(mailList, info)
|
|
|
132
|
+ end
|
|
|
133
|
+ end
|
|
|
134
|
+ end
|
|
|
135
|
+ local ret = {
|
|
|
136
|
+ mailList = mailList,
|
|
|
137
|
+ sysTime = timeUtil.now(self.uid)
|
|
|
138
|
+ }
|
|
|
139
|
+ return code.OK, ret
|
|
|
140
|
+end
|
|
|
141
|
+-- 读取
|
|
|
142
|
+function root:itf_read(msg)
|
|
|
143
|
+ local idList = msg.idList
|
|
|
144
|
+ if msg == nil or is_empty(idList) then
|
|
|
145
|
+ return code.PARAMTER_ERROR
|
|
|
146
|
+ end
|
|
|
147
|
+ for _, id in ipairs(idList) do
|
|
|
148
|
+ self:add_read_mail(id)
|
|
|
149
|
+ end
|
|
|
150
|
+ return code.OK
|
|
|
151
|
+end
|
|
|
152
|
+-- 删除
|
|
|
153
|
+function root:itf_del(msg)
|
|
|
154
|
+ local idList = msg.idList
|
|
|
155
|
+ if msg == nil or is_empty(idList) then
|
|
|
156
|
+ return code.PARAMTER_ERROR
|
|
|
157
|
+ end
|
|
|
158
|
+ for _, id in ipairs(idList) do
|
|
|
159
|
+ self:add_del_mail(id)
|
|
|
160
|
+ end
|
|
|
161
|
+ return code.OK
|
|
|
162
|
+end
|
|
|
163
|
+-- 获取邮件奖励
|
|
|
164
|
+function root:itf_get_award(msg)
|
|
|
165
|
+ local idList = msg.idList
|
|
|
166
|
+ if msg == nil or is_empty(idList) then
|
|
|
167
|
+ return code.PARAMTER_ERROR
|
|
|
168
|
+ end
|
|
|
169
|
+
|
|
|
170
|
+ local awardIdList = self:redis_get_key_info("awardIdList")
|
|
|
171
|
+ local mailItems = nil
|
|
|
172
|
+ for _, id in ipairs(idList) do
|
|
|
173
|
+ -- 是否已领取
|
|
|
174
|
+ if not self:is_awarded(id) then
|
|
|
175
|
+ local errCode, items = util_mail:user_get_mail_award(self.uid, id)
|
|
|
176
|
+ if not code.is_not_ok(errCode) then
|
|
|
177
|
+ table.insert(awardIdList, id)
|
|
|
178
|
+ if not is_empty(items) then
|
|
|
179
|
+ -- 发放邮件物品
|
|
|
180
|
+ local keyEvent = string.format("mail-award-%s", tostring(id))
|
|
|
181
|
+ bagData:add_items(self.uid, items, keyEvent)
|
|
|
182
|
+ end
|
|
|
183
|
+
|
|
|
184
|
+ mailItems = itemUtil.items_merge(mailItems, items)
|
|
|
185
|
+ end
|
|
|
186
|
+ end
|
|
|
187
|
+ end
|
|
|
188
|
+ self:redis_update_key_info("awardIdList", awardIdList)
|
|
|
189
|
+
|
|
|
190
|
+ return code.OK, {items = mailItems}
|
|
|
191
|
+end
|
|
|
192
|
+
|
|
|
193
|
+return root
|