-- 测试工具 local code = require "code" local timeUtil = require "utils.timeUtil" local util_order = require("utils.util_order") local moduleData = require("data.module") local bagData = require("data.bag") local root = {} -- if not IS_TEST then return end -- 调试系统时间 function root.test_debug_system_time(role, msg) if not IS_TEST then return code.UNKNOWN end local uid = msg.uid if not uid then return code.PARAMTER_ERROR end local time, reset = msg.time, msg.reset or 0 if reset == 0 then moduleData:hset(uid, "user", "time:sys") moduleData:hset(uid, "user", "time:logout") elseif reset == 1 then -- 间隔时间 local deltaTime = time - skynet_time() moduleData:hset(uid, "user", "time:sys", deltaTime) elseif reset == 2 then moduleData:hset(uid, "user", "registerTime", time) elseif reset == 3 then local deltaTime = time - skynet_time() moduleData:hset(uid, "user", "time:logout", deltaTime) end local ret = {} ret.sysTime = timeUtil.now(uid) ret.debugTime = moduleData:hget_int(uid, "user", "time:sys") return code.OK, ret end function root.test_add_items(role, msg) local uid = role.uid local items = msg.items if not items then return code.PARAMTER_ERROR end for k, v in ipairs(items) do v.force = true end bagData:add_items(uid, items, "gmset") return code.OK, {} end function root.test_pay_goods(role, msg) local orderId = msg.orderId local payName = msg.payName local status = msg.status local resMsg = msg.resMsg local amount = msg.amount / 100.0 local errCode = 1 if not msg.status then errCode = 0 end local data = string.split(orderId, "_") local channel, uid, gid = tonumber(data[2]), tonumber(data[3]), tonumber(data[4]) log.print("orderId:%s uid:%s channel:%s gid:%s", orderId, uid, channel, gid) local pack = { ["code"] = errCode, ["orderNo"] = msg.orderId, ["orderAction"] = { ["type"] = 0, ["code"] = "TRADE_FINISHED", ["id"] = 0, ["cut"] = 0, ["createtime"] = "", ["uid"] = uid, ["itemId"] = gid, ["amount"] = amount, ["time"] = tostring(timeUtil.now(role.uid)), ["channel"] = channel, ["status"] = errCode, ["orderNo"] = msg.orderId, ["pay"] = "test_pay_goods", ["resMsg"] = "TRADE_FINISHED", ["tradeNo"] = msg.orderId }, ["goodsId"] = gid, ["name"] = "test_pay_goods", ["channel"] = channel, ["cmd"] = "test_pay_goods", ["uid"] = uid, ["pp"] = "shop", ["gid"] = gid } pack.amount = amount -- 测试订单入库 util_order:add_order(pack.orderAction) util_order:on_shop_order(pack.orderAction) pack.orderAction.id = util_order:get_order_id(pack.orderAction.orderNo, pack.orderAction.uid) if errCode ~= 1 then return code.OK end -- 发送物品 local shopInterface = require "interface.shop" return shopInterface.on_pay(role, pack) end return root