1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- --[[
- Descripttion:支付服务
- version:
- Author: Neo,Huang
- Date: 2021-08-24 19:40:15
- LastEditors: Neo,Huang
- LastEditTime: 2021-09-24 10:26:38
- --]]
- local nodeMgr = require "nodeMgr"
- local baseService = require "baseService"
- local util_order = require("utils.util_order")
- local sessionData = require("data.session")
- local CMD = {}
- local INTERVAL = 180 -- 每3分钟轮询一次
- local orderReissue = {} -- {uid --> {order1, order2}}
- -- 加载未处理的订单
- local function loadUnprocessedOrder()
- local ret = util_order:get_unhandle_order_list()
- if ret and not table.empty(ret) then
- for _, v in ipairs(ret) do
- local uid = tonumber(v.uid)
- orderReissue[uid] = orderReissue[uid] or {}
- if not table.key_find(orderReissue[uid], "id", v.id) then
- table.insert(orderReissue[uid], v)
- end
- end
- end
- collectgarbage "collect"
- create_timeout(
- INTERVAL * 100,
- function()
- loadUnprocessedOrder()
- end
- )
- end
- -- 玩家登录处理订单
- function CMD.loginOrder(uid)
- -- log.print("玩家登录处理订单 uid:%s, %s", uid, tostring(orderReissue[uid]))
- local orderList = orderReissue[uid]
- if not orderList then
- return
- end
- local nodeInfo = sessionData:user_get_cluster_info(uid, "game")
- if nodeMgr.is_node_info_valid(nodeInfo) then
- -- 回调到逻辑服处理
- for _, orderAction in pairs(orderList) do
- local msg = {
- orderAction = orderAction,
- goodsId = tonumber(orderAction.itemId)
- }
- nodeMgr.send_with_node_info(nodeInfo, "doCmd", uid, "shop", "on_pay", msg)
- end
- end
- end
- -- 完成订单处理
- function CMD.finishOrder(uid, id)
- if not uid or not id then
- return
- end
- util_order:update_order_status(id, 1)
- local orderList = orderReissue[uid]
- if not orderList then
- return
- end
- log.print("完成订单处理 uid:%s, id:%s", uid, id)
- table.key_delete(orderList, "id", id)
- if table.empty(orderList) then
- orderReissue[uid] = nil
- end
- end
- -- 同步订单
- function CMD.syncOrder(uid, orderAction)
- log.print("同步订单 uid:%s, orderAction:%s", uid, tostring(orderAction))
- orderReissue[uid] = orderReissue[uid] or {}
- table.insert(orderReissue[uid], orderAction)
- end
- function CMD.onStart()
- loadUnprocessedOrder()
- end
- baseService.start(CMD, ".paySrv", true)
|