local TequanExcel = require("excel.qqTequan")
local Msg = require("core.Msg")
local Grid = require("bag.Grid")
local BagLogic = require("bag.BagLogic")
local Util = require("common.Util")
local Lang = require("common.Lang")
local HeroLogic = require("hero.HeroLogic")
local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
local RoleSystemDefine = require("roleSystem.RoleSystemDefine")

TEQUAN_TYPE_1 = 1               -- 黄钻特权
TEQUAN_TYPE_2 = 2               -- 蓝钻特权

function activateTequan(human,type,tequanType,lv,hh,pf)
    if lv ~= nil and lv < 0 then
        return
    end
    if type == TEQUAN_TYPE_1 then                   -- 黄钻
        if human.db.yellow == nil then
            human.db.yellow = {}
            human.db.yellow.lv = lv
            human.db.yellow.isAdd = 1
            if tequanType == 1 then
                human.db.yellow.year = human.db.yellow.year or {}
            else
                human.db.yellow.year = nil
            end
            if hh == 1 then
                human.db.yellow.lux = human.db.yellow.lux or {}
            else
                human.db.yellow.lux = nil
            end
        else
            human.db.yellow.lv = lv
            if tequanType == 1 then
                human.db.yellow.year = human.db.yellow.year or {}
            else
                human.db.yellow.year = nil
            end
            if hh == 1 then
                human.db.yellow.lux = human.db.yellow.lux or {}
            else
                human.db.yellow.lux = nil
            end
        end
    elseif type == TEQUAN_TYPE_2 then
        if human.db.blue == nil then
            human.db.blue = {}
            human.db.blue.lv = lv
            human.db.blue.isAdd = 1
            if tequanType == 1 then
                human.db.blue.year = human.db.blue.year or {}
            else
                human.db.blue.year = nil
            end
            if hh == 1 then
                human.db.blue.lux = human.db.blue.lux or {}
            else
                human.db.blue.lux = nil
            end
        else
            human.db.blue.lv = lv
            if tequanType == 1 then
                human.db.blue.year = human.db.blue.year or {}
            else
                human.db.blue.year = nil
            end
            if hh == 1 then
                human.db.blue.lux = human.db.blue.lux or {}
            else
                human.db.blue.lux = nil
            end
        end
    end
    if pf == 1 then
        human.db.txHall = {}
        human.pf_info.pf = "qqgame"
    elseif pf == 2 then
        human.db.qqZone = {}
        human.pf_info.pf = "qzone"
    end
    HeroLogic.sendHeroBagCap(human)
end

function tencentXinShouQuery(human,tType,platformType)
    local msgRet = Msg.gc.GC_QQ_TEQUAN_VIP_XINSHOU_QUERY
    local config = nil
    if platformType ~= 2 then               -- 查询平台类型
        if platformType == tType then
            config = TequanExcel.txXinshou
            local len = #config[1].reward
            if platformType == 1 then
                if human.pf_info.pf ~= "qqgame" then
                    checkDot(human,tType,platformType)
                    return
                end
                if human.db.txHall == nil then
                    msgRet.isGet = 2
                else
                    if human.db.txHall.isGet ~= nil then
                        msgRet.isGet = 1
                    else
                        msgRet.isGet = 0
                    end
                end
            else
                if human.pf_info.pf ~= "qzone" and human.pf_info.pf ~= "website" then
                    checkDot(human,tType,platformType)
                    return
                end
                if human.db.qqZone == nil then
                    msgRet.isGet = 2
                else
                    if human.db.qqZone.isGet ~= nil then
                        msgRet.isGet = 1
                    else
                        msgRet.isGet = 0
                    end
                end
            end
            
            for i = 1,len do
                Grid.makeItem(msgRet.reward[i], config[1].reward[i][1],config[1].reward[i][2])
            end
            msgRet.reward[0] = len
            msgRet.str = ""
            Msg.send(msgRet,human.fd)
            checkDot(human,tType,platformType)
        end
        return
    end
    if tType == 1 then --  蓝钻
        config = TequanExcel.lzXinshou
        local len = #config[1].reward
        if human.db.blue == nil or human.db.blue.lv == 0 then
            msgRet.isGet = 2
        else
            if human.db.blue.isGet ~= nil then
                msgRet.isGet = 1
            else
                msgRet.isGet = 0
            end
        end
        for i = 1,len do
            Grid.makeItem(msgRet.reward[i], config[1].reward[i][1],config[1].reward[i][2])
        end
        config = TequanExcel.tequan[1]
        msgRet.str = Util.format(Lang.YELLOW_VIP_PRIVILEGE,config.privilege)
        msgRet.reward[0] = len
    elseif tType == 0 then   -- 黄钻
        config = TequanExcel.hzXinshou
        local len = #config[1].reward
        if human.db.yellow == nil or human.db.yellow.lv == 0 then
            msgRet.isGet = 2
        else
            if human.db.yellow.isGet ~= nil then
                msgRet.isGet = 1
            else
                msgRet.isGet = 0
            end
        end
        for i = 1,len do
            Grid.makeItem(msgRet.reward[i], config[1].reward[i][1],config[1].reward[i][2])
        end
        config = TequanExcel.tequan[2]
        msgRet.str = Util.format(Lang.YELLOW_VIP_PRIVILEGE,config.privilege)
        msgRet.reward[0] = len
    else
        checkDot(human,tType,platformType)
        return
    end
    Msg.send(msgRet,human.fd)
    checkDot(human,tType,platformType)
