123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- --[[
- Descripttion:邮件
- version:
- Author: Neo,Huang
- Date: 2022-08-17 16:04:20
- LastEditors: Neo,Huang
- LastEditTime: 2022-08-19 20:12:34
- --]]
- local code = require("code")
- local util_mail = require("utils.util_mail")
- local timeUtil = require("utils.timeUtil")
- local itemUtil = require("utils.itemUtil")
- local bagData = require("data.bag")
- local root = class("pmail", require("base.baseModule"))
- function root:ctor(uid)
- root.super.ctor(self, uid, "pmail", "uid", true)
- self.uid = uid
- end
- function root:getInitColumnNameOptions()
- return {
- uid = "bigint(20) unsigned NOT NULL COMMENT '用户ID'",
- readIdList = "JSON COMMENT '已读邮件ID列表'",
- delIdList = "JSON COMMENT '已删邮件ID列表'",
- awardIdList = "JSON COMMENT '已领取奖励邮件ID列表'"
- }
- end
- -- 读邮件 - 新增
- function root:add_read_mail(id)
- if is_empty(id) then
- return false
- end
- local readIdList = self:redis_get_key_info("readIdList")
- if table.include(readIdList, id) then
- return false
- end
- table.insetr(readIdList, id)
- self:redis_update_key_info("readIdList", readIdList)
- end
- -- 是否已读
- function root:is_read(id)
- if is_empty(id) then
- return false
- end
- local readIdList = self:redis_get_key_info("readIdList")
- if table.include(readIdList, id) then
- return true
- end
- return false
- end
- -- 读邮件 - 新增
- function root:add_del_mail(id)
- if is_empty(id) then
- return false
- end
- local delIdList = self:redis_get_key_info("delIdList")
- if table.include(delIdList, id) then
- return false
- end
- table.insetr(delIdList, id)
- self:redis_update_key_info("delIdList", delIdList)
- end
- -- 是否已读
- function root:is_del(id)
- if is_empty(id) then
- return false
- end
- local delIdList = self:redis_get_key_info("delIdList")
- if table.include(delIdList, id) then
- return true
- end
- return false
- end
- -- 奖励 - 新增
- function root:add_award_mail(id)
- if is_empty(id) then
- return false
- end
- local awardIdList = self:redis_get_key_info("awardIdList")
- if table.include(awardIdList, id) then
- return false
- end
- table.insetr(awardIdList, id)
- self:redis_update_key_info("awardIdList", awardIdList)
- return true
- end
- -- 是否已读
- function root:is_awarded(id)
- if is_empty(id) then
- return false
- end
- local awardIdList = self:redis_get_key_info("awardIdList")
- if table.include(awardIdList, id) then
- return true
- end
- return false
- end
- ----------------------------------------
- -- 接口
- ----------------------------------------
- -- 模块信息
- function root:itf_get_info(msg)
- local lastTime = msg.lastTime or 0
- local list = util_mail:user_get_mail_info_list(self.uid, lastTime)
- local mailList = {}
- if not is_empty(list) then
- for _, v in ipairs(list) do
- if not self:is_del(v.id) then
- local info = {
- id = v.id,
- title = v.title,
- cnt = v.cnt,
- ty = v.ty,
- createTime = v.createTime,
- expireTime = v.expireTime,
- status = v.status,
- statusItems = self:is_awarded(v.id) and 1 or 0
- }
- if not is_empty(v.items) then
- info.items = cjson_decode(v.items)
- end
- info.status = self:is_read(v.id) and 1 or 0
- table.insert(mailList, info)
- end
- end
- end
- local ret = {
- mailList = mailList,
- sysTime = timeUtil.now(self.uid)
- }
- return code.OK, ret
- end
- -- 读取
- function root:itf_read(msg)
- local idList = msg.idList
- if msg == nil or is_empty(idList) then
- return code.PARAMTER_ERROR
- end
- for _, id in ipairs(idList) do
- self:add_read_mail(id)
- end
- return code.OK
- end
- -- 删除
- function root:itf_del(msg)
- local idList = msg.idList
- if msg == nil or is_empty(idList) then
- return code.PARAMTER_ERROR
- end
- for _, id in ipairs(idList) do
- self:add_del_mail(id)
- end
- return code.OK
- end
- -- 获取邮件奖励
- function root:itf_get_award(msg)
- local idList = msg.idList
- if msg == nil or is_empty(idList) then
- return code.PARAMTER_ERROR
- end
- local awardIdList = self:redis_get_key_info("awardIdList")
- local mailItems = nil
- for _, id in ipairs(idList) do
- -- 是否已领取
- if not self:is_awarded(id) then
- local errCode, items = util_mail:user_get_mail_award(self.uid, id)
- if not code.is_not_ok(errCode) then
- table.insert(awardIdList, id)
- if not is_empty(items) then
- -- 发放邮件物品
- local keyEvent = string.format("mail-award-%s", tostring(id))
- bagData:add_items(self.uid, items, keyEvent)
- end
- mailItems = itemUtil.items_merge(mailItems, items)
- end
- end
- end
- self:redis_update_key_info("awardIdList", awardIdList)
- return code.OK, {items = mailItems}
- end
- return root
|