util_record_item.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. --[[
  2. Descripttion:明细
  3. version:
  4. Author: Neo,Huang
  5. Date: 2023-11-22 22:52:54
  6. LastEditors: Neo,Huang
  7. LastEditTime: 2023-11-22 23:29:30
  8. --]]
  9. local mysqlUtil = require("utils.mysqlUtil")
  10. local timeUtil = require("utils.timeUtil")
  11. local gameConst = require("const.gameConst")
  12. local root = {}
  13. -- 新增记录
  14. function root:add_item_record(list)
  15. if is_empty(list) then
  16. return
  17. end
  18. -- 2023-11-22;2023-11-22 20:35:51;1000001;nil;999;shop-pay-10203;102;680;3400;
  19. local columns = "(`createTime`,`uid`,`bandShareCode`,`channel`,`eventId`,`itemId`,`delta`,`remainCount`)"
  20. local values = nil
  21. for _, v in ipairs(list) do
  22. local params = string.split(v, ";")
  23. local value =
  24. string.format(
  25. "(%s,%s,'%s',%s,'%s',%s,%s,%s)",
  26. getTimestamp(params[2]), -- createTime
  27. tostring(params[3]), -- uid
  28. tostring(params[4]), -- bandShareCode
  29. tostring(params[5]), -- channel
  30. tostring(params[6]), -- eventId
  31. tostring(params[7]), -- itemId
  32. tostring(params[8]), -- delta
  33. tostring(params[9]) -- remainCount
  34. )
  35. if values == nil then
  36. values = value
  37. else
  38. values = string.format("%s,%s", values, value)
  39. end
  40. end
  41. local sql = string.format("INSERT INTO `mdl_itemrecord` %s VALUES %s; ", columns, values)
  42. local ok = mysqlUtil:insert(sql)
  43. log.info("add_battle_record sql[%s] ok[%s]", tostring(sql), tostring(ok))
  44. return ok
  45. end
  46. -- 打包明细
  47. function root:pack_item_record_list(data)
  48. local list = {}
  49. if is_empty(data) then
  50. return list
  51. end
  52. for _, v in ipairs(data) do
  53. local info = {
  54. id = tonumber(v.id),
  55. createTime = tonumber(v.createTime),
  56. reason = v.eventId,
  57. itemId = tonumber(v.itemId),
  58. delta = tonumber(v.delta),
  59. remainCount = tonumber(v.remainCount)
  60. }
  61. table.insert(list, info)
  62. end
  63. return list
  64. end
  65. -- 获取流水记录
  66. function root:get_gold_record(uid, lastTime)
  67. if is_empty(uid) then
  68. return
  69. end
  70. lastTime = lastTime or timeUtil.now()
  71. local count = 20
  72. local sql =
  73. string.format(
  74. "SELECT * FROM `mdl_itemrecord` WHERE `uid`=%s and (`itemId`=%s or `itemId`=%s) `createTime`<%s ORDER BY createTime DESC limit %s",
  75. tostring(uid),
  76. tostring(gameConst.ITEM_ID.GOLD),
  77. tostring(gameConst.ITEM_ID.DIAMOND),
  78. tostring(lastTime),
  79. tostring(count)
  80. )
  81. local ok, ret = mysqlUtil:select(sql)
  82. if not ok or is_empty(ret) then
  83. return
  84. end
  85. return self:pack_item_record_list(ret)
  86. end
  87. -- 获取流水记录
  88. function root:get_wapon_record(uid, lastTime)
  89. if is_empty(uid) then
  90. return
  91. end
  92. lastTime = lastTime or timeUtil.now()
  93. local count = 20
  94. local sql =
  95. string.format(
  96. "SELECT * FROM `mdl_itemrecord` WHERE `uid`=%s and `itemId`!=%s and `itemId`!=%s `createTime`<%s ORDER BY createTime DESC limit %s",
  97. tostring(uid),
  98. tostring(gameConst.ITEM_ID.GOLD),
  99. tostring(gameConst.ITEM_ID.DIAMOND),
  100. tostring(lastTime),
  101. tostring(count)
  102. )
  103. local ok, ret = mysqlUtil:select(sql)
  104. if not ok or is_empty(ret) then
  105. return
  106. end
  107. return self:pack_item_record_list(ret)
  108. end
  109. return root