end

function tencentXinShouGet(human,tType,platformType)
    if platformType ~= 2 then
        if platformType == tType then
            if platformType == 1 then
                if human.pf_info.pf ~= "qqgame" then
                    return
                end
                if human.db.txHall == nil then
                    return -- 不是大厅玩
                end
                if human.db.txHall.isGet ~= nil then
                    return -- 已经领取过
                end
                human.db.txHall.isGet = 1
            else
                if human.pf_info.pf ~= "qzone" and human.pf_info.pf ~= "website" then
                    return
                end
                if human.db.qqZone == nil then
                    return -- 不是大厅玩
                end
                if human.db.qqZone.isGet ~= nil then
                    return -- 已经领取过
                end
                human.db.qqZone.isGet = 1
            end
            
            local config = TequanExcel.txXinshou
            BagLogic.addItemList(human,config[1].reward, "hall_reward")
        end
        tencentXinShouQuery(human,tType,platformType)
        
        RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_107)
        return
    end
    if tType == 1 then
        if human.db.blue == nil or human.db.blue.lv == 0 then
            return -- 当前黄钻未开通
        end
        if human.db.blue.isGet ~= nil then
            return -- 已经领取过
        end
        human.db.blue.isGet = 1
        local config = TequanExcel.lzXinshou
        BagLogic.addItemList(human,config[1].reward, "blue_reward")
    elseif tType == 0 then
        if human.db.yellow == nil or human.db.yellow.lv == 0 then
            return -- 当前黄钻未开通
        end
        if human.db.yellow.isGet ~= nil then
            return -- 已经领取过
        end
        human.db.yellow.isGet = 1
        local config = TequanExcel.hzXinshou
        BagLogic.addItemList(human,config[1].reward, "yellow_reward")
    else
        return
    end
    tencentXinShouQuery(human,tType,platformType)
    RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_106)
end

