-- 模块通用函数 -- 需要加载其他模块的放这里 local common_fun = require "model.common_fun" local asset = require "model.asset" local currency local module_fun = {} function module_fun.get_goods_num(character, id) currency = currency or require "model.currency" if not id then return 0 end local gtype = common_fun.goods_type(id) if gtype == GOODS_MONEY then return currency.get_money(character, id) end return 0 end function module_fun.reward_check(list) if type(list) ~= "table" then return STD_ERR.COMMON_AWARD_FORMAT_ERR end for _, v in ipairs(list or {}) do if type(v) ~= "table" then return STD_ERR.COMMON_AWARD_FORMAT_ERR end local id = v.id local num = v.num if not id or not num or num < 0 then return STD_ERR.COMMON_AWARD_FORMAT_ERR end local errno = common_fun.goods_check(id) if errno ~= 0 then return errno end end return 0 end function module_fun.paymeny_check(character, list) currency = currency or require "model.currency" if not next(list or {}) then return STD_ERR.PAYMENT_NUM_ERR -- 消耗数量异常 end for _, v in ipairs(list) do if type(v) ~= "table" then return STD_ERR.PAYMENT_LIST_ERR -- 支付格式异常 end local num = v.num local id = v.id if not num or not id then return STD_ERR.PAYMENT_LIST_ERR -- 支付格式异常 end if num <= 0 then return STD_ERR.PAYMENT_NUM_ERR -- 消耗数量异常 end local gtype = common_fun.goods_type(id) if gtype == GOODS_MONEY then local errno = currency.check_money(character, id, num) if errno ~= 0 then return errno end else return STD_ERR.PAYMENT_UNKNOWN_ITEM -- 支付未注册的道具 end return 0 end end function module_fun.buy_gift(character, conf) if not conf then return STD_ERR.COMMON_PARM_ERR end end function module_fun.simple_role(character) return { uid = character.uid, nickname = character.nickname, avatar = character.avatar, level = character.level } end return module_fun