test.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. bagData:add_items(uid, items, "gmset")
  44. return code.OK, {}
  45. end
  46. function root:test_pay_goods(role, msg)
  47. local orderId = msg.orderId
  48. local payName = msg.payName
  49. local status = msg.status
  50. local resMsg = msg.resMsg
  51. local amount = msg.amount / 100.0
  52. local errCode = 1
  53. if not msg.status then
  54. errCode = 0
  55. end
  56. local data = string.split(orderId, "_")
  57. local channel, uid, gid = tonumber(data[2]), tonumber(data[3]), tonumber(data[4])
  58. log.print("orderId:%s uid:%s channel:%s gid:%s", orderId, uid, channel, gid)
  59. local pack = {
  60. ["code"] = errCode,
  61. ["orderNo"] = msg.orderId,
  62. ["orderAction"] = {
  63. ["type"] = 0,
  64. ["code"] = "TRADE_FINISHED",
  65. ["id"] = 0,
  66. ["cut"] = 0,
  67. ["createtime"] = "",
  68. ["uid"] = uid,
  69. ["itemId"] = gid,
  70. ["amount"] = amount,
  71. ["time"] = tostring(timeUtil.now(role.uid)),
  72. ["channel"] = channel,
  73. ["status"] = errCode,
  74. ["orderNo"] = msg.orderId,
  75. ["pay"] = "test_pay_goods",
  76. ["resMsg"] = "TRADE_FINISHED",
  77. ["tradeNo"] = msg.orderId
  78. },
  79. ["goodsId"] = gid,
  80. ["name"] = "test_pay_goods",
  81. ["channel"] = channel,
  82. ["cmd"] = "test_pay_goods",
  83. ["uid"] = uid,
  84. ["pp"] = "shop",
  85. ["gid"] = gid
  86. }
  87. pack.amount = amount
  88. -- 测试订单入库
  89. util_order:add_order(pack.orderAction)
  90. pack.orderAction.id = util_order:get_order_id(pack.orderAction.orderNo, pack.orderAction.uid)
  91. if errCode ~= 1 then
  92. return code.OK
  93. end
  94. -- 发送物品
  95. local shopInterface = require "interface.shop"
  96. return shopInterface:on_pay(role, pack)
  97. end
  98. return root