浏览代码

修改http服务器架构

neo 1 年之前
父节点
当前提交
c7916db4b2

+ 94 - 0
common/service/paySrv.lua

@@ -0,0 +1,94 @@
1
+--[[
2
+Descripttion:支付服务
3
+version:
4
+Author: Neo,Huang
5
+Date: 2021-08-24 19:40:15
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2021-09-24 10:26:38
8
+--]]
9
+local nodeMgr = require "nodeMgr"
10
+local baseService = require "baseService"
11
+local util_order = require("utils.util_order")
12
+
13
+local sessionData = require("data.session")
14
+
15
+local CMD = {}
16
+
17
+local INTERVAL = 180 -- 每3分钟轮询一次
18
+local orderReissue = {} -- {uid --> {order1, order2}}
19
+
20
+-- 加载未处理的订单
21
+local function loadUnprocessedOrder()
22
+    local ret = util_order:get_unhandle_order_list()
23
+    if ret and not table.empty(ret) then
24
+        for _, v in ipairs(ret) do
25
+            local uid = tonumber(v.uid)
26
+            orderReissue[uid] = orderReissue[uid] or {}
27
+            if not table.key_find(orderReissue[uid], "id", v.id) then
28
+                table.insert(orderReissue[uid], v)
29
+            end
30
+        end
31
+    end
32
+
33
+    collectgarbage "collect"
34
+    create_timeout(
35
+        INTERVAL * 100,
36
+        function()
37
+            loadUnprocessedOrder()
38
+        end
39
+    )
40
+end
41
+
42
+-- 玩家登录处理订单
43
+function CMD.loginOrder(uid)
44
+    -- log.print("玩家登录处理订单 uid:%s, %s", uid, tostring(orderReissue[uid]))
45
+    local orderList = orderReissue[uid]
46
+    if not orderList then
47
+        return
48
+    end
49
+
50
+    local nodeInfo = sessionData:user_get_cluster_info(uid, "game")
51
+    if nodeMgr.is_node_info_valid(nodeInfo) then
52
+        -- 回调到逻辑服处理
53
+        for _, orderAction in pairs(orderList) do
54
+            local msg = {
55
+                orderAction = orderAction,
56
+                goodsId = tonumber(orderAction.itemId)
57
+            }
58
+            nodeMgr.send_with_node_info(nodeInfo, "doCmd", uid, "shop", "on_pay", msg)
59
+        end
60
+    end
61
+end
62
+
63
+-- 完成订单处理
64
+function CMD.finishOrder(uid, id)
65
+    if not uid or not id then
66
+        return
67
+    end
68
+
69
+    util_order:update_order_status(id, 1)
70
+    local orderList = orderReissue[uid]
71
+    if not orderList then
72
+        return
73
+    end
74
+
75
+    log.print("完成订单处理 uid:%s, id:%s", uid, id)
76
+    table.key_delete(orderList, "id", id)
77
+    if table.empty(orderList) then
78
+        orderReissue[uid] = nil
79
+    end
80
+end
81
+
82
+-- 同步订单
83
+function CMD.syncOrder(uid, orderAction)
84
+    log.print("同步订单 uid:%s, orderAction:%s", uid, tostring(orderAction))
85
+
86
+    orderReissue[uid] = orderReissue[uid] or {}
87
+    table.insert(orderReissue[uid], orderAction)
88
+end
89
+
90
+function CMD.onStart()
91
+    loadUnprocessedOrder()
92
+end
93
+
94
+baseService.start(CMD, ".paySrv", true)

+ 2 - 6
common/utils/serverLogUtil.lua

@@ -156,18 +156,14 @@ function root.logPay(playerInfo, orderInfo)
156
         date,
156
         date,
157
         dateStr,
157
         dateStr,
158
         playerInfo.uid or "",
158
         playerInfo.uid or "",
159
-        playerInfo.uuid or "",
160
-        playerInfo.channel or "",
159
+        playerInfo.bandShareCode or "",
161
         playerInfo.version or "",
160
         playerInfo.version or "",
