--------------------------------
-- 文件名       ：  WeekendLoopActRank.lua
-- 文件说明     ：  周末冲刺-排行榜
-- 创建时间     :   2024/12/09
-- 创建人       :   FC
--------------------------------

local Msg = require("core.Msg")
local Util = require("common.Util")
local Lang = require("common.Lang")
local CommonDB = require("common.CommonDB")
local Broadcast = require("broadcast.Broadcast")
local CommonDefine = require("common.CommonDefine")
local Timer = require("core.Timer")
local Config = require("Config")
local Grid = require("bag.Grid")
local ObjHuman = require("core.ObjHuman")
local MailExcel = require("excel.mail")
local MailManager = require("mail.MailManager")
local RoleDBLogic = require("role.RoleDBLogic")
local ServerCommerceMiddle = require("serverCommerce.ServerCommerceMiddle")
local ServerCommerceDefine = require("serverCommerce.ServerCommerceActDefine")
local ServerCommerceRankConf = require("excel.ServerCommerce").CommerceRank
local ServerCommerceManager = require("serverCommerce.ServerCommerceManager")

-- 缓存的排行榜数据 
local COMMERCE_RANK_CACHE = {}

-- 缓存的ServerKey
local COMMERCE_RANK_SERVER_KEY = nil

-- 缓存的服务器排名
local COMMERCE_RANK_SERVER_RANK = nil

-- 待发送全服奖励的玩家
local COMMRCE_RANK_SERVERMAIL_HUMAN = nil

----------------------------------------- 内部处理开始 -------------------------------------
function CommercerActRank_QueryRankInfo(nRankType, nRankSubType)
    ServerCommerceMiddle.CommerveMiddle_QueryRankInfo(nRankType, nRankSubType)
    print("[CommercerActRank_QueryRankInfo] 向中心服请求排行榜 nRankType = "..nRankType.." nRankSubType = "..nRankSubType)

    CommercerActRank_CreateTime(ServerCommerceDefine.COMMERCEACT_RANKUPDATE, nRankType, nRankSubType)
end

-- 检查是否存在对应缓存
local function CommercerActRank_CheckCache(nRankType, nRankSubType, nServerKey)
    if not COMMERCE_RANK_CACHE then
        return false
    end

    if not COMMERCE_RANK_CACHE[nRankType] or not COMMERCE_RANK_CACHE[nRankType][nRankSubType] 
        or not COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey] then
        return false
    end

    return true
end

-- 获取上榜的最小条件
local function CommercerActRank_GetInRankMinValue(nRankSubType, nRank)
    for nID, v in ipairs(ServerCommerceRankConf) do
        if v.nRankType == nRankSubType then
            if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
                return v.nPoint
            end
        end
    end

    return 0
end

-- 创建缓存
local function CommercerActRank_CreateCache(nRankType, nRankSubType, nServerKey)
    if not COMMERCE_RANK_CACHE then
        COMMERCE_RANK_CACHE = {}
    end

    if not COMMERCE_RANK_CACHE[nRankType] then
        COMMERCE_RANK_CACHE[nRankType] = {}
    end

    if not COMMERCE_RANK_CACHE[nRankType][nRankSubType] then
        COMMERCE_RANK_CACHE[nRankType][nRankSubType] = {}
    end

    if not COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey] then
        COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey] = {}
    end
end

-- 获取缓存的排行榜数据
local function CommercerActRank_GetCacheRankData(nRankType, nRankSubType, nServerKey)
    return COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey]
end

local function CommercerActRank_GetCacheRankDataByRank(nRankType, nRankSubType, nServerKey, nRank)
    return COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey][nRank]
end

-- 清空对应的排行榜
local function CommercerActRank_ClearCache(nRankType, nRankSubType, nServerKey)
    COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey] = {}
end