function tencentLvUpQuery(human,tType,platformType)
    local msgRet = Msg.gc.GC_QQ_TEQUAN_VIP_LVUP_QUERY
    if platformType ~= 2 then
        if platformType == tType then
            local config = TequanExcel.txLvUp
            local lenConfig = #config
            for i = 1,lenConfig do
                if platformType == 1 then
                    if human.pf_info.pf ~= "qqgame" then
                        return
                    end
                    if human.db.txHall ~= nil and human.db.txHall.lvup ~= nil and human.db.txHall.lvup[i] ~= nil then
                        msgRet.rewardMsg[i].isGet = 1
                    else
                        if human.db.txHall == nil then
                            msgRet.rewardMsg[i].isGet = 2
                        else
                            msgRet.rewardMsg[i].isGet = 0
                        end
                    end
                else
                    if human.pf_info.pf ~= "qzone" and human.pf_info.pf ~= "website" then
                        return
                    end
                    if human.db.qqZone ~= nil and human.db.qqZone.lvup ~= nil and human.db.qqZone.lvup[i] ~= nil then
                        msgRet.rewardMsg[i].isGet = 1
                    else
                        if human.db.qqZone == nil then
                            msgRet.rewardMsg[i].isGet = 2
                        else
                            msgRet.rewardMsg[i].isGet = 0
                        end
                    end
                end
                
                if human.db.lv < config[i].needLv then
                    msgRet.rewardMsg[i].isGet = 2
                end
                msgRet.rewardMsg[i].id = i
                msgRet.rewardMsg[i].lv = config[i].needLv
                local lenReward = #config[i].reward
                for j = 1,lenReward do
                    Grid.makeItem(msgRet.rewardMsg[i].reward[j],config[i].reward[j][1],config[i].reward[j][2])
                end
                msgRet.rewardMsg[i].reward[0] = lenReward
            end
            msgRet.rewardMsg[0] = lenConfig
        end
        Msg.send(msgRet,human.fd)
        return
    end
    if tType == 1 then
        local config = TequanExcel.lzLvUp
        local lenConfig = #config
        for i = 1,lenConfig do
            if human.db.blue ~= nil and human.db.blue.lv ~= 0 and human.db.blue.lvup ~= nil and human.db.blue.lvup[i] ~= nil then
                msgRet.rewardMsg[i].isGet = 1
            else
                if human.db.blue == nil or human.db.blue.lv == 0 then
                    msgRet.rewardMsg[i].isGet = 2
                else
                    msgRet.rewardMsg[i].isGet = 0
                end
            end
            if human.db.lv < config[i].needLv then
                msgRet.rewardMsg[i].isGet = 2
            end
            
            msgRet.rewardMsg[i].id = i
            msgRet.rewardMsg[i].lv = config[i].needLv
            local lenReward = #config[i].reward
            for j = 1,lenReward do
                Grid.makeItem(msgRet.rewardMsg[i].reward[j],config[i].reward[j][1],config[i].reward[j][2])
            end
            msgRet.rewardMsg[i].reward[0] = lenReward
        end
        msgRet.rewardMsg[0] = lenConfig
    elseif tType == 0 then
        local config = TequanExcel.hzLvUp
        local lenConfig = #config
        for i = 1,lenConfig do
            if human.db.yellow ~= nil and human.db.yellow.lv ~= 0 and human.db.yellow.lvup ~= nil and human.db.yellow.lvup[i] ~= nil then
                msgRet.rewardMsg[i].isGet = 1
            else
                if human.db.yellow == nil or human.db.yellow.lv == 0 then
                    msgRet.rewardMsg[i].isGet = 2
                else
                    msgRet.rewardMsg[i].isGet = 0
                end
            end
            if human.db.lv < config[i].needLv then
                msgRet.rewardMsg[i].isGet = 2
            end
            msgRet.rewardMsg[i].id = i
            msgRet.rewardMsg[i].lv = config[i].needLv
            local lenReward = #config[i].reward
            for j = 1,lenReward do
                Grid.makeItem(msgRet.rewardMsg[i].reward[j],config[i].reward[j][1],config[i].reward[j][2])
            end
            msgRet.rewardMsg[i].reward[0] = lenReward
        end
        msgRet.rewardMsg[0] = lenConfig
    else
        return
    end

    Msg.send(msgRet,human.fd)
end