162
-        playerInfo.gold or "",
163
-        playerInfo.diamond or "",
164
         orderInfo.orderNo or "",
161
         orderInfo.orderNo or "",
165
         orderInfo.pay or "",
162
         orderInfo.pay or "",
166
         orderInfo.itemId or "",
163
         orderInfo.itemId or "",
167
         orderInfo.amount or "",
164
         orderInfo.amount or "",
168
         orderInfo.status or "",
165
         orderInfo.status or "",
169
-        orderInfo.retmsg or "",
170
-        playerInfo.nickname or ""
166
+        orderInfo.retmsg or ""
171
     }
167
     }
172
     local dataStr = root.formatData(data)
168
     local dataStr = root.formatData(data)
173
 
169
 

+ 20 - 0
dev/data/user.lua

@@ -89,4 +89,24 @@ function root:band_share_code(uid, sharecode)
89
     return true
89
     return true
90
 end
90
 end
91
 
91
 
92
+-- 获取属性
93
+function root:get_key_int(uid, key)
94
+    if uid == nil or is_empty(key) then
95
+        return 0
96
+    end
97
+    return moduleData:hget_int(uid, MODULE_NAME, key)
98
+end
99
+function root:get_key_info(uid, key)
100
+    if uid == nil or is_empty(key) then
101
+        return 0
102
+    end
103
+    return moduleData:hget(uid, MODULE_NAME, key)
104
+end
105
+function root:get_key_json(uid, key)
106
+    if uid == nil or is_empty(key) then
107
+        return 0
108
+    end
109
+    return moduleData:hget_json(uid, MODULE_NAME, key)
110
+end
111
+
92
 return root
112
 return root

nodes/login/controllers/event.lua → nodes/web/controllers/event.lua


+ 138 - 0
nodes/web/controllers/gm.lua

