local addonName, ZLAUTO = ...

local ZL = ZLAUTO.mainFrame
local PlayerIsML = ZL.PlayerIsML
local pruneCrossRealm = ZL.pruneCrossRealm
local FetchDataFromItemId = ZL.FetchDataFromItemId
local TransmitAddonInfo_Pro = ZL.TransmitAddonInfo_Pro
local tableSort = ZL.tableSort
local GetClassColorName = ZL.GetClassColorName
local ParseClassColorName = ZL.ParseClassColorName
local cGetItemInfo = C_Item and C_Item.GetItemInfo or GetItemInfo
local cGetItemIcon = C_Item and C_Item.GetItemIconByID or GetItemIcon
local IsAddonMessagePrefixRegistered = C_ChatInfo and C_ChatInfo.IsAddonMessagePrefixRegistered or IsAddonMessagePrefixRegistered
local DisableAddOn = C_AddOns and C_AddOns.DisableAddOn or DisableAddOn
local SyncAuctionData = ZL.SyncAuctionData
local MyAddon = ZL.MyAddon
local LibSerialize = LibStub("LibSerialize")
local LibDeflate = LibStub("LibDeflate")
local LibFroznFunctions = LibStub:GetLibrary("LibFroznFunctions-1.0")
local CHUNK_SIZE = 2500
local DATA_MAX = 25000
local receivedChunks = {}
local receivedIndex = {}
local totalChunksExpected = {}
-- 插件启用时的函数
function MyAddon:OnEnable()
    --因API限制，每个注册的前缀10秒内最多只能发送10条插件消息，每隔1秒增加1条消息额度，只能通过细分多注册前缀
    for i = 0, 30 do
        self:RegisterComm("AUTOAUC SYNC" .. i)  --6,7,8已弃用
    end
    --同步超大数据用
    for i = 1, 30 do
        self:RegisterComm("AUTOAUC ALL" .. i)
    end
    --团队密语用
    for i = 1, 40 do
        self:RegisterComm("AUTOAUC MY" .. i)
    end

    self:RegisterComm("AUTOAUC RETAKE")--申请流拍物品重拍用
    -- self:RegisterComm("AUTOAUC SYNC") --已弃用
    -- self:RegisterComm("AUTOAUC TONGBU") --将ML数据同步给其他人，已弃用
    self:RegisterComm("AUTOAUC RESET") --初始化全员拍卖插件
    self:RegisterComm("AUTOAUC REQ") --登录或重载UI时请求同步ML数据
    self:RegisterComm("AUTOAUC PRO") --同步全局配置参数
    self:RegisterComm("AUTOAUC REVOKE") --删除指定玩家的出价
    self:RegisterComm("AUTOAUC VER") --请求检测全团是否有安装插件及插件的版本并且处理反馈回的消息(data.type=request, requestback)
    self:RegisterComm("AUTOAUC SOUND") --发送语音
    self:RegisterComm("AUTOAUC STATIS") --共享数据
    self:RegisterComm("AUTOAUC ROLES") --共享不同子账号数据
    self:RegisterComm("AUTOAUC VOTE") --切换为匿名拍卖模式投票
    self:RegisterComm("AUTOAUC BID") -- 出价通道
    self:RegisterComm("AUTOAUC ROLL") -- ROLL
    self:RegisterComm("AUTOAUC ML") --指定队伍拾取模式下拍卖人
    self:RegisterComm("AUTOAUC TALENT") --同步天赋等信息

    if not IsAddonMessagePrefixRegistered("tdInspect") then
        self:RegisterComm("tdInspect")
    end
    if not IsAddonMessagePrefixRegistered("EMUCOM") then
        self:RegisterComm("EMUCOM")
    end
end