function tencentLvUpGet(human,id,tType,platformType)
    if platformType ~= 2 then
        if platformType == tType then
            local config = TequanExcel.txLvUp
            if id == nil or id > #config or id <= 0 then
                return -- 无效礼包id
            end
            if human.db.lv < config[id].needLv then
                return
            end
            if platformType == 1 then
                if human.pf_info.pf ~= "qqgame" then
                    return
                end
                if human.db.txHall == nil then
                    return -- 当前黄钻未开通
                end
                if human.db.txHall.lvup ~= nil and human.db.txHall.lvup[id] ~= nil then
                    return -- 已经领取过
                end
                human.db.txHall.lvup = human.db.txHall.lvup or {}
                human.db.txHall.lvup[id] = 1
            else
                if human.pf_info.pf ~= "qzone" and human.pf_info.pf ~= "website" then
                    return
                end
                if human.db.qqZone == nil then
                    return -- 当前黄钻未开通
                end
                if human.db.qqZone.lvup ~= nil and human.db.qqZone.lvup[id] ~= nil then
                    return -- 已经领取过
                end
                human.db.qqZone.lvup = human.db.qqZone.lvup or {}
                human.db.qqZone.lvup[id] = 1
            end
            
            BagLogic.addItemList(human,config[id].reward, "hall_reward")
        end
        tencentLvUpQuery(human,tType,platformType)
        checkDot(human,tType,platformType)
        RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_107)
        return
    end
    if tType == 1 then
        if human.db.blue == nil or human.db.blue.lv == 0 then
            return -- 当前黄钻未开通
        end
        local config = TequanExcel.lzLvUp
        if human.db.lv < config[id].needLv then
            return
        end
        if id == nil or id > #config or id <= 0 then
            return -- 无效礼包id
        end
        if human.db.blue.lvup ~= nil and human.db.blue.lvup[id] ~= nil then
            return -- 已经领取过
        end
        human.db.blue.lvup = human.db.blue.lvup or {}
        human.db.blue.lvup[id] = 1
        BagLogic.addItemList(human,config[id].reward, "yellow_reward")
    elseif tType == 0 then
        if human.db.yellow == nil or human.db.yellow.lv == 0 then
            return -- 当前黄钻未开通
        end
        local config = TequanExcel.hzLvUp
        if human.db.lv < config[id].needLv then
            return
        end
        if id == nil or id > #config or id <= 0 then
            return -- 无效礼包id
        end
        if human.db.yellow.lvup ~= nil and human.db.yellow.lvup[id] ~= nil then
            return -- 已经领取过
        end
        human.db.yellow.lvup = human.db.yellow.lvup or {}
        human.db.yellow.lvup[id] = 1
        
        BagLogic.addItemList(human,config[id].reward, "yellow_reward")
    else
        return
    end
    tencentLvUpQuery(human,tType,platformType)
    checkDot(human,tType,platformType)
    RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_106)
end