@@ -0,0 +1,138 @@
1
+local code = require "code"
2
+local machine = require "machine"
3
+local noticeUtil = require "utils.noticeUtil"
4
+local timeUtil = require "utils.timeUtil"
5
+local nodeMgr = require "nodeMgr"
6
+local loginPlatformModule = require "modules.loginPlatformModule"
7
+local chatUtil = require "utils.chatUtil"
8
+local util_user = require("utils.util_user")
9
+local util_mail = require("utils.util_mail")
10
+local lib_game_mysql = require("lib_game_mysql")
11
+local gameConst = require("const.gameConst")
12
+
13
+local baseAdapt = require("base.baseAdapt")
14
+local resAdapt = require "adapt.resAdapt"
15
+local shopAdapt = require "adapt.shopAdapt"
16
+local chatAdapt = require "adapt.chatAdapt"
17
+
18
+local moduleData = require("data.module")
19
+local sessionData = require("data.session")
20
+local payData = require("data.pay")
21
+local userData = require("data.user")
22
+local arenaData = require("data.arena")
23
+local battleData = require("data.battle")
24
+local resData = require("data.res")
25
+local playerData = require("data.player")
26
+
27
+local root = {}
28
+
29
+-- 获取玩家信息
30
+function root.gm_get_player_info(msg)
31
+    local uid = tonumber(msg.uid)
32
+
33
+    log.info("gm_get_player_info msg[%s]", tostring(msg))
34
+    --.玩家id	.玩家昵称	.国王等级	.竞技场等级	.玩家密码	-是否在线	.渠道号	.版本号	-账号状态	.注册时间	.最近登录时间	-状态
35
+    --.战斗局数	.广告次数	。金币	。钻石	.充值金额	-充值次数	.当前城市	.UUID	.UDID
36
+    local _, items = root.getBagInfo({uid = uid})
37
+    local userInfo = userData:user_get_info(uid)
38
+    userInfo.lv = playerData:get_level(uid)
39
+    userInfo.status = ""
40
+    userInfo.gold = resData:get_item_count(uid, gameConst.ITEM_ID.GOLD) -- 金币
41
+    userInfo.diamond = resData:get_item_count(uid, gameConst.ITEM_ID.DIAMOND) -- 钻石
42
+    userInfo.RechargeAmount = payData:user_get_total_pay_count(uid) -- 充值总额 integer
43
+    userInfo.RechargeCount = 0 -- 充值次数 integer
44
+
45
+    return code.OK, {user = userInfo, bag = {items = items}}
46
+end
47
+
48
+-- 背包信息
49
+function root.gm_get_player_bag_info(msg)
50
+    local uid = tonumber(msg.uid)
51
+
52
+    local itemList = {}
53
+    local itemInfo = moduleData:hget_json(uid, "bag", "itemInfo")
54
+    for k, v in ipairs(itemInfo) do
55
+        if v.count > 0 then
56
+            table.insert(itemList, {id = v.id, count = v.count, endTime = v.endTime})
57
+        end
58
+    end
59
+    for i, v in pairs(itemList) do
60
+        v.name = resAdapt:get_item_name(v.id)
61
+        if v.sceneLv then
62
+            v.name = string.format("%s-%s", v.name, v.sceneLv)
63
+            v.sceneLv = nil
64
+        elseif v.endTime then
65
+            v.name = string.format("%s(%s)", v.name, timeUtil.toString(v.endTime))
66
+            v.endTime = nil
67
+        end
68
+    end
69
+    return code.OK, itemList
70
+end
71
+
72
+-- 获取道具配置
73
+function root.gm_get_conf_items(msg)
74
+    local items = {}
75
+    local conf = resAdapt:get_item_conf_list()
76
+    for _, v in ipairs(conf) do
77
+        table.insert(items, {id = v.id, name = v.name, price = v.price})
78
+    end
79
+    return code.OK, {list = items}
80
+end
81
+
82
+-- 获取商品配置
83
+function root.gm_get_conf_goods(msg)
84
+    local list = {}
85
+    local shConf = baseAdapt:getConfig("GoodsConfig")
86
+    for k, v in ipairs(shConf) do
87
+        table.insert(list, {id = v.id, name = v.name, rmb = v.rmb})
88
+    end
89
+    return code.OK, {goods = list}
90
+end
91
+
92
+-- 对某个玩家发送邮件
93
+function root.send_mail(msg)
94
+    local uid = tonumber(msg.uid)
95
+
96
+    for i, v in pairs(msg.items) do
97
+        if not resAdapt:get_item_conf(v.id) then
98
+            return code.RES.ID_ERROR
99
+        end
100
+    end
101
+
102
+    local ok = util_mail:add_mail(uid, 0, msg.title, msg.message, msg.items, msg.type, nil, nil, "GM后台")
103
+
104
+    do
105
+        -- 埋点
106
+        local keyEvent = "message"
107
+        for _, value in ipairs(msg.items or {}) do
108
+            local text = string.format("%s,%s,%s", tostring(1), tostring(value.id), tostring(value.count))
109
+            util_user:log_event(uid, keyEvent, text)
110
+        end
111
+    end
112
+
113
+    if not ok then
114
+        return code.UNKNOWN
115
+    end
116
+    return code.OK, {}
117
+end
118
+
119
+-- 玩家状态
120
+function root.update_player_status(msg)
121
+    log.info("update_player_status msg[%s]", tostring(msg))
122
+    if msg == nil then
123
+        return code.PARAMTER_ERROR
124
+    end
125
+    local uid = tonumber(msg.uid)
126
+    local status = msg.status
127
+    if uid == nil or status == nil then
128
+        return code.PARAMTER_ERROR
129
+    end
130
+    if util_user:user_is_online_game(uid) then
131
+        util_user:user_call_game_agent(uid, "user.updateStatus", msg)
132
+    else
133
+        moduleData:hset(uid, "user", "status", status)
134
+    end
135
+    return code.OK
136
+end
137
+
138
+return root

+ 103 - 0
nodes/web/controllers/pay.lua

