payment.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. -- 支付模块
  2. local log = require "model.log"
  3. local common_fun = require "model.common_fun"
  4. local module_fun = require "model.module_fun"
  5. local currency
  6. local function payment(character, receipt, not_check)
  7. assert(character)
  8. assert(receipt)
  9. local module = assert(receipt.module)
  10. local brief = assert(receipt.brief)
  11. local context = receipt.context
  12. local record = {}
  13. local detail = common_fun.merge_award(assert(receipt.detail))
  14. local errno = 0
  15. if not not_check then
  16. errno = module_fun.paymeny_check(character, detail)
  17. end
  18. if errno ~= 0 then
  19. return errno
  20. end
  21. local now = {}
  22. local debris_list = {}
  23. for _, v in ipairs(detail) do
  24. local num = v.num
  25. local id = v.id
  26. local gtype = common_fun.goods_type(id)
  27. currency = currency or require "model.currency"
  28. if gtype == GOODS_MONEY then
  29. local cur = currency.pay_money(character, id, num)
  30. table.insert(now, {id = id, num = cur})
  31. end
  32. end
  33. -- 记录日志
  34. if next(detail) then
  35. log.receipt(character, module, brief, context, detail)
  36. end
  37. --向客户端发送货币
  38. if next(now) then
  39. character.send("pay_currency", {now = now, pay = detail})
  40. end
  41. if next(debris_list) then
  42. character.send("pay_debris_nty", {list = debris_list})
  43. end
  44. return 0
  45. end
  46. return payment