function tencentDailyQuery(human,tType,platformType)
    local msgRet = Msg.gc.GC_QQ_TEQUAN_VIP_DAILY_QUERY
    if platformType ~= 2 then
        if platformType == tType then
            local config = TequanExcel.txDaily[1]
            msgRet.tencent_daily[1].vipLv = 0
            local lenReward = #config.reward
            for j = 1,lenReward do
                Grid.makeItem(msgRet.tencent_daily[1].reward[j],config.reward[j][1],config.reward[j][2])
            end
            msgRet.tencent_daily[1].reward[0] = lenReward
            if platformType == 1 then
                if human.pf_info.pf ~= "qqgame" then
                    return
                end
                if human.db.txHall ~= nil and human.db.txHall.daily == nil then
                    msgRet.isGet = {0,0,0}
                elseif human.db.txHall == nil then
                    msgRet.isGet = {2,0,0}
                else
                    msgRet.isGet = {1,0,0}
                end
            else
                if human.pf_info.pf ~= "qzone" and human.pf_info.pf ~= "website" then
                    return
                end
                if human.db.qqZone ~= nil and human.db.qqZone.daily == nil then
                    msgRet.isGet = {0,0,0}
                elseif human.db.qqZone == nil then
                    msgRet.isGet = {2,0,0}
                else
                    msgRet.isGet = {1,0,0}
                end
            end
            
            msgRet.tencent_daily[0] = 1
            msgRet.extraRewardYear[0] = 0
            msgRet.extraRewardLux[0] = 0
            msgRet.isGet[0] = 3
            Msg.send(msgRet,human.fd)
        end
        return
    end
    local config = nil
    if tType == 1 then
        config = TequanExcel.lzDaily
    elseif tType == 0 then
        config = TequanExcel.hzDaily
    else
        return
    end

    local lenConfig = #config
    for i = 1,lenConfig do
        msgRet.tencent_daily[i].vipLv = config[i].needVipLv
         local lenReward = #config[i].reward
        for j = 1,lenReward do
            Grid.makeItem(msgRet.tencent_daily[i].reward[j],config[i].reward[j][1],config[i].reward[j][2])
        end
        msgRet.tencent_daily[i].reward[0] = lenReward
    end
    msgRet.tencent_daily[0] = lenConfig
    local lenExtra = #config[1].extraRewardYear
     for i = 1,lenExtra do
        Grid.makeItem(msgRet.extraRewardYear[i],config[1].extraRewardYear[i][1],config[1].extraRewardYear[i][2])
    end
    msgRet.extraRewardYear[0] = lenExtra
    lenExtra = #config[1].extraRewardLux
    for i = 1,lenExtra do
        Grid.makeItem(msgRet.extraRewardLux[i],config[1].extraRewardLux[i][1],config[1].extraRewardLux[i][2])
    end
    msgRet.extraRewardLux[0] = lenExtra
    msgRet.isGet = {0,0,0}
    if tType == 0 then
        if human.db.yellow == nil or human.db.yellow.lv == 0 then
            msgRet.isGet = {2,2,2}
        else
            if human.db.yellow.daily ~= nil then
                msgRet.isGet[1] = 1
            end
            if human.db.yellow.lux ~= nil and human.db.yellow.lux.isGet ~= nil then
                msgRet.isGet[2] = 1
            elseif human.db.yellow.lux == nil then
                msgRet.isGet[2] = 2
            end
            if human.db.yellow.year ~= nil and human.db.yellow.year.isGet ~= nil then
                msgRet.isGet[3] = 1
            elseif human.db.yellow.year == nil then
                msgRet.isGet[3] = 2
            end
        end
    elseif tType == 1 then
        if human.db.blue == nil or human.db.blue.lv == 0 then
            msgRet.isGet = {2,2,2}
        else
            if human.db.blue.daily ~= nil then
                msgRet.isGet[1] = 1
            end
            if human.db.blue.lux ~= nil and human.db.blue.lux.isGet ~= nil then
                msgRet.isGet[2] = 1
            elseif human.db.blue.lux == nil then
                msgRet.isGet[2] = 2
            end
            if human.db.blue.year ~= nil and human.db.blue.year.isGet ~= nil then
                msgRet.isGet[3] = 1
            elseif human.db.blue.year == nil then
                msgRet.isGet[3] = 2
            end
        end
    end
    msgRet.isGet[0] = 3
    Msg.send(msgRet,human.fd)
end

