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 | 3 | local serverId = tonumber(skynet.getenv("servId")) |
| 4 | 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 | 20 | local orderId = redisproxy:hincrby("autoincrement_set", "order", 1) |
| 8 | 21 | local partnerOrderId = string.format("%d_%d_%d", serverId, roleId, orderId) |
| 9 | 22 | local orderKey = string.format("order:%d:%d", roleId, orderId) |
| ... | ... | @@ -29,7 +42,7 @@ function _M.rechargeRpc(agent , data) |
| 29 | 42 | local roleId = role:getProperty("id") |
| 30 | 43 | |
| 31 | 44 | --创建订单号 |
| 32 | - local partnerOrderId = makeOrder(roleId, id) | |
| 45 | + local partnerOrderId = makeOrder(role, id) | |
| 33 | 46 | SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({ order = partnerOrderId })) |
| 34 | 47 | |
| 35 | 48 | -- 测试的 直接发奖励了 |
| ... | ... | @@ -77,7 +90,7 @@ function _M.googleRechargeRpc(agent, data) |
| 77 | 90 | |
| 78 | 91 | role.ignoreHeartbeat = true |
| 79 | 92 | --创建订单号 |
| 80 | - local partnerOrderId = makeOrder(roleId, id) | |
| 93 | + local partnerOrderId = makeOrder(role, id) | |
| 81 | 94 | -- 签名 |
| 82 | 95 | local secret_key = "b7657fa7ccd44c16a35e3f454ac7a075" |
| 83 | 96 | local need = { |
| ... | ... | @@ -104,7 +117,7 @@ function _M.myCardRechargeRpc(agent, data) |
| 104 | 117 | |
| 105 | 118 | role.ignoreHeartbeat = true |
| 106 | 119 | --创建订单号 |
| 107 | - local partnerOrderId = makeOrder(roleId, id) | |
| 120 | + local partnerOrderId = makeOrder(role, id) | |
| 108 | 121 | -- 签名 |
| 109 | 122 | local secret_key = "48759e07540f46d9af17ec82669b4272" |
| 110 | 123 | local need = { |
| ... | ... | @@ -130,7 +143,7 @@ function _M.iosRechargeRpc(agent, data) |
| 130 | 143 | |
| 131 | 144 | role.ignoreHeartbeat = true |
| 132 | 145 | --创建订单号 |
| 133 | - local partnerOrderId = makeOrder(roleId, id) | |
| 146 | + local partnerOrderId = makeOrder(role, id) | |
| 134 | 147 | -- 签名 |
| 135 | 148 | local secret_key = "9647d2efe1074c73b9ac19af4337a70e" |
| 136 | 149 | local need = { | ... | ... |
src/models/Store.lua
| ... | ... | @@ -224,7 +224,7 @@ end |
| 224 | 224 | |
| 225 | 225 | --检测购买是否超过限制数量 |
| 226 | 226 | function Store:checkRechargeRecord(limit, id) |
| 227 | - local rechargeRecord = self:getProperty("payR") | |
| 227 | + local rechargeRecord = self:getProperty("payR") or {} | |
| 228 | 228 | if limit ~= 0 and limit <= (rechargeRecord[id] or 0) then |
| 229 | 229 | skynet.error(string.format("recharge id:%d count over limit, user id:%d", id, self.owner:getProperty("id"))) |
| 230 | 230 | return false | ... | ... |