ソースを参照

新增支付/调试功能模块

neo 1 年間 前
コミット
b9881c4b99

+ 41 - 0
dev/adapt/resAdapt.lua

@@ -0,0 +1,41 @@
1
+-- 资源配置
2
+local baseAdapt = require "base.baseAdapt"
3
+
4
+local root = {}
5
+
6
+-- 获取指定id的资源配置
7
+function root:get_init_conf()
8
+    return baseAdapt:getConfig("ResInitConfig")
9
+end
10
+
11
+-- 获取物品配置
12
+function root:get_item_conf_list()
13
+    return baseAdapt:getConfig("ResItemConfig") or {}
14
+end
15
+
16
+-- 获取指定id的资源配置
17
+function root:get_item_conf(id)
18
+    if not id then
19
+        return nil
20
+    end
21
+    return baseAdapt:getOneConfig("ResItemConfig", id)
22
+end
23
+
24
+-- 获取物品名称
25
+function root:get_item_name(id)
26
+    local item = self:get_item_conf(id)
27
+    return item and item.name
28
+end
29
+
30
+-- 获取物品类型
31
+function root:get_item_type(id)
32
+    local item = self:get_item_conf(id)
33
+    return item and item.type
34
+end
35
+
36
+-- 判断是否是某个类型的资源id
37
+function root:is_type(id, resType)
38
+    return self:get_item_type(id) == resType
39
+end
40
+
41
+return root

+ 42 - 0
dev/adapt/shopAdapt.lua

@@ -0,0 +1,42 @@
1
+--[[
2
+Descripttion:商城配置
3
+version:
4
+Author: Neo,Huang
5
+Date: 2022-08-19 17:36:25
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2022-08-31 20:25:35
8
+--]]
9
+local baseAdapt = require "base.baseAdapt"
10
+
11
+local root = {}
12
+
13
+-- 商品信息
14
+function root:goods_get_info(gid)
15
+    if gid == nil then
16
+        return
17
+    end
18
+
19
+    local shConf = baseAdapt:getConfig("GoodsConfig")
20
+    for k, v in ipairs(shConf) do
21
+        if v.id == gid then
22
+            return v
23
+        end
24
+    end
25
+end
26
+-- 获取商品价格
27
+function root:goods_get_rmb(gid)
28
+    local conf = self:goods_get_info(gid)
29
+    if conf and conf.rmb then
30
+        return conf.rmb
31
+    end
32
+    return 0
33
+end
34
+-- 商品物品
35
+function root:goods_get_items(gid)
36
+    local conf = self:goods_get_info(gid)
37
+    if conf and not is_empty(conf.items) then
38
+        return table.copy(conf.items)
39
+    end
40
+end
41
+
42
+return root

+ 2 - 1
dev/base/baseModule.lua

@@ -11,11 +11,12 @@ local lib_game_mysql = require("lib_game_mysql")
11 11
 
12 12
 local root = class("base")
13 13
 
14
-function root:ctor(uid, mdlName, keyName, isSaveDB)
14
+function root:ctor(uid, mdlName, keyName, isSaveDB, isPersonal)
15 15
     self.uid = uid
16 16
     self.mdlName = mdlName
17 17
     self.keyName = keyName
18 18
     self.isSaveDB = isSaveDB
19
+    self.isPersonal = isPersonal or true
19 20
 end
20 21
 
21 22
 -- 模块sql属性

+ 2 - 1
dev/const/gameConst.lua

@@ -17,7 +17,8 @@ root.TASK_STATUS = {
17 17
 
18 18
 -- 事件ID
19 19
 root.EVENT_ID = {
20
-    RES = 101 -- 资源变化
20
+    RES = 101, -- 资源变化
21
+    PAY = 102 -- 支付
21 22
 }
22 23
 
23 24
 -- 战斗类型

File diff suppressed because it is too large
+ 5 - 947
dev/data/bag.lua


+ 204 - 0
dev/data/pay.lua

@@ -0,0 +1,204 @@
1
+--[[
2
+Descripttion:支付
3
+version:
4
+Author: Neo,Huang
5
+Date: 2022-03-14 20:21:10
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2022-03-14 20:21:10
8
+--]]
9
+local timeUtil = require("utils.timeUtil")
10
+local util_user = require("utils.util_user")
11
+
12
+local shopAdapt = require("adapt.shopAdapt")
13
+
14
+local moduleData = require("data.module")
15
+
16
+local MODULE_NAME = "pay"
17
+
18
+local root = {}
19
+
20
+-- 支付金额:分
21
+-- 新增支付
22
+function root:user_add_pay(uid, gid, pennys)
23
+    log.info("user_add_pay uid[%s] gid[%s] pennys[%s]", tostring(uid), tostring(gid), tostring(pennys))
24
+    if uid == nil or gid == nil then
25
+        return
26
+    end
27
+    -- 总金额
28
+    pennys = pennys or shopAdapt:goods_get_rmb(gid)
29
+    local totalAmount = moduleData:hget_int(uid, MODULE_NAME, "totalAmount")
30
+    totalAmount = totalAmount + pennys
31
+    moduleData:hset(uid, MODULE_NAME, "totalAmount", totalAmount)
32
+    -- 购买商品列表
33
+    local currTime = timeUtil.now(uid)
34
+    local goodsList = moduleData:hget_json(uid, MODULE_NAME, "goodsList")
35
+    table.insert(goodsList, {gid = gid, amount = pennys, time = currTime})
36
+    moduleData:hset(uid, MODULE_NAME, "goodsList", goodsList)
37
+    -- 当天信息
38
+    local dayInfo = self:get_day_info(uid)
39
+    dayInfo.lastPayTime = currTime
40
+    if dayInfo.goodsList == nil then
41
+        dayInfo.goodsList = {}
42
+    end
43
+    table.insert(dayInfo.goodsList, {gid = gid, amount = pennys, time = currTime})
44
+    moduleData:hset(uid, MODULE_NAME, "dayInfo", dayInfo)
45
+
46
+    return true
47
+end
48
+-- 累计支付金额
49
+function root:user_get_total_pay_count(uid)
50
+    if uid == nil then
51
+        return
52
+    end
53
+    return moduleData:hget_int(uid, MODULE_NAME, "totalAmount")
54
+end
55
+
56
+-- 是否首次付费
57
+function root:is_first_pay(uid)
58
+    local goodsList = moduleData:hget_json(uid, MODULE_NAME, "goodsList")
59
+    return is_empty(goodsList)
60
+end
61
+-- 是否商品首次付费
62
+function root:is_goods_first_pay(uid, gid)
63
+    local goodsList = moduleData:hget_json(uid, MODULE_NAME, "goodsList")
64
+    for _, v in ipairs(goodsList) do
65
+        if v.gid == gid then
66
+            return false
67
+        end
68
+    end
69
+    return true
70
+end
71
+-- 商品购买次数
72
+function root:get_goods_pay_times(uid, gid)
73
+    local times = 0
74
+    local goodsList = moduleData:hget_json(uid, MODULE_NAME, "goodsList")
75
+    for _, v in ipairs(goodsList) do
76
+        if v.gid == gid then
77
+            times = times + 1
78
+        end
79
+    end
80
+    return times
81
+end
82
+
83
+----------------------------------------
84
+-- 当天
85
+----------------------------------------
86
+-- 获取信息
87
+function root:get_day_info(uid)
88
+    local currTime = timeUtil.now(uid)
89
+    local dayInfo = moduleData:hget_json(uid, MODULE_NAME, "dayInfo")
90
+    if dayInfo.lastPayTime and not timeUtil.is_same_day(dayInfo.lastPayTime, currTime) then
91
+        dayInfo = {}
92
+    end
93
+    return dayInfo
94
+end
95
+-- 支付金额
96
+function root:get_day_total_amount(uid)
97
+    local dayInfo = self:get_day_info(uid)
98
+    local amount = 0
99
+    if not is_empty(dayInfo.goodsList) then
100
+        for _, v in ipairs(dayInfo.goodsList) do
101
+            amount = amount + v.amount
102
+        end
103
+    end
104
+    return amount
105
+end
106
+----------------------------------------
107
+-- 商品定制
108
+----------------------------------------
109
+-- 定制商品物品
110
+function root:update_goods_pre_custom_items(uid, gid, items)
111
+    if uid == nil or gid == nil or is_empty(items) then
112
+        return false
113
+    end
114
+    local goodsPreCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPreCustomItems")
115
+    local isMatch = false
116
+    for k, v in ipairs(goodsPreCustomItems) do
117
+        if v.gid == gid then
118
+            isMatch = true
119
+            v.items = items
120
+            break
121
+        end
122
+    end
123
+    if not isMatch then
124
+        table.insert(goodsPreCustomItems, {gid = gid, items = items})
125
+    end
126
+    moduleData:hset(uid, MODULE_NAME, "goodsPreCustomItems", goodsPreCustomItems)
127
+    return true
128
+end
129
+-- 打包 - 商品定制信息
130
+function root:pack_goods_pre_custom_info_list(uid)
131
+    if uid == nil then
132
+        return
133
+    end
134
+
135
+    local goodsPreCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPreCustomItems")
136
+    if not is_empty(goodsPreCustomItems) then
137
+        return goodsPreCustomItems
138
+    end
139
+end
140
+-- 获取商品定制物品
141
+function root:get_goods_pre_custom_items(uid, gid)
142
+    if uid == nil or gid == nil then
143
+        return
144
+    end
145
+    local goodsPreCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPreCustomItems")
146
+    for k, v in ipairs(goodsPreCustomItems) do
147
+        if v.gid == gid then
148
+            return v.items
149
+        end
150
+    end
151
+end
152
+-- 删除商品定制物品
153
+function root:del_goods_pre_custom_items(uid, gid)
154
+    if uid == nil or gid == nil then
155
+        return false
156
+    end
157
+    local goodsPreCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPreCustomItems")
158
+    for k, v in ipairs(goodsPreCustomItems) do
159
+        if v.gid == gid then
160
+            table.remove(goodsPreCustomItems, k)
161
+            moduleData:hset(uid, MODULE_NAME, "goodsPreCustomItems", goodsPreCustomItems)
162
+            return true
163
+        end
164
+    end
165
+    return false
166
+end
167
+
168
+-- 支付 - 更新商品定制物品
169
+function root:update_goods_pay_custom_items(uid, gid, items)
170
+    if uid == nil or gid == nil then
171
+        return false
172
+    end
173
+    local goodsPayCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPayCustomItems")
174
+    local isMatch = false
175
+    for k, v in ipairs(goodsPayCustomItems) do
176
+        if v.gid == gid then
177
+            isMatch = true
178
+            if is_empty(items) then
179
+                table.remove(goodsPayCustomItems, k)
180
+            else
181
+                v.items = items
182
+            end
183
+            break
184
+        end
185
+    end
186
+    if not isMatch then
187
+        table.insert(goodsPayCustomItems, {gid = gid, items = items})
188
+    end
189
+    moduleData:hset(uid, MODULE_NAME, "goodsPayCustomItems", goodsPayCustomItems)
190
+    return true
191
+end
192
+-- 打包 - 商品定制信息
193
+function root:pack_goods_pay_custom_info_list(uid)
194
+    if uid == nil then
195
+        return
196
+    end
197
+
198
+    local goodsPayCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPayCustomItems")
199
+    if not is_empty(goodsPayCustomItems) then
200
+        return goodsPayCustomItems
201
+    end
202
+end
203
+
204
+return root

+ 1 - 1
dev/data/session.lua

@@ -8,7 +8,7 @@ LastEditTime: 2021-09-17 10:06:57
8 8
 --]]
9 9
 local moduleData = require("data.module")
10 10
 
11
-local MODULE_NAME = "tb_session"
11
+local MODULE_NAME = "session"
12 12
 
13 13
 local root = {}
14 14
 

+ 38 - 0
dev/modules/order.lua

@@ -0,0 +1,38 @@
1
+--[[
2
+Descripttion:支付订单模块
3
+version:
4
+Author: Neo,Huang
5
+Date: 2022-08-17 16:04:20
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2022-09-05 10:05:30
8
+--]]
9
+local root = class("moduleOrder", require("base.baseModule"))
10
+
11
+function root:ctor()
12
+    root.super.ctor(self, "order", "id", true, false)
13
+end
14
+
15
+function root:mysql_get_init_columns()
16
+    return {
17
+        id = "bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'ID'",
18
+        payName = "varchar(64) DEFAULT '' COMMENT '支付名称'",
19
+        code = "varchar(128) DEFAULT '' COMMENT 'SDK支付方回调错误码'",
20
+        uid = "int(11) NOT NULL COMMENT '用户id'",
21
+        orderNo = "varchar(64) DEFAULT '' COMMENT '订单号'",
22
+        diamond = "int(11) DEFAULT '0' COMMENT '钻石'",
23
+        gold = "bigint(20) DEFAULT '0' COMMENT '金币'",
24
+        gid = "int(10) DEFAULT NULL COMMENT '商品ID'",
25
+        amount = "decimal(5,2) DEFAULT NULL COMMENT '订单金额,单位分'", -- 入库单位元
26
+        time = "varchar(32) DEFAULT NULL COMMENT '订单时间'",
27
+        createtime = "varchar(50) DEFAULT NULL COMMENT '支付服处理时间'",
28
+        status = "tinyint(1) DEFAULT NULL COMMENT '订单状态:0手动发放订单,1游戏逻辑自动发放订单'",
29
+        resMsg = "varchar(255) DEFAULT NULL COMMENT '注释'",
30
+        channel = "int(11) DEFAULT 0 COMMENT '渠道'",
31
+        type = "int(11) DEFAULT 0 COMMENT '支付类型'",
32
+        readStatus = "int(11) DEFAULT 0 COMMENT '状态:1客户端是否已经被轮询获取'",
33
+        cut = "tinyint(1) DEFAULT 0 COMMENT '状态: 1 订单扣除'",
34
+        gameStatus = "tinyint(1) DEFAULT 0 COMMENT '游戏服处理:0未处理,1处理'"
35
+    }
36
+end
37
+
38
+return root

+ 69 - 0
dev/modules/pay.lua

@@ -0,0 +1,69 @@
1
+--[[
2
+Descripttion:支付订单模块
3
+version:
4
+Author: Neo,Huang
5
+Date: 2022-08-17 16:04:20
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2022-09-05 10:05:30
8
+--]]
9
+local shopAdapt = require("adapt.shopAdapt")
10
+
11
+local payData = require("data.pay")
12
+local bagData = require("data.bag")
13
+
14
+local root = class("modulePay", require("base.baseModule"))
15
+
16
+function root:ctor(uid)
17
+    root.super.ctor(self, "pay", "uid", true)
18
+    self.uid = uid
19
+end
20
+
21
+function root:mysql_get_init_columns()
22
+    return {
23
+        uid = "int(11) NOT NULL COMMENT '用户id'",
24
+        totalAmount = "int(10) DEFAULT NULL COMMENT '总支付金额(单位分)'",
25
+        goodsList = "JSON COMMENT '支付商品信息列表'",
26
+        dayInfo = "JSON COMMENT '当天支付商品信息'",
27
+        goodsPreCustomItems = "JSON COMMENT '定制商品信息列表'",
28
+        goodsPayCustomItems = "JSON COMMENT '定制商品信息列表'"
29
+    }
30
+end
31
+
32
+-- 发放商品物品
33
+function root:dispatch_goods_items(role, gid)
34
+    local uid = self.uid
35
+    local conf = gid and shopAdapt:goods_get_info(gid)
36
+    if not conf then
37
+        return code.PARAMTER_ERROR
38
+    end
39
+    -- 获取物品
40
+    local eventId = string.format("shop-pay-%s", tostring(gid))
41
+    local items = payData:get_goods_pre_custom_items(uid, gid) or conf.items
42
+    bagData:add_items(uid, items, eventId)
43
+    -- 定制信息
44
+    if payData:del_goods_pre_custom_items(uid, gid) then
45
+        payData:update_goods_pay_custom_items(uid, gid, items)
46
+    end
47
+
48
+    -- 通知前端 - 商品发货
49
+    local pack = {goodsId = gid, items = items}
50
+    util_user:user_proto_notify(uid, "on_shop_buy_goods", pack)
51
+    -- 事件
52
+    local evtParams = {
53
+        times = 1,
54
+        gid = gid
55
+    }
56
+    evtParams.isFirstPay = payData:is_first_pay(uid)
57
+    evtParams.isGoodsFirstPay = payData:is_goods_first_pay(uid, gid)
58
+    if not is_empty(conf.rmb) then
59
+        payData:user_add_pay(uid, gid, conf.rmb)
60
+
61
+        evtParams.amount = conf.rmb
62
+        evtParams.totalAmount = self:redis_get_key_info("totalAmount")
63
+    end
64
+    util_user:user_dispatch_event(uid, gameConst.EVENT_ID.PAY, evtParams)
65
+
66
+    return code.OK, {items = items}
67
+end
68
+
69
+return root

+ 23 - 15
dev/utils/util_order.lua

@@ -20,7 +20,7 @@ function root:add_order(orderAction)
20 20
     end
21 21
     local sql =
22 22
         string.format(
23
-        "INSERT INTO `tb_order` (`pay`,`orderNo`,`uid`,`diamond`,`gold`,`itemId`,`amount`,`time`,`status`,`resMsg`," ..
23
+        "INSERT INTO `mdl_order` (`pay`,`orderNo`,`uid`,`diamond`,`gold`,`itemId`,`amount`,`time`,`status`,`resMsg`," ..
24 24
             "`channel`,`type`,`createtime`,`cut`) VALUES ('%s','%s',%d,%s,%s,%d,%s,%d,%d,'%s',%d,%d,'%s',%d); ",
25 25
         orderAction.pay or "",
26 26
         orderAction.orderNo or "",
@@ -40,21 +40,28 @@ function root:add_order(orderAction)
40 40
 
41 41
     return mysqlUtil:insert(sql)
42 42
 end
43
+-- 打包订单信息
44
+function root:pack_order_info(orderAction)
45
+    if orderAction == nil then
46
+        return
47
+    end
48
+    return {
49
+        status = orderAction.status,
50
+        orderId = orderAction.orderNo,
51
+        gid = orderAction.itemId,
52
+        errMsg = orderAction.resMsg,
53
+        payName = orderAction.pay,
54
+        errCode = orderAction.code,
55
+        amount = orderAction.amount
56
+    }
57
+end
43 58
 -- 通知
44 59
 function root:on_shop_order(orderAction)
45 60
     if orderAction == nil or orderAction.status ~= 1 then
46 61
         return false
47 62
     end
48 63
     local msg = {
49
-        orderInfo = {
50
-            status = orderAction.status,
51
-            orderId = orderAction.orderNo,
52
-            gid = orderAction.itemId,
53
-            errMsg = orderAction.resMsg,
54
-            payName = orderAction.pay,
55
-            errCode = orderAction.code,
56
-            amount = orderAction.amount
57
-        }
64
+        orderInfo = self:pack_order_info(orderAction)
58 65
     }
59 66
     util_user:user_proto_notify(orderAction.uid, "on_shop_order", msg)
60 67
     return true
@@ -64,7 +71,7 @@ function root:is_order_exist(orderId)
64 71
     if is_empty(orderId) then
65 72
         return false
66 73
     end
67
-    local sql = string.format("SELECT 1 FROM `tb_order` WHERE orderNo = '%s';", orderId)
74
+    local sql = string.format("SELECT 1 FROM `mdl_order` WHERE orderNo = '%s';", orderId)
68 75
     lib_game_mysql:query(sql)
69 76
     local ok, ret = mysqlUtil:select(sql)
70 77
     if not ok or is_empty(ret) then
@@ -76,7 +83,7 @@ end
76 83
 function root:get_order_id(orderId, uid)
77 84
     local sql =
78 85
         string.format(
79
-        "SELECT id FROM `tb_order` WHERE orderNo = '%s' and uid = %d ORDER BY id DESC LIMIT 1 ;",
86
+        "SELECT id FROM `mdl_order` WHERE orderNo = '%s' and uid = %d ORDER BY id DESC LIMIT 1 ;",
80 87
         orderId or "",
81 88
         uid or 0
82 89
     )
@@ -91,12 +98,13 @@ function root:update_order_status(id, status)
91 98
     if id == nil or status == nil then
92 99
         return false
93 100
     end
94
-    local sql = string.format("UPDATE `tb_order` SET `gameStatus` = %s where `id` = %s", tostring(status), tostring(id))
101
+    local sql =
102
+        string.format("UPDATE `mdl_order` SET `gameStatus` = %s where `id` = %s", tostring(status), tostring(id))
95 103
     return mysqlUtil:update(sql)
96 104
 end
97 105
 -- 获取未处理订单列表
98 106
 function root:get_unhandle_order_list()
99
-    local sql = string.format("SELECT * FROM `tb_order` WHERE `gameStatus`=0 AND `status`=1 ORDER BY id DESC")
107
+    local sql = string.format("SELECT * FROM `mdl_order` WHERE `gameStatus`=0 AND `status`=1 ORDER BY id DESC")
100 108
     local ok, ret = mysqlUtil:select(sql)
101 109
     if not ok or is_empty(ret) then
102 110
         return
@@ -110,7 +118,7 @@ function root:handle_invalid_order(orderAction)
110 118
     -- 标记为已经处理并更新到数据库
111 119
     local sql =
112 120
         string.format(
113
-        "UPDATE `tb_order` SET `gameStatus` = 1,`status`=%s,`resMsg`='%s' where `id` = %s",
121
+        "UPDATE `mdl_order` SET `gameStatus` = 1,`status`=%s,`resMsg`='%s' where `id` = %s",
114 122
         tostring(orderAction.status),
115 123
         tostring(orderAction.resMsg),
116 124
         tostring(orderAction.id)

+ 174 - 0
nodes/game/interface/shop.lua

@@ -0,0 +1,174 @@
1
+-- 商城接口
2
+local code = require "code"
3
+local util_user = require("utils.util_user")
4
+local lib_game_mysql = require("lib_game_mysql")
5
+local util_order = require("utils.util_order")
6
+
7
+local shopAdapt = require("adapt.shopAdapt")
8
+
9
+local dataBag = require("data.bag")
10
+
11
+local root = {}
12
+
13
+-- 购买商品
14
+function root.shop_buy_goods(role, msg)
15
+    local gid = msg.goodsId
16
+    local conf = shopAdapt:goods_get_info(gid)
17
+    if conf == nil or conf.price == nil then
18
+        return code.PARAMTER_ERROR
19
+    end
20
+    local uid = role.uid
21
+    local ok = dataBag:is_enough(uid, conf.price)
22
+    if not ok then
23
+        return code.RES.NOT_ENOUGH
24
+    end
25
+    local eventId = "shop-pay-" .. tostring(gid)
26
+    dataBag:consume_items(uid, conf.price, eventId)
27
+
28
+    return role.pay:dispatch_goods_items(role, gid)
29
+end
30
+
31
+-- 充值成功回调
32
+function root.on_pay(role, msg)
33
+    local uid = role.uid
34
+    log.print("充值成功回调 %s, %s", uid, tostring(msg))
35
+    local order = msg.orderAction
36
+    local logEvent = function(seasonId)
37
+        local extraParams =
38
+            table.concat(
39
+            {
40
+                order and order.orderNo or "",
41
+                order and order.type or "",
42
+                order and order.itemId or "",
43
+                order and order.amount or "",
44
+                order and order.status or "",
45
+                seasonId or ""
46
+            },
47
+            ","
48
+        )
49
+        util_user:log_event(uid, "OrderError", extraParams)
50
+    end
51
+    local gid = msg.goodsId
52
+    local conf = goodsId and shopAdapt:goods_get_info(gid)
53
+    if is_empty(conf) then
54
+        log.error("商城充值回调 gid =%s", gid)
55
+        logEvent(1)
56
+        return code.PARAMTER_ERROR
57
+    end
58
+    -- 订单先完成
59
+    util_order:update_order_status(order and order.id, 1)
60
+
61
+    -- 统计 - 充值金额
62
+    local amount = math.floor(tonumber(msg.orderAction.amount) * 100)
63
+
64
+    -- 增加物品
65
+    local errCode, res = role.pay:dispatch_goods_items(role, gid, amount)
66
+    if code.is_not_ok(errCode) then
67
+        return errCode
68
+    end
69
+
70
+    -- 推送客户端
71
+    util_order:on_shop_order(order)
72
+
73
+    return code.OK, res
74
+end
75
+
76
+-- 1.5版本订单BUG,修复代码
77
+local function is_order(str)
78
+    if str == nil or #str == 0 then
79
+        return false
80
+    end
81
+
82
+    for i = 1, #str do
83
+        local cur_byte = string.byte(str, i)
84
+        if cur_byte > 127 then
85
+            return false
86
+        end
87
+    end
88
+    return true
89
+end
90
+-- 查询订单结果
91
+function root.shop_get_order(role, msg)
92
+    if msg == nil or msg.orderId == nil then
93
+        return code.PARAMTER_ERROR
94
+    end
95
+    local uid = role.uid
96
+    local orderId = msg.orderId
97
+
98
+    log.info("itf_get_order uid[%s] orderId[%s]", uid, orderId)
99
+    if not is_order(orderId) then
100
+        return code.SHOP.ALREADY_GET_ORDER
101
+    end
102
+
103
+    -- 订单是否已入库
104
+    local sql =
105
+        string.format(
106
+        "SELECT `id`, `gid`, `status`, `resMsg`, `pay`, `amount` FROM `mdl_order` WHERE orderNo='%s';",
107
+        orderId
108
+    )
109
+    local ret = lib_game_mysql:query(sql)
110
+    if is_empty(ret) then
111
+        return code.SHOP.NO_FOUND_ORDER
112
+    end
113
+    -- 修改订单状态
114
+    sql = string.format("UPDATE `mdl_order` SET `readStatus`=99 WHERE `orderNo`='%s';", orderId)
115
+    lib_game_mysql:query(sql)
116
+
117
+    local id = tonumber(ret[1].id)
118
+    local status = tonumber(ret[1].status)
119
+    local goodsId = tonumber(ret[1].gid)
120
+    local resMsg = ret[1].resMsg
121
+    local payName = ret[1].pay
122
+    local amount = ret[1].amount
123
+    local order = {
124
+        status = status,
125
+        goodsId = goodsId,
126
+        orderId = orderId,
127
+        errMsg = resMsg,
128
+        payName = payName,
129
+        amount = tostring(amount)
130
+    }
131
+    if status ~= 1 then
132
+        -- 订单支付失败
133
+        return code.OK, {order = order}
134
+    end
135
+
136
+    local logEvent = function(seasonId)
137
+        local extraParams =
138
+            table.concat(
139
+            {
140
+                orderId,
141
+                payName,
142
+                goodsId,
143
+                amount,
144
+                status,
145
+                seasonId or ""
146
+            },
147
+            ","
148
+        )
149
+        util_user:log_event(uid, "OrderError", extraParams)
150
+    end
151
+
152
+    local conf = goodsId and shopAdapt:goods_get_info(goodsId)
153
+    if is_empty(conf) then
154
+        log.error("商城充值回调 goodsId =%s", goodsId)
155
+        logEvent(1)
156
+        return code.PARAMTER_ERROR
157
+    end
158
+    -- TODO 订单回调是否重复
159
+    -- 订单先完成
160
+    util_order:update_order_status(id, 1)
161
+    -- 增加物品
162
+    local errCode, res = role.pay:dispatch_goods_items(role, goodsId)
163
+    if errCode ~= code.OK then
164
+        return errCode
165
+    end
166
+
167
+    -- 推送客户端
168
+    util_order:on_shop_order(order)
169
+
170
+    local ret = {orderInfo = util_order:pack_order_info(order)}
171
+    return code.OK, ret
172
+end
173
+
174
+return root

+ 118 - 0
nodes/game/interface/test.lua

@@ -0,0 +1,118 @@
1
+-- 测试工具
2
+local code = require "code"
3
+local gameConst = require("const.gameConst")
4
+local timeUtil = require "utils.timeUtil"
5
+local honorAdapt = require("adapt.honorAdapt")
6
+local redisUtil = require "utils.redisUtil"
7
+local whiteAdapt = require "adapt.whiteAdapt"
8
+local nodeMgr = require "nodeMgr"
9
+local util_user = require("utils.util_user")
10
+local util_order = require("utils.util_order")
11
+
12
+local moduleData = require("data.module")
13
+local bagData = require("data.bag")
14
+
15
+local root = {}
16
+-- if not IS_TEST then return end
17
+
18
+-- 调试系统时间
19
+function root.test_debug_system_time(role, msg)
20
+    if not IS_TEST then
21
+        return code.UNKNOWN
22
+    end
23
+    local uid = msg.uid
24
+    if not uid then
25
+        return code.PARAMTER_ERROR
26
+    end
27
+
28
+    local time, reset = msg.time, msg.reset or 0
29
+    if reset == 0 then
30
+        moduleData:hset(uid, "user", "time:sys")
31
+        moduleData:hset(uid, "user", "time:logout")
32
+    elseif reset == 1 then
33
+        -- 间隔时间
34
+        local deltaTime = time - skynet_time()
35
+        moduleData:hset(uid, "user", "time:sys", deltaTime)
36
+    elseif reset == 2 then
37
+        moduleData:hset(uid, "user", "registerTime", time)
38
+    elseif reset == 3 then
39
+        local deltaTime = time - skynet_time()
40
+        moduleData:hset(uid, "user", "time:logout", deltaTime)
41
+    end
42
+
43
+    local ret = {}
44
+    ret.sysTime = timeUtil.now(uid)
45
+    ret.debugTime = moduleData:hget_int(uid, "user", "time:sys")
46
+    return code.OK, ret
47
+end
48
+
49
+function root.test_add_items(role, msg)
50
+    local uid = role.uid
51
+    local items = msg.items
52
+    if not items then
53
+        return code.PARAMTER_ERROR
54
+    end
55
+    for k, v in ipairs(items) do
56
+        v.force = true
57
+    end
58
+    bagData:add_items(uid, items, "gmset")
59
+    return code.OK, {}
60
+end
61
+
62
+function root.test_pay_goods(role, msg)
63
+    local orderId = msg.orderId
64
+    local payName = msg.payName
65
+    local status = msg.status
66
+    local resMsg = msg.resMsg
67
+    local amount = msg.amount / 100.0
68
+
69
+    local errCode = 1
70
+    if not msg.status then
71
+        errCode = 0
72
+    end
73
+    local data = string.split(orderId, "_")
74
+    local channel, uid, gid = tonumber(data[2]), tonumber(data[3]), tonumber(data[4])
75
+    log.print("orderId:%s uid:%s channel:%s gid:%s", orderId, uid, channel, gid)
76
+    local pack = {
77
+        ["code"] = errCode,
78
+        ["orderNo"] = msg.orderId,
79
+        ["orderAction"] = {
80
+            ["type"] = 0,
81
+            ["code"] = "TRADE_FINISHED",
82
+            ["id"] = 0,
83
+            ["cut"] = 0,
84
+            ["createtime"] = "",
85
+            ["uid"] = uid,
86
+            ["itemId"] = gid,
87
+            ["amount"] = amount,
88
+            ["time"] = tostring(timeUtil.now(role.uid)),
89
+            ["channel"] = channel,
90
+            ["status"] = errCode,
91
+            ["orderNo"] = msg.orderId,
92
+            ["pay"] = "test_pay_goods",
93
+            ["resMsg"] = "TRADE_FINISHED",
94
+            ["tradeNo"] = msg.orderId
95
+        },
96
+        ["goodsId"] = gid,
97
+        ["name"] = "test_pay_goods",
98
+        ["channel"] = channel,
99
+        ["cmd"] = "test_pay_goods",
100
+        ["uid"] = uid,
101
+        ["pp"] = "shop",
102
+        ["gid"] = gid
103
+    }
104
+    pack.amount = amount
105
+    -- 测试订单入库
106
+    util_order:add_order(pack.orderAction)
107
+    util_order:on_shop_order(pack.orderAction)
108
+    pack.orderAction.id = util_order:get_order_id(pack.orderAction.orderNo, pack.orderAction.uid)
109
+    if errCode ~= 1 then
110
+        return code.OK
111
+    end
112
+
113
+    -- 发送物品
114
+    local shopInterface = require "interface.shop"
115
+    return shopInterface.on_pay(role, pack)
116
+end
117
+
118
+return root

+ 1 - 1
nodes/game/lib/role.lua

@@ -19,7 +19,7 @@ function root:ctor(uid, gSession)
19 19
         assert(self[cname] == nil)
20 20
 
21 21
         local moduleObj = moduleClass.new(uid)
22
-        if not moduleObj.noPersonal then
22
+        if moduleObj.isPersonal then
23 23
             self[cname] = moduleObj
24 24
             table.insert(self.moduleList, cname)
25 25
         end

+ 1 - 1
nodes/global/lib/backupRole.lua

@@ -24,7 +24,7 @@ function root:ctor(uid)
24 24
         assert(self[cname] == nil)
25 25
 
26 26
         local moduleObj = moduleClass.new(uid)
27
-        if not moduleObj.noPersonal then
27
+        if moduleObj.isPersonal then
28 28
             self[cname] = moduleObj
29 29
             table.insert(self.moduleList, cname)
30 30
         end