function tencentDailyGet(human,tType,platformType,rType)
    if platformType ~= 2 then
        if platformType == tType then
            if platformType == 1 then
                if human.pf_info.pf ~= "qqgame" then
                    return
                end
                if human.db.txHall ~= nil and human.db.txHall.daily ~= nil then
                    return
                end
                human.db.txHall.daily = 1
            else
                if human.pf_info.pf ~= "qzone" and human.pf_info.pf ~= "website" then
                    return
                end
                if human.db.qqZone ~= nil and human.db.qqZone.daily ~= nil then
                    return
                end
                human.db.qqZone.daily = 1
            end
            
            local config = TequanExcel.txDaily[1]
            BagLogic.addItemList(human,config.reward, "blue_reward")
        end
        tencentDailyQuery(human,tType,platformType)
        checkDot(human,tType,platformType)
        RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_107)
        return
    end
    if tType == 1 then
        if human.db.blue == nil or human.db.blue.lv == 0 then
            return -- 当前黄钻未开通
        end
        local config = TequanExcel.lzDaily
        local lv = human.db.blue.lv 
        local lenItem = 0
        local item = nil
        if human.db.blue.daily == nil then
            human.db.blue.daily = 1
            local lenReward = #config[lv].reward
            for i = 1,lenReward do
                lenItem = lenItem + 1
                item = item or {}
                item[lenItem] = {}
                item[lenItem][1] = config[lv].reward[i][1]
                item[lenItem][2] = config[lv].reward[i][2]
            end
        end
        if human.db.blue.year ~= nil and human.db.blue.year.isGet == nil then
            human.db.blue.year.isGet = 1
            local lenExtra = #config[lv].extraRewardYear
            for i = 1,lenExtra do
                lenItem = lenItem + 1
                item = item or {}
                item[lenItem] = {}
                item[lenItem][1] = config[1].extraRewardYear[i][1]
                item[lenItem][2] = config[1].extraRewardYear[i][2]
            end
        end
        
        if human.db.blue.lux ~= nil and human.db.blue.lux.isGet == nil then
            human.db.blue.lux.isGet = 1
            local lenExtra = #config[lv].extraRewardLux
            for i = 1,lenExtra do
                lenItem = lenItem + 1
                item = item or {}
                item[lenItem] = {}
                item[lenItem][1] = config[1].extraRewardLux[i][1]
                item[lenItem][2] = config[1].extraRewardLux[i][2]
            end
        end
        if item then
            BagLogic.addItemList(human,item, "blue_reward")
        end
    elseif tType == 0 then
        if human.db.yellow == nil or human.db.yellow.lv == 0 then
            return -- 当前黄钻未开通
        end
        local config = TequanExcel.hzDaily
        local lv = human.db.yellow.lv 
        local lenItem = 0
        local item = nil
        if human.db.yellow.daily == nil then
            human.db.yellow.daily = 1
            local lenReward = #config[lv].reward
            for i = 1,lenReward do
                lenItem = lenItem + 1
                item = item or {}
                item[lenItem] = {}
                item[lenItem][1] = config[lv].reward[i][1]
                item[lenItem][2] = config[lv].reward[i][2]
            end
        end
        if human.db.yellow.year ~= nil and human.db.yellow.year.isGet == nil then
            human.db.yellow.year.isGet = 1
            local lenExtra = #config[lv].extraRewardYear
            for i = 1,lenExtra do
                lenItem = lenItem + 1
                item = item or {}
                item[lenItem] = {}
                item[lenItem][1] = config[1].extraRewardYear[i][1]
                item[lenItem][2] = config[1].extraRewardYear[i][2]
            end
        end
        
        if human.db.yellow.lux ~= nil and human.db.yellow.lux.isGet == nil then
            human.db.yellow.lux.isGet = 1
            local lenExtra = #config[lv].extraRewardLux
            for i = 1,lenExtra do
                lenItem = lenItem + 1
                item = item or {}
                item[lenItem] = {}
                item[lenItem][1] = config[1].extraRewardLux[i][1]
                item[lenItem][2] = config[1].extraRewardLux[i][2]
            end
        end
        if item then
            BagLogic.addItemList(human,item, "blue_reward")
        end
    else
        return
    end
    tencentDailyQuery(human,tType,platformType)
    checkDot(human,tType,platformType)
    RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_106)
end

function cleanDaily(human)
    if human.db.yellow ~= nil and human.db.yellow.lv ~= 0 then
        human.db.yellow.daily = nil
        if human.db.yellow.year ~= nil then
            human.db.yellow.year = {}
        end
        if human.db.yellow.lux ~= nil then
            human.db.yellow.lux = {}
        end
    end
    if human.db.blue ~= nil and human.db.blue.lv ~= 0 then
        human.db.blue.daily = nil
        if human.db.blue.year ~= nil then
            human.db.blue.year = {}
        end
        if human.db.blue.lux ~= nil then
            human.db.blue.lux = {}
        end
    end
    if human.db.txHall ~= nil then
        human.db.txHall.daily = nil 
    end
    if human.db.qqZone ~= nil then
        human.db.qqZone.daily = nil 
    end
end