-- 插入排行榜数据
local function CommercerActRank_InsertRank(nRankType, nRankSubType, nServerKey, nRank, tRankInfo)
    local tCacheRankData = CommercerActRank_GetCacheRankData(nRankType, nRankSubType, nServerKey)
    tCacheRankData[nRank] = tRankInfo
end

local function CommercerActRank_GetRankInfoByUuid(nRankType, nRankSubType, uuid)
    local tCacheRankData = CommercerActRank_GetCacheRankData(nRankType, nRankSubType, COMMERCE_RANK_SERVER_KEY)
    if not tCacheRankData then
        return nil, nil
    end

    -- table.print_lua_table(tCacheRankData)
    local nGetRank, tGetRankInfo = nil, nil
    for nRank, v in pairs(tCacheRankData) do
        if "table" ==  type(v) then
            print("[CommercerActRank_GetRankInfoByUuid] v.uuid = "..v.uuid.." uuid = "..uuid)
            if v.uuid == uuid  then
                print("[CommercerActRank_GetRankInfoByUuid] 相等的")
            end
        end
        if "table" == type(v) and v.uuid == uuid then
            nGetRank = nRank
            tGetRankInfo = v
            break
        end
    end

    return nGetRank, tGetRankInfo
end


-- 包装自己名次数据
local function CommercerActRank_WrapOwnerData(nRankType, nRankSubType, net, uuid)
	local nRank, tRankInfo = CommercerActRank_GetRankInfoByUuid(nRankType, nRankSubType, uuid)

	net.rank = nRank or -1
	net.rankValue = tRankInfo and tRankInfo.nValue or 0

 	local len = 0
    local nNeedPoint = 0
 	if nRank and tRankInfo then
        for _, v in ipairs(ServerCommerceRankConf) do
            if v.nRankType == nRankSubType then
                if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
                    for index, itemInfo in ipairs(v.Prize) do
                        len = len + 1
                        Grid.makeItem(net.items[index], itemInfo[1], itemInfo[2])
                        nNeedPoint = v.nPoint
                    end
                    break
                end
            end
        end
    else
        local nMinRank, tMinPrize = 0, nil
        for _, v in ipairs(ServerCommerceRankConf) do
            if v.nRankType == nRankSubType then
                if v.nOrder[1] > nMinRank then
                    nMinRank = v.nOrder[1]
                    tMinPrize = v.Prize
                    nNeedPoint = v.nPoint
                end
            end
        end

        if nil ~= tMinPrize then
            for index, itemInfo in ipairs(tMinPrize) do
                len = len + 1
                Grid.makeItem(net.items[index], itemInfo[1], itemInfo[2])
            end
        end
 	end

    net.rankNeedValue = nNeedPoint
    net.servername = Config.NEW_SVR_INDEX.."区"
	net.items[0] = len
end

-- 包装档位名次数据
local function CommercerActRank_WrapRankList(nRankType, nRankSubType, net, nRank)
	local tRankData = CommercerActRank_GetCacheRankDataByRank(nRankType, nRankSubType, COMMERCE_RANK_SERVER_KEY, nRank)
	
    net.rank = nRank
    net.rankNeedValue = CommercerActRank_GetInRankMinValue(nRankSubType, nRank)
	if tRankData and tRankData ~= -1 then
		net.uid = tRankData.uuid
		net.name = tRankData.name
		net.head = tRankData.head
		net.rankValue = tRankData.nValue
		net.headFrame = tRankData.headFrame
        net.servername = tRankData.servername
	else
		net.uid = "-1"
		net.name = ""
		net.head = -1
		net.rankValue = 0
		net.headFrame = -1
        net.servername = ""
	end

    local len, nNeedPoint = 0, 0
    for _, v in ipairs(ServerCommerceRankConf) do
        if v.nRankType == nRankSubType then
            if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
                nNeedPoint = v.nPoint
                for index, itemInfo in ipairs(v.Prize) do
                    len = len + 1
                    Grid.makeItem(net.items[index], itemInfo[1], itemInfo[2])
                end
                break
            end
        end
    end
 	
    --Grid.makeItem(net.pointItem, ServerCommerceDefine.COMERCEACT_POINT_GOODSID, nNeedPoint)
	net.items[0] = len
