--[[ Descripttion:兑换码 version: Author: Neo,Huang Date: 2023-11-19 21:28:04 LastEditors: Neo,Huang LastEditTime: 2023-11-19 21:29:10 --]] local code = require("code") local util_exchange_code = require("utils.util_exchange_code") local bagData = require("data.bag") local root = class("exchangecode", require("base.baseModule")) function root:ctor(uid) root.super.ctor(self, uid, "exchangecode", "uid", true) self.uid = uid end function root:mysql_get_init_columns() return { uid = "int(11) NOT NULL COMMENT '用户id'", awardList = "JSON COMMENT '已领取兑换码列表'" } end -- 兑换码 function root:itf_exchange_code(role, msg) local pCode = msg.pCode if is_empty(pCode) then return code.PARAMTER_ERROR end local awardList = self:redis_get_key_info("awardList") if table.include(awardList, pCode) then -- 已领取奖励 return code.EXCHANGE_CODE.AWARDED end -- 获取兑换码奖励权重物品列表 local errcode, weightItems = util_exchange_code:get_exchange_code_items(pCode) if code.is_not_ok(errcode) then return errcode end -- 增加领奖次数 errcode = util_exchange_code:add_award_times(pCode) if code.is_not_ok(errcode) then return errcode end table.insert(awardList, pCode) self:redis_update_key_info("awardList", awardList) -- 减少领奖次数 -- 随机物品 local index = random_list_by_weight(weightItems) local items = {{id = weightItems[index].id, count = weightItems[index].count}} local keyEvent = string.format("exchange-code-%s", tostring(pCode)) bagData:add_items(self.uid, items, keyEvent) return code.OK, {items = items} end return root