function isDot(human)
    if (human.db.yellow == nil or human.db.yellow.lv == 0) and (human.db.blue == nil or human.db.blue.lv == 0) and human.db.txHall == nil and human.db.qqZone == nil then
        return 
    end
    if human.db.yellow ~= nil and human.db.yellow.lv ~= 0 then
        if human.db.yellow.isGet == nil then
            return true
        end
        if human.db.yellow.daily == nil then
            return true
        end
        if human.db.yellow.year ~= nil and human.db.yellow.year.isGet == nil then
            return true
        end
        if human.db.yellow.lux ~= nil and human.db.yellow.lux.isGet == nil then
            return true
        end
        local config = TequanExcel.hzLvUp
        local lenConfig = #config
        for i = 1,lenConfig do
            if human.db.yellow ~= nil and human.db.yellow.lv ~= 0 and (human.db.yellow.lvup == nil or human.db.yellow.lvup[i] == nil) then
                if human.db.lv >= config[i].needLv then
                    return true
                end
            end
        end
    end
    if human.db.blue ~= nil and human.db.blue.lv ~= 0 then
        if human.db.blue.isGet == nil then
            return true
        end
        if human.db.blue.daily == nil then
            return true
        end
        if human.db.blue.year ~= nil and human.db.blue.year.isGet == nil then
            return true
        end
        if human.db.blue.lux ~= nil and human.db.blue.lux.isGet == nil then
            return true
        end
        local config = TequanExcel.lzLvUp
        local lenConfig = #config
        for i = 1,lenConfig do
            if human.db.blue ~= nil and human.db.blue.lv ~= 0 and (human.db.blue.lvup == nil or human.db.blue.lvup[i] == nil) then
                if human.db.lv >= config[i].needLv then
                    return true
                end
            end
        end
    end
    return
end

function checkDot(human,tType,platformType)
    local msgRet = Msg.gc.GC_QQ_TEQUAN_CHECK_DOT
    msgRet.xinshou = 0
    msgRet.daily = 0
    msgRet.lvup = 0
    if platformType == 2 then
        msgRet.type = 1
        if tType == 0 then
            if human.db.yellow ~= nil and human.db.yellow.lv ~= 0 then
                if human.db.yellow.isGet == nil then
                    msgRet.xinshou = 1
                end
                if human.db.yellow.daily == nil then
                    msgRet.daily = 1
                end
                if human.db.yellow.year ~= nil and human.db.yellow.year.isGet == nil then
                    msgRet.daily = 1
                end
                if human.db.yellow.lux ~= nil and human.db.yellow.lux.isGet == nil then
                    msgRet.daily = 1
                end
                local config = TequanExcel.hzLvUp
                local lenConfig = #config
                for i = 1,lenConfig do
                    if human.db.yellow ~= nil and human.db.yellow.lv ~= 0 then
                        if human.db.yellow.lvup == nil or human.db.yellow.lvup[i] == nil  then
                            if human.db.lv >= config[i].needLv then
                                msgRet.lvup = 1
                                break
                            end
                        end
                    end
                end
            end
        else
            if human.db.blue ~= nil and human.db.blue.lv ~= 0 then
                if human.db.blue.isGet == nil then
                    msgRet.xinshou = 1
                end
                if human.db.blue.daily == nil then
                    msgRet.daily = 1
                end
                if human.db.blue.year ~= nil and human.db.blue.year.isGet == nil then
                    msgRet.daily = 1
                end
                if human.db.blue.lux ~= nil and human.db.blue.lux.isGet == nil then
                    msgRet.daily = 1
                end
                local config = TequanExcel.lzLvUp
                local lenConfig = #config
                for i = 1,lenConfig do
                    if human.db.blue ~= nil and human.db.blue.lv ~= 0 then
                        if human.db.blue.lvup == nil or human.db.blue.lvup[i] == nil  then
                            if human.db.lv >= config[i].needLv then
                                msgRet.lvup = 1
                                break
                            end
                        end
                    end
                end
            end    
        end
    else
        msgRet.type = 2
        if platformType == 1 then
            if human.pf_info.pf ~= "qqgame" then
                return
            end
            if human.db.txHall ~= nil then
                if human.db.txHall.isGet == nil then
                    msgRet.xinshou = 1
                end
                if human.db.txHall.daily == nil then
                    msgRet.daily = 1
                end
                local config = TequanExcel.txLvUp
                local lenConfig = #config
                for i = 1,lenConfig do
                    if human.db.txHall ~= nil then
                        if human.db.txHall.lvup == nil or human.db.txHall.lvup[i] == nil then
                            if human.db.lv >= config[i].needLv then
                                msgRet.lvup = 1
                                break
                            end
                        end
                    end
                end
            end
        else
            if human.pf_info.pf ~= "qzone" and human.pf_info.pf ~= "website" then
                return
            end
            if human.db.qqZone ~= nil then
                if human.db.qqZone.isGet == nil then
                    msgRet.xinshou = 1
                end
                if human.db.qqZone.daily == nil then
                    msgRet.daily = 1
                end
                local config = TequanExcel.txLvUp
                local lenConfig = #config
                for i = 1,lenConfig do
                    if human.db.qqZone ~= nil then
                        if human.db.qqZone.lvup == nil or human.db.qqZone.lvup[i] == nil then
                            if human.db.lv >= config[i].needLv then
                                msgRet.lvup = 1
                                break
                            end
                        end
                    end
                end
            end
        end
    end
    Msg.send(msgRet,human.fd)