end
----------------------------------------- 外部调用 -------------------------------------
function CommercerActRank_ResetData(human)
    if not human then
        return
    end

    --CommercerActRank_ResetCharge(human)
end

-- 活动结束
function CommercerActRank_End()
    
end

function ClearCache()
    COMMERCE_RANK_CACHE = {}
    COMMERCE_RANK_SERVER_KEY = nil
    COMMERCE_RANK_SERVER_RANK = nil
    COMMRCE_RANK_SERVERMAIL_HUMAN = nil
end

-- 玩家点数改变
function CommercerActRank_HumanPointChange(human, nNowPoint)
    ServerCommerceMiddle.CommerveMiddle_HumanPointChange(human, nNowPoint)
end

-- 服务器总点数改变
function onAllPointChange()
    local nNowPoint = CommonDB.GetCommerceActInfo_Point()
    ServerCommerceMiddle.CommerveMiddle_ServerPointChange(nNowPoint)
end

-- 定时请求数据
function CommercerActRank_CreateTime(nTime, nRankType, nRankSubType)
    local nNowTime = os.time()
    local nOpenTime, nEndTime = ServerCommerceManager.CommerceAct_GetOpenAndEndTime()
    if nEndTime == 0 or nEndTime < nNowTime then
        print("[CommercerActRank_CreateTime] 当前活动时间不满足条件 nEndTime = "..nEndTime.." nNowTime = "..nNowTime)
        return
    end

    Timer.addLater(nTime, CommercerActRank_QueryRankInfo, nRankType, nRankSubType)
    print("[CommercerActRank_CreateTime] 重新创建定时器成功")
end

-- 起服活动开启 请求排行榜数据
function CommercerActRank_InitServerQueryRank()
    CommercerActRank_QueryRankInfo(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, 
            CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER)

    -- 延迟20秒请求 个人排行榜
    Timer.addLater(20, CommercerActRank_QueryRankInfo,
        CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_HUMAN)
end

-- 获取到排行榜数据
function CommercerActRank_GetRankInfo(tGetData)
    local nRankType = tGetData.nRankType
    local nRankSubType = tGetData.nRankSubType
    local nServerKey = tGetData.nServerKey
    local nBegin = tGetData.nBegin
    local nEnd = tGetData.nEnd
    local tRankData = tGetData.tRankData

    print("[CommercerActRank_GetRankInfo] nRankType = "..nRankType.." nRankSubType = "..nRankSubType.." nServerKey = "..nServerKey
            .." nBegin = "..nBegin.." nEnd = "..nEnd)

    CommercerActRank_CreateCache(nRankType, nRankSubType, nServerKey)

    if COMMERCE_RANK_SERVER_KEY == nil then
        print("[CommercerActRank_GetRankInfo] 设置 nServerKey = "..nServerKey)
        COMMERCE_RANK_SERVER_KEY = nServerKey
    else
        if COMMERCE_RANK_SERVER_KEY ~= nServerKey then
            print("[CommercerActRank_GetRankInfo] 一个战区的 nServerKey 为什么会改变")
            COMMERCE_RANK_SERVER_KEY = nServerKey
        end
    end

    if nBegin == 1 then
        CommercerActRank_ClearCache(nRankType, nRankSubType, nServerKey)
    end

    local nAllLen = tRankData[0]
    if 0 < nAllLen then
        print("[CommercerActRank_GetRankInfo] 获取到排行榜数据，进行插入")
        for i = 1, nAllLen, 1 do
            CommercerActRank_InsertRank(nRankType, nRankSubType, nServerKey, tRankData[i].nRank, tRankData[i].tRankData)
        end
    end
end

