Commit 192b96d36b4ff53faf252fe6b70dd0609f1e513a
1 parent
17d9316a
重置
Showing
4 changed files
with
159 additions
and
22 deletions
Show diff stats
src/actions/GmAction.lua
src/actions/StoreAction.lua
1 | local _M = {} | 1 | local _M = {} |
2 | 2 | ||
3 | +local serverId = tonumber(skynet.getenv("servId")) | ||
4 | + | ||
3 | function _M.rechargeRpc(agent , data) | 5 | function _M.rechargeRpc(agent , data) |
6 | + | ||
4 | local role = agent.role | 7 | local role = agent.role |
5 | local msg = MsgPack.unpack(data) | 8 | local msg = MsgPack.unpack(data) |
6 | local id = msg.id | 9 | local id = msg.id |
7 | local dataSet = csvdb["shop_rechargeCsv"][id] | 10 | local dataSet = csvdb["shop_rechargeCsv"][id] |
11 | + local roleId = role:getProperty("id") | ||
8 | if not dataSet then return end | 12 | if not dataSet then return end |
9 | - local diamondCount | ||
10 | - if dataSet.type == 0 then -- 钻石 | ||
11 | - local rechargeF = role:getProperty("rechargeF") | ||
12 | - diamondCount = dataSet.diamond + dataSet.diamondExtra | ||
13 | - if not rechargeF[id] then | ||
14 | - diamondCount = diamondCount + dataSet.diamondFirst | ||
15 | - rechargeF[id] = 1 | ||
16 | - role:updateProperty({field = "rechargeF", value = rechargeF}) | ||
17 | - end | ||
18 | - role:gainDiamond({count = diamondCount, isRecharge = true, log = {desc = "recharge", int1 = id}}) | ||
19 | - elseif dataSet.type == 1 then --月卡 | ||
20 | - return | ||
21 | - elseif dataSet.type == 2 then -- 赛季通行证 | ||
22 | - return | ||
23 | - else | ||
24 | - return | 13 | + |
14 | + --创建订单号 | ||
15 | + local orderId = redisproxy:hincrby("autoincrement_set", "order", 1) | ||
16 | + local partnerOrderId = string.format("%d_%d_%d", serverId, roleId, orderId) | ||
17 | + local orderKey = string.format("order:%d:%d", roleId, orderId) | ||
18 | + redisproxy:del(orderKey) | ||
19 | + | ||
20 | + local order = require("models.Order").new({ key = orderKey, order = partnerOrderId, rechargeId = dataSet.id }) | ||
21 | + order:create() | ||
22 | + redisproxy:sadd(string.format("role:%d:orders", roleId), partnerOrderId) | ||
23 | + | ||
24 | + -- 暂时忽略心跳检查 | ||
25 | + role.ignoreHeartbeat = true | ||
26 | + SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({ rechargeId = id, order = partnerOrderId })) | ||
27 | + return true | ||
28 | +end | ||
29 | + | ||
30 | +function _M.purchaseOrderResult(agent, data) | ||
31 | + local role = agent.role | ||
32 | + | ||
33 | + local roleId = role:getProperty("id") | ||
34 | + local msg = MsgPack.unpack(data) | ||
35 | + | ||
36 | + role.ignoreHeartbeat = false | ||
37 | + | ||
38 | + local partnerOrderStr = msg.order | ||
39 | + local _, _, orderId = string.match(partnerOrderStr, "(.+)_(.+)_(.+)") | ||
40 | + local orderObject = require("models.Order").new({ key = string.format("order:%d:%d", roleId, orderId) }) | ||
41 | + if not orderObject:load() then | ||
42 | + -- 订单不存在 | ||
43 | + skynet.error("cancelPurchaseRpc", string.format("order %s not exist", partnerOrderStr)) | ||
44 | + return true | ||
25 | end | 45 | end |
26 | 46 | ||
27 | - -- 累充 | ||
28 | - local rmb = dataSet.rmb | ||
29 | - role:updateProperty({field = "rmbC", delta = rmb}) | ||
30 | - | ||
31 | - role:log("role_action", {desc = "recharge", int1 = id, int2 = rmb}) | 47 | + if msg.status == "success" then |
48 | + orderObject:setProperty("transactionId", msg.platformOrder or "") | ||
49 | + return true | ||
50 | + end | ||
51 | + | ||
52 | + if orderObject:getProperty("finishTime") > 0 then | ||
53 | + return true | ||
54 | + end | ||
55 | + | ||
56 | + orderObject:setProperty("status", msg.status) | ||
32 | 57 | ||
33 | - SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({diamond = diamondCount})) | 58 | + redisproxy:srem(string.format("role:%d:orders", roleId), partnerOrderStr) |
34 | return true | 59 | return true |
35 | end | 60 | end |
36 | 61 |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +local Order = class("Order", require("shared.ModelBase")) | ||
2 | + | ||
3 | +function Order:ctor(properties) | ||
4 | + Order.super.ctor(self, properties) | ||
5 | +end | ||
6 | + | ||
7 | +Order.schema = { | ||
8 | + key = {"string"}, -- redis key | ||
9 | + order = {"string"}, -- 自己订单号 | ||
10 | + rechargeId = {"number", 0}, | ||
11 | + transactionId = {"string", ""}, | ||
12 | + createTime = {"number", skynet.timex()}, -- 订单创建时间 | ||
13 | + finishTime = {"number", 0}, -- 服务端验证完成时间 | ||
14 | + status = {"string", "create"}, | ||
15 | +} | ||
16 | + | ||
17 | +Order.fields = { | ||
18 | + order = true, | ||
19 | + rechargeId = true, | ||
20 | + transactionId = true, | ||
21 | + createTime = true, | ||
22 | + finishTime = true, | ||
23 | + status = true, | ||
24 | +} | ||
25 | + | ||
26 | +return Order | ||
0 | \ No newline at end of file | 27 | \ No newline at end of file |
src/models/RolePlugin.lua
@@ -1397,6 +1397,88 @@ function RolePlugin.bind(Role) | @@ -1397,6 +1397,88 @@ function RolePlugin.bind(Role) | ||
1397 | self:updateProperty({field = "redp", value = redp}) | 1397 | self:updateProperty({field = "redp", value = redp}) |
1398 | end | 1398 | end |
1399 | 1399 | ||
1400 | + | ||
1401 | + -- 充值 -- | ||
1402 | + function Role:handlePurchase(params) | ||
1403 | + local roleId = self:getProperty("id") | ||
1404 | + local partnerOrderStr = params.order | ||
1405 | + | ||
1406 | + local _, _, orderId = string.match(partnerOrderStr, "(.+)_(.+)_(.+)") | ||
1407 | + local orderObject = require("models.Order").new({ key = string.format("order:%d:%d", roleId, orderId) }) | ||
1408 | + if not orderObject:load() then | ||
1409 | + -- 订单不存在 | ||
1410 | + skynet.error("ayncPurchaseRpc", string.format("order %s not exist", partnerOrderStr)) | ||
1411 | + return | ||
1412 | + end | ||
1413 | + | ||
1414 | + if orderObject:getProperty("finishTime") > 0 then | ||
1415 | + -- 订单已经处理 | ||
1416 | + SendPacket(actionCodes.Store_ayncPurchaseRpc, MsgPack.pack({ result = "handled" })) | ||
1417 | + return | ||
1418 | + end | ||
1419 | + | ||
1420 | + | ||
1421 | + local rechargeData = csvdb["shop_rechargeCsv"][orderObject:getProperty("rechargeId")] | ||
1422 | + if rechargeData.rmb ~= tonumber(params.amount) then | ||
1423 | + skynet.error(string.format("fake order: %s, roleId: %d, order: %s", | ||
1424 | + params.transactionId, roleId, partnerOrderStr | ||
1425 | + )) | ||
1426 | + return | ||
1427 | + end | ||
1428 | + | ||
1429 | + local diamond = self:recharge({ | ||
1430 | + id = orderObject:getProperty("rechargeId"), | ||
1431 | + transactionId = params.transactionId, | ||
1432 | + pay_time = params.pay_time, | ||
1433 | + order = partnerOrderStr | ||
1434 | + }) | ||
1435 | + orderObject:setProperty("finishTime", skynet.time()) | ||
1436 | + orderObject:setProperty("status", "finish") | ||
1437 | + | ||
1438 | + redisproxy:srem(string.format("role:%d:orders", roleId), partnerOrderStr) | ||
1439 | + | ||
1440 | + SendPacket(actionCodes.Store_ayncPurchaseRpc, MsgPack.pack({ order = partnerOrderStr, | ||
1441 | + result = "success", diamond = diamond})) | ||
1442 | + | ||
1443 | + return orderObject:getProperty("rechargeId") | ||
1444 | + end | ||
1445 | + | ||
1446 | + | ||
1447 | + function Role:recharge(params) | ||
1448 | + local id = tonumber(params.id) | ||
1449 | + local rechargeData = csvdb["shop_rechargeCsv"][id] | ||
1450 | + if not rechargeData then | ||
1451 | + skynet.error("recharge id not exist", id) | ||
1452 | + return | ||
1453 | + end | ||
1454 | + | ||
1455 | + local diamondCount = 0 | ||
1456 | + if rechargeData.type == 0 then -- 钻石 | ||
1457 | + local rechargeF = role:getProperty("rechargeF") | ||
1458 | + diamondCount = rechargeData.diamond + rechargeData.diamondExtra | ||
1459 | + if not rechargeF[id] then | ||
1460 | + diamondCount = diamondCount + rechargeData.diamondFirst | ||
1461 | + rechargeF[id] = 1 | ||
1462 | + role:updateProperty({field = "rechargeF", value = rechargeF}) | ||
1463 | + end | ||
1464 | + role:gainDiamond({count = diamondCount, isRecharge = true, log = {desc = "recharge", int1 = id}}) | ||
1465 | + elseif rechargeData.type == 1 then --月卡 | ||
1466 | + return | ||
1467 | + elseif rechargeData.type == 2 then -- 赛季通行证 | ||
1468 | + return | ||
1469 | + else | ||
1470 | + return | ||
1471 | + end | ||
1472 | + | ||
1473 | + -- 累充 | ||
1474 | + local rmb = rechargeData.rmb | ||
1475 | + role:updateProperty({field = "rmbC", delta = rmb}) | ||
1476 | + | ||
1477 | + self:log("role_action", {desc = "recharge", int1 = id, int2 = rmb, key1 = params.transactionId, key2 = params.order, long1 = params.pay_time}) | ||
1478 | + | ||
1479 | + return diamondCount | ||
1480 | + end | ||
1481 | + | ||
1400 | end | 1482 | end |
1401 | 1483 | ||
1402 | return RolePlugin | 1484 | return RolePlugin |
1403 | \ No newline at end of file | 1485 | \ No newline at end of file |