123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- -- 支付
- local code = require "code"
- local skynet = require "skynet"
- local nodeMgr = require "nodeMgr"
- local timeUtil = require "utils.timeUtil"
- local serverLogUtil = require "utils.serverLogUtil"
- local util_order = require("utils.util_order")
- local sessionData = require("data.session")
- local userData = require("data.user")
- local root = {}
- -- 支付埋点日志
- local function logPay(uid, orderAction)
- skynet.fork(
- function()
- local playerInfo = {
- uid = uid,
- bandShareCode = userData:get_key_info(uid, "bandShareCode"),
- version = userData:get_key_info(uid, "version")
- }
- -- 生成支付日志
- serverLogUtil.logPay(playerInfo, orderAction)
- end
- )
- end
- -- 充值到账
- function root.recharge(msg)
- -- 检查回调参数
- local payCode, orderAction = msg.code, msg.orderAction
- if not orderAction then
- log.error("[支付回调]订单无效")
- return false
- end
- local uid, orderId = tonumber(orderAction.uid), orderAction.orderNo
- -- 检查订单有效性
- local orderStatus = tonumber(orderAction.status or 0)
- if orderStatus == 0 then
- return util_order:handle_invalid_order(orderAction)
- end
- -- 检查订单物品是否存在
- local itemId = tonumber(orderAction.itemId or 0)
- if itemId <= 0 then
- orderAction.status = 0
- orderAction.resMsg = "订单参数错误"
- log.error("订单参数错误1, itemId:%d, uid:%d", itemId, uid)
- return util_order:handle_invalid_order(orderAction)
- end
- -- 检查玩家的在线情况
- local nodeInfo = sessionData:user_get_cluster_info(uid, "game")
- -- 玩家在线的处理
- if nodeMgr.is_node_info_valid(nodeInfo) then
- -- 回调到逻辑服处理
- local pack = {
- orderAction = orderAction,
- goodsId = tonumber(orderAction.itemId)
- }
- nodeMgr.send_with_node_info(nodeInfo, "doCmd", uid, "shop", "on_pay", pack)
- else
- nodeMgr.send("global", ".paySrv", "syncOrder", uid, orderAction)
- end
- pcall(logPay, uid, orderAction)
- return true
- end
- -- 支付服订单回调
- function root.pay_notify(msg)
- if (not msg) or (not msg.orderAction) or (not msg.orderAction.orderNo) or (not msg.orderAction.uid) then
- log.error("[支付回调]订单错误, data:%s", tostring(msg or ""))
- return code.OK
- end
- local orderAction = msg.orderAction
- local orderType = string.find(orderAction.pay, "baidu")
- if not orderType then
- local isExist = util_order:is_order_exist(orderAction.orderNo)
- if isExist then
- log.error("[支付回调]订单重复:Order:%s", tostring(msg or ""))
- return code.OK
- end
- end
- if orderAction.createtime and #(orderAction.createtime) <= 0 then
- orderAction.createtime = timeUtil.toString(timeUtil.currentTime())
- end
- -- 订单入库
- util_order:add_order(orderAction)
- util_order:on_shop_order(orderAction)
- orderAction.id = util_order:get_order_id(orderAction.orderNo, orderAction.uid)
- log.info("payOrder orderAction[%s]", tostring(orderAction))
- -- 支付到账
- root.recharge(msg)
- return code.OK
- end
- return root
|