-- 获取到排名信息
function CommercerActRank_GetServerRank(tData)
    COMMERCE_RANK_SERVER_RANK = tData.nRank
    if tData.nOperate == ServerCommerceDefine.COMMERCEACT_SENDSERVERMAIL then
        CommercerActRank_SendServerRankPrize(tData)
    else
        CommercerActRank_SendServerMail2Human()
    end
end

-- 发送服务器排行榜奖励
function CommercerActRank_SendServerRankPrize(tData)
    local nRank = tData.nRank
    local nNowServerPoint = CommonDB.GetCommerceActInfo_Point()
    local nMinPoint = nil
    local tPrize = nil
    for _, v in ipairs(ServerCommerceRankConf) do
        if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER then
            if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
                tPrize = v.Prize
            end

            if not nMinPoint then
                nMinPoint = v.nPoint
            else
                nMinPoint = math.min(nMinPoint, v.nPoint)
            end
        end
    end

    -- 写一次日志    
    local szLogText = "[CommercerActRank_SendServerRankPrize] 发送服务器奖励 nRank = "..nRank.." 寻宝"..Config.NEW_SVR_INDEX.."区"
    ServerCommerceManager.CommerveManager_WriteLog(szLogText)

    if not tPrize then
        szLogText = szLogText .. "获取不到对应奖励"
        ServerCommerceManager.CommerveManager_WriteLog(szLogText)
        return
    end
    
    local nSendMail = ServerCommerceManager.CommerveManager_GetCommDBSendMail()
    if 1 == nSendMail then
        szLogText = szLogText .. "当前设置过全服奖励邮件了"
        ServerCommerceManager.CommerveManager_WriteLog(szLogText)
        return
    end

    -- 设置当前发送邮件奖励
    ServerCommerceManager.CommerveManager_SetCommDBSendMail(1)

    if nNowServerPoint < nMinPoint then
        szLogText = szLogText .. "当前服务器总积分小于最小排行奖励积分直接返回 nMinPoint = "..nMinPoint.." nNowServerPoint = "..nNowServerPoint
        ServerCommerceManager.CommerveManager_WriteLog(szLogText)
    else
        -- 遍历在线玩家
        local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_SERVERMAILID]
        local title = mailConfig.title
        local senderName = mailConfig.senderName
        local content = mailConfig.content   
        for uuid, human in pairs(ObjHuman.onlineUuid) do
            local nNowHumanPoint = ServerCommerceManager.CommerceAct_GetHumanPoint(human)
            if nNowHumanPoint >= 1 then
                MailManager.add(MailManager.SYSTEM, uuid,
                                        title, Util.format(content, nRank), tPrize, senderName)
                -- 设置该玩家已经发送邮件
                ServerCommerceManager.CommerveManager_SetHumanSendServerMail(human, true)
    
                -- 记录信息
                ServerCommerceManager.CommerveManager_WriteLog(szLogText.."当前玩家发送战区排名奖励完成", human)
            end
        end

        -- 告诉中心服全服邮件在线的处理完成
        ServerCommerceMiddle.CommerceMiddle_TellServerMailOk()
        ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendServerRankPrize] 全服在线玩家邮件处理完成 向中心服发送处理个人排行榜奖励")
    end

    print("[CommercerActRank_SendServerRankPrize] 全服在线玩家邮件处理完成")
end

