|
@@ -0,0 +1,83 @@
|
|
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-20 15:18:25
|
|
8
|
+--]]
|
|
9
|
+local timer = require("timer")
|
|
10
|
+local baseService = require("baseService")
|
|
11
|
+local util_mail = require("utils.util_mail")
|
|
12
|
+local lib_game_mysql = require("lib_game_mysql")
|
|
13
|
+local bagData = require("data.bag")
|
|
14
|
+
|
|
15
|
+local timerDelExpireMail = nil
|
|
16
|
+local timerExpireMail = nil
|
|
17
|
+
|
|
18
|
+local CMD = {}
|
|
19
|
+
|
|
20
|
+-- 清理过期邮件
|
|
21
|
+-- 过期后保留30天 - 永久邮件保留
|
|
22
|
+local function l_del_expire_mail()
|
|
23
|
+ -- 全服/渠道邮件且有过期时间要马上删除
|
|
24
|
+ local currTime = skynet_time()
|
|
25
|
+ local sql =
|
|
26
|
+ string.format(
|
|
27
|
+ "delete from mdl_mail where (uid=0 or uid=-1) and expireTime >0 and expireTime < %s;",
|
|
28
|
+ tostring(currTime)
|
|
29
|
+ )
|
|
30
|
+ local ret = lib_game_mysql:query(sql)
|
|
31
|
+ log.info("l_del_expire_mail sql[%s] ret[%s]", tostring(sql), tostring(ret))
|
|
32
|
+
|
|
33
|
+ -- 删除保留邮件
|
|
34
|
+ local expireTime = currTime - 3600 * 24 * 30
|
|
35
|
+ sql = string.format("delete from mdl_mail where expireTime >0 and expireTime < %s;", tostring(expireTime))
|
|
36
|
+ ret = lib_game_mysql:query(sql)
|
|
37
|
+ log.info("l_del_expire_mail sql[%s] ret[%s]", tostring(sql), tostring(ret))
|
|
38
|
+end
|
|
39
|
+
|
|
40
|
+-- 过期且有物品未领取
|
|
41
|
+local function l_expire_items_mail()
|
|
42
|
+ local currTime = skynet_time()
|
|
43
|
+ local sql =
|
|
44
|
+ string.format(
|
|
45
|
+ "SELECT * FROM `mdl_mail` WHERE expireTime < %s and JSON_LENGTH(items) > 0 limit 100;",
|
|
46
|
+ tostring(currTime)
|
|
47
|
+ )
|
|
48
|
+ log.info("l_expire_items_mail sql[%s]", tostring(sql))
|
|
49
|
+
|
|
50
|
+ local ret = lib_game_mysql:query(sql)
|
|
51
|
+ if ret.errno and ret.errno > 0 then
|
|
52
|
+ log.error("l_expire_items_mail 获取过期物品邮件列表失败 ret[%s] sql[%s]", tostring(ret), tostring(sql))
|
|
53
|
+ return
|
|
54
|
+ end
|
|
55
|
+ if not is_empty(ret) then
|
|
56
|
+ for k, v in ipairs(ret) do
|
|
57
|
+ local id = tonumber(v.id)
|
|
58
|
+ local uid = tonumber(v.uid)
|
|
59
|
+ -- 玩家邮件且未领取
|
|
60
|
+ if not is_robot(uid) and not util_mail:user_is_awarded_mail(uid, id) then
|
|
61
|
+ util_mail:user_add_award_mail(uid, id)
|
|
62
|
+ -- 发放邮件物品
|
|
63
|
+ local items = cjson_decode(v.items)
|
|
64
|
+ local keyEvent = string.format("mail-expire-award-%s", tostring(id))
|
|
65
|
+ bagData:add_items(uid, items, keyEvent)
|
|
66
|
+ end
|
|
67
|
+ end
|
|
68
|
+ end
|
|
69
|
+end
|
|
70
|
+
|
|
71
|
+function CMD.onStart()
|
|
72
|
+ timerDelExpireMail = timer.timeOut(60, l_del_expire_mail)
|
|
73
|
+ timerExpireMail = timer.timeOut(60, l_expire_items_mail)
|
|
74
|
+end
|
|
75
|
+
|
|
76
|
+function CMD.onStop()
|
|
77
|
+ -- 取消定时器
|
|
78
|
+ timerDelExpireMail.func = nil
|
|
79
|
+
|
|
80
|
+ timerExpireMail.func = nil
|
|
81
|
+end
|
|
82
|
+
|
|
83
|
+baseService.start(CMD, ".mailCenter", true)
|