源战役客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

411 rindas
10 KiB

MailModel = MailModel or BaseClass(EventDispatcher)
function MailModel:__init()
MailModel.Instance = self
self.mail_list = {} --邮件的基本信息列表
self.business_mail_list = {} --交易邮件的基本信息列表
self.mail_tab_index = 1
self.now_select_mail = nil --目前正在查看的邮件基本信息
self.select_mail_list = {} --被选中的邮件列表
self.attachment_time_list = {} --提取附件后的邮件列表,key为ID,value为提取时的时间
end
function MailModel:getInstance()
if MailModel.Instance == nil then
MailModel.New()
end
return MailModel.Instance
end
function MailModel:Clear()
self:CancelTimer()
self.now_select_mail = nil
self.select_mail_list = {}
end
function MailModel:SetAllMailList(list)
local mail_list = {}
local business_mail_list = {}
for k,v in pairs(list) do
if v.type == 5 then
table.insert(business_mail_list,v)
else
table.insert(mail_list,v)
end
end
self:SetMailList(mail_list)
self:SetBusinessMailList(business_mail_list)
end
--设置保存邮件的列表(接受所有存储在服务器的邮件,筛选出要显示的邮件)
function MailModel:SetMailList(list)
self.mail_list = list --邮件列表
local delete_index = {} --要删除的邮件的索引集合
for i, v in ipairs(self.mail_list) do
local gap = tonumber(v.effect_et) - TimeUtil:getServerTime() --获取信件存储剩余时间
if gap < 0 then
table.insert(delete_index, i)
end
end
--删除超出限制的邮件
local del_num = 0
for i, v in ipairs(delete_index) do
local index = v - del_num
table.remove(self.mail_list, index)
del_num = del_num + 1
end
self:SortFun(1)
self:Fire(MailEvent.UPDATE_MAIL_LIST) --更新邮件显示列表
end
function MailModel:SetBusinessMailList(list)
self.business_mail_list = list --邮件列表
local delete_index = {} --要删除的邮件的索引集合
for i, v in ipairs(self.business_mail_list) do
local gap = tonumber(v.effect_et) - TimeUtil:getServerTime() --获取信件存储剩余时间
if gap < 0 then
table.insert(delete_index, i)
end
end
--删除超出限制的邮件
local del_num = 0
for i, v in ipairs(delete_index) do
local index = v - del_num
table.remove(self.business_mail_list, index)
del_num = del_num + 1
end
self:SortFun(5)
self:Fire(MailEvent.UPDATE_MAIL_LIST) --更新邮件显示列表
end
function MailModel:GetMailList()
self.mail_list = self.mail_list or {}
local delete_index = {} --要删除的邮件的索引集合
for i, v in ipairs(self.mail_list) do
local gap = tonumber(v.effect_et) - TimeUtil:getServerTime() --获取信件存储剩余时间
if gap < 0 then
table.insert(delete_index, i)
end
end
--删除超出限制的邮件
local del_num = 0
for i, v in ipairs(delete_index) do
local index = v - del_num
table.remove(self.mail_list, index)
del_num = del_num + 1
end
self:SortFun(1)
return self.mail_list
end
function MailModel:GetBusinessMailList()
self.business_mail_list = self.business_mail_list or {}
local delete_index = {} --要删除的邮件的索引集合
for i, v in ipairs(self.business_mail_list) do
local gap = tonumber(v.effect_et) - TimeUtil:getServerTime() --获取信件存储剩余时间
if gap < 0 then
table.insert(delete_index, i)
end
end
--删除超出限制的邮件
local del_num = 0
for i, v in ipairs(delete_index) do
local index = v - del_num
table.remove(self.business_mail_list, index)
del_num = del_num + 1
end
self:SortFun(5)
return self.business_mail_list
end
--对邮件进行排序(按接受时间排序,最新收到的邮件最高)
--新 先是分为两部分,未读的在顶部,已读的在下面,两部分再分别按时间排序
function MailModel:SortFun(type)
local not_read = {}
local has_read = {}
if type == 5 then
for i,v in ipairs(self.business_mail_list) do
if v.state == 2 or ( v.is_attach == 1 and v.state ~= 3) then --未读
v.client_read_state = 0
table.insert(not_read, self.business_mail_list[i])
elseif v.state == 1 or v.state == 3 then --已读 和 已领取
v.client_read_state = 1
table.insert(has_read, self.business_mail_list[i])
end
end
else
for i,v in ipairs(self.mail_list) do
if v.state == 2 or ( v.is_attach == 1 and v.state ~= 3) then --未读
v.client_read_state = 0
table.insert(not_read, self.mail_list[i])
elseif v.state == 1 or v.state == 3 then --已读 和 已领取
v.client_read_state = 1
table.insert(has_read, self.mail_list[i])
end
end
end
-- not_read = self:SortMore(not_read)
-- has_read = self:SortMore(has_read)
for i,v in ipairs(has_read) do
table.insert(not_read, v)
end
local arg = {"important","client_read_state","time", "mail_id"}
local condition = {Array.UPPER,Array.LOWER,Array.UPPER, Array.UPPER}
SortTools.MoreKeysSorter(not_read, arg, condition)
if type == 5 then
self.business_mail_list = not_read
else
self.mail_list = not_read
end
end
function MailModel:SortMore(list)
if not list then return end
local arg = {"time", "mail_id"}
local condition = {Array.UPPER, Array.UPPER}
SortTools.MoreKeysSorter(list, arg, condition)
return list
end
--增加邮件
function MailModel:AddMailList(list)
if list then
for i, v in ipairs(list) do
if v.type == 5 then
table.insert(self.business_mail_list, v)
else
table.insert(self.mail_list, v)
end
end
end
self:SortFun(1)
self:SortFun(5)
self:Fire(MailEvent.UPDATE_MAIL_LIST)
end
--删除邮件
function MailModel:DeleteMail(mail_ids)
local is_find = false
if mail_ids then
for i = 1, #mail_ids do
for k, v in ipairs(self.mail_list) do
if v.mail_id == mail_ids[i].mail_id then
table.remove(self.mail_list, k)
is_find = true
break
end
end
for k, v in ipairs(self.business_mail_list) do
if v.mail_id == mail_ids[i].mail_id then
table.remove(self.business_mail_list, k)
break
end
end
end
self:Clear()
self:SortFun(1)
self:SortFun(5)
-- self:Fire(MailEvent.UPDATE_MAIL_LIST)
end
end
--更改邮件的数据
function MailModel:UpdateMailData(data)
if data == nil then return end
if data.type ~= 5 then
for i, v in ipairs(self.mail_list) do
if v.mail_id == data.mail_id then
v.type = data.type
v.state = data.state
v.title = data.title
v.is_attach = data.is_attach
v.time = data.time
v.effect_et = data.effect_et
self:Fire(MailEvent.UPDATE_MAIL_ITEM, v)
break
end
end
elseif data.type == 5 then
for i, v in ipairs(self.business_mail_list) do
if v.mail_id == data.mail_id then
v.type = data.type
v.state = data.state
v.title = data.title
v.is_attach = data.is_attach
v.time = data.time
v.effect_et = data.effect_et
self:Fire(MailEvent.UPDATE_MAIL_ITEM, v)
break
end
end
end
end
--检查系统邮件的红点
function MailModel:CheckSystemMailRedDot()
local mail_list = self:GetMailList()
if not mail_list or #mail_list <= 0 then
return
end
local show = false
for i,v in ipairs(mail_list) do
if v.state == 2 or (v.state ~= 3 and v.is_attach == 1) then
show = true
break
end
end
return show
end
--检查交易邮件的红点
function MailModel:CheckBusinessMailRedDot()
local business_mail_list = self:GetBusinessMailList()
if not business_mail_list or #business_mail_list <= 0 then
return
end
local show = false
for i,v in ipairs(business_mail_list) do
if v.state == 2 or (v.state ~= 3 and v.is_attach == 1) then
show = true
break
end
end
return show
end
--判断邮件红点数量
function MailModel:GetMailRedNum( )
local red_num = 0
local mail_list = self:GetMailList()
local business_mail_list = self:GetBusinessMailList()
for i,v in ipairs(mail_list) do
if v.state == 2 or (v.state ~= 3 and v.is_attach == 1) then
red_num = red_num + 1
end
end
for i,v in ipairs(business_mail_list) do
if v.state == 2 or (v.state ~= 3 and v.is_attach == 1) then
red_num = red_num + 1
end
end
return red_num
end
--再处理一次邮件的详细信息 避免有些标题空白的情况
function MailModel:HandleMailDetail(vo)
if not vo then return end
local is_system_mail = false
if vo.title == nil or vo.title == "" then
for k,v in pairs(self.mail_list) do
if vo.mail_id == v.mail_id then
if v.type == 1 or v.type == 3 then
is_system_mail = true
end
end
end
if is_system_mail then
if vo.module_id and vo.sub_module_id then
local cfg
if vo.sub_module_id == 0 then
cfg = Config.Moduleid[vo.module_id]
vo.title = cfg.module_name.."内容"
vo.content = cfg.module_name.."内容"
else
cfg = Config.Modulesub[vo.module_id.."@"..vo.sub_module_id]
vo.title = cfg.sub_name.."内容"
vo.content = cfg.module_name.."内容"
end
end
end
end
return vo
end
-- 获取到邮件的类型
function MailModel:GetMailType(mail_id)
local type
if self.mail_list and mail_id then
for k,v in pairs(self.mail_list) do
if v and v.mail_id == mail_id then
type = v.type
return type
end
end
for k,v in pairs(self.business_mail_list) do
if v and v.mail_id == mail_id then
type = v.type
return type
end
end
end
return 0
end
function MailModel:GetMailEffectTime(mail_id)
for k,v in pairs(self.business_mail_list) do
if mail_id ==v.mail_id then
return v.effect_et
end
end
for k,v in pairs(self.mail_list) do
if mail_id ==v.mail_id then
return v.effect_et
end
end
end
function MailModel:SortMailEffectTime()
self:CancelTimer()
local tb = {}
for k,v in pairs(self.business_mail_list) do
local temp = {}
temp.mail_id = v.mail_id
temp.runout_time = v.effect_et - TimeUtil:getServerTime()
table.insert(tb,temp)
end
for k,v in pairs(self.mail_list) do
local temp = {}
temp.mail_id = v.mail_id
temp.runout_time = v.effect_et - TimeUtil:getServerTime()
table.insert(tb,temp)
end
local sort_func = function ( a, b )
return a.runout_time < b.runout_time
end
table.sort(tb, sort_func)
local timer_func = function()
self:CancelTimer()
self:Fire(MailEvent.UPDATE_TOP_BAR_RED)
end
if tb and tb[1] and tb[1].runout_time>0 then
self.timer_id = GlobalTimerQuest:AddPeriodQuest(timer_func, tb[1].runout_time+2)
end
end
function MailModel:CancelTimer()
if self.timer_id then
GlobalTimerQuest:CancelQuest(self.timer_id)
self.timer_id = nil
end
end