-- 代金券特惠 -- 每日每档限购1次,跨天重置 -- db.voucherSpecialOfferData = { [buyId] = buyCnt } local Lang = require("common.Lang") local Msg = require("core.Msg") local Broadcast = require("broadcast.Broadcast") local Grid = require("bag.Grid") local BagLogic = require("bag.BagLogic") local BuyLogic = require("topup.BuyLogic") local YunYingLogic = require("yunying.YunYingLogic") local VoucherShopLogic = require("voucher.VoucherShopLogic") local CommonDefine = require("common.CommonDefine") local giftConfig = require("excel.VoucherSpecialOffer").gift local LOGTYPE = "VoucherSpecialOffer" local VOUCHERSHOP_ACTID = 27 local function isXiaoQiChannel(human) local channelID = human.db.phpChanelID or human.phpChanelID return channelID == CommonDefine.CHANNEL_TAG_XIAOQI or channelID == tostring(CommonDefine.CHANNEL_TAG_XIAOQI) end local function getCfg(buyId) for _, v in ipairs(giftConfig) do if buyId == v.buyId then return v end end end local function updateIcon(human) YunYingLogic.sendIconUpdate(VOUCHERSHOP_ACTID, human) end function isOpen(human, YYInfo, funcConfig) if not isXiaoQiChannel(human) then return false end return VoucherShopLogic.isOpen(human, YYInfo, funcConfig) end function isRed(human) return false end function updateDaily(human) if not isOpen(human) then return end human.db.voucherSpecialOfferData = nil if human.fd then VoucherSpecialOffer_Query(human) end end function VoucherSpecialOffer_Query(human) if not isOpen(human) then return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME) end local buyData = human.db.voucherSpecialOfferData local msgRet = Msg.gc.GC_VOUCHER_SPECIAL_OFFER_QUERY local giftArr = msgRet.giftArr giftArr[0] = 0 for k, v in ipairs(giftConfig) do giftArr[0] = k giftArr[k].nowBuyCnt = buyData and buyData[v.buyId] or 0 giftArr[k].maxBuyCnt = v.amount BuyLogic.fontBuyItem(human, giftArr[k].buyItem, v.buyId) giftArr[k].giftItem[0] = #v.rewards for idx, itemCfg in ipairs(v.rewards) do Grid.makeItem(giftArr[k].giftItem[idx], itemCfg[1], itemCfg[2]) end end Msg.send(msgRet, human.fd) end function onCharge(human, buyId, buyNum) if not isOpen(human) then return end local giftCfg = getCfg(buyId) if not giftCfg then return end buyNum = buyNum or 1 local buyData = human.db.voucherSpecialOfferData local nowBuyCnt = buyData and buyData[buyId] or 0 if nowBuyCnt + buyNum > giftCfg.amount then return Broadcast.sendErr(human, Lang.ABS_GIFT_BUY_LIMIT) end local itemArr = {} for idx, itemCfg in ipairs(giftCfg.rewards) do itemArr[idx] = {itemCfg[1], itemCfg[2] * buyNum} end BagLogic.addItemList(human, itemArr, LOGTYPE) buyData = buyData or {} buyData[buyId] = nowBuyCnt + buyNum human.db.voucherSpecialOfferData = buyData updateIcon(human) VoucherSpecialOffer_Query(human) end function GetRemainNum(human, nBuyID) if not isOpen(human) then return 0 end local giftCfg = getCfg(nBuyID) if not giftCfg then return 0 end local buyData = human.db.voucherSpecialOfferData if not buyData or not buyData[nBuyID] then return giftCfg.amount end local leftCnt = giftCfg.amount - buyData[nBuyID] return leftCnt > 0 and leftCnt or 0 end