123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- --[[
- Descripttion:战斗
- version:
- Author: Neo,Huang
- Date: 2023-11-18 12:21:05
- LastEditors: Neo,Huang
- LastEditTime: 2023-11-18 12:26:57
- --]]
- local timeUtil = require("utils.timeUtil")
- local mysqlUtil = require("utils.mysqlUtil")
- local util_player = require("utils.util_player")
- local boxAdapt = require("adapt.boxAdapt")
- local root = {}
- -- 新增记录
- function root:add_battle_record(settle, totalPrice)
- if is_empty(settle) then
- return false
- end
- if
- is_empty(settle.roomId) or is_empty(settle.battleBoxList) or is_empty(settle.createTime) or
- is_empty(settle.battleTime) or
- is_empty(settle.battleId) or
- is_empty(settle.winUid) or
- is_empty(settle.battlePlayerList)
- then
- return false
- end
- local expireTime = timeUtil.now() + timeUtil.SEC_PER_DAY * 365
- local columns =
- "`roomId`,`battleBoxList`,`createTime`,`battleTime`,`battleId`,`winUid`,`totalPrice`,`battlePlayerList`,`expireTime`"
- local values =
- string.format(
- "%s,'%s',%s,%s,'%s',%s,%s,'%s',%s",
- tostring(settle.roomId),
- cjson_encode(settle.battleBoxList),
- tostring(settle.createTime),
- tostring(settle.battleTime),
- tostring(settle.battleId),
- tostring(settle.winUid),
- tostring(totalPrice),
- cjson_encode(settle.battlePlayerList),
- tostring(expireTime)
- )
- for k, v in ipairs(settle.battlePlayerList) do
- local key = string.format("`battleUid%s`", tostring(k))
- columns = columns .. "," .. key
- values = values .. string.format(",%s", tostring(v.uid))
- end
- local sql = string.format("INSERT INTO `mdl_battlerecord` (%s) VALUES (%s); ", columns, values)
- local ok = mysqlUtil:insert(sql)
- log.info("add_battle_record sql[%s] ok[%s]", tostring(sql), tostring(ok))
- return ok
- end
- -- 打包历史战绩
- function root:pack_battle_record_list(data)
- local list = {}
- if is_empty(data) then
- return list
- end
- for _, v in ipairs(data) do
- -- 房间信息
- local roomInfo = {
- roomId = tonumber(v.roomId),
- battleBoxList = cjson_decode(v.battleBoxList),
- status = 2,
- createTime = tonumber(v.createTime),
- battleTime = tonumber(v.battleTime),
- playerList = {}
- }
- -- 战斗玩家列表
- local battlePlayerList = cjson_decode(v.battlePlayerList)
- for _, _v in ipairs(battlePlayerList) do
- local info = {
- playerInfo = util_player:get_base_info(v.uid),
- seatId = _v.seatId
- }
- table.insert(roomInfo.playerList, info)
- end
- local info = {
- roomInfo = roomInfo,
- battleId = v.battleId,
- winUid = tonumber(v.winUid),
- battlePlayerList = battlePlayerList
- }
- table.insert(list, info)
- end
- return list
- end
- -- 获取精彩对战记录
- function root:get_brilliant_record_list()
- local minTotalPrice = boxAdapt:battle_const("battle_box_open_total_price_is_exciting_battle") or 10000
- local count = boxAdapt:battle_const("exciting_battle_record_num") or 20
- local sql =
- string.format(
- "SELECT * FROM `mdl_battlerecord` WHERE `totalPrice`>=%s ORDER BY battleTime DESC limit %s",
- tostring(minTotalPrice),
- tostring(count)
- )
- local ok, ret = mysqlUtil:select(sql)
- if not ok or is_empty(ret) then
- return
- end
- return self:pack_battle_record_list(ret)
- end
- -- 获取对战记录
- function root:get_record_list(lastTime)
- lastTime = lastTime or timeUtil.now()
- local count = 20
- local sql =
- string.format(
- "SELECT * FROM `mdl_battlerecord` WHERE `battleTime`<%s ORDER BY battleTime DESC limit %s",
- tostring(lastTime),
- tostring(count)
- )
- local ok, ret = mysqlUtil:select(sql)
- if not ok or is_empty(ret) then
- return
- end
- return self:pack_battle_record_list(ret)
- end
- -- 获取玩家个人对战记录
- function root:get_player_record_list(uid, lastTime)
- if is_empty(uid) then
- return
- end
- lastTime = lastTime or timeUtil.now()
- local count = 20
- local sql =
- string.format(
- "SELECT * FROM `mdl_battlerecord` WHERE `battleTime`<%s and (`battleUid1`=%s or `battleUid2`=%s or `battleUid3`=%s or `battleUid4`=%s or `battleUid5`=%s) ORDER BY battleTime DESC limit %s",
- tostring(lastTime),
- tostring(uid),
- tostring(uid),
- tostring(uid),
- tostring(uid),
- tostring(uid),
- tostring(count)
- )
- local ok, ret = mysqlUtil:select(sql)
- if not ok or is_empty(ret) then
- return
- end
- return self:pack_battle_record_list(ret)
- end
- return root
|