end

function setHumanTequan(human,net)
    if net.lvYellow ~= nil and net.lvYellow ~= "0" and net.lvYellow ~= 0 then
        human.db.yellow = human.db.yellow or {}
        human.db.yellow.isAdd = 1
        human.db.yellow.lv = tonumber(net.lvYellow)
    else
        if human.db.yellow ~= nil then
            human.db.yellow.lv = 0
            human.db.yellow.isAdd = nil
        end
    end
    if net.lvBlue ~= nil and net.lvBlue ~= "0" and net.lvBlue ~= 0 then
        human.db.blue = human.db.blue or {}
        human.db.blue.isAdd = 1
        human.db.blue.lv = tonumber(net.lvBlue)
    else
        if human.db.blue ~= nil then
            human.db.blue.lv = 0
            human.db.blue.isAdd = nil
        end
    end
    if net.yearYellow ~= nil and net.yearYellow ~= "0" and net.yearYellow ~= 0 then
        human.db.yellow = human.db.yellow or {}
        human.db.yellow.year = human.db.yellow.year or {}
    else
        if human.db.yellow ~= nil then
            human.db.yellow.year = nil
        end
    end
    if net.yearBlue ~= nil and net.yearBlue ~= "0" and net.yearBlue ~= 0 then
        human.db.blue = human.db.blue or {}
        human.db.blue.year = human.db.blue.year or {}
    else
        if human.db.blue ~= nil then
            human.db.blue.year = nil
        end
    end
    if net.superYellow ~= nil and net.superYellow ~= "0" and net.superYellow ~= 0 then
        human.db.yellow = human.db.yellow or {}
        human.db.yellow.lux = human.db.yellow.lux or {}
    else
        if human.db.yellow ~= nil then
            human.db.yellow.lux = nil
        end
    end
    if net.superBlue ~= nil and net.superBlue ~= "0" and net.superBlue ~= 0 then
        human.db.blue = human.db.blue or {}
        human.db.blue.lux = human.db.blue.lux or {}
    else
        if human.db.blue ~= nil then
            human.db.blue.lux = nil
        end
    end
    if net.pf == "qzone" or net.pf == "website" then
        human.db.qqZone = human.db.qqZone or {}
    end
    if net.pf == "qqgame" then
        human.db.txHall = human.db.txHall or {}
    end
end

function jihuopt(human)
    if human.pf_info.pf == "qzone" or human.pf_info.pf == "website" then
        human.db.qqZone = human.db.qqZone or {}
    end
    if human.pf_info.pf == "qqgame" then
        human.db.txHall = human.db.txHall or {}
    end
end