-- PHP文档地址,用户名:dd 密码:ddtech -- http://120.76.238.236:8999/wiki/index.php?title=%E9%A6%96%E9%A1%B5 local ProtocolClubZhanji = class("ProtocolClubZhanji", require("luaScript.Protocol.ProtocolZhanJi")) local InterfaceKey = { idx = "gamb.gidx", -- 茶馆战绩新接口 PHP_CLUB_ZHANJI_CONSUME = "group.getGroupDateStat",--茶馆请求战绩消耗 } function ProtocolClubZhanji:ctor() ProtocolClubZhanji.super.ctor(self); self.fileName = "ZhanJi_Club" --[[ self.zhanJiIdxs = { [clubid] = { [usertype] = { tpage = 18, infos = { [page] = {idx, idx, idx, idx, ...}, [page] = {idx, idx, idx, idx, ...}, ... } }, ... }, ... }, ... --]] self.zhanJiIdxs = {} self.zhanJiIdxStatus = {} self.zhanJiIdxLocals = {} -- 当前显示的战绩的总页数 self.tpage = 0 --大赢家详情数据 self.dayijingjiadetail = nil self.shareUrl = "http://m.xiaopengol.com/replay.php" --分享战绩链接 self:loadFromFile(); end -- 初始化 function ProtocolClubZhanji:init() end -- 获取指定的战绩信息列表 -- clubId:茶馆ID -- usertype:用户类型 -- page:页数 function ProtocolClubZhanji:getZhanJiList(clubId, usertype, page) -- 首先找到对应的 idx_list local zhanjiInfoList = app.club_zhanji.zhanjiInfoList; if not zhanjiInfoList then return end if not self.zhanJiIdxs[clubId] or not self.zhanJiIdxs[clubId][usertype] or not self.zhanJiIdxs[clubId][usertype]["infos"] or not self.zhanJiIdxs[clubId][usertype]["infos"][page] then return {} end local zhanjiList = {} local idx_list = self.zhanJiIdxs[clubId][usertype]["infos"][page] local index = 10000--保持原有顺序,这里用递减 for _,pid in pairs(idx_list) do if self.zhanjiInfoList[pid] and self.zhanjiInfoList[pid].hide ~= 1 then index = index - 1 local endtime = tostring(index) zhanjiList[endtime] = self.zhanjiInfoList[pid] end end return zhanjiList; end --请求战绩的编号列表 -- 通过ID查找指定ID玩家的战绩 function ProtocolClubZhanji:getIdxlistByPlayerUid(clubId, userType, time, page,suid,isSearch) local tt = { action = InterfaceKey.idx; app = getAppId(); --应用id uid = app.user.loginInfo.uid; --用户id suid = suid; --需要查询的战绩的玩家ID gid = clubId; --茶馆ID date = time; --格式:"2018-02-02" 获取时间,如传空则获取当天 type = userType; --1管理員查詢,2玩家查詢 page = page or 1; --是否是新版(针对新版有两种游戏战绩的情况) }; log("ProtocolClubZhanji:getIdxlist", table.tostring(tt)) httpPost(self.phpUrl, tt, function(status, response) self:getIdxlistResponse(status, response, clubId, userType,isSearch) end) end --请求战绩的编号列表 -- 茶馆的战绩分不同茶馆的不同类型的战绩,所以在这里单独保存ID,无需存文件 function ProtocolClubZhanji:getIdxlist(clubId, userType, time, page) local tt = { action = InterfaceKey.idx; app = getAppId(); --应用id uid = app.user.loginInfo.uid; --用户id gid = clubId; --茶馆ID date = time; --格式:"2018-02-02" 获取时间,如传空则获取当天 type = userType; --1管理員查詢,2玩家查詢 page = page or 1; --是否是新版(针对新版有两种游戏战绩的情况) }; log("ProtocolClubZhanji:getIdxlist", table.tostring(tt)) httpPost(self.phpUrl, tt, function(status, response) self:getIdxlistResponse(status, response, clubId, userType) end) end -- 获取战绩ID列表的回复 -- 并和本地数据进行比较,找出本地未下载的部分进行下载 function ProtocolClubZhanji:getIdxlistResponse(status, response, clubId, userType,isSearch) --test local test = app.club_php:getCestIsOpen(clubId) logD("ProtocolClubZhanji:getIdxlistResponse()", status, response) local ret, ttResult = checkPhpResponse(status, response) if not ret then logE("ProtocolClubZhanji:getIdxlistResponse()", tostring(ttResult)) local ttResposne = json.decode(response) if ttResposne and type(ttResposne) == "table" and ttResposne.error then showTooltip(ttResposne.error) end return end if ret and table.nums(ttResult.idx) == 0 and isSearch then showTooltip("该玩家暂无战绩") end -- 保存页数对应的idx local page = ttResult.page local tpage = ttResult.tpage self.tpage = tpage; -- 茶馆 if not self.zhanJiIdxs[clubId] then self.zhanJiIdxs[clubId] = {} end -- 用户类型 if not self.zhanJiIdxs[clubId][userType] then self.zhanJiIdxs[clubId][userType] = {} end -- 页数 self.zhanJiIdxs[clubId][userType].tpage = tonumber(tpage) if not self.zhanJiIdxs[clubId][userType].infos then self.zhanJiIdxs[clubId][userType].infos = {} end local idxs = {} for k,pid in pairs(ttResult.idx) do table.insert(idxs, pid) end self.zhanJiIdxs[clubId][userType]["infos"][page] = idxs; --确认状态 for pid,v in pairs(ttResult.idxStatus) do self.zhanJiIdxStatus[pid] = v.status self.zhanJiIdxLocals[pid] = v.locals -- table.insert(idxs, pid) end if ttResult.url and ttResult.url~="" then self.shareUrl = ttResult.url end -- 比较没有的战绩并下载 self:checkAndDownload(ttResult.idx); end --请求战绩的消耗 function ProtocolClubZhanji:requestZhanjiConsume(gID, time) local tt = { action = "group.getGroupDateStat"; --接口 uid = app.user.loginInfo.uid; --群用户id app = getAppId(); --应用id gid = gID; --群id date = time; --日期 }; logD("ProtocolClubZhanji:requestZhanjiConsume()", table.tostring(tt)) httpPost(self.phpUrl, tt, handler(self, self.onZhanjiConsumeResponse)) end function ProtocolClubZhanji:onZhanjiConsumeResponse(status, response) logD("ProtocolClubZhanji:onZhanjiConsumeResponse()", tostring(status), table.tostring(response)) if status ~= "successed" then -- showTooltip("获取消耗数据失败,链接失败") return end --do return end local ttResponse = json.decode(response) if not ttResponse or type(ttResponse) ~= "table" then -- showTooltip("获取消耗数据失败,数据为空") return end self.ZhanjiXiaohao = {}; if ttResponse.code == 200 and ttResponse.result and type(ttResponse.result) == "table" then local roomNum = ttResponse.result.openhouse_count; --成局数 local cardCost = ttResponse.result.card_consume_count; --房卡消耗 local activityCardCost = ttResponse.result.owner_props_card_count; --活动房卡消耗 local costCardCount = ttResponse.result.owner_openhouse_count; --扣卡局数 local notCostCardCount = ttResponse.result.owner_unconsume_count; --未扣卡局数 local propList = ttResponse.result.propList; -- 专用钻石消耗明细 app:dispatchEvent({name = "ClubZhanjiConsumeCallback", roomNum = roomNum, cardCost = cardCost, activityCardCost = activityCardCost, costCardCount = costCardCount,notCostCardCount = notCostCardCount, propList = propList}); end end --请求战绩确认 function ProtocolClubZhanji:requestZhanjiSure(gID,idx ,callback) local phpAddress = getGlobalPhpUrl() local tt = {}; tt.action = "group.setupRoomlog"; tt.uid = app.user.loginInfo.uid;--设置人 tt.app = getAppId(); --应用id tt.gid = gID; --茶馆ID tt.gamb_id = idx --战绩标示 tt.type = 1 --1茶馆状态确认 logD("ProtocolClubZhanji:requestZhanjiSure()", table.tostring(tt)) httpPost(phpAddress, tt, function(status, response) logD("ProtocolClubZhanji:requestZhanjiSure() response", response) local clubResponse = json.decode(response) if type(clubResponse) ~= "table" then showPHPFailedResult("请求战绩确认 response type is not table") return end logD("ProtocolClubZhanji:requestZhanjiSure() response", table.tostring(clubResponse)) -- self.zhanjiTongjiDataList = {}; local result = clubResponse.result if clubResponse.code == 200 then self.zhanJiIdxStatus[result.gamb_id] = result.status if callback then callback() end -- app:dispatchEvent({name = "ClubZhanjiSureCallback", result = result}); elseif clubResponse.code == 1052 then --已经确认过了 self.zhanJiIdxStatus[idx] = 2 if callback then callback() end else showConfirmDialog(clubResponse.error) end end) end --获取战绩统计数据 function ProtocolClubZhanji:requestZhanjiGroupDateList(gID, startdate, enddate) local phpAddress = getGlobalPhpUrl() local tt = {}; tt.action = "group.getGroupDateStatList"; tt.uid = app.user.loginInfo.uid;--设置人 tt.app = getAppId(); --应用id tt.gid = gID; --茶馆ID tt.startdate = startdate; --不传参数默认最近一周 tt.enddate = enddate; --不传参数默认当天日期 tt.version="20190122" log("ProtocolClubZhanji:requestZhanjiGroupDateList_send", table.tostring(tt)) app.waitDialogManager:showWaitNetworkDialog("连接中..."); httpPost(phpAddress, tt, function(status, response) app.waitDialogManager:closeWaitNetworkDialog(); log("ProtocolClubZhanji:requestZhanjiGroupDateList", table.tostring(response)) local clubResponse = json.decode(response) if type(clubResponse) ~= "table" then showPHPFailedResult("获取战绩统计数据 response type is not table") return end self.zhanjiTongjiDataList = {}; local result = clubResponse.result if clubResponse.code == 200 then if result.list and table.nums(result.list) > 0 then local tTongjiList = {}; -- local idx = 1 for date,list in pairs(result.list) do local zhanjiTongjiDataList = {} -- for _,list local zhanjiTongjiData = {} zhanjiTongjiData.create_date = date zhanjiTongjiData.openhouse_count = 0 zhanjiTongjiData.owner_card_consume_count = 0 zhanjiTongjiData.owner_props_card_count = 0 zhanjiTongjiData.play_win_number = 0 zhanjiTongjiData.cost_card_count = 0--扣卡局 zhanjiTongjiData.not_cost_card_count = 0--未扣卡局 for _,v in pairs(list) do -- zhanjiTongjiData.create_date = zhanjiTongjiData.create_date + v.create_date;--日期 zhanjiTongjiData.openhouse_count = zhanjiTongjiData.openhouse_count + v.openhouse_count;--开房成局 zhanjiTongjiData.owner_card_consume_count = zhanjiTongjiData.owner_card_consume_count + v.owner_card_consume_count;--群主消耗 zhanjiTongjiData.owner_props_card_count = zhanjiTongjiData.owner_props_card_count + v.owner_props_card_count;--群主专属房卡/房卡消耗 --新加 zhanjiTongjiData.cost_card_count = zhanjiTongjiData.cost_card_count + v.owner_openhouse_count;--扣卡局 zhanjiTongjiData.not_cost_card_count = zhanjiTongjiData.not_cost_card_count + v.owner_unconsume_count;--未扣卡局 end zhanjiTongjiData.list = list if result.extlist and result.extlist[date] then zhanjiTongjiData.play_win_number = result.extlist[date].play_win_number or 0 end tTongjiList[date] = zhanjiTongjiData -- idx = idx + 1 end self.zhanjiTongjiDataList[tonumber(gID)] = tTongjiList; end self:dispatchEvent({name = "onGetZhanjiGroupDateListSucc"}); elseif clubResponse.code == 1020 then showConfirmDialog("获取战绩统计数据,参数错误 code = "..clubResponse.code) elseif clubResponse.code == 1026 then showConfirmDialog("获取战绩统计数据,非管理员操作 code = "..clubResponse.code); elseif clubResponse.code == 1014 then showConfirmDialog(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_ZHANJI_ERR_1104 or PLN.CLUB_ZHANJI_ERR_1104..clubResponse.code); else showConfirmDialog("获取战绩统计数据 code = "..clubResponse.code) end end) end --请求大赢家明细 function ProtocolClubZhanji:requestDaYingJiaZhanJi(gID, suid,lastday) local tt = { action = "group.winlog"; --接口 uid = app.user.loginInfo.uid; --群用户id app = getAppId(); --应用id gid = gID; --群id suid = suid; lastday = lastday; }; logD("ProtocolClubZhanji:requestDaYingJiaZhanJi()", table.tostring(tt)) httpPost(self.phpUrl, tt, handler(self, self.onDaYingJiaZhanJiresponse)) app.waitDialogManager:showWaitNetworkDialog(); end function ProtocolClubZhanji:onDaYingJiaZhanJiresponse(status, response) logD("ProtocolClubZhanji:onDaYingJiaZhanJiresponse()", tostring(status), table.tostring(response)) app.waitDialogManager:closeWaitNetworkDialog(); if status ~= "successed" then showTooltip("获取大赢家数据列表失败") return end --do return end local ttResponse = json.decode(response) if not ttResponse or type(ttResponse) ~= "table" then showTooltip("获取大赢家数据列表失败,数据为空") return end self.dayijingjiadetail = ttResponse.result --确认状态 for k,v in pairs(self.dayijingjiadetail.list) do local pid = v.gambid self.zhanJiIdxStatus[pid] = v.status end app:dispatchEvent({name = "onDaYingJiaZhanJiresponse"}) end --- ProtocolClubZhanji:requestDeleteZhanJi 请求删除战绩 -- @param gID 群id -- @param zhangjiid 战绩id -- @param optype 操作类型 function ProtocolClubZhanji:requestDeleteZhanJi(gID, zhangjiid, optype) optype = optype or 1 local tt = { action = "group.setupRoomlog"; --接口 uid = app.user.loginInfo.uid; --群用户id app = getAppId(); --应用id gid = gID; --群id gamb_id = zhangjiid; type = 2; value = optype }; app.waitDialogManager:showWaitNetworkDialog(); logD("ProtocolClubZhanji:requestDeleteZhanJi()", table.tostring(tt)) httpPost(self.phpUrl, tt, function(status, response) app.waitDialogManager:closeWaitNetworkDialog(); if status ~= "successed" then showTooltip("操作失败") return end local ttResponse = json.decode(response) if not ttResponse or type(ttResponse) ~= "table" or ttResponse.code ~= 200 then showTooltip(ttResponse.error) return end showTooltip("删除成功") local pid = ttResponse.result.gamb_id self.zhanjiInfoList[pid].hide = ttResponse.result.hide self:dispatchEvent({name = "onDeleteZhanJiResponse"}) end) end return ProtocolClubZhanji