You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

432 lines
14 KiB

  1. -- PHP文档地址,用户名:dd 密码:ddtech
  2. -- http://120.76.238.236:8999/wiki/index.php?title=%E9%A6%96%E9%A1%B5
  3. local ProtocolClubZhanji = class("ProtocolClubZhanji", require("luaScript.Protocol.ProtocolZhanJi"))
  4. local InterfaceKey =
  5. {
  6. idx = "gamb.gidx", -- 茶馆战绩新接口
  7. PHP_CLUB_ZHANJI_CONSUME = "group.getGroupDateStat",--茶馆请求战绩消耗
  8. }
  9. function ProtocolClubZhanji:ctor()
  10. ProtocolClubZhanji.super.ctor(self);
  11. self.fileName = "ZhanJi_Club"
  12. --[[
  13. self.zhanJiIdxs =
  14. {
  15. [clubid] =
  16. {
  17. [usertype] =
  18. {
  19. tpage = 18,
  20. infos =
  21. {
  22. [page] = {idx, idx, idx, idx, ...},
  23. [page] = {idx, idx, idx, idx, ...},
  24. ...
  25. }
  26. },
  27. ...
  28. },
  29. ...
  30. },
  31. ...
  32. --]]
  33. self.zhanJiIdxs = {}
  34. self.zhanJiIdxStatus = {}
  35. self.zhanJiIdxLocals = {}
  36. -- 当前显示的战绩的总页数
  37. self.tpage = 0
  38. --大赢家详情数据
  39. self.dayijingjiadetail = nil
  40. self.shareUrl = "http://m.xiaopengol.com/replay.php" --分享战绩链接
  41. self:loadFromFile();
  42. end
  43. -- 初始化
  44. function ProtocolClubZhanji:init()
  45. end
  46. -- 获取指定的战绩信息列表
  47. -- clubId:茶馆ID
  48. -- usertype:用户类型
  49. -- page:页数
  50. function ProtocolClubZhanji:getZhanJiList(clubId, usertype, page)
  51. -- 首先找到对应的 idx_list
  52. local zhanjiInfoList = app.club_zhanji.zhanjiInfoList;
  53. if not zhanjiInfoList then
  54. return
  55. end
  56. if not self.zhanJiIdxs[clubId]
  57. or not self.zhanJiIdxs[clubId][usertype]
  58. or not self.zhanJiIdxs[clubId][usertype]["infos"]
  59. or not self.zhanJiIdxs[clubId][usertype]["infos"][page] then
  60. return {}
  61. end
  62. local zhanjiList = {}
  63. local idx_list = self.zhanJiIdxs[clubId][usertype]["infos"][page]
  64. local index = 10000--保持原有顺序,这里用递减
  65. for _,pid in pairs(idx_list) do
  66. if self.zhanjiInfoList[pid] and self.zhanjiInfoList[pid].hide ~= 1 then
  67. index = index - 1
  68. local endtime = tostring(index)
  69. zhanjiList[endtime] = self.zhanjiInfoList[pid]
  70. end
  71. end
  72. return zhanjiList;
  73. end
  74. --请求战绩的编号列表
  75. -- 通过ID查找指定ID玩家的战绩
  76. function ProtocolClubZhanji:getIdxlistByPlayerUid(clubId, userType, time, page,suid,isSearch)
  77. local tt =
  78. {
  79. action = InterfaceKey.idx;
  80. app = getAppId(); --应用id
  81. uid = app.user.loginInfo.uid; --用户id
  82. suid = suid; --需要查询的战绩的玩家ID
  83. gid = clubId; --茶馆ID
  84. date = time; --格式:"2018-02-02" 获取时间,如传空则获取当天
  85. type = userType; --1管理員查詢,2玩家查詢
  86. page = page or 1; --是否是新版(针对新版有两种游戏战绩的情况)
  87. };
  88. log("ProtocolClubZhanji:getIdxlist", table.tostring(tt))
  89. httpPost(self.phpUrl, tt, function(status, response)
  90. self:getIdxlistResponse(status, response, clubId, userType,isSearch)
  91. end)
  92. end
  93. --请求战绩的编号列表
  94. -- 茶馆的战绩分不同茶馆的不同类型的战绩,所以在这里单独保存ID,无需存文件
  95. function ProtocolClubZhanji:getIdxlist(clubId, userType, time, page)
  96. local tt =
  97. {
  98. action = InterfaceKey.idx;
  99. app = getAppId(); --应用id
  100. uid = app.user.loginInfo.uid; --用户id
  101. gid = clubId; --茶馆ID
  102. date = time; --格式:"2018-02-02" 获取时间,如传空则获取当天
  103. type = userType; --1管理員查詢,2玩家查詢
  104. page = page or 1; --是否是新版(针对新版有两种游戏战绩的情况)
  105. };
  106. log("ProtocolClubZhanji:getIdxlist", table.tostring(tt))
  107. httpPost(self.phpUrl, tt, function(status, response)
  108. self:getIdxlistResponse(status, response, clubId, userType)
  109. end)
  110. end
  111. -- 获取战绩ID列表的回复
  112. -- 并和本地数据进行比较,找出本地未下载的部分进行下载
  113. function ProtocolClubZhanji:getIdxlistResponse(status, response, clubId, userType,isSearch)
  114. --test
  115. local test = app.club_php:getCestIsOpen(clubId)
  116. logD("ProtocolClubZhanji:getIdxlistResponse()", status, response)
  117. local ret, ttResult = checkPhpResponse(status, response)
  118. if not ret then
  119. logE("ProtocolClubZhanji:getIdxlistResponse()", tostring(ttResult))
  120. local ttResposne = json.decode(response)
  121. if ttResposne and type(ttResposne) == "table" and ttResposne.error then
  122. showTooltip(ttResposne.error)
  123. end
  124. return
  125. end
  126. if ret and table.nums(ttResult.idx) == 0 and isSearch then
  127. showTooltip("该玩家暂无战绩")
  128. end
  129. -- 保存页数对应的idx
  130. local page = ttResult.page
  131. local tpage = ttResult.tpage
  132. self.tpage = tpage;
  133. -- 茶馆
  134. if not self.zhanJiIdxs[clubId] then
  135. self.zhanJiIdxs[clubId] = {}
  136. end
  137. -- 用户类型
  138. if not self.zhanJiIdxs[clubId][userType] then
  139. self.zhanJiIdxs[clubId][userType] = {}
  140. end
  141. -- 页数
  142. self.zhanJiIdxs[clubId][userType].tpage = tonumber(tpage)
  143. if not self.zhanJiIdxs[clubId][userType].infos then
  144. self.zhanJiIdxs[clubId][userType].infos = {}
  145. end
  146. local idxs = {}
  147. for k,pid in pairs(ttResult.idx) do
  148. table.insert(idxs, pid)
  149. end
  150. self.zhanJiIdxs[clubId][userType]["infos"][page] = idxs;
  151. --确认状态
  152. for pid,v in pairs(ttResult.idxStatus) do
  153. self.zhanJiIdxStatus[pid] = v.status
  154. self.zhanJiIdxLocals[pid] = v.locals
  155. -- table.insert(idxs, pid)
  156. end
  157. if ttResult.url and ttResult.url~="" then
  158. self.shareUrl = ttResult.url
  159. end
  160. -- 比较没有的战绩并下载
  161. self:checkAndDownload(ttResult.idx);
  162. end
  163. --请求战绩的消耗
  164. function ProtocolClubZhanji:requestZhanjiConsume(gID, time)
  165. local tt =
  166. {
  167. action = "group.getGroupDateStat"; --接口
  168. uid = app.user.loginInfo.uid; --群用户id
  169. app = getAppId(); --应用id
  170. gid = gID; --群id
  171. date = time; --日期
  172. };
  173. logD("ProtocolClubZhanji:requestZhanjiConsume()", table.tostring(tt))
  174. httpPost(self.phpUrl, tt, handler(self, self.onZhanjiConsumeResponse))
  175. end
  176. function ProtocolClubZhanji:onZhanjiConsumeResponse(status, response)
  177. logD("ProtocolClubZhanji:onZhanjiConsumeResponse()", tostring(status), table.tostring(response))
  178. if status ~= "successed" then
  179. -- showTooltip("获取消耗数据失败,链接失败")
  180. return
  181. end
  182. --do return end
  183. local ttResponse = json.decode(response)
  184. if not ttResponse or type(ttResponse) ~= "table" then
  185. -- showTooltip("获取消耗数据失败,数据为空")
  186. return
  187. end
  188. self.ZhanjiXiaohao = {};
  189. if ttResponse.code == 200 and ttResponse.result and type(ttResponse.result) == "table" then
  190. local roomNum = ttResponse.result.openhouse_count; --成局数
  191. local cardCost = ttResponse.result.card_consume_count; --房卡消耗
  192. local activityCardCost = ttResponse.result.owner_props_card_count; --活动房卡消耗
  193. local costCardCount = ttResponse.result.owner_openhouse_count; --扣卡局数
  194. local notCostCardCount = ttResponse.result.owner_unconsume_count; --未扣卡局数
  195. local propList = ttResponse.result.propList; -- 专用钻石消耗明细
  196. app:dispatchEvent({name = "ClubZhanjiConsumeCallback", roomNum = roomNum, cardCost = cardCost, activityCardCost = activityCardCost,
  197. costCardCount = costCardCount,notCostCardCount = notCostCardCount, propList = propList});
  198. end
  199. end
  200. --请求战绩确认
  201. function ProtocolClubZhanji:requestZhanjiSure(gID,idx ,callback)
  202. local phpAddress = getGlobalPhpUrl()
  203. local tt = {};
  204. tt.action = "group.setupRoomlog";
  205. tt.uid = app.user.loginInfo.uid;--设置人
  206. tt.app = getAppId(); --应用id
  207. tt.gid = gID; --茶馆ID
  208. tt.gamb_id = idx --战绩标示
  209. tt.type = 1 --1茶馆状态确认
  210. logD("ProtocolClubZhanji:requestZhanjiSure()", table.tostring(tt))
  211. httpPost(phpAddress, tt, function(status, response)
  212. logD("ProtocolClubZhanji:requestZhanjiSure() response", response)
  213. local clubResponse = json.decode(response)
  214. if type(clubResponse) ~= "table" then
  215. showPHPFailedResult("请求战绩确认 response type is not table")
  216. return
  217. end
  218. logD("ProtocolClubZhanji:requestZhanjiSure() response", table.tostring(clubResponse))
  219. -- self.zhanjiTongjiDataList = {};
  220. local result = clubResponse.result
  221. if clubResponse.code == 200 then
  222. self.zhanJiIdxStatus[result.gamb_id] = result.status
  223. if callback then callback() end
  224. -- app:dispatchEvent({name = "ClubZhanjiSureCallback", result = result});
  225. elseif clubResponse.code == 1052 then --已经确认过了
  226. self.zhanJiIdxStatus[idx] = 2
  227. if callback then callback() end
  228. else
  229. showConfirmDialog(clubResponse.error)
  230. end
  231. end)
  232. end
  233. --获取战绩统计数据
  234. function ProtocolClubZhanji:requestZhanjiGroupDateList(gID, startdate, enddate)
  235. local phpAddress = getGlobalPhpUrl()
  236. local tt = {};
  237. tt.action = "group.getGroupDateStatList";
  238. tt.uid = app.user.loginInfo.uid;--设置人
  239. tt.app = getAppId(); --应用id
  240. tt.gid = gID; --茶馆ID
  241. tt.startdate = startdate; --不传参数默认最近一周
  242. tt.enddate = enddate; --不传参数默认当天日期
  243. tt.version="20190122"
  244. log("ProtocolClubZhanji:requestZhanjiGroupDateList_send", table.tostring(tt))
  245. app.waitDialogManager:showWaitNetworkDialog("连接中...");
  246. httpPost(phpAddress, tt, function(status, response)
  247. app.waitDialogManager:closeWaitNetworkDialog();
  248. log("ProtocolClubZhanji:requestZhanjiGroupDateList", table.tostring(response))
  249. local clubResponse = json.decode(response)
  250. if type(clubResponse) ~= "table" then
  251. showPHPFailedResult("获取战绩统计数据 response type is not table")
  252. return
  253. end
  254. self.zhanjiTongjiDataList = {};
  255. local result = clubResponse.result
  256. if clubResponse.code == 200 then
  257. if result.list and table.nums(result.list) > 0 then
  258. local tTongjiList = {};
  259. -- local idx = 1
  260. for date,list in pairs(result.list) do
  261. local zhanjiTongjiDataList = {}
  262. -- for _,list
  263. local zhanjiTongjiData = {}
  264. zhanjiTongjiData.create_date = date
  265. zhanjiTongjiData.openhouse_count = 0
  266. zhanjiTongjiData.owner_card_consume_count = 0
  267. zhanjiTongjiData.owner_props_card_count = 0
  268. zhanjiTongjiData.play_win_number = 0
  269. zhanjiTongjiData.cost_card_count = 0--扣卡局
  270. zhanjiTongjiData.not_cost_card_count = 0--未扣卡局
  271. for _,v in pairs(list) do
  272. -- zhanjiTongjiData.create_date = zhanjiTongjiData.create_date + v.create_date;--日期
  273. zhanjiTongjiData.openhouse_count = zhanjiTongjiData.openhouse_count + v.openhouse_count;--开房成局
  274. zhanjiTongjiData.owner_card_consume_count = zhanjiTongjiData.owner_card_consume_count + v.owner_card_consume_count;--群主消耗
  275. zhanjiTongjiData.owner_props_card_count = zhanjiTongjiData.owner_props_card_count + v.owner_props_card_count;--群主专属房卡/房卡消耗
  276. --新加
  277. zhanjiTongjiData.cost_card_count = zhanjiTongjiData.cost_card_count + v.owner_openhouse_count;--扣卡局
  278. zhanjiTongjiData.not_cost_card_count = zhanjiTongjiData.not_cost_card_count + v.owner_unconsume_count;--未扣卡局
  279. end
  280. zhanjiTongjiData.list = list
  281. if result.extlist and result.extlist[date] then
  282. zhanjiTongjiData.play_win_number = result.extlist[date].play_win_number or 0
  283. end
  284. tTongjiList[date] = zhanjiTongjiData
  285. -- idx = idx + 1
  286. end
  287. self.zhanjiTongjiDataList[tonumber(gID)] = tTongjiList;
  288. end
  289. self:dispatchEvent({name = "onGetZhanjiGroupDateListSucc"});
  290. elseif clubResponse.code == 1020 then
  291. showConfirmDialog("获取战绩统计数据,参数错误 code = "..clubResponse.code)
  292. elseif clubResponse.code == 1026 then
  293. showConfirmDialog("获取战绩统计数据,非管理员操作 code = "..clubResponse.code);
  294. elseif clubResponse.code == 1014 then
  295. showConfirmDialog(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_ZHANJI_ERR_1104 or PLN.CLUB_ZHANJI_ERR_1104..clubResponse.code);
  296. else
  297. showConfirmDialog("获取战绩统计数据 code = "..clubResponse.code)
  298. end
  299. end)
  300. end
  301. --请求大赢家明细
  302. function ProtocolClubZhanji:requestDaYingJiaZhanJi(gID, suid,lastday)
  303. local tt =
  304. {
  305. action = "group.winlog"; --接口
  306. uid = app.user.loginInfo.uid; --群用户id
  307. app = getAppId(); --应用id
  308. gid = gID; --群id
  309. suid = suid;
  310. lastday = lastday;
  311. };
  312. logD("ProtocolClubZhanji:requestDaYingJiaZhanJi()", table.tostring(tt))
  313. httpPost(self.phpUrl, tt, handler(self, self.onDaYingJiaZhanJiresponse))
  314. app.waitDialogManager:showWaitNetworkDialog();
  315. end
  316. function ProtocolClubZhanji:onDaYingJiaZhanJiresponse(status, response)
  317. logD("ProtocolClubZhanji:onDaYingJiaZhanJiresponse()", tostring(status), table.tostring(response))
  318. app.waitDialogManager:closeWaitNetworkDialog();
  319. if status ~= "successed" then
  320. showTooltip("获取大赢家数据列表失败")
  321. return
  322. end
  323. --do return end
  324. local ttResponse = json.decode(response)
  325. if not ttResponse or type(ttResponse) ~= "table" then
  326. showTooltip("获取大赢家数据列表失败,数据为空")
  327. return
  328. end
  329. self.dayijingjiadetail = ttResponse.result
  330. --确认状态
  331. for k,v in pairs(self.dayijingjiadetail.list) do
  332. local pid = v.gambid
  333. self.zhanJiIdxStatus[pid] = v.status
  334. end
  335. app:dispatchEvent({name = "onDaYingJiaZhanJiresponse"})
  336. end
  337. --- ProtocolClubZhanji:requestDeleteZhanJi 请求删除战绩
  338. -- @param gID 群id
  339. -- @param zhangjiid 战绩id
  340. -- @param optype 操作类型
  341. function ProtocolClubZhanji:requestDeleteZhanJi(gID, zhangjiid, optype)
  342. optype = optype or 1
  343. local tt =
  344. {
  345. action = "group.setupRoomlog"; --接口
  346. uid = app.user.loginInfo.uid; --群用户id
  347. app = getAppId(); --应用id
  348. gid = gID; --群id
  349. gamb_id = zhangjiid;
  350. type = 2;
  351. value = optype
  352. };
  353. app.waitDialogManager:showWaitNetworkDialog();
  354. logD("ProtocolClubZhanji:requestDeleteZhanJi()", table.tostring(tt))
  355. httpPost(self.phpUrl, tt, function(status, response)
  356. app.waitDialogManager:closeWaitNetworkDialog();
  357. if status ~= "successed" then
  358. showTooltip("操作失败")
  359. return
  360. end
  361. local ttResponse = json.decode(response)
  362. if not ttResponse or type(ttResponse) ~= "table" or ttResponse.code ~= 200 then
  363. showTooltip(ttResponse.error)
  364. return
  365. end
  366. showTooltip("删除成功")
  367. local pid = ttResponse.result.gamb_id
  368. self.zhanjiInfoList[pid].hide = ttResponse.result.hide
  369. self:dispatchEvent({name = "onDeleteZhanJiResponse"})
  370. end)
  371. end
  372. return ProtocolClubZhanji