Commit 167d24dc52a40fc2b5b149c10289845f1f0de058

Authored by zhangqijia
1 parent a4d3a28a

fix: shopnormal 商品购买,消耗物品以后再添加购买记录

Showing 1 changed file with 12 additions and 13 deletions   Show diff stats
src/actions/StoreAction.lua
... ... @@ -365,7 +365,7 @@ function _M.shopBuyRpc(agent , data)
365 365 local id = msg.id
366 366 local count = msg.count or 1
367 367  
368   - local dataSet = csvdb["shop_normalCsv"][id]
  368 + local dataSet = csvdb["shop_normalCsv"][id]
369 369 if not dataSet then return end
370 370  
371 371 if dataSet.unlock ~= "" then
... ... @@ -382,20 +382,13 @@ function _M.shopBuyRpc(agent , data)
382 382 if not role.activity:isOpenById(dataSet.activity_id, "ActShopGoods") then return 3 end
383 383 end
384 384  
385   - local buyRecord = role.storeData:getProperty("buyR")
386   - if math.illegalNum(count, 1, (dataSet.limit == 0 and 10000 or dataSet.limit - (buyRecord[id] or 0))) then
387   - skynet.error(string.format("shop buy over limit, user_id:%d, goods_id:%d", role:getProperty("id"), id))
388   - return 6
389   - end
390   -
391   - local cost
392   - if dataSet.disount == 0 then
  385 + local cost
  386 + if dataSet.disount == 0 then
393 387 cost = {[dataSet.icon] = math.ceil(dataSet.cost * count)}
394 388 else
395 389 cost = {[dataSet.icon] = math.ceil(dataSet.cost * count * ((dataSet.disount or 10) / 10))}
396 390 end
397 391  
398   -
399 392 local desc = "unknowShop"
400 393 if dataSet.shop == 1 then -- 普通商店
401 394 desc = "dailyShop"
... ... @@ -406,14 +399,20 @@ function _M.shopBuyRpc(agent , data)
406 399 end
407 400  
408 401 if not role:checkItemEnough(cost) then return 4 end
  402 + if not role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count, long1= dataSet.shop}}) then return 5 end
409 403  
410   - local limitStr = ""
  404 + local buyRecord = role.storeData:getProperty("buyR")
  405 + if math.illegalNum(count, 1, (dataSet.limit == 0 and 10000 or dataSet.limit - (buyRecord[id] or 0))) then
  406 + skynet.error(string.format("shop buy over limit, user_id:%d, goods_id:%d", role:getProperty("id"), id))
  407 + return 6
  408 + end
  409 +
  410 + local limitStr = ""
411 411 if dataSet.limit ~= 0 then
412 412 buyRecord[id] = (buyRecord[id] or 0) + count
413 413 role.storeData:updateProperty({field = "buyR", value = buyRecord})
414   - limitStr = string.format("%s/%s", buyRecord[id], dataSet.limit)
  414 + limitStr = string.format("%s/%s", buyRecord[id], dataSet.limit)
415 415 end
416   - if not role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count, long1= dataSet.shop}}) then return 5 end
417 416  
418 417 local gift = {}
419 418 for _id, _count in pairs(dataSet.gift:toNumMap()) do
... ...