test.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. -- 测试工具
  2. local code = require "code"
  3. local timeUtil = require "utils.timeUtil"
  4. local util_order = require("utils.util_order")
  5. local moduleData = require("data.module")
  6. local bagData = require("data.bag")
  7. local root = {}
  8. -- if not IS_TEST then return end
  9. -- 调试系统时间
  10. function root.test_debug_system_time(role, msg)
  11. if not IS_TEST then
  12. return code.UNKNOWN
  13. end
  14. local uid = msg.uid
  15. if not uid then
  16. return code.PARAMTER_ERROR
  17. end
  18. local time, reset = msg.time, msg.reset or 0
  19. if reset == 0 then
  20. moduleData:hset(uid, "user", "time:sys")
  21. moduleData:hset(uid, "user", "time:logout")
  22. elseif reset == 1 then
  23. -- 间隔时间
  24. local deltaTime = time - skynet_time()
  25. moduleData:hset(uid, "user", "time:sys", deltaTime)
  26. elseif reset == 2 then
  27. moduleData:hset(uid, "user", "registerTime", time)
  28. elseif reset == 3 then
  29. local deltaTime = time - skynet_time()
  30. moduleData:hset(uid, "user", "time:logout", deltaTime)
  31. end
  32. local ret = {}
  33. ret.sysTime = timeUtil.now(uid)
  34. ret.debugTime = moduleData:hget_int(uid, "user", "time:sys")
  35. return code.OK, ret
  36. end
  37. function root.test_add_items(role, msg)
  38. local uid = role.uid
  39. local items = msg.items
  40. if not items then
  41. return code.PARAMTER_ERROR
  42. end
  43. for k, v in ipairs(items) do
  44. v.force = true
  45. end
  46. bagData:add_items(uid, items, "gmset")
  47. return code.OK, {}
  48. end
  49. function root.test_pay_goods(role, msg)
  50. local orderId = msg.orderId
  51. local payName = msg.payName
  52. local status = msg.status
  53. local resMsg = msg.resMsg
  54. local amount = msg.amount / 100.0
  55. local errCode = 1
  56. if not msg.status then
  57. errCode = 0
  58. end
  59. local data = string.split(orderId, "_")
  60. local channel, uid, gid = tonumber(data[2]), tonumber(data[3]), tonumber(data[4])
  61. log.print("orderId:%s uid:%s channel:%s gid:%s", orderId, uid, channel, gid)
  62. local pack = {
  63. ["code"] = errCode,
  64. ["orderNo"] = msg.orderId,
  65. ["orderAction"] = {
  66. ["type"] = 0,
  67. ["code"] = "TRADE_FINISHED",
  68. ["id"] = 0,
  69. ["cut"] = 0,
  70. ["createtime"] = "",
  71. ["uid"] = uid,
  72. ["itemId"] = gid,
  73. ["amount"] = amount,
  74. ["time"] = tostring(timeUtil.now(role.uid)),
  75. ["channel"] = channel,
  76. ["status"] = errCode,
  77. ["orderNo"] = msg.orderId,
  78. ["pay"] = "test_pay_goods",
  79. ["resMsg"] = "TRADE_FINISHED",
  80. ["tradeNo"] = msg.orderId
  81. },
  82. ["goodsId"] = gid,
  83. ["name"] = "test_pay_goods",
  84. ["channel"] = channel,
  85. ["cmd"] = "test_pay_goods",
  86. ["uid"] = uid,
  87. ["pp"] = "shop",
  88. ["gid"] = gid
  89. }
  90. pack.amount = amount
  91. -- 测试订单入库
  92. util_order:add_order(pack.orderAction)
  93. util_order:on_shop_order(pack.orderAction)
  94. pack.orderAction.id = util_order:get_order_id(pack.orderAction.orderNo, pack.orderAction.uid)
  95. if errCode ~= 1 then
  96. return code.OK
  97. end
  98. -- 发送物品
  99. local shopInterface = require "interface.shop"
  100. return shopInterface.on_pay(role, pack)
  101. end
  102. return root