function MyAddon:TransmitAddonInfo(prefix, data, prio)
    if IsInRaid(1) and PlayerIsML() and data then
        prio = prio or "ALERT"
        local serialized = LibSerialize:Serialize(data)
        local compressed = LibDeflate:CompressDeflate(serialized)
        local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
        -- print(Prefix(prefix .. "数据大小：" .. #encoded .. "字节"))
        -- print("TransmitAddonInfo:", prefix, "RAID")
        self:SendCommMessage(prefix, encoded, "RAID", nil, prio)
        serialized = nil
        compressed = nil
        encoded = nil
    end
end

function MyAddon:TransmitAddonInfo2(prefix, data, chatType, targetName, prio)
    if data then
        prio = prio or "ALERT"
        local serialized = LibSerialize:Serialize(data)
        local compressed = LibDeflate:CompressDeflate(serialized)
        local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
        -- print(Prefix(prefix .. "数据大小：" .. #encoded .. "字节"))
        if targetName then
            chatType = "WHISPER"
        else
            if not chatType and IsInRaid(1) then
                chatType = "RAID"
            elseif chatType == "PARTY" and (not IsInGroup(1)) then
                chatType = nil
            end
        end
        if chatType == "WHISPER" then
            -- print(format("TransmitAddonInfo2:%s，%s", prefix, chatType))
            self:SendCommMessage(prefix, encoded, chatType, targetName, prio)
        elseif chatType then
            self:SendCommMessage(prefix, encoded, chatType, nil, prio)
        end
        serialized = nil
        compressed = nil
        encoded = nil
    end
end

--发送同步当前所有数据
function MyAddon:SYNCALL(data, chatType, targetName, prio)
    if data then
        -- local msgStr
        prio = prio or "ALERT"
        local serialized = LibSerialize:Serialize(data)
        local compressed = LibDeflate:CompressDeflate(serialized)
        local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
        local dataType = data.type
        -- print(GetTime(), Prefix(dataType .. "发送数据大小：" .. #encoded .. "字节"))
        -- if #encoded > DATA_MAX then
        --     msgStr = "文件数据过大，发送失败！"
        --     ZL.Print(msgStr)
        --     return
        -- end
        local totalChunks = math.ceil(#encoded / CHUNK_SIZE) -- 计算需要多少片段
        local startByte, endByte, chunk, chunkMessage
        local i = 1
        local function tempfunc()
            if i <= totalChunks then
                -- 获取当前片段
                startByte = (i - 1) * CHUNK_SIZE + 1
                endByte = math.min(i * CHUNK_SIZE, #encoded)
                chunk = encoded:sub(startByte, endByte)
                -- 构造发送内容：包含片段编号和总片段数
                chunkMessage = string.format("%d§§%d§§%s§§%s", i, totalChunks, dataType, chunk) --新版本格式
                -- print(string.format("%d§§%d§§%s§§%d", i, totalChunks, dataType, #chunk))
                -- 发送消息
                if not chatType and IsInRaid(1) then
                    chatType = "RAID"
                elseif chatType == "PRATY" and (not IsInGroup(1)) then
                    chatType = nil
                end
                -- print("SYNCALL:", "AUTOAUC ALL", chatType)
                if chatType == "WHISPER" then
                    if targetName then
                        self:SendCommMessage("AUTOAUC ALL" .. i, chunkMessage, chatType, targetName, prio)
                    end
                elseif chatType then
                    self:SendCommMessage("AUTOAUC ALL" .. i, chunkMessage, chatType, nil, prio)
                end
                i = i + 1
                C_Timer.After(0.2, tempfunc)
            else
                serialized = nil
                compressed = nil
                encoded = nil
                startByte = nil
                endByte = nil
                chunk = nil
                chunkMessage = nil
            end
        end
        tempfunc()
    end
end
function MyAddon:OnCommReceived(prefix, payload, chatType, sender)
    -- print("接收到信息：", prefix, sender, chatType)
    local AuctionFrame = ZL.AuctionFrame2
    local fullName = ZL.GetFullName(sender)
    local fullColorName = ZL.GetClassColorName(fullName)
    local pruneName = pruneCrossRealm(sender)
    receivedIndex[pruneName] = receivedIndex[pruneName] or {}
    receivedChunks[pruneName] = receivedChunks[pruneName] or {}
    if prefix:match("^AUTOAUC ALL%d+$") then
        --接收当前所有拍卖数据
        -- 解析片段编号、总片段数和实际数据
        local chunkIndex, totalChunks, dataType, chunkData, completeData
        chunkIndex, totalChunks, dataType, chunkData = payload:match("^(%d+)§§(%d+)§§(.-)§§(.+)$")
        if chunkIndex and totalChunks and dataType and chunkData then
            chunkIndex = tonumber(chunkIndex)
            totalChunks = tonumber(totalChunks)
            -- print("新版本接收数据：" .. chunkIndex .. "/" .. totalChunks, pruneName, dataType, #chunkData)
            receivedChunks[pruneName][dataType] = receivedChunks[pruneName][dataType] or {}
            receivedChunks[pruneName][dataType].totalChunks = receivedChunks[pruneName][dataType].totalChunks or totalChunks
            receivedChunks[pruneName][dataType].chunkIndex = receivedChunks[pruneName][dataType].chunkIndex or {}
            receivedChunks[pruneName][dataType].chunks = receivedChunks[pruneName][dataType].chunks or {}
            -- 保存片段
            local isExist
            for _, value in ipairs(receivedChunks[pruneName][dataType].chunkIndex) do
                if value == chunkIndex then
                    isExist = true
                    break
                end
            end
            if not isExist then
                table.insert(receivedChunks[pruneName][dataType].chunkIndex, chunkIndex)
            end
            receivedChunks[pruneName][dataType].chunks[chunkIndex] = chunkData
            if #receivedChunks[pruneName][dataType].chunkIndex == receivedChunks[pruneName][dataType].totalChunks then
                -- 所有片段已接收，开始重组
                completeData = table.concat(receivedChunks[pruneName][dataType].chunks)
                -- print(GetTime(), Prefix("新版本接收数据大小：" .. #completeData .. "字节"))
            end
        else
            chunkIndex, totalChunks, chunkData = payload:match("^(%d+):(%d+):(.+)$")
            chunkIndex = tonumber(chunkIndex)
            totalChunks = tonumber(totalChunks)
            -- print("老版本接收数据：" .. chunkIndex .. "/" .. totalChunks, pruneName)
            -- 如果是第一次接收到片段，记录总片段数
            if not totalChunksExpected[pruneName] then
                totalChunksExpected[pruneName] = totalChunks
            end
            -- 保存片段
            local isExist
            for _, value in ipairs(receivedIndex[pruneName]) do
                if value == chunkIndex then
                    isExist = true
                    break
                end
            end
            if not isExist then
                table.insert(receivedIndex[pruneName], chunkIndex)
            end
            receivedChunks[pruneName][chunkIndex] = chunkData
            if #receivedIndex[pruneName] == totalChunksExpected[pruneName] then
                -- 所有片段已接收，开始重组
                completeData = table.concat(receivedChunks[pruneName])
                -- print(GetTime(), Prefix("老版本接收数据大小：" .. #completeData .. "字节"))
            end
        end
        if completeData then
            -- 解码、解压缩、反序列化
            local decodedData = LibDeflate:DecodeForWoWAddonChannel(completeData)
            local decompressedData = LibDeflate:DecompressDeflate(decodedData)
            local success, myReceivedData = LibSerialize:Deserialize(decompressedData)
            if success then
                local msgStr
                if myReceivedData.type == "all" then --全部同步
                    if PlayerIsML(pruneName) then
                        if PlayerIsML() then
                            ZL.Print("数据同步完成！")
                        end
                        ZL_CURRENT = myReceivedData.data
                        ZL.AuctionListSort()
                        ZL.syncAll = nil
                    end
                elseif myReceivedData.type == "bathFailed" then --批量流拍
                    if PlayerIsML(pruneName) then
                        AuctionFrame.piLiangBtn:Enable()
                        local fdata = myReceivedData.data
                        local msglist = {}
                        local data
                        for _, _data in ipairs(fdata) do
                            local _, index = FetchDataFromItemId(_data.itemlink, _data.itemindex)
                            if index then
                                data = ZL_CURRENT.auctionlist[index]
                                data.state = "failed"
                                data.endTime = nil
                                data.isPaused = nil
                                data.bidderlist = {}
                                data.tradeId = nil
                                if data.itemCount == 1 then
                                    table.insert(msglist, data.itemlink .. "(" .. data.startbidamount .. ")")
                                else
                                    table.insert(msglist, data.itemlink .. "(" .. data.startbidamount .. "x" .. data.itemCount .. ")")
                                end
                            end
                        end
                        data = nil
                        msgStr = "有批量流拍物品，请注意查看团队信息\n如有需要的，请联系" .. fullColorName .. "重拍"
                        ZL.Print(msgStr)
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            C_VoiceChat.StopSpeakingText()
                            local soundName = "piliangliupai.mp3"
                            PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                        end
                        AuctionFrame:Update()
                        if PlayerIsML() then
                            msgStr = "{rt6}批量流拍物品如下{rt6}"
                            SendChatMessage(msgStr, "RAID")
                            C_Timer.After(0.3, function ()
                                for _, itemlink in ipairs(msglist) do
                                    SendChatMessage(itemlink, "RAID")
                                end
                                C_Timer.After(0.3, function ()
                                    msgStr = "{rt6}以上物品已批量流拍，如有需要的请联系我重拍{rt6}"
                                    SendChatMessage(msgStr, "RAID")
                                end)
                            end)
                            ZL.syncAll = nil
                        end
                        if ZL.DisenchantingFrame and (not ZL.DisenchantingFrame.hasSpellcastSucceeded) and ZL.DisenchantingFrame:IsShown() then
                            ZL.DisenchantingFrame:Update()
                        end
                    end
                elseif myReceivedData.type == "bathStart" then --批量拍卖
                    if PlayerIsML(pruneName) then
                        local startTime = time()
                        AuctionFrame.piLiangBtn:Enable()
                        ZL_CURRENT.globalConfig = myReceivedData.globalConfigData
                        ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
                        local msglist = {}
                        for _, _data in ipairs(myReceivedData.data) do
                            local index = SyncAuctionData(_data)
                            local data = ZL_CURRENT.auctionlist[index]
                            local bidIncrement = data.bidIncrement
                            local startbidamount = data.startbidamount
                            bidIncrement = ZL.GetDiffrentIncrementBid(startbidamount, bidIncrement)
                            data.tradeId = nil
                            data.startbidamount = startbidamount
                            data.bidIncrement = bidIncrement
                            data.endTime = startTime + ZL_CURRENT.globalConfig.auctionTimer
                            data.state = "auctioning"
                            data.isPaused = nil
                            data.bidderlist = {}
                            if data.itemCount == 1 then
                                table.insert(msglist, data.itemlink .. "，起拍价：" .. data.startbidamount)
                            else
                                table.insert(msglist, data.itemlink .. "x" .. data.itemCount .. "，起拍价：" .. data.startbidamount)
                            end
                        end
                        if not ZL.AuctionFrame2:IsShown() and ZL.opt.autoShowAuctionFrame then
                            ZL.AuctionFrame2:Show()
                        end
                        _G["ZL_NewAuctionFrameTab1"]:Click()
                        AuctionFrame:Update()
                        msgStr = "有批量拍卖物品，请注意及时出价"
                        ZL.Print(msgStr)
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            ZL.SpeakText(msgStr)
                        end
                        if PlayerIsML() then
                            msgStr = "{rt1}批量开始拍卖物品如下{rt1}"
                            SendChatMessage(msgStr, "RAID")
                            C_Timer.After(0.3, function ()
                                for _, itemlink in ipairs(msglist) do
                                    SendChatMessage(itemlink, "RAID")
                                end
                                C_Timer.After(0.3, function ()
                                    msgStr = "{rt1}以上物品已批量拍卖，有需要的及时出价{rt1}"
                                    SendChatMessage(msgStr, "RAID")
                                end)
                            end)
                            ZL.syncAll = nil
                        end
                        ZL.miniMapIconAnimation()
                    end
                elseif myReceivedData.type == "bathStop" then --批量取消
                    if PlayerIsML(pruneName) then
                        AuctionFrame.piLiangBtn:Enable()
                        local fdata = myReceivedData.data
                        local Frame1, curAuction
                        for _, _data in ipairs(fdata) do
                            local _, index = FetchDataFromItemId(_data.itemlink, _data.itemindex)
                            if index then
                                Frame1 = AuctionFrame.entries[index]
                                if Frame1.countDownTimer then
                                    Frame1.countDownTimer:Cancel()
                                    Frame1.countDownTimer = nil
                                end
                                curAuction = ZL_CURRENT.auctionlist[index]
                                curAuction.confirmBid = nil
                                curAuction.canUseConfirgBid = nil
                                curAuction.index = nil
                                curAuction.endTime = nil
                                curAuction.state = "waiting"
                                curAuction.isPaused = nil
                                curAuction.bidderlist = {}
                            end
                        end
                        ZL.AuctionListSort()
                        msgStr = "注意：已取消本次所有拍卖！"
                        ZL.Print(msgStr)
                        if PlayerIsML() then
                            SendChatMessage(msgStr, "RAID")
                            ZL.syncAll = nil
                        end
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            ZL.SpeakText(msgStr)
                        end
                    end
                    ZL.miniMapIconAnimation()
                elseif myReceivedData.type == "bathPause" then --批量暂停
                    if PlayerIsML(pruneName) then
                        AuctionFrame.piLiangBtn:Enable()
                        local fdata = myReceivedData.data
                        for _, _data in ipairs(fdata) do
                            local _, index = FetchDataFromItemId(_data.itemlink, _data.itemindex)
                            if index then
                                ZL_CURRENT.auctionlist[index].isPaused = true
                            end
                        end
                        ZL.AuctionListSort()
                        msgStr = "注意：已暂停所有拍卖！"
                        ZL.Print(msgStr)
                        if PlayerIsML() then
                            SendChatMessage(msgStr, "RAID")
                            ZL.syncAll = nil
                        end
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            ZL.SpeakText(msgStr)
                        end
                    end
                elseif myReceivedData.type == "bathContinue" then --批量继续
                    if PlayerIsML(pruneName) then
                        AuctionFrame.piLiangBtn:Enable()
                        local fdata = myReceivedData.data
                        for _, _data in ipairs(fdata) do
                            local _, index = FetchDataFromItemId(_data.itemlink, _data.itemindex)
                            if index then
                                ZL_CURRENT.auctionlist[index].isPaused = nil
                            end
                        end
                        ZL.AuctionListSort()
                        msgStr = "注意：已恢复拍卖, 请注意及时出价！"
                        ZL.Print(msgStr)
                        if PlayerIsML() then
                            SendChatMessage(msgStr, "RAID")
                            ZL.syncAll = nil
                        end
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            ZL.SpeakText(msgStr)
                        end
                    end
                elseif myReceivedData.type == "auctioning" then --同步拍卖中物品
                    if PlayerIsML(pruneName) and (not PlayerIsML()) then
                        ZL_CURRENT.globalConfig = myReceivedData.globalConfigData
                        ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
                        local fdata = myReceivedData.data2
                        if #fdata > 0 then
                            for _, _data in ipairs(fdata) do
                                if (_data.endTime or 0) - 1 > time() then
                                    SyncAuctionData(_data)
                                end
                            end
                            ZL.AuctionListSort()
                            ZL.Print("已同步|cff87CEEB拍卖中|r的物品。", true)
                        else
                            -- ZL.Print("没有正在拍卖的物品。", true)
                        end
                        ZL.miniMapIconAnimation()
                    end
                elseif myReceivedData.type == "remainAll" then
                    if PlayerIsML(pruneName) and (not PlayerIsML()) then
                        local fdata = myReceivedData.data2
                        --检测拍卖中的物品是否已经过时，已过时的剔除掉
                        for i = #fdata.auctionlist, 1, -1 do
                            local data = fdata.auctionlist[i]
                            if data.state == "auctioning" then
                                if (data.endTime or 0) - 1 <= time() then
                                    tremove(fdata.auctionlist, i)
                                end
                            end
                        end
                        --将本身有的拍卖物品更新到传送来的数据中
                        if ZL_CURRENT["auctionlist"] then
                            for _, data in ipairs(ZL_CURRENT["auctionlist"]) do
                                for index, _data in ipairs(fdata.auctionlist) do
                                    if (_data.itemlink == data.itemlink) and (_data.itemindex == data.itemindex) then
                                        fdata.auctionlist[index] = data
                                        break
                                    end
                                end
                            end
                        end
                        ZL_CURRENT = fdata
                        ZL.AuctionListSort()
                        ZL.Print("已同步全部拍卖数据。")
                        ZL.miniMapIconAnimation()
                    end
                elseif myReceivedData.type == "statistics" then --加到同步数据里
                    if PlayerIsML(sender) then
                        if (not PlayerIsML()) then
                            ZL_CURRENT = myReceivedData.data
                        else
                            ZL.billMsg = true
                        end
                        --保存对账单
                        if ZL_CURRENT.IncomeList and (#ZL_CURRENT.IncomeList > 0) then
                            local zhangDan = {}
                            local total = 0
                            local itemLink
                            local itemStr = "|c.-|Hitem:.+|h%[.-%]|h|r"
                            for _, data in ipairs(ZL_CURRENT.IncomeList) do
                                itemLink = data.notes
                                if itemLink:match(itemStr) then
                                    total = total + data.amount
                                    if not zhangDan.zhangDan then zhangDan.zhangDan = {} end
                                    if not zhangDan.zhangDan[itemLink] then zhangDan.zhangDan[itemLink] = {counts=0, totalAmount=0} end
                                    zhangDan.zhangDan[itemLink].counts = zhangDan.zhangDan[itemLink].counts + data.itemCount
                                    zhangDan.zhangDan[itemLink].totalAmount = zhangDan.zhangDan[itemLink].totalAmount + data.amount
                                end
                            end
                            if total > 0 then
                                zhangDan.type = "AutoAuction"
                                zhangDan.totalAmount = total
                                zhangDan.player = fullColorName
                                zhangDan.time = date("%Y-%m-%d %H:%M:%S", time())
                                ZL_PLAYERLIST.zhangDan = zhangDan
                                zhangDan = nil
                            end
                        end
                    end
                end
            else
                if PlayerIsML() then
                    local msgStr = "数据同步失败，可能是插件通信受限制，请稍后重试！"
                    ZL.Print(msgStr, true)
                end
            end
            -- 清空存储的片段，准备下一次接收
            if dataType then
                receivedChunks[pruneName][dataType] = nil
            else
                receivedIndex[pruneName] = {}
                receivedChunks[pruneName] = {}
                totalChunksExpected[pruneName] = nil
            end
        end
    else
        local tryCounts = 0
        local success, fdata
        local function Deserialize()
            tryCounts = tryCounts + 1
            local isSuccessed = true
            local decoded = LibDeflate:DecodeForWoWAddonChannel(payload)
            if (not decoded) then
                isSuccessed = false
            end
            local decompressed = LibDeflate:DecompressDeflate(decoded)
            if (not decompressed) then
                isSuccessed = false
            end
            success, fdata = LibSerialize:Deserialize(decompressed)
            if (not success) then
                isSuccessed = false
            end
            if isSuccessed then
                return
            end
            if tryCounts >= 10 then
                return
            end
            C_Timer.After(0.3, Deserialize)
        end
        Deserialize()
        if (not success) then return end
        if (prefix == "AUTOAUC SYNC0") then--拾取创建
            if (PlayerIsML(pruneName)) then
                ZL_CURRENT.globalConfig = fdata.globalConfigData
                ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
                for _, data3 in ipairs(fdata.data) do
                    if (not PlayerIsML()) then
                        SyncAuctionData(data3.data2)
                    end
                    if data3.type == "创建拍卖" and ZL.opt.autoPackage and data3.data2.bindType ~= 1 and PlayerIsML() then
                        local _, index = FetchDataFromItemId(data3.data2.itemlink, data3.data2.itemindex)
                        --自动添加到打包拍卖
                        ZL.packageAuction(index)
                    end
                end
                if not PlayerIsML() then
                    ZL.AuctionListSort()
                else
                    if ZL.opt.bathStartAuctionNotice then
                        C_Timer.After(2, function ()
                            StaticPopup_Show("ZL_BATHSTARTAUCTIONNOTICE")
                        end)
                    end
                end
            end
        elseif (prefix == "AUTOAUC SYNC1") then--开始拍卖
            local startTime = time()
            ZL_CURRENT.globalConfig = fdata.globalConfigData
            ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
            local isRestart = fdata.isRestart
            local tradeId = fdata.tradeId
            local quickFailed = fdata.quickFailed
            if isRestart == "success" and tradeId and ZL_CURRENT.IncomeList and #ZL_CURRENT.IncomeList > 0 then
                for i = #ZL_CURRENT.IncomeList, 1, -1 do
                    local _tradeId = ZL_CURRENT.IncomeList[i].tradeId
                    if _tradeId and _tradeId == tradeId then
                        table.remove(ZL_CURRENT.IncomeList, i)
                    end
                end
                if ZL.AuctionRecordFrame.currentIncomeFrame:IsShown() then
                    ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                end
            end
            local index = SyncAuctionData(fdata.data2)
            local curAuctionList = ZL_CURRENT.auctionlist[index]
            local itemLink = curAuctionList.itemlink
            local itemId = curAuctionList.itemId
            local bindType = curAuctionList.bindType
            local msgStr = ""
            AuctionFrame.entries[index].sync = nil
            if isRestart == "success" and curAuctionList["spawnUID"] and next(curAuctionList["spawnUID"], nil) then
                for _, value in pairs(curAuctionList["spawnUID"]) do
                    value["successBidder"] = nil
                    if value["itemGUID"] and next(value["itemGUID"], nil) then
                        for _, value2 in pairs(value["itemGUID"]) do
                            value2["isUsed"] = nil
                        end
                    end
                end
            end
            local bidIncrement = curAuctionList.bidIncrement
            local startbidamount = curAuctionList.startbidamount
            bidIncrement = ZL.GetDiffrentIncrementBid(startbidamount, bidIncrement)
            curAuctionList.tradeId = nil
            curAuctionList.bidIncrement = bidIncrement
            if quickFailed and (curAuctionList.state == "waiting" or curAuctionList.state == "success"
            or (curAuctionList.state == "failed" and #curAuctionList.bidderlist > 0) ) then
                curAuctionList.endTime = startTime + 1
            else
                curAuctionList.endTime = startTime + ZL_CURRENT.globalConfig.auctionTimer
            end
            curAuctionList.state = "auctioning"
            curAuctionList.isPaused = nil
            if isRestart == "success" then
                curAuctionList.bidderlist = {}
            end
            local selectCharKey = ZL.GetClassColorName() .. " - " .. GetRealmName()
            local modeMsg
            if ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                modeMsg = "，插件匿名模式"
            elseif ZL_CURRENT.globalConfig.auctionMode == "|cff00ff00明拍|r" then
                modeMsg = "，插件明拍模式"
            elseif ZL_CURRENT.globalConfig.auctionMode == "团队" then
                modeMsg = "，团队拍卖模式，直接团队出价"
            end
            local countdownremaining = (curAuctionList.endTime or 0) - time()
            local bidderlist = curAuctionList.bidderlist
            if countdownremaining > 1 then
                if curAuctionList.itemCount == 1 then
                    if bindType == 2 then
                        if #bidderlist > 0 then
                            if ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                                msgStr = ("开始拍卖装绑%s，当前出价：%s(%d)"):format(curAuctionList.itemlink, "匿名", bidderlist[1].bidamount)
                            else
                                msgStr = ("开始拍卖装绑%s，当前出价：%s(%d)"):format(curAuctionList.itemlink, ParseClassColorName(bidderlist[1].bidder), bidderlist[1].bidamount)
                            end
                            if not ZL.opt.conciseSound and modeMsg then
                                msgStr = msgStr .. modeMsg
                            end
                        else
                            if ZL.opt.conciseSound then
                                msgStr = ("装绑%s起拍价：%d"):format(curAuctionList.itemlink, startbidamount)
                            else
                                msgStr = ("装绑%s起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, startbidamount, bidIncrement)
                                if modeMsg then msgStr = msgStr .. modeMsg end
                            end
                        end
                    else
                        if curAuctionList.itemlink == "[打包拍卖]" then
                            local itemList = curAuctionList["itemList"]
                            if itemList and next(itemList, nil) then
                                msgStr = "打包拍卖清单："
                                ZL.Print(msgStr)
                                if PlayerIsML() then
                                    SendChatMessage(msgStr, ZL.MsgChannel())
                                end
                                C_Timer.After(0.3, function ()
                                    for _itemlink, data in pairs(itemList) do
                                        msgStr = _itemlink .. "x" .. data.itemCount
                                        ZL.Print(msgStr)
                                        if PlayerIsML() then
                                            SendChatMessage(msgStr, ZL.MsgChannel())
                                        end
                                    end
                                    C_Timer.After(0.3, function ()
                                        if ZL.opt.conciseSound then
                                            msgStr = ("以上%s，起拍价：%d"):format(curAuctionList.itemlink, startbidamount)
                                        else
                                            msgStr = ("以上%s，起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, startbidamount, bidIncrement)
                                            if modeMsg then msgStr = msgStr .. modeMsg end
                                        end
                                        ZL.ScrollingMessageFrame:AddMessage(msgStr)
                                        if PlayerIsML() then
                                            SendChatMessage(msgStr, ZL.MsgChannel())
                                        end
                                    end)
                                end)
                            end
                        else
                            if #bidderlist > 0 then
                                if ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                                    msgStr = ("开始拍卖%s，当前出价：%s(%d)"):format(
                                        curAuctionList.itemlink, "匿名", bidderlist[1].bidamount
                                    )
                                else
                                    msgStr = ("开始拍卖%s，当前出价：%s(%d)"):format(
                                        curAuctionList.itemlink, ParseClassColorName(bidderlist[1].bidder), bidderlist[1].bidamount
                                    )
                                end
                                if not ZL.opt.conciseSound and modeMsg then
                                    msgStr = msgStr .. modeMsg
                                end
                            else
                                if ZL.opt.conciseSound then
                                    msgStr = ("%s起拍价：%d"):format(curAuctionList.itemlink, startbidamount)
                                else
                                    msgStr = ("%s起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, startbidamount, bidIncrement)
                                    if modeMsg then msgStr = msgStr .. modeMsg end
                                end
                            end
                        end
                    end
                else
                    if bindType == 2 then
                        if #bidderlist > 0 then
                            if ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                                msgStr = ("开始拍卖装绑%sx%d，当前出价：%s(%dx%d)"):format(
                                    curAuctionList.itemlink, curAuctionList.itemCount, "匿名",
                                    bidderlist[1].bidamount, bidderlist[1].bidCount
                                )
                            else
                                msgStr = ("开始拍卖装绑%sx%d，当前出价：%s(%dx%d)"):format(
                                    curAuctionList.itemlink, curAuctionList.itemCount, ParseClassColorName(bidderlist[1].bidder),
                                    bidderlist[1].bidamount, bidderlist[1].bidCount
                                )
                            end
                            if not ZL.opt.conciseSound and modeMsg then
                                msgStr = msgStr .. modeMsg
                            end
                        else
                            if ZL.opt.conciseSound then
                                msgStr = ("装绑%sx%d，起拍价：%d"):format(curAuctionList.itemlink, curAuctionList.itemCount, startbidamount)
                            else
                                msgStr = ("装绑%sx%d，起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, curAuctionList.itemCount, startbidamount, bidIncrement)
                                if modeMsg then msgStr = msgStr .. modeMsg end
                            end
                        end
                    else
                        if #bidderlist > 0 then
                            if ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                                msgStr = ("开始拍卖%sx%d，当前出价：%s(%dx%d)"):format(
                                    curAuctionList.itemlink, curAuctionList.itemCount, "匿名",
                                    bidderlist[1].bidamount, bidderlist[1].bidCount
                                )
                            else
                                msgStr = ("开始拍卖%sx%d，当前出价：%s(%dx%d)"):format(
                                    curAuctionList.itemlink, curAuctionList.itemCount, ParseClassColorName(bidderlist[1].bidder),
                                    bidderlist[1].bidamount, bidderlist[1].bidCount
                                )
                            end
                            if not ZL.opt.conciseSound and modeMsg then
                                msgStr = msgStr .. modeMsg
                            end
                        else
                            if ZL.opt.conciseSound then
                                msgStr = ("%sx%d，起拍价：%d"):format(curAuctionList.itemlink, curAuctionList.itemCount, startbidamount)
                            else
                                msgStr = ("%sx%d，起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, curAuctionList.itemCount, startbidamount, bidIncrement)
                                if modeMsg then msgStr = msgStr .. modeMsg end
                            end
                        end
                    end
                end
                if curAuctionList.itemlink ~= "[打包拍卖]" then
                    ZL.Print(msgStr)
                    if PlayerIsML() then
                        SendChatMessage(msgStr, ZL.MsgChannel())
                    end
                end
                if ZL.opt.concernList and ZL.opt.concernList[selectCharKey]
                and ZL.opt.concernList[selectCharKey]["itemList"][itemId] and select(4, ZL.GetItemNumbers(itemId)) == 0 then
                    local targetAmount
                    if type(ZL.opt.concernList[selectCharKey]["itemList"][itemId]) == "number" then
                        targetAmount = ZL.opt.concernList[selectCharKey]["itemList"][itemId]
                    end
                    local data = {index=index, f=ZL.AuctionFrame2.entries[index], targetAmount = targetAmount}
                    StaticPopup_Show("ZL_AUTOBID", curAuctionList.itemlink, nil, data)
                end
            end
            AuctionFrame.entries[index].MLframe.functionFrame.CancelBtn:Enable()
            if (not PlayerIsML()) or (PlayerIsML() and (not ZL_CURRENT.globalConfig.allowMultipleAuctions)) then
                if not ZL.AuctionFrame2:IsShown() and ZL.opt.autoShowAuctionFrame then
                    ZL.AuctionFrame2:Show()
                end
                _G["ZL_NewAuctionFrameTab1"]:Click()
            else
                ZL.AuctionListSort()
            end
            if countdownremaining > 1 then
                ZL.miniMapIconAnimation()
                local soundName = ""
                if ZL.opt.concernList and ZL.opt.concernList[selectCharKey]
                and ZL.opt.concernList[selectCharKey]["itemList"][itemId] and select(4, ZL.GetItemNumbers(itemId)) == 0 then
                    if not ZL.AuctionFrame2:IsShown() then
                        ZL.AuctionFrame2:Show()
                        _G["ZL_NewAuctionFrameTab1"]:Click()
                    end
                    C_VoiceChat.StopSpeakingText()
                    soundName = "guanzhuwupinpaimai.mp3"
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                else
                    if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) and countdownremaining > 2 then
                        if ZL.opt.startAuctionSound then
                            local function linshi()
                                if ZL.opt.conciseSound then
                                    if itemLink == "[打包拍卖]" then itemLink = string.gsub(itemLink, "[%[%]]", "") end
                                    soundName = "开始拍卖：" .. itemLink
                                else
                                    soundName = "开始拍卖" .. ZL.GetAuctionSoundText(itemLink)
                                end
                                ZL.SpeakText(soundName)
                            end
                            if itemId ~= 0 then
                                ZL.LoadItemDataByID(itemId, linshi) --先缓存物品信息
                            else
                                linshi()
                            end
                        else
                            C_VoiceChat.StopSpeakingText()
                            soundName = "kaishipaimai.mp3"
                            PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                        end
                    end
                end
            end
        elseif (prefix == "AUTOAUC SYNC2") then--取消拍卖
            local _, index = FetchDataFromItemId(fdata.data2.itemlink, fdata.data2.itemindex)
            if index then
                local data = ZL_CURRENT.auctionlist[index]
                local Frame1 = AuctionFrame.entries[index]
                Frame1.sync = nil
                if Frame1.countDownTimer then
                    if not Frame1.countDownTimer:IsCancelled() then
                        Frame1.countDownTimer:Cancel()
                    end
                    Frame1.countDownTimer = nil
                end
                data.confirmBid = nil
                data.canUseConfirgBid = nil
                data.endTime = nil
                data.state = "waiting"
                data.isPaused = nil
                data.bidderlist = {}
                if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                    C_VoiceChat.StopSpeakingText()
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\paimaiyiquxiao.mp3", "Master")
                end
                local msgStr
                if data.bindType == 2 then
                    msgStr = ("装绑%s拍卖已取消，本次拍卖无效"):format(data.itemlink)
                else
                    msgStr = ("%s拍卖已取消，本次拍卖无效"):format(data.itemlink)
                end
                ZL.Print(msgStr)
                if PlayerIsML() then
                    AuctionFrame.entries[index].MLframe.functionFrame.CancelBtn:Enable()
                    SendChatMessage(msgStr, ZL.MsgChannel())
                    if not ZL_CURRENT.globalConfig.allowMultipleAuctions then
                        _G["ZL_NewAuctionFrameTab5"]:Click()
                    else
                        ZL.AuctionListSort()
                    end
                else
                    ZL.AuctionListSort()
                end
                ZL.miniMapIconAnimation()
            end
        elseif (prefix == "AUTOAUC SYNC3") or (prefix == "AUTOAUC SYNC4") or (prefix == "AUTOAUC SYNC5") then
            --3暂停拍卖/继续拍卖，4竞拍信息，5手动倒数/取消倒数
            local _, index = FetchDataFromItemId(fdata.data2.itemlink, fdata.data2.itemindex)
            if index then
                local resetAuctionTimeTimer = fdata.resetAuctionTimeTimer
                local msgStr = ""
                local Frame1 = AuctionFrame.entries[index]
                local curAuctionList = ZL_CURRENT.auctionlist[index]
                Frame1.sync = nil
                if fdata.type == "取消倒数" and (time() - resetAuctionTimeTimer >= 0) and (not curAuctionList.isPaused) then
                    if PlayerIsML() then
                        Frame1.MLframe.functionFrame.CountDownBtn:Enable()
                        msgStr = "重置倒计时超时，如需要可重拍。"
                        ZL.Print(msgStr)
                    end
                    return
                end

                local itemLink = curAuctionList.itemlink
                local soundName
                if fdata.type == "暂停拍卖" then
                    curAuctionList.isPaused = true
                    curAuctionList.pausedTime = time()
                    msgStr = itemLink .. "拍卖已暂停！"
                    soundName = "paimaiyizanting.mp3"
                    AuctionFrame.entries[index].MLframe.functionFrame.CancelBtn:Enable()
                elseif fdata.type == "继续拍卖" then
                    curAuctionList.endTime = curAuctionList.endTime + time() - curAuctionList.pausedTime
                    curAuctionList.pausedTime = nil
                    curAuctionList.isPaused = nil
                    local bidderlist = curAuctionList.bidderlist
                    tableSort(bidderlist)
                    local _, _, newBid, bidCount = ZL.GetNewBidAmount(index)
                    if #bidderlist > 0 then
                        local totalBidCount = 0
                        for _, bidData in ipairs(bidderlist) do
                            if totalBidCount < curAuctionList.itemCount then
                                local count = bidData["bidCount"] or 1
                                local newTotalBidCount = totalBidCount + count
                                if newTotalBidCount > curAuctionList.itemCount then
                                    count = curAuctionList.itemCount - totalBidCount
                                end
                                if ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                                    if count  > 1 then
                                        msgStr = msgStr .. "匿名(" .. bidData.bidamount .. "x" .. count .. ")，"
                                    else
                                        msgStr = msgStr .. "匿名(" .. bidData.bidamount .. ")，"
                                    end
                                else
                                    if count  > 1 then
                                        msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. "x" .. count .. ")，"
                                    else
                                        msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. ")，"
                                    end
                                end
                                totalBidCount = newTotalBidCount
                            else
                                break
                            end
                        end
                        if curAuctionList.itemCount > 1 then
                            msgStr = ("%s拍卖已恢复，有效出价：%s下次最低出价：%d，对应最大竞拍数量：%d"):format(
                                itemLink, msgStr, newBid, bidCount
                            )
                        else
                            msgStr = ("%s拍卖已恢复，有效出价：%s下次最低出价：%d"):format(
                                itemLink, msgStr, newBid
                            )
                        end
                    else
                        if curAuctionList.itemCount > 1 then
                            msgStr = ("%s拍卖已恢复，当前无人出价，下次最低出价：%d，对应最大竞拍数量：%d"):format(itemLink, newBid, bidCount)
                        else
                            msgStr = ("%s拍卖已恢复，当前无人出价，下次最低出价：%d"):format(itemLink, newBid)
                        end
                    end
                    soundName = "paimaiyihuifu.mp3"
                    AuctionFrame.entries[index].MLframe.functionFrame.CancelBtn:Enable()
                elseif fdata.type == "竞拍信息" then
                    AuctionFrame.entries[index].MLframe.functionFrame.syncBtn:Enable()
                    local itemCount = curAuctionList.itemCount
                    local bidderlist = curAuctionList.bidderlist
                    local _, _, tarbidamount, bidCount = ZL.GetNewBidAmount(index)
                    if #bidderlist > 0 and ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                        msgStr = curAuctionList.itemlink .. "即将倒数，请及时确认是否还需要竞价！"
                        if curAuctionList.itemlink == "[打包拍卖]" then
                            soundName = string.gsub(msgStr, "[%[%]]", "")
                        else
                            soundName = msgStr
                        end
                    else
                        if #bidderlist > 0 then
                            local totalBidCount = 0
                            for _, bidData in ipairs(bidderlist) do
                                if totalBidCount < itemCount then
                                    local count = bidData["bidCount"] or 1
                                    local newTotalBidCount = totalBidCount + count
                                    if newTotalBidCount > itemCount then
                                        count = itemCount - totalBidCount
                                    end
                                    if count  > 1 then
                                        msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. tostring(bidData.bidamount) .. "×" .. count .. ")，"
                                    else
                                        msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. ")，"
                                    end
                                    totalBidCount = newTotalBidCount
                                else
                                    break
                                end
                            end
                            if itemCount == 1 then
                                msgStr = ("%s当前出价：%s下次最低出价：%d，不要就打P"):format(curAuctionList.itemlink, msgStr, tarbidamount)
                            else
                                msgStr = ("%s当前出价：%s下次最低出价：%d，对应最大数量%d，不要就打P"):format(curAuctionList.itemlink, msgStr, tarbidamount, bidCount)
                            end
                        else
                            if itemCount == 1 then
                                msgStr = ("%s当前无人出价，下次最低出价：%d"):format(curAuctionList.itemlink, tarbidamount)
                            else
                                msgStr = ("%s当前无人出价，下次最低出价：%d，对应最大数量%d"):format(curAuctionList.itemlink, tarbidamount, bidCount)
                            end
                        end
                        if curAuctionList.itemlink == "[打包拍卖]" then
                            soundName = string.gsub(msgStr, "[%[%]]", "")
                        else
                            soundName = msgStr
                        end
                        soundName = string.gsub(soundName, "丶", ""):gsub("丨", ""):gsub("卍", ""):gsub("乄", ""):gsub("×", "乘")
                        if ZL.opt.conciseSound then
                            soundName = curAuctionList.itemlink .. "马上倒数，有需要的尽快出价！"
                            if curAuctionList.itemlink == "[打包拍卖]" then
                                soundName = string.gsub(soundName, "[%[%]]", "")
                            end
                        end
                        soundName = "拍卖提醒：" .. soundName
                    end
                elseif fdata.type == "手动倒数" then
                    if Frame1.countDownTimer then
                        if not Frame1.countDownTimer:IsCancelled() then
                            Frame1.countDownTimer:Cancel()
                        end
                        Frame1.countDownTimer = nil
                    end
                    local startTime = time()
                    local bidderlist = curAuctionList.bidderlist
                    curAuctionList.pausedTime = nil
                    curAuctionList.isPaused = nil
                    if #bidderlist > 0 then --有人出价直接5秒倒数
                        curAuctionList.endTime = startTime + 6
                        Frame1.infoFrame.sb:SetMinMaxValues(0, 6)
                        local auctioningCount = ZL.GetAuctioningCount()
                        if not ZL_CURRENT.globalConfig.allowMultipleAuctions or auctioningCount == 1 then
                            soundName="paimaidaoshu.mp3"
                        end
                    else
                        --无人出价直接流拍
                        curAuctionList.endTime = startTime + 0.001
                    end
                    Frame1.MLframe.functionFrame.CountDownBtn:Enable()
                elseif fdata.type == "取消倒数" then
                    local startTime = time()
                    local itemlink = curAuctionList.itemlink
                    local itemCount = curAuctionList.itemCount
                    local bidderlist = curAuctionList.bidderlist
                    local _, _, tarbidamount, bidCount = ZL.GetNewBidAmount(index)
                    curAuctionList.isPaused = nil
                    if Frame1.countDownTimer then
                        if not Frame1.countDownTimer:IsCancelled() then
                            Frame1.countDownTimer:Cancel()
                        end
                        Frame1.countDownTimer = nil
                    end
                    curAuctionList.endTime = startTime + ZL_CURRENT.globalConfig.auctionTimerRefresh
                    if #bidderlist > 0 then
                        local totalBidCount = 0
                        for _, bidData in ipairs(bidderlist) do
                            if totalBidCount < curAuctionList.itemCount then
                                local count = bidData["bidCount"] or 1
                                local newTotalBidCount = totalBidCount + count
                                if newTotalBidCount > curAuctionList.itemCount then
                                    count = curAuctionList.itemCount - totalBidCount
                                end
                                if ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                                    if count  > 1 then
                                        msgStr = msgStr .. "匿名(" .. bidData.bidamount .. "x" .. count .. ")，"
                                    else
                                        msgStr = msgStr .. "匿名(" .. bidData.bidamount .. ")，"
                                    end
                                else
                                    if count  > 1 then
                                        msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. "x" .. count .. ")，"
                                    else
                                        msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. ")，"
                                    end
                                end
                                totalBidCount = newTotalBidCount
                            else
                                break
                            end
                        end
                        if itemCount > 1 then
                            msgStr = ("%s已重置倒计时，当前出价：%s下次最低出价：%d，对应最大竞拍数量：%d"):format(
                                curAuctionList.itemlink, msgStr, tarbidamount, bidCount
                            )
                        else
                            msgStr = ("%s已重置倒计时，当前出价：%s下次最低出价：%d"):format(
                                curAuctionList.itemlink, msgStr, tarbidamount
                            )
                        end
                    else
                        if itemCount > 1 then
                            msgStr = ("%s已重置倒计时，当前无人出价，下次最低出价：%d，对应最大竞拍数量：%d"):format(
                                curAuctionList.itemlink, tarbidamount, bidCount
                            )
                        else
                            msgStr = ("%s已重置倒计时，当前无人出价，下次最低出价：%d"):format(
                                curAuctionList.itemlink, tarbidamount
                            )
                        end
                    end
                    if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                        ZL.SpeakText(itemlink .. "已重置倒计时！")
                    end
                    Frame1.MLframe.functionFrame.CountDownBtn:Enable()
                end
                if #msgStr > 0 then
                    ZL.Print(msgStr)
                    if PlayerIsML() then
                        SendChatMessage(msgStr, ZL.MsgChannel())
                    end
                end
                if soundName and ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                    C_VoiceChat.StopSpeakingText()
                    local willPlay = PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                    if not willPlay then
                        if soundName and ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            ZL.SpeakText(soundName)
                        end
                    end
                end
                ZL.AuctionListSort()
            end
        elseif (prefix == "AUTOAUC SYNC6") then --修改出价记录
            local _, index = FetchDataFromItemId(fdata.data2.itemlink, fdata.data2.itemindex)
            if index then
                local data = ZL_CURRENT.auctionlist[index]
                local bidderlist = data.bidderlist
                if bidderlist and #bidderlist > 0 then
                    for _index, bidData in ipairs(bidderlist) do
                        if bidData.bidder == fdata.data2.oldName then
                            local msgStr = ""
                            if fdata.type == "修改名字" then
                                msgStr = format("名字修改：已将%s(%d)修改为%s(%d)", bidData.bidder, bidData.bidamount, fdata.data2.newName, bidData.bidamount)
                                bidderlist[_index].bidder = fdata.data2.newName
                            elseif fdata.type == "修改出价" then
                                msgStr = format("出价修改：已将%s(%d)修改为%s(%d)", bidData.bidder, bidData.bidamount, bidData.bidder, fdata.data2.newBidAmount)
                                bidderlist[_index].bidamount = fdata.data2.newBidAmount
                            elseif fdata.type == "修改数量" then
                                msgStr = format("数量修改：已将%s(数量%d)修改为%s(数量%d)", bidData.bidder, bidData.bidCount, bidData.bidder, fdata.data2.newBidCount)
                                bidderlist[_index].bidCount = fdata.data2.newBidCount
                            end
                            ZL.AuctionFrame2.entries[index]:SetValues(index)
                            if data.state == "auctioning" then
                                ZL.Print(data.itemlink .. msgStr)
                            end
                            if ZL.BidderListFrame:IsShown() then
                                ZL.BidderListFrame:Update(index)
                            end
                            if data.state == "success" then
                                if data.tradeId and ZL_CURRENT.IncomeList and #ZL_CURRENT.IncomeList > 0 then
                                    for i = #ZL_CURRENT.IncomeList, 1, -1 do
                                        local _tradeId = ZL_CURRENT.IncomeList[i].tradeId
                                        if _tradeId and _tradeId == data.tradeId then
                                            table.remove(ZL_CURRENT.IncomeList, i)
                                        end
                                    end
                                    if ZL.AuctionRecordFrame.currentIncomeFrame:IsShown() then
                                        ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                                    end
                                end
                                if data["spawnUID"] and next(data["spawnUID"], nil) then
                                    for _, value in pairs(data["spawnUID"]) do
                                        value["successBidder"] = nil
                                        if value["itemGUID"] and next(value["itemGUID"], nil) then
                                            for _, value2 in pairs(value["itemGUID"]) do
                                                value2["isUsed"] = nil
                                            end
                                        end
                                    end
                                end
                                data.state = "waiting"
                                if PlayerIsML() then
                                    ZL.startOrCanelAuction(index, true)
                                end
                            elseif data.state == "auctioning" and PlayerIsML() then
                                SendChatMessage(data.itemlink .. ParseClassColorName(msgStr), "RAID")
                            end
                            break
                        end
                    end
                end
                ZL.updateTargetAmount(index)
                if ZL.BillOverviewFrame:IsShown() then
                    ZL.BillOverviewFrame:Update()
                end
            end
        elseif (prefix == "AUTOAUC SYNC9") or (prefix == "AUTOAUC SYNC13") then
            --9手动创建，13同步单个
            ZL_CURRENT.globalConfig = fdata.globalConfigData
            ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
            local index = SyncAuctionData(fdata.data2)
            if fdata.type == "手动创建" then
                ZL.Print("已手动创建拍卖物品：" .. fdata.data2.itemlink, true)
            elseif fdata.type == "同步单个" then
                if PlayerIsML() then
                    AuctionFrame.entries[index].sync = nil
                    AuctionFrame.entries[index].MLframe.functionFrame.syncBtn:Enable()
                    ZL.Print(fdata.data2.itemlink .. "数据同步成功")
                end
            end
            ZL.AuctionListSort()
            ZL.miniMapIconAnimation()
        elseif (prefix == "AUTOAUC SYNC10") then--删除拍卖物品
            if (PlayerIsML(pruneName)) then
                local _, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                if index then
                    ZL.AuctionFrame2.entries[index].sync = nil
                    local curAuctionList = ZL_CURRENT.auctionlist[index]
                    local itemlink = curAuctionList.itemlink
                    if curAuctionList.spawnUID and next(curAuctionList.spawnUID, nil) then
                        for _, value in pairs(curAuctionList.spawnUID) do
                            if value.itemGUID and next(value.itemGUID, nil) then
                                for itemGUID, _ in pairs(value.itemGUID) do
                                    if ZL_CURRENT.itemGUIDUsed then
                                        ZL_CURRENT.itemGUIDUsed[itemGUID] = nil
                                    end
                                end
                            end
                        end
                    end
                    if itemlink == "[打包拍卖]" then
                        local itemList = curAuctionList["itemList"]
                        if itemList and next(itemList, nil) then
                            for _itemlink, _data in pairs(itemList) do
                                for _, __itemindex in ipairs (_data.itemindex) do
                                    local _, __index = ZL.FetchDataFromItemId(_itemlink, __itemindex)
                                    if __index then ZL_CURRENT.auctionlist[__index].isPackage = nil end
                                end
                            end
                        end
                    end
                    table.remove(ZL_CURRENT.auctionlist, index)
                    ZL.AuctionListSort()
                    ZL.Print("注意：已删除拍卖物品" .. itemlink, true)
                end
            end
        elseif (prefix == "AUTOAUC SYNC11") then--添加收支
            if (PlayerIsML(pruneName)) and (not PlayerIsML()) then
                ZL_CURRENT.globalConfig = fdata.globalConfigData
                ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
                ZL_CURRENT.IncomeList = fdata.data
                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            end
        elseif (prefix == "AUTOAUC SYNC12") then--删除收支记录
            if (PlayerIsML(pruneName)) and (not PlayerIsML()) then
                ZL_CURRENT.globalConfig = fdata.globalConfigData
                ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
                local v = fdata.index
                table.remove(ZL_CURRENT["IncomeList"], v)
                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            end
        elseif (prefix == "AUTOAUC SYNC14") then --添加打包拍卖
            if (PlayerIsML(pruneName)) then
                ZL_CURRENT.globalConfig = fdata.globalConfigData
                ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
                do
                    local ffdata = fdata.data1
                    local _, index = FetchDataFromItemId(ffdata.itemlink, ffdata.itemindex)
                    if (not PlayerIsML()) then
                        if not index then
                            ZL_CURRENT.auctionlist = ZL_CURRENT.auctionlist or {}
                            table.insert(ZL_CURRENT.auctionlist, ffdata)
                            index = #ZL_CURRENT.auctionlist
                            ZL_CURRENT.auctionlist[index].lgnore = false
                        end
                        ZL_CURRENT.auctionlist[index].isPackage = true
                    end
                    ZL.AuctionFrame2.entries[index].sync = nil
                    local msgStr = ffdata.itemlink .. "已添加到[打包拍卖]"
                    ZL.Print(msgStr, true)
                end
                if (not PlayerIsML()) then
                    SyncAuctionData(fdata.data2)
                    ZL.AuctionListSort()
                end
            end
        elseif (prefix == "AUTOAUC SYNC15") then --剔除打包拍卖
            if (PlayerIsML(pruneName)) and (not PlayerIsML()) then
                ZL_CURRENT.globalConfig = fdata.globalConfigData
                local _, __index = FetchDataFromItemId("[打包拍卖]", 1)
                if __index then
                    local itemLink = fdata.itemLink
                    local itemindexList = ZL_CURRENT.auctionlist[__index]["itemList"][itemLink]["itemindex"]
                    --先把需要剔除的物品isPackage清楚
                    if itemindexList and #itemindexList > 0 then
                        for _, _itemindex in ipairs(itemindexList) do
                            local _, index = ZL.FetchDataFromItemId(itemLink, _itemindex)
                            if index then
                                ZL_CURRENT.auctionlist[index]["isPackage"] = nil
                            end
                        end
                    end
                    ZL_CURRENT.auctionlist[__index]["itemList"][itemLink] = nil
                    ZL.PackageListFrame:Update(__index)
                    ZL.AuctionListSort()
                end
            end
        elseif (prefix == "AUTOAUC BID") then --竞价
            local index, matchStr
            if fdata:match("^(|c.-|Hitem:.+|r)(%d+)[x]?(%d*)$") then
                matchStr = "^(|c.-|Hitem:.+|r)"
            else
                matchStr = "^(%[打包拍卖%])"
            end
            local bidItemLink, newBid, bidCount = fdata:match(matchStr .. "(%d+)[x]?(%d*)$")
            if bidItemLink and newBid then
                if ZL_CURRENT.auctionlist and #ZL_CURRENT.auctionlist > 0 then
                    for num, data in ipairs(ZL_CURRENT.auctionlist) do
                        if (data.itemlink == bidItemLink) and (data.state == "auctioning") then
                            index = num
                            break
                        end
                    end
                end
            end
            if index then
                if (not ZL.IsCandidate(index, fullColorName)) then
                    if pruneName == UnitName("player") then
                        ZL.Print(bidItemLink .. "没有拾取权限，无法参与竞拍", true)
                    end
                    return
                end
                newBid = tonumber(newBid)
                bidCount = bidCount and tonumber(bidCount) or 1
                local data = ZL_CURRENT.auctionlist[index]
                local Frame1 = AuctionFrame.entries[index]
                local bidderlist = data.bidderlist
                local _, bidIncrement, tarbidamount = ZL.GetNewBidAmount(index)
                if newBid >= tarbidamount then
                    if (data.endTime or 0) - time() > 0 then
                        data.endTime = time() + ZL_CURRENT.globalConfig.auctionTimerRefresh
                        Frame1:SetValues(index)
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) and ((not ZL.jiayou) or ((ZL.jiayou + 30 -GetTime()) < 0))
                        and ((newBid-tarbidamount+bidIncrement) >= 2000 or (newBid >= 10000 )) then
                            C_VoiceChat.StopSpeakingText()
                            PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\laogongjiayou.mp3", "Master")
                            ZL.jiayou = GetTime()
                            if not ZL.playerModel then
                                ZL.playerModel = CreateFrame("PlayerModel", nil, UIParent)
                                local playerModel = ZL.playerModel
                                playerModel:SetPoint("CENTER")
                                playerModel:SetSize(200, 200)
                                playerModel:SetCreature(25305)
                                playerModel:SetFacing(-0.4)
                                playerModel:SetAnimation(69)
                                playerModel:SetAlpha(1)
                            end
                            ZL.playerModel:Show()
                            C_Timer.After(5, function ()
                                ZL.playerModel:Hide()
                            end)
                        end
                        local isSenderExist = false
                        for bindex, b in ipairs(bidderlist) do
                            if b.bidder == fullColorName then
                                bidderlist[bindex].bidamount = newBid
                                bidderlist[bindex].bidCount = bidCount
                                bidderlist[bindex].time = GetTime()*1000
                                isSenderExist = true
                                break
                            end
                        end
                        if (not isSenderExist) then --如不存在，则直接插入
                            table.insert(bidderlist, {
                                bidder = fullColorName,
                                bidamount = newBid,
                                bidCount = bidCount,
                                time = GetTime()*1000,
                            })
                        end
                        tableSort(bidderlist)
                        local totalBidCount = 0
                        for bidindex, bidData in ipairs(bidderlist) do
                            if totalBidCount < data.itemCount then
                                local count = bidData["bidCount"] or 1
                                local newTotalBidCount = totalBidCount + count
                                if newTotalBidCount > data.itemCount then
                                    count = data.itemCount - totalBidCount
                                    bidderlist[bidindex].bidCount = count
                                    if bidData.bidder == fullColorName and pruneName == UnitName("player") then
                                        ZL.Print("已自动将您当前出价数量调整为：" .. count, true)
                                    end
                                end
                                totalBidCount = newTotalBidCount
                            else
                                break
                            end
                        end
                        Frame1:SetValues(index)
                        ZL.updateTargetAmount(index)
                    else
                        if pruneName == UnitName("player") then
                            ZL.Print(bidItemLink.itemlink .. "拍卖已结束！", true)
                        end
                    end
                else
                    if pruneName == UnitName("player") then
                        ZL.Print(("%s出价过低，请至少出价(%d)"):format(bidItemLink, tarbidamount), true)
                    end
                end
            end
        elseif (prefix == "AUTOAUC REQ") then --登录或重载UI时请求同步ML数据
            if (not PlayerIsML(pruneName)) and PlayerIsML() then
                if fdata == "auctioning" then
                    local auctioningList = {}
                    if ZL_CURRENT["auctionlist"] then
                        for _, _data in ipairs(ZL_CURRENT["auctionlist"]) do
                            if _data.state == "auctioning" then
                                tinsert(auctioningList, _data)
                            end
                        end
                    end
                    local data = {
                        type = "auctioning",
                        data2 = auctioningList,
                        globalConfigData = ZL.globalConfigData(),
                    }
                    MyAddon:SYNCALL(data, "WHISPER", pruneName)
                elseif fdata == "remainAll" then
                    local data = {
                        type = "remainAll",
                        data2 = ZL_CURRENT,
                    }
                    -- MyAddon:SYNCALL(data, "WHISPER", pruneName)
                end
            end
        elseif prefix:match("^AUTOAUC MY%d+$") then
            if PlayerIsML(pruneName) and (not PlayerIsML()) then
                if fdata.type == "groupGongZi" then
                    ZL_PLAYERLIST.groupGongZi = true
                end
            end
        elseif (prefix == "AUTOAUC RETAKE") then --申请重拍
            if (not PlayerIsML(pruneName)) and PlayerIsML() then
                local msgStr = ""
                local AuctioningCount = ZL.GetAuctioningCount()
                if (not ZL_CURRENT.globalConfig.allowMultipleAuctions) and AuctioningCount > 0 then
                    msgStr = "当前为单拍模式，有物品正在拍卖，请结束后再提交重拍申请"
                    SendChatMessage(msgStr, "WHISPER", nil, pruneName)
                else
                    local data = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                    if data and data.state == "failed" then
                        local isExist
                        local isSelf
                        if ZL.retake and #ZL.retake > 0 then
                            for _, value in ipairs(ZL.retake) do
                                if value.itemlink == fdata.itemlink and value.itemindex == fdata.itemindex then
                                    isExist = true
                                    if value.fullName == fullName then
                                        isSelf = true
                                    end
                                    break
                                end
                            end
                        end
                        if isExist then
                            if isSelf then
                                msgStr = fdata.itemlink .. "你已提交过重拍申请，请勿重复提交"
                            else
                                msgStr = fdata.itemlink .. "已有人提交过重拍申请，请耐心等候"
                            end
                            SendChatMessage(msgStr, "WHISPER", nil, pruneName)
                        else
                            if ZL.IsCanAuction(data, fullColorName) then
                                msgStr = ">>>" .. fullColorName .. "<<<申请重拍|cffff0000流拍|r物品：" .. fdata.itemlink .. "是否重拍？"
                                fdata.fullName = fullName
                                ZL.retake = ZL.retake or {}
                                tinsert(ZL.retake, fdata)
                                if not StaticPopup1:IsShown() then
                                    StaticPopup_Show("ZL_RETAKE", msgStr, nil, fullName)
                                else
                                    StaticPopup1Text:SetText(msgStr)
                                end
                            else
                                msgStr = fdata.itemlink.. "无法申请重拍，原因可能是：已分解或无法交易"
                                SendChatMessage(msgStr, "WHISPER", nil, pruneName)
                            end
                        end
                    else
                        msgStr = "未找到流拍物品：" .. fdata.itemlink
                        SendChatMessage(msgStr, "WHISPER", nil, pruneName)
                    end
                end
            end
        elseif (prefix == "AUTOAUC RESET") then --重置其它成员的
            if (not PlayerIsML()) and PlayerIsML(pruneName) then
                if ZL_CURRENT["auctionlist"] and (#ZL_CURRENT["auctionlist"] > 0) then
                    for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                        local f = AuctionFrame.entries[num]
                        if data.state == "auctioning" then
                            ZL_CURRENT.auctionlist[num].state = "waiting"
                            ZL_CURRENT.auctionlist[num].endTime = nil
                            ZL_CURRENT.auctionlist[num].isPaused = nil
                            ZL_CURRENT.auctionlist[num].bidderlist = {}
                            f:SetValues(num)
                        end
                        f:Hide()
                    end
                    local totalincome = 0
                    if ZL_CURRENT.IncomeList and #ZL_CURRENT.IncomeList > 0 then
                        for _, data in ipairs(ZL_CURRENT.IncomeList) do
                            totalincome = totalincome + data.amount
                        end
                    end
                    ZL_CURRENT.totalincome = totalincome
                    if (not ZL_CURRENT.name) then ZL_CURRENT.name = GetInstanceInfo() end
                    if (not ZL_CURRENT.auctiondate) then ZL_CURRENT.auctiondate = date("%Y-%m-%d %H:%M:%S", GetServerTime()) end
                    local index
                    local auctionGUID = (ZL_CURRENT.globalConfig and ZL_CURRENT.globalConfig.auctionGUID) and ZL_CURRENT.globalConfig.auctionGUID or ZL_CURRENT.auctionGUID
                    if auctionGUID then
                        for _index, _data in ipairs(ZL_HISTORY) do
                            local _acutionGUID = (_data.globalConfig and _data.globalConfig.auctionGUID) and _data.globalConfig.auctionGUID or _data.auctionGUID
                            if auctionGUID == _acutionGUID then
                                index = _index
                                break
                            end
                        end
                    end
                    if index then
                        ZL_HISTORY[index] = ZL_CURRENT
                    else
                        table.insert(ZL_HISTORY, ZL_CURRENT)
                    end
                    ZL.AuctionRecordFrame.historyFrame:Update()
                    ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                    ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                end
                ZL_CURRENT = {}
                ZL_PLAYERLIST = {}
                ZL.CreateAuctionInfo()
                ZL.AuctionFrame2:Update()
                ZL.AuctionRecordFrame.historyFrame:Update()
                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                AuctionFrame:Update()
            end
            if PlayerIsML() then
                TransmitAddonInfo_Pro()
            end
        elseif (prefix == "AUTOAUC PRO") then --同步配置文件全局参数
            if PlayerIsML(pruneName) then
                ZL_CURRENT.globalConfig = fdata
                ZL.opt.auctionMode = ZL_CURRENT.globalConfig.auctionMode
                AuctionFrame:Update()
            end
        elseif (prefix == "AUTOAUC REVOKE") then --撤销指定玩家出价
            if (PlayerIsML(pruneName)) then
                local itemlink = fdata.itemlink
                local itemindex = fdata.itemindex
                local _, index = FetchDataFromItemId(itemlink, itemindex)
                if index then
                    local playerName = fdata.playerName
                    local curAuctionList = ZL_CURRENT.auctionlist[index]
                    local bidderlist = curAuctionList.bidderlist
                    if bidderlist and #bidderlist > 0 then
                        for num, data in ipairs(bidderlist) do
                            if data.bidder == playerName then
                                table.remove(ZL_CURRENT.auctionlist[index].bidderlist, num)
                                tableSort(ZL_CURRENT.auctionlist[index].bidderlist)
                                bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                                if #bidderlist > 0 then
                                    ZL_CURRENT.auctionlist[index].endTime = time() + ZL_CURRENT.globalConfig.auctionTimerRefresh
                                else
                                    ZL_CURRENT.auctionlist[index].endTime = time() + ZL_CURRENT.globalConfig.auctionTimer--更新了出价，重新倒计时
                                end
                                local Frame1 = AuctionFrame.entries[index]
                                Frame1:SetValues(index)
                                if ZL.BidderListFrame:IsShown() then
                                    ZL.BidderListFrame:Update(index)
                                end
                                local msgStr = ""
                                local curAuctionList = ZL_CURRENT.auctionlist[index]
                                local _, _, tarbidamount, bidCount = ZL.GetNewBidAmount(index)
                                bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                                if ZL_CURRENT.globalConfig.auctionMode == "|cffff0000匿名|r" then
                                    msgStr = ("%s已撤销>>>%s<<<的出价"):format(curAuctionList.itemlink, ParseClassColorName(playerName))
                                else
                                    if #bidderlist > 0 then
                                        local totalBidCount = 0
                                        for _, bidData in ipairs(bidderlist) do
                                            if totalBidCount < curAuctionList.itemCount then
                                                local count = bidData["bidCount"] or 1
                                                local newTotalBidCount = totalBidCount + count
                                                if newTotalBidCount > curAuctionList.itemCount then
                                                    count = curAuctionList.itemCount - totalBidCount
                                                end
                                                if count  > 1 then
                                                    msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. "x" .. count .. ")，"
                                                else
                                                    msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. ")，"
                                                end
                                                totalBidCount = newTotalBidCount
                                            else
                                                break
                                            end
                                        end
                                        if curAuctionList.itemCount > 1 then
                                            msgStr = ("%s已撤销>>>%s<<<的出价，当前出价：%s下次最低出价：%d，对应最大数量%d"):format(
                                                curAuctionList.itemlink, ParseClassColorName(playerName), msgStr, tarbidamount, bidCount
                                            )
                                        else
                                            msgStr = ("%s已撤销>>>%s<<<的出价，当前出价：%s下次最低出价：%d"):format(
                                                curAuctionList.itemlink, ParseClassColorName(playerName), msgStr, tarbidamount
                                            )
                                        end
                                    else
                                        if curAuctionList.itemCount > 1 then
                                            msgStr = ("%s已撤销>>>%s<<<的出价，当前无人出价，下次最低出价：%d，对应最大数量%d"):format(
                                                curAuctionList.itemlink, ParseClassColorName(playerName), tarbidamount, bidCount)
                                        else
                                            msgStr = ("%s已撤销>>>%s<<<的出价，当前无人出价，下次最低出价：%d"):format(
                                                curAuctionList.itemlink, ParseClassColorName(playerName), tarbidamount)
                                        end
                                    end
                                end
                                ZL.Print(msgStr)
                                if PlayerIsML() then
                                    Frame1.MLframe.functionFrame.syncBtn:Enable()
                                    SendChatMessage(msgStr, ZL.MsgChannel())
                                end
                                break
                            end
                        end
                    end
                    ZL.AuctionFrame2.entries[index].MLframe.functionFrame.syncBtn:Enable()
                    ZL.updateTargetAmount(index)
                end
            end
        elseif (prefix == "AUTOAUC VER") then
            if fdata.type == "request" then
                ZL_PLAYERLIST.autoNotice = nil
                if (IsInRaid(1) or IsInGroup(1)) then
                    RequestRaidInfo()
                else
                    local data = {
                        type="myVer", ver=ZL.addonVersion, autoNoticeFoodInRaid=ZL.opt.autoNoticeFoodInRaid,
                        confirmLootAnnounce=ZL.opt.confirmLootAnnounce,
                    }
                    MyAddon:TransmitAddonInfo2("AUTOAUC VER", data, chatType, nil, "BULK")
                end
            elseif fdata.type == "requestback" or fdata.type == "myVer" then
                ZL_PLAYERLIST.GroupMembersVersion = ZL_PLAYERLIST.GroupMembersVersion or {}
                ZL_PLAYERLIST.GroupMembersVersion[fullName] = fdata.ver
                ZL_PLAYERLIST.autoNotice = ZL_PLAYERLIST.autoNotice or {}
                ZL_PLAYERLIST.autoNotice[fullName] = ZL_PLAYERLIST.autoNotice[fullName] or {}
                ZL_PLAYERLIST.autoNotice[fullName].autoNoticeFoodInRaid = fdata.autoNoticeFoodInRaid
                ZL_PLAYERLIST.autoNotice[fullName].confirmLootAnnounce = fdata.confirmLootAnnounce
                if fdata.instancesInfo and (UnitInRaid(pruneName) or UnitInParty(pruneName)) then
                    ZL_PLAYERLIST.instancesInfo = ZL_PLAYERLIST.instancesInfo or {}
                    if ZL.InstancesInfoFrame and ZL.InstancesInfoFrame:IsShown() then
                        if not ZL_PLAYERLIST.instancesInfo[fullColorName] then
                            ZL.InstancesInfoFrame.hasNewInfo = true
                        else
                            local lhsTable = CopyTable(fdata.instancesInfo)
                            local rhsTable = CopyTable(ZL_PLAYERLIST.instancesInfo[fullColorName])
                            lhsTable.updateTime = nil
                            rhsTable.updateTime = nil
                            if not tCompare(lhsTable, rhsTable, 3) then
                                ZL.InstancesInfoFrame.hasNewInfo = true
                            end
                            lhsTable = nil
                            rhsTable = nil
                        end
                        ZL.InstancesInfoFrame.UpdateSpellHighlightAnim()
                    end
                    ZL_PLAYERLIST.instancesInfo[fullColorName] = fdata.instancesInfo
                end
            elseif fdata.type == "updateCheck" then
                if pruneName == UnitName("player") then return end
                local function UpdateCheckNotice()
                    if ZL.updateCheckNoticed == nil then
                        ZL.updateCheckNoticed = true
                        ZL.Print("有新的版本，请及时到各大插件平台更新。", true, true)
                        ZL.SpeakText("AutoAuction有新的版本，请注意及时更新")
                    end
                end
                local senderVerA, senderVerB, senderVerC = fdata.ver:match("^V(%d+)%.(%d+)%.(%d+)")
                senderVerA = tonumber(senderVerA) or 0
                senderVerB = tonumber(senderVerB) or 0
                senderVerC = tonumber(senderVerC) or 0
                if senderVerA > ZL.addonVersionA then
                    UpdateCheckNotice()
                elseif senderVerA == ZL.addonVersionA then
                    if senderVerB > ZL.addonVersionB then
                        UpdateCheckNotice()
                    elseif senderVerB == ZL.addonVersionB then
                        if senderVerC > ZL.addonVersionC then
                            UpdateCheckNotice()
                        end
                    end
                end
            end
        elseif (prefix == "AUTOAUC VOTE") then
            if fdata.type == "开始投票" then
                ZL.voteTotalMembers = fdata.totalMembers
                ZL.voteAgree = 0
                ZL.voteRefuse = 0
                local msgStr = fullColorName .. "正在进行|cffff0000【匿名】|r拍卖投票\n请选择"
                StaticPopup_Show("ZL_CHANGEAUCTIONMODEVOTE", msgStr, nil ,fullColorName)
                ZL.SpeakText(msgStr)
            elseif fdata.type == "同意" then
                ZL.voteAgree = ZL.voteAgree + 1
                local total = ZL.voteAgree + ZL.voteRefuse
                if total <= ZL.voteTotalMembers then
                    if total == ZL.voteTotalMembers then
                        if ZL.voteTimer then
                            if not ZL.voteTimer:IsCancelled() then
                                ZL.voteTimer:Cancel()
                            end
                            ZL.voteTimer = nil
                        end
                        local pass = ZL.voteAgree*100/ZL.voteTotalMembers
                        local msgStr = "|cff00ff00同意：|r" .. ZL.voteAgree .. " |cffff0000反对：|r" .. ZL.voteRefuse .. " |cff0070dd总人数：|r" .. ZL.voteTotalMembers
                        ZL.Print(msgStr, true)
                        if pass > 50 then
                            if PlayerIsML() then
                                ZL.opt.auctionMode = ZL.AuctionFrame2.auctionModeDropdown:GetText()
                                TransmitAddonInfo_Pro()
                                ZL.AuctionFrame2.auctionModeDropdown:Enable()
                                SendChatMessage("通过！赞成：" .. format("%.2f%%", pass) .. "，大于50%，拍卖模式已切换为【匿名】拍卖！", "RAID")
                            end
                            msgStr = "|cff00ff00通过！|r赞成：" .. format("%.2f%%", pass) .. "，大于50%，拍卖模式已切换为【|cffff0000匿名|r】拍卖！"
                            ZL.Print(msgStr, true)
                        else
                            msgStr = "|cffff0000失败！|r赞成：" .. format("%.2f%%", pass) .. "，没有大于50%，拍卖模式已切换为【团队】模式！"
                            ZL.Print(msgStr, true)
                            if PlayerIsML() then
                                ZL.AuctionFrame2.auctionModeDropdown:SetValue(1)
                                ZL.AuctionFrame2.auctionModeDropdown:Enable()
                            end
                        end
                    else
                        local msgStr = "|cff00ff00同意：|r" .. ZL.voteAgree .. " |cffff0000反对：|r" .. ZL.voteRefuse .. " |cff0070dd总人数：|r" .. ZL.voteTotalMembers
                        ZL.Print(msgStr, true)
                    end
                end
            elseif fdata.type == "反对" then
                ZL.voteRefuse = ZL.voteRefuse + 1
                local total = ZL.voteAgree + ZL.voteRefuse
                if total <= ZL.voteTotalMembers then
                    if total == ZL.voteTotalMembers then
                        if ZL.voteTimer then
                            if not ZL.voteTimer:IsCancelled() then
                                ZL.voteTimer:Cancel()
                            end
                            ZL.voteTimer = nil
                        end
                        local pass = ZL.voteAgree*100/ZL.voteTotalMembers
                        local msgStr = "|cff00ff00同意：|r" .. ZL.voteAgree .. " |cffff0000反对：|r" .. ZL.voteRefuse .. " |cff0070dd总人数：|r" .. ZL.voteTotalMembers
                        ZL.Print(msgStr, true)
                        if pass > 50 then
                            if PlayerIsML() then
                                ZL.opt.auctionMode = ZL.AuctionFrame2.auctionModeDropdown:GetText()
                                TransmitAddonInfo_Pro()
                                ZL.AuctionFrame2.auctionModeDropdown:Enable()
                                SendChatMessage("通过！赞成：" .. format("%.2f%%", pass) .. "，大于50%，拍卖模式已切换为【匿名】拍卖！", "RAID")
                            end
                            msgStr = "|cff00ff00通过！|r赞成：" .. format("%.2f%%", pass) .. "，大于50%，拍卖模式已切换为【|cffff0000匿名|r】拍卖！"
                            ZL.Print(msgStr, true)
                        else
                            msgStr = "|cffff0000失败！|r赞成：" .. format("%.2f%%", pass) .. "，没有大于50%，拍卖模式已切换为【团队】模式！"
                            ZL.Print(msgStr, true)
                            if PlayerIsML() then
                                ZL.AuctionFrame2.auctionModeDropdown:SetValue(1)
                                ZL.AuctionFrame2.auctionModeDropdown:Enable()
                            end
                        end
                    else
                        local msgStr = "|cff00ff00同意：|r" .. ZL.voteAgree .. " |cffff0000反对：|r" .. ZL.voteRefuse .. " |cff0070dd总人数：|r" .. ZL.voteTotalMembers
                        ZL.Print(msgStr, true)
                    end
                end
            end
        elseif (prefix == "AUTOAUC SOUND") then
            if ZL.opt.IsVoiceReminder and ((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound) or PlayerIsML()) then
                if fdata.type == "录制" then
                    C_VoiceChat.StopSpeakingText()
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. fdata.soundName, "Master")
                elseif fdata.type == "系统" then
                    ZL.SpeakText(fdata.soundName)
                end
            end
        elseif (prefix == "AUTOAUC ROLES") then --同步不同子账号之间的数据
            if fdata.type == "addnew" then
                if not ZL.opt.rolesRefuse then
                    StaticPopup_Show("ZL_SYNCROLES", fdata.playerName .. "请求与你共享角色数据，是否同意？", nil ,fdata)
                end
            elseif fdata.type == "addnewAgree" then
                ZL.RequestReceived[fullName] = true
                ZL.SaveRoles(fdata)
                ZL.RolesOverViewFrame.battleTagDropdown:SetMenuTable(ZL.GetBattleTagDropdownList())
                ZL.RolesOverViewFrame.battleTagDropdown:SetDefaultText("全部")
                ZL.RolesOverViewFrame.BNChildDropdown:SetMenuTable(ZL.GetBNChildDropdownList())
                ZL.RolesOverViewFrame.BNChildDropdown:SetDefaultText("全部")
                ZL.RolesOverViewFrame.BNChildDropdown:SetValue("全部")
                ZL.RolesOverViewFrame.realmDropdown:SetMenuTable(ZL.GetRealmDropdownList())
                ZL.RolesOverViewFrame.realmDropdown:SetDefaultText(GetRealmName())
                ZL.RolesOverViewFrame:Update()
                ZL.LgnoreRolesFrame:Update()
                RolesOverView["syncKeyUnBind"][fdata.OwnRolesSyncKey] = nil --从新绑定的从这里面移除
                local msgStr = fdata.playerName .. "|cff00ff00绑定成功|r"
                ZL.Print(msgStr, true)
                LibStub("AceConfigRegistry-3.0"):NotifyChange("金团拍卖助手")
            elseif fdata.type == "addnewRefuse" then
                ZL.RequestReceived[fullName] = false
                local msgStr = fdata.data .. "|cffff0000已拒绝了你的请求！|r"
                ZL.options.args.rolesOverView.args.bindNewRoles.args.tipsDescription1.name = msgStr
                LibStub("AceConfigRegistry-3.0"):NotifyChange("金团拍卖助手")
                ZL.Print(msgStr, true)
            elseif fdata.type == "sendRoles" then
                --判断对方子账号是否存在,存在则发送数据，不存在则发送已解绑信息
                local accountIsExist
                for _, syncKey in pairs(RolesOverView.syncKey) do
                    if syncKey == fdata.accountSyncKey and (not RolesOverView["syncKeyUnBind"][fdata.accountSyncKey]) then
                        accountIsExist = true
                        break
                    end
                end
                if accountIsExist then
                    --存在则回应并发送自己的roles,保存对方发过来的roles
                    ZL.SaveRoles(fdata)
                    ZL.ackRoles = ZL.ackRoles or {}
                    local inInstance, instanceType = IsInInstance()
                    if not (IsInRaid(1) and inInstance and instanceType == "raid") then
                        if ZL.ackRoles[fullName] then
                            ZL.ackRoles[fullName]:Cancel()
                            ZL.ackRoles[fullName] = nil
                        end
                        ZL.SendOrAckRoles(fullName, "ackRoles")
                    else
                        if not ZL.ackRoles[fullName] then
                            ZL.ackRoles[fullName] = C_Timer.NewTicker(30, function (self)
                                inInstance, instanceType = IsInInstance()
                                if not (IsInRaid(1) and inInstance and instanceType == "raid") then
                                    self:Cancel()
                                    ZL.ackRoles[fullName] = nil
                                    ZL.SendOrAckRoles(fullName, "ackRoles")
                                end
                            end)
                        end
                    end
                else
                    --不存在则发送已解绑信息
                    local _, _, ownSyncKey = ZL.GetOwnRolesSyncKey()
                    local data = {
                        type = "unBind",
                        playerName = GetClassColorName(UnitName("player")),
                        rolesData = "已解绑",
                        accountSyncKey = ownSyncKey,
                    }
                    MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", data, "WHISPER", pruneName, "BULK")
                end
            elseif fdata.type == "ackRoles" then
                ZL.SaveRoles(fdata)
            elseif fdata.type == "unBind" then
                --添加到已解绑数据库
                RolesOverView["syncKeyUnBind"][fdata.accountSyncKey] = true
                --删除syncKey里面的数据，避免下次重复调用
                for key, value in pairs(RolesOverView["syncKey"]) do
                    if value == fdata.accountSyncKey then
                        RolesOverView["syncKey"][key] = nil
                    end
                end
                --删除sync里的数据
                local battleTag, BNChild = strsplit(":", fdata.accountSyncKey)
                if RolesOverView["sync"] and RolesOverView["sync"][battleTag] then
                    RolesOverView["sync"][battleTag][BNChild] = nil
                end
                --删除rolesLgnore
                if ZL.glb["rolesLgnore"] then
                    for key in pairs(ZL.glb["rolesLgnore"]) do
                        local _, _, _BNChild, _battleTag = strsplit(":", key)
                        if BNChild == _BNChild and battleTag == _battleTag then
                            ZL.glb["rolesLgnore"][key] = nil
                        end
                    end
                end
                --删除rolesDel
                if ZL.glb["rolesDel"] then
                    for key in pairs(ZL.glb["rolesDel"]) do
                        local _, _, _BNChild, _battleTag = strsplit(":", key)
                        if BNChild == _BNChild and battleTag == _battleTag then
                            ZL.glb["rolesDel"][key] = nil
                        end
                    end
                end
                ZL.RolesOverViewFrame.battleTagDropdown:SetMenuTable(ZL.GetBattleTagDropdownList())
                ZL.RolesOverViewFrame.battleTagDropdown:SetDefaultText("全部")
                ZL.RolesOverViewFrame.BNChildDropdown:SetMenuTable(ZL.GetBNChildDropdownList())
                ZL.RolesOverViewFrame.BNChildDropdown:SetDefaultText("全部")
                ZL.RolesOverViewFrame.BNChildDropdown:SetValue("全部")
                ZL.RolesOverViewFrame.realmDropdown:SetMenuTable(ZL.GetRealmDropdownList())
                ZL.RolesOverViewFrame.realmDropdown:SetDefaultText(GetRealmName())
                ZL.RolesOverViewFrame:Update()
                ZL.LgnoreRolesFrame:Update()
            end
        elseif (prefix == "AUTOAUC ROLL") then
            if fdata.type == "start" then
                ZL.rollList = {}
                local countDown = fdata.rollCountDown
                local msgStr = "===ROLL开始，" .. tostring(countDown) .. "秒后结束==="
                if PlayerIsML() then
                    SendChatMessage("{rt4}" .. msgStr .. "{rt4}", "RAID")
                end
                ZL.Print("|T137004:20:20:0:0|t" .. msgStr .. "|T137004:20:20:0:0|t", true)
                if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                    ZL.SpeakText(msgStr)
                end
                ZL.rollTimer = C_Timer.NewTicker(1, function (self)
                    countDown = countDown - 1
                    if countDown == 6 then
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            ZL.SpeakText("ROLL倒数")
                        end
                    elseif countDown > 0 and countDown <= 5 then
                        if PlayerIsML() then
                            SendChatMessage("ROLL倒数：" .. countDown, "RAID")
                        end
                        ZL.Print("ROLL倒数：" .. countDown)
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            C_VoiceChat.StopSpeakingText()
                            PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\count\\" .. tostring(countDown) .. ".mp3", "Master")
                        end
                    elseif countDown <= 0 then
                        self:Cancel()
                        local msgStr2 = "ROLL结束，"
                        if next(ZL.rollList) then
                            local maxRollPlayer, maxRollNumber = unpack(ZL.sortRollNumber()[1])
                            msgStr = "获胜者：" .. ParseClassColorName(maxRollPlayer) .. "(" .. maxRollNumber .. "点)"
                            msgStr2 = msgStr2 .. "获胜者：" .. maxRollPlayer .. "(" .. maxRollNumber .. "点)"
                        else
                            msgStr = "没有人ROLL！"
                            msgStr2 = msgStr2 .. msgStr
                        end
                        if ZL.opt.IsVoiceReminder and (((not ZL_CURRENT.globalConfig) or (not ZL_CURRENT.globalConfig.YYSound)) or PlayerIsML()) then
                            ZL.SpeakText("ROLL结束！")
                        end
                        ZL.Print("|T137004:20:20:0:0|t" .. msgStr2 .. "|T137004:20:20:0:0|t", true)
                        if PlayerIsML() then
                            SendChatMessage("{rt4}=====ROLL结束====={rt4}", "RAID")
                            C_Timer.After(0.3, function ()
                                SendChatMessage(msgStr, "RAID")
                            end)
                            ZL.updateRollGameToolTip(AuctionFrame.rollBtn)
                        end
                        
                        
                    end
                end, fdata.rollCountDown)
                ZL.updateRollGameToolTip(AuctionFrame.rollBtn)
                if PlayerIsML() then
                    C_Timer.After(0.5, function ()
                        RandomRoll(1, 100)
                    end)
                end
            end
        elseif (prefix == "AUTOAUC ML") then
            if fdata.type == "requestback" then
                ZL.opt.appointMLName = fdata.appointMLName
                AuctionFrame:Update()
                if fdata.notice and ZL.opt.appointMLName then
                    ZL.Print("已指定>>>" .. GetClassColorName(ZL.opt.appointMLName) .. "<<<为拍卖负责人")
                    if ZL.IsRaidLeader() then
                        SendChatMessage("已指定>>>" .. ZL.opt.appointMLName .. "<<<为拍卖负责人", "RAID")
                    end
                end
            elseif fdata.type == "request" then
                if ZL.IsRaidLeader() and not ZL.IsRaidLeader(pruneName) then
                    if (not ZL.opt.appointMLName) or (not UnitInRaid(ZL.opt.appointMLName)) then
                        ZL.opt.appointMLName = ZL.GetFullName()
                    end
                    MyAddon:TransmitAddonInfo2("AUTOAUC ML", {type="requestback", appointMLName=ZL.opt.appointMLName})
                end
            end
        elseif prefix == "AUTOAUC TALENT" then
            if fdata.type == "talent" then
                local unitCacheRecord = LibFroznFunctions:InspectUnit("player", nil, nil, true)
                if unitCacheRecord then
                    ZL.GetTalent(unitCacheRecord)
                    MyAddon:TransmitAddonInfo2("AUTOAUC TALENT", {type="back", data=ZL.opt.playerInfo[unitCacheRecord.fullPlayerName]}, 'WHISPER', pruneName)
                end
            elseif fdata.type == "back" then
                ZL.opt.playerInfo = ZL.opt.playerInfo or {}
                ZL.opt.playerInfo[fullName] = fdata.data
            end
        end
    end
end