-- 发送玩家邮件奖励
function CommercerActRank_SendHumanRankPrize(tData)
    local nRank, uuid = tData.nRank, tData.uuid

    local tPrize = nil
    for _, v in ipairs(ServerCommerceRankConf) do
        if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_HUMAN then
            if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
                tPrize = v.Prize
                break
            end
        end
    end

    local szLogText = "[CommercerActRank_SendHumanRankPrize] 发送个人奖励 nRank = "..nRank

    if not tPrize then
        szLogText = szLogText .. "获取不到对应奖励"
        ServerCommerceManager.CommerveManager_WriteLog(szLogText)
        return
    end

    local human = ObjHuman.onlineUuid[uuid]
    local bNowSave = false
    if not human then
        human = {}
        human.db = RoleDBLogic.getDb(uuid)
        bNowSave = true
    end

    if not human then
        szLogText = szLogText.." 获取不到玩家DB数据信息 uuid = "..uuid
        ServerCommerceManager.CommerveManager_WriteLog(szLogText)
        return
    end

    -- table.print_lua_table(human.db.ServerCommerce)
    print("[CommercerActRank_SendHumanRankPrize] 下发玩家奖励 name = "..human.db.name)

    local bSendMail = ServerCommerceManager.CommerveManager_GetHumanSendPlayerMail(human)
    if true == bSendMail then
        szLogText = szLogText .. "已经发送了邮件为什么又一次走到这里 name = "..human.db.name
        ServerCommerceManager.CommerveManager_WriteLog(szLogText)
        print(szLogText)
        return
    end

    -- 设置发送了邮件奖励
    ServerCommerceManager.CommerveManager_SetHumanSendPlayerMail(human, true)

    -- 发奖励
    local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_HUMANMAILID]
    local title = mailConfig.title
    local senderName = mailConfig.senderName
    local content = mailConfig.content
    MailManager.add(MailManager.SYSTEM, uuid, 
						        title, Util.format(content, nRank), tPrize, senderName)

    -- 写日志
    szLogText = szLogText.."发送奖励成功"
    ServerCommerceManager.CommerveManager_WriteLog(szLogText, human)

    print("[CommercerActRank_SendHumanRankPrize] 发送玩家奖励结束 name = "..human.db.name.." nRank = "..nRank)

    if true == bNowSave then
        print("[CommercerActRank_SendHumanRankPrize] 发送玩家奖励结束, 玩家不在线进行存库 name = "..human.db.name.." nRank = "..nRank)
        RoleDBLogic.saveRole(human.db)
    end
end

-- 玩家登录发送玩家邮件奖励(全服邮件奖励)
function CommercerActRank_SendServerMailHumanLogin(human)
    if not COMMRCE_RANK_SERVERMAIL_HUMAN then
        COMMRCE_RANK_SERVERMAIL_HUMAN = {}
    end

    table.insert(COMMRCE_RANK_SERVERMAIL_HUMAN, human.db._id)

    -- 不存在请求一次排名
    if not COMMERCE_RANK_SERVER_RANK then
        print("[CommercerActRank_SendServerMailHumanLogin] 不存在排名直接请求")
        ServerCommerceMiddle.CommerceMiddle_QueryServerRank(ServerCommerceDefine.COMMERCEACT_GETSERVERRANK)
    else
        CommercerActRank_SendServerMail2Human()
    end
end

-- 发送活动结束后登录的的玩家(全服邮件奖励)
function CommercerActRank_SendServerMail2Human()
    if not COMMRCE_RANK_SERVERMAIL_HUMAN or not COMMERCE_RANK_SERVER_RANK then
        print("[CommercerActRank_SendServerMail2Human] 不存在对应的数据")
        return
    end

    if COMMERCE_RANK_SERVER_RANK >= CommonDefine.COMMONRANK_SAVE_DB_LEN + 1 then
        ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendServerMail2Human] 获取到的名称不正确 "..COMMERCE_RANK_SERVER_RANK.." 寻宝"..Config.NEW_SVR_INDEX.."区")
        return
    end

    local nNowServerPoint = CommonDB.GetCommerceActInfo_Point()
    local tPrize = nil
    local nMinPoint = nil
    for _, v in ipairs(ServerCommerceRankConf) do
        if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER then
            if v.nOrder[1] <= COMMERCE_RANK_SERVER_RANK and v.nOrder[2] >= COMMERCE_RANK_SERVER_RANK then
                tPrize = v.Prize
            end

            if not nMinPoint then
                nMinPoint = v.nPoint
            else
                nMinPoint = math.min(nMinPoint, v.nPoint)
            end
        end
    end

    if not tPrize then
        return
    end

    if nNowServerPoint < nMinPoint then
        print("[CommercerActRank_SendServerMail2Human] 积分不满足直接返回 nMinPoint = "..nMinPoint.." nNowServerPoint = "..nNowServerPoint)
        return
    end

    local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_SERVERMAILID]
    local title = mailConfig.title
    local senderName = mailConfig.senderName
    local content = mailConfig.content
    for _, uuid in ipairs(COMMRCE_RANK_SERVERMAIL_HUMAN) do
        
        -- 设置该玩家已经发送邮件
        local human = ObjHuman.onlineUuid[uuid]
        if not human then
            human = RoleDBLogic.getDb(uuid)
        end

        if human then
            MailManager.add(MailManager.SYSTEM, uuid,
						        title, Util.format(content, COMMERCE_RANK_SERVER_RANK), tPrize, senderName)

            -- 记录信息
            ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendServerMail2Human] 玩家登录发送全服奖励邮件完成", human)
        end
    end

    COMMRCE_RANK_SERVERMAIL_HUMAN = nil
end

-- 玩家登录活动结束发送个人排行榜邮件
function CommercerActRank_SendHumanMailHumanLogin(human)
    local tPrize, nRank = nil, 0
    for _, v in ipairs(ServerCommerceRankConf) do
        if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_HUMAN then
            if v.nOrder[1] >= nRank then
                tPrize = v.Prize
                nRank = v.nOrder[1]
            end
        end
    end

    local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_HUMANMAILID]
    local title = mailConfig.title
    local senderName = mailConfig.senderName
    local content = mailConfig.content
    
    local newcontent = string.gsub(content, "{1}", "21+")

    MailManager.add(MailManager.SYSTEM, human.db._id,
						        title, newcontent, tPrize, senderName)

    -- 写日志
    ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendHumanMailHumanLogin] 玩家登录发送邮件完成", human)
end

function CommercerActRank_GetRankServerKey(nServerKey)
    COMMERCE_RANK_SERVER_KEY = nServerKey
    print("[CommercerActRank_GetRankServerKey] 当前服务器收到战区Key nServerID = "..Config.SVR_INDEX.." nServerKey = "..COMMERCE_RANK_SERVER_KEY)
end
----------------------------------------- 客户端请求 -------------------------------------

-- 客户端请求
function CommercerActRank_Query(human, nRankSubType)
    local msgRet = Msg.gc.GC_SERVEERCOMMERCE_ACT_RANK_QUERY
    local maxSendRank = CommonDefine.COMMONRANK_SENDPRIZE_LEN
    if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
        maxSendRank = ServerCommerceDefine.COMMERCEACT_SERVER_RANKLEN
    end

    local uuid = human.db._id
    if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
        uuid = tostring(Config.NEW_SVR_INDEX)
    end

    -- print("[CommercerActRank_Query] uuid = "..uuid)

    if false == CommercerActRank_CheckCache(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, COMMERCE_RANK_SERVER_KEY) then
        CommercerActRank_CreateCache(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, COMMERCE_RANK_SERVER_KEY)
    end

    CommercerActRank_WrapOwnerData(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, msgRet.ownerData, uuid)
    if 0 == msgRet.ownerData.rankValue then
        if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
            msgRet.ownerData.rankValue = CommonDB.GetCommerceActInfo_Point()
        else
            msgRet.ownerData.rankValue = ServerCommerceManager.CommerceAct_GetHumanPoint(human)
        end
    end
	
    print("[CommercerActRank_Query] 玩家的rank = "..msgRet.ownerData.rank)

    for rank = 1, maxSendRank do
		CommercerActRank_WrapRankList(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, msgRet.list[rank], rank)
        print("[CommercerActRank_Query] 遍历的rank = "..rank.." 下发的 "..msgRet.list[rank].rank)
	end
    
	msgRet.list[0] = maxSendRank

	Msg.send(msgRet, human.fd)
end

