123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- --[[
- Descripttion:明细
- version:
- Author: Neo,Huang
- Date: 2023-11-22 22:52:54
- LastEditors: Neo,Huang
- LastEditTime: 2023-11-22 23:29:30
- --]]
- local mysqlUtil = require("utils.mysqlUtil")
- local timeUtil = require("utils.timeUtil")
- local gameConst = require("const.gameConst")
- local root = {}
- -- 新增记录
- function root:add_item_record(list)
- if is_empty(list) then
- return
- end
- -- 2023-11-22;2023-11-22 20:35:51;1000001;nil;999;shop-pay-10203;102;680;3400;
- local columns = "(`createTime`,`uid`,`bandShareCode`,`channel`,`eventId`,`itemId`,`delta`,`remainCount`)"
- local values = nil
- for _, v in ipairs(list) do
- local params = string.split(v, ";")
- local value =
- string.format(
- "(%s,%s,'%s',%s,'%s',%s,%s,%s)",
- getTimestamp(params[2]), -- createTime
- tostring(params[3]), -- uid
- tostring(params[4]), -- bandShareCode
- tostring(params[5]), -- channel
- tostring(params[6]), -- eventId
- tostring(params[7]), -- itemId
- tostring(params[8]), -- delta
- tostring(params[9]) -- remainCount
- )
- if values == nil then
- values = value
- else
- values = string.format("%s,%s", values, value)
- end
- end
- local sql = string.format("INSERT INTO `mdl_itemrecord` %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_item_record_list(data)
- local list = {}
- if is_empty(data) then
- return list
- end
- for _, v in ipairs(data) do
- local info = {
- id = tonumber(v.id),
- createTime = tonumber(v.createTime),
- reason = v.eventId,
- itemId = tonumber(v.itemId),
- delta = tonumber(v.delta),
- remainCount = tonumber(v.remainCount)
- }
- table.insert(list, info)
- end
- return list
- end
- -- 获取流水记录
- function root:get_gold_record(uid, lastTime)
- if is_empty(uid) then
- return
- end
- lastTime = lastTime or timeUtil.now()
- local count = 20
- local sql =
- string.format(
- "SELECT * FROM `mdl_itemrecord` WHERE `uid`=%s and (`itemId`=%s or `itemId`=%s) `createTime`<%s ORDER BY createTime DESC limit %s",
- tostring(uid),
- tostring(gameConst.ITEM_ID.GOLD),
- tostring(gameConst.ITEM_ID.DIAMOND),
- tostring(lastTime),
- tostring(count)
- )
- local ok, ret = mysqlUtil:select(sql)
- if not ok or is_empty(ret) then
- return
- end
- return self:pack_item_record_list(ret)
- end
- -- 获取流水记录
- function root:get_wapon_record(uid, lastTime)
- if is_empty(uid) then
- return
- end
- lastTime = lastTime or timeUtil.now()
- local count = 20
- local sql =
- string.format(
- "SELECT * FROM `mdl_itemrecord` WHERE `uid`=%s and `itemId`!=%s and `itemId`!=%s `createTime`<%s ORDER BY createTime DESC limit %s",
- tostring(uid),
- tostring(gameConst.ITEM_ID.GOLD),
- tostring(gameConst.ITEM_ID.DIAMOND),
- tostring(lastTime),
- tostring(count)
- )
- local ok, ret = mysqlUtil:select(sql)
- if not ok or is_empty(ret) then
- return
- end
- return self:pack_item_record_list(ret)
- end
- return root
|