@@ -0,0 +1,103 @@
1
+-- 支付
2
+local code = require "code"
3
+local skynet = require "skynet"
4
+local nodeMgr = require "nodeMgr"
5
+local timeUtil = require "utils.timeUtil"
6
+local serverLogUtil = require "utils.serverLogUtil"
7
+local util_order = require("utils.util_order")
8
+
9
+local sessionData = require("data.session")
10
+local userData = require("data.user")
11
+
12
+local root = {}
13
+
14
+-- 支付埋点日志
15
+local function logPay(uid, orderAction)
16
+    skynet.fork(
17
+        function()
18
+            local playerInfo = {
19
+                uid = uid,
20
+                bandShareCode = userData:get_key_info(uid, "bandShareCode"),
21
+                version = userData:get_key_info(uid, "version")
22
+            }
23
+            -- 生成支付日志
24
+            serverLogUtil.logPay(playerInfo, orderAction)
25
+        end
26
+    )
27
+end
28
+
29
+-- 充值到账
30
+function root.recharge(msg)
31
+    -- 检查回调参数
32
+    local payCode, orderAction = msg.code, msg.orderAction
33
+    if not orderAction then
34
+        log.error("[支付回调]订单无效")
35
+        return false
36
+    end
37
+
38
+    local uid, orderId = tonumber(orderAction.uid), orderAction.orderNo
39
+    -- 检查订单有效性
40
+    local orderStatus = tonumber(orderAction.status or 0)
41
+    if orderStatus == 0 then
42
+        return util_order:handle_invalid_order(orderAction)
43
+    end
44
+    -- 检查订单物品是否存在
45
+    local itemId = tonumber(orderAction.itemId or 0)
46
+    if itemId <= 0 then
47
+        orderAction.status = 0
48
+        orderAction.resMsg = "订单参数错误"
49
+        log.error("订单参数错误1, itemId:%d, uid:%d", itemId, uid)
50
+        return util_order:handle_invalid_order(orderAction)
51
+    end
52
+
53
+    -- 检查玩家的在线情况
54
+    local nodeInfo = sessionData:user_get_cluster_info(uid, "game")
55
+    -- 玩家在线的处理
56
+    if nodeMgr.is_node_info_valid(nodeInfo) then
57
+        -- 回调到逻辑服处理
58
+        local pack = {
59
+            orderAction = orderAction,
60
+            goodsId = tonumber(orderAction.itemId)
61
+        }
62
+        nodeMgr.send_with_node_info(nodeInfo, "doCmd", uid, "shop", "on_pay", pack)
63
+    else
64
+        nodeMgr.send("global", ".paySrv", "syncOrder", uid, orderAction)
65
+    end
66
+
67
+    pcall(logPay, uid, orderAction)
68
+
69
+    return true
70
+end
71
+
72
+-- 支付服订单回调
73
+function root.pay_notify(msg)
74
+    if (not msg) or (not msg.orderAction) or (not msg.orderAction.orderNo) or (not msg.orderAction.uid) then
75
+        log.error("[支付回调]订单错误, data:%s", tostring(msg or ""))
76
+        return code.OK
77
+    end
78
+
79
+    local orderAction = msg.orderAction
80
+    local orderType = string.find(orderAction.pay, "baidu")
81
+    if not orderType then
82
+        local isExist = util_order:is_order_exist(orderAction.orderNo)
83
+        if isExist then
84
+            log.error("[支付回调]订单重复:Order:%s", tostring(msg or ""))
85
+            return code.OK
86
+        end
87
+    end
88
+
89
+    if orderAction.createtime and #(orderAction.createtime) <= 0 then
90
+        orderAction.createtime = timeUtil.toString(timeUtil.currentTime())
91
+    end
92
+    -- 订单入库
93
+    util_order:add_order(orderAction)
94
+    util_order:on_shop_order(orderAction)
95
+    orderAction.id = util_order:get_order_id(orderAction.orderNo, orderAction.uid)
96
+    log.info("payOrder orderAction[%s]", tostring(orderAction))
97
+    -- 支付到账
98
+    root.recharge(msg)
99
+
100
+    return code.OK
101
+end
102
+
103
+return root

nodes/login/controllers/server.lua → nodes/web/controllers/server.lua


nodes/login/controllers/usr.lua → nodes/web/controllers/usr.lua


nodes/login/lib/staticfile.lua → nodes/web/lib/staticfile.lua


nodes/login/lib/webapp.lua → nodes/web/lib/webapp.lua


nodes/login/main.lua → nodes/web/main.lua


nodes/login/service/srvHttpAgent.lua → nodes/web/service/srvHttpAgent.lua


nodes/login/service/srvHttpServer.lua → nodes/web/service/srvHttpServer.lua


nodes/login/service/srvhttpClient.lua → nodes/web/service/srvhttpClient.lua


nodes/login/static/app.js → nodes/web/static/app.js


nodes/login/static/bootstrap.min.js → nodes/web/static/bootstrap.min.js


nodes/login/static/index.html → nodes/web/static/index.html


nodes/login/static/jquery-3.4.1.min.js → nodes/web/static/jquery-3.4.1.min.js


nodes/login/static/popper.min.js → nodes/web/static/popper.min.js


+ 2 - 2
run/common/login.conf

@@ -1,7 +1,7 @@
1
 include "public.conf"
1
 include "public.conf"
2
 
2
 
3
 -- 节点集群名
3
 -- 节点集群名
4
-clusterName = "login"
4
+clusterName = "web"
5
 -- 节点名
5
 -- 节点名
6
 nodeName = "login"
6
 nodeName = "login"
7
 
7
 
@@ -14,5 +14,5 @@ start = "main"
14
 
14
 
15
 -- daemon
15
 -- daemon
16
 if system == "linux" then
16
 if system == "linux" then
17
-    daemon = "./skynet_"..nodeName..".pid"
17
+daemon = "./skynet_"..nodeName..".pid"
18
 end
18
 end

+ 18 - 0
run/common/web.conf

@@ -0,0 +1,18 @@
1
+include "public.conf"
2
+
3
+-- 节点集群名
4
+clusterName = "web"
5
+-- 节点名
6
+nodeName = "web"
7
+
8
+lroot = root.."nodes/"..clusterName.."/"
9
+luaservice = luaservice..lroot.."service/?.lua;"..lroot.."?.lua;"
10
+lua_path = lua_path..lroot.."?.lua;"..lroot.."service/?.lua;"..lroot.."lib/?.lua;"
11
+snax = luaservice
12
+
13
+start = "main"
14
+
15
+-- daemon
16
+if system == "linux" then
17
+daemon = "./skynet_"..nodeName..".pid"
18
+end

+ 1 - 0
run/neo-test1/clustername.lua

@@ -5,3 +5,4 @@ login_1_1 = "127.0.0.1:3003"
5
 gate_1_1 = "127.0.0.1:3004"
5
 gate_1_1 = "127.0.0.1:3004"
6
 game_1_1 = "127.0.0.1:3005"
6
 game_1_1 = "127.0.0.1:3005"
7
 match = "127.0.0.1:3006"
7
 match = "127.0.0.1:3006"
8
+web = "127.0.0.1:3007"

+ 1 - 1
run/neo-test1/machine.conf

@@ -5,4 +5,4 @@ statistic_path = ./log/statistic/
5
 zip_statistic_path = ./log/zip_path/
5
 zip_statistic_path = ./log/zip_path/
6
 
6
 
7
 #启动进程配置
7
 #启动进程配置
8
-nodeList = master resource global match game_1_1 gate_1_1 login_1_1
8
+nodeList = master resource global match web game_1_1 gate_1_1 login_1_1

+ 8 - 0
run/neo-test1/nodes.lua

@@ -52,4 +52,12 @@ root["game_1_1"] = {
52
     weight = 50 -- 权重
52
     weight = 50 -- 权重
53
 }
53
 }
54
 
54
 
55
+root["web"] = {
56
+    ip = "0.0.0.0",
57
+    debugPort = 8207,
58
+    port = 8303,
59
+    agentCount = 5,
60
+    bodyLimit = 8192
61
+}
62
+
55
 return root
63
 return root