Commit 7a515b6020ea0ec64b56c40948591ec4be6525f3

Authored by zhangqijia
1 parent 7eda801e

feat: 增加一个礼包码的接口

1. 把原来的礼包码协议和新增的礼包码接口的共同部分写成一个函数
2. 增加一个GM指令调用获取礼包。
src/actions/GmAction.lua
... ... @@ -1139,4 +1139,14 @@ function _M.get_draw_hero_pro(role, pms)
1139 1139 return json.encode(result)
1140 1140 end
1141 1141  
  1142 +function _M.draw_code(role, pms)
  1143 + local code = pms.pm1
  1144 + if type(code) ~= "string" then return -2 end
  1145 + if code:find("[^0-9a-zA-Z]") then return -3 end
  1146 +
  1147 + local ret, _, _= role:getCodeGift(code)
  1148 + return ret
  1149 +end
  1150 +
  1151 +
1142 1152 return _M
1143 1153 \ No newline at end of file
... ...
src/actions/RoleAction.lua
... ... @@ -1355,53 +1355,23 @@ end
1355 1355  
1356 1356 function _M.drawCodeRpc(agent, data)
1357 1357 local msg = MsgPack.unpack(data)
1358   - local codeurl = skynet.getenv("codeurl")
1359 1358 local role = agent.role
1360   - local msg = MsgPack.unpack(data)
1361 1359 local code = msg.code
1362 1360  
1363   - if type(code) ~= "string" then return end
1364   - if code:find("[^0-9a-zA-Z]") then return end
  1361 + if type(code) ~= "string" then return 1 end
  1362 + if code:find("[^0-9a-zA-Z]") then return 2 end
1365 1363  
1366   - local codestr = role:getProperty("codeStr")
1367   - local content = {
1368   - ["platformId"] = role:getProperty("sid"),
1369   - ["code"] = code,
1370   - ["itemIds"] = codestr,
1371   - ["key"] = "zhaolugame20170831",
1372   - }
1373   - local status, body = httpc.get(codeurl, "/libaoma?" .. httpGetFormatData(content), {})
1374   - if status == 200 then
1375   - local result = json.decode(body)
1376   - local ret = tonum(result.ret)
1377   - if ret == 0 then
1378   - local giftId = tonumber(result.giftId)
1379   - role:setProperty("codeStr", codestr:setv(giftId, 1))
1380   - local reward, change = role:award(result.gift, {log = {desc = "drawCode", int1 = giftId}})
1381   -
1382   - role:log("get_gift", {
1383   - gift_id = giftId, -- 礼包ID
1384   - gift_key = code, -- 礼包key
1385   - gift_reward = reward, -- 礼包奖励,json格式记录,{"itemid1":123,"itemid2":12,……….}
1386   - gift_name = "", -- 礼包名称
1387   - gift_reason = 0, -- 礼包发放原因,见发放原因枚举表
1388   - })
1389   - role:mylog("role_action", {desc = "drawCode", int1 = giftId, key1 = code, key2 = role:getRewardLogStr(result.gift)})
1390   - SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({
1391   - result = ret,
1392   - reward = reward,
1393   - change = change,
1394   - }))
1395   - return true
1396   - end
1397   - -- 1 不存在的礼包码
1398   - -- 2 已经领取过相同类型物品
1399   - -- 3 领取数量达到上限
1400   - -- 4 过期了
1401   - SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = ret}))
1402   - return true
  1364 + local ret, reward, change= role:getCodeGift(code)
  1365 + if ret == 0 then
  1366 + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({
  1367 + result = ret,
  1368 + reward = reward,
  1369 + change = change,
  1370 + }))
  1371 + return true
1403 1372 end
1404   - SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = -1}))
  1373 +
  1374 + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = ret}))
1405 1375 return true
1406 1376 end
1407 1377  
... ...
src/models/RolePlugin.lua
... ... @@ -3303,6 +3303,43 @@ function RolePlugin.bind(Role)
3303 3303 end
3304 3304 self:updateProperty({field = "worldChangePoints", value = worldChangePoints})
3305 3305 end
  3306 +
  3307 + function Role:getCodeGift(code)
  3308 + local codeurl = skynet.getenv("codeurl")
  3309 + local codestr = self:getProperty("codeStr")
  3310 + local content = {
  3311 + ["platformId"] = self:getProperty("sid"),
  3312 + ["code"] = code,
  3313 + ["itemIds"] = codestr,
  3314 + ["key"] = "zhaolugame20170831",
  3315 + }
  3316 + local status, body = httpc.get(codeurl, "/libaoma?" .. httpGetFormatData(content), {})
  3317 + if status == 200 then
  3318 + local result = json.decode(body)
  3319 + local ret = tonum(result.ret)
  3320 + if ret == 0 then
  3321 + local giftId = tonumber(result.giftId)
  3322 + self:setProperty("codeStr", codestr:setv(giftId, 1))
  3323 + local reward, change = self:award(result.gift, {log = {desc = "drawCode", int1 = giftId}})
  3324 +
  3325 + self:log("get_gift", {
  3326 + gift_id = giftId, -- 礼包ID
  3327 + gift_key = code, -- 礼包key
  3328 + gift_reward = reward, -- 礼包奖励,json格式记录,{"itemid1":123,"itemid2":12,……….}
  3329 + gift_name = "", -- 礼包名称
  3330 + gift_reason = 0, -- 礼包发放原因,见发放原因枚举表
  3331 + })
  3332 + self:mylog("role_action", {desc = "drawCode", int1 = giftId, key1 = code, key2 = self:getRewardLogStr(result.gift)})
  3333 + return ret, result, reward, change
  3334 + end
  3335 + -- 1 不存在的礼包码
  3336 + -- 2 已经领取过相同类型物品
  3337 + -- 3 领取数量达到上限
  3338 + -- 4 过期了
  3339 + return ret
  3340 + end
  3341 + return -1
  3342 + end
3306 3343 end
3307 3344  
3308 3345 return RolePlugin
3309 3346 \ No newline at end of file
... ...