Commit e183e51b65f0ba19596f95963571cc413fa30d79
Merge branch 'develop' into tr/ob
* develop: 下单前检测商品限购次数
Showing
2 changed files
with
19 additions
and
6 deletions
Show diff stats
src/actions/StoreAction.lua
@@ -3,7 +3,20 @@ local _M = {} | @@ -3,7 +3,20 @@ local _M = {} | ||
3 | local serverId = tonumber(skynet.getenv("servId")) | 3 | local serverId = tonumber(skynet.getenv("servId")) |
4 | local md5 = require "md5" | 4 | local md5 = require "md5" |
5 | 5 | ||
6 | -local function makeOrder(roleId, rechargeId) | 6 | +local function makeOrder(role, rechargeId) |
7 | + local roleId = role:getProperty("id") | ||
8 | + local rechargeData = csvdb["shop_rechargeCsv"][rechargeId] | ||
9 | + if not rechargeData then | ||
10 | + skynet.error("recharge id not exist", rechargeId) | ||
11 | + return "" | ||
12 | + end | ||
13 | + local limit = rechargeData.limit | ||
14 | + local rechargeRecord = role:getProperty("payR") or {} | ||
15 | + if limit ~= 0 and limit <= (rechargeRecord[rechargeId] or 0) then | ||
16 | + skynet.error(string.format("recharge id:%d count over limit, user id:%d", rechargeId, roleId)) | ||
17 | + return "" | ||
18 | + end | ||
19 | + | ||
7 | local orderId = redisproxy:hincrby("autoincrement_set", "order", 1) | 20 | local orderId = redisproxy:hincrby("autoincrement_set", "order", 1) |
8 | local partnerOrderId = string.format("%d_%d_%d", serverId, roleId, orderId) | 21 | local partnerOrderId = string.format("%d_%d_%d", serverId, roleId, orderId) |
9 | local orderKey = string.format("order:%d:%d", roleId, orderId) | 22 | local orderKey = string.format("order:%d:%d", roleId, orderId) |
@@ -29,7 +42,7 @@ function _M.rechargeRpc(agent , data) | @@ -29,7 +42,7 @@ function _M.rechargeRpc(agent , data) | ||
29 | local roleId = role:getProperty("id") | 42 | local roleId = role:getProperty("id") |
30 | 43 | ||
31 | --创建订单号 | 44 | --创建订单号 |
32 | - local partnerOrderId = makeOrder(roleId, id) | 45 | + local partnerOrderId = makeOrder(role, id) |
33 | SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({ order = partnerOrderId })) | 46 | SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({ order = partnerOrderId })) |
34 | 47 | ||
35 | -- 测试的 直接发奖励了 | 48 | -- 测试的 直接发奖励了 |
@@ -77,7 +90,7 @@ function _M.googleRechargeRpc(agent, data) | @@ -77,7 +90,7 @@ function _M.googleRechargeRpc(agent, data) | ||
77 | 90 | ||
78 | role.ignoreHeartbeat = true | 91 | role.ignoreHeartbeat = true |
79 | --创建订单号 | 92 | --创建订单号 |
80 | - local partnerOrderId = makeOrder(roleId, id) | 93 | + local partnerOrderId = makeOrder(role, id) |
81 | -- 签名 | 94 | -- 签名 |
82 | local secret_key = "b7657fa7ccd44c16a35e3f454ac7a075" | 95 | local secret_key = "b7657fa7ccd44c16a35e3f454ac7a075" |
83 | local need = { | 96 | local need = { |
@@ -104,7 +117,7 @@ function _M.myCardRechargeRpc(agent, data) | @@ -104,7 +117,7 @@ function _M.myCardRechargeRpc(agent, data) | ||
104 | 117 | ||
105 | role.ignoreHeartbeat = true | 118 | role.ignoreHeartbeat = true |
106 | --创建订单号 | 119 | --创建订单号 |
107 | - local partnerOrderId = makeOrder(roleId, id) | 120 | + local partnerOrderId = makeOrder(role, id) |
108 | -- 签名 | 121 | -- 签名 |
109 | local secret_key = "48759e07540f46d9af17ec82669b4272" | 122 | local secret_key = "48759e07540f46d9af17ec82669b4272" |
110 | local need = { | 123 | local need = { |
@@ -130,7 +143,7 @@ function _M.iosRechargeRpc(agent, data) | @@ -130,7 +143,7 @@ function _M.iosRechargeRpc(agent, data) | ||
130 | 143 | ||
131 | role.ignoreHeartbeat = true | 144 | role.ignoreHeartbeat = true |
132 | --创建订单号 | 145 | --创建订单号 |
133 | - local partnerOrderId = makeOrder(roleId, id) | 146 | + local partnerOrderId = makeOrder(role, id) |
134 | -- 签名 | 147 | -- 签名 |
135 | local secret_key = "9647d2efe1074c73b9ac19af4337a70e" | 148 | local secret_key = "9647d2efe1074c73b9ac19af4337a70e" |
136 | local need = { | 149 | local need = { |
src/models/Store.lua
@@ -224,7 +224,7 @@ end | @@ -224,7 +224,7 @@ end | ||
224 | 224 | ||
225 | --检测购买是否超过限制数量 | 225 | --检测购买是否超过限制数量 |
226 | function Store:checkRechargeRecord(limit, id) | 226 | function Store:checkRechargeRecord(limit, id) |
227 | - local rechargeRecord = self:getProperty("payR") | 227 | + local rechargeRecord = self:getProperty("payR") or {} |
228 | if limit ~= 0 and limit <= (rechargeRecord[id] or 0) then | 228 | if limit ~= 0 and limit <= (rechargeRecord[id] or 0) then |
229 | skynet.error(string.format("recharge id:%d count over limit, user id:%d", id, self.owner:getProperty("id"))) | 229 | skynet.error(string.format("recharge id:%d count over limit, user id:%d", id, self.owner:getProperty("id"))) |
230 | return false | 230 | return false |