gitxsm 2 долоо хоног өмнө
parent
commit
8a2feae6a6

+ 97 - 0
script/module/roleSystem/RoleDailyGift.lua

@@ -0,0 +1,97 @@
+-- 每日好礼(小7渠道专属)
+-- db.roleDailyGiftData = { getTime = 领取时间戳 }
+
+local Util = require("common.Util")
+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 ObjHuman = require("core.ObjHuman")
+local CommonDefine = require("common.CommonDefine")
+-- local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
+-- local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
+
+local LOGTYPE = "roleDailyGift"
+local REWARD_ITEM_ID = 31
+local REWARD_ITEM_CNT = 648
+
+local function getChannelId(human)
+    return human.db.phpChanelID or human.phpChanelID
+end
+
+local function isXiaoQiChannel(human)
+    local channelID = getChannelId(human)
+    return channelID == CommonDefine.CHANNEL_TAG_XIAOQI
+        or channelID == tostring(CommonDefine.CHANNEL_TAG_XIAOQI)
+end
+
+function ModuleisOpen(human)
+    return isXiaoQiChannel(human)
+end
+
+local function isClaimedToday(human)
+    local data = human.db.roleDailyGiftData
+    if not data or not data.getTime then
+        return false
+    end
+    return Util.isSameDay(data.getTime)
+end
+
+local function getPrizeState(human)
+    if isClaimedToday(human) then
+        return CommonDefine.COMMON_PRIZE_STATE_GET
+    end
+    return CommonDefine.COMMON_PRIZE_STATE_CANGET
+end
+
+-- function isDot(human)
+--     if not ModuleisOpen(human) then
+--         return false
+--     end
+--     return getPrizeState(human) == CommonDefine.COMMON_PRIZE_STATE_CANGET
+-- end
+
+function updateDaily(human)
+    if not ModuleisOpen(human) then
+        return
+    end
+    -- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_113)
+    if human.fd then
+        Query(human)
+    end
+end
+
+function Query(human)
+    if not ModuleisOpen(human) then
+        return
+    end
+
+    ObjHuman.updateDaily(human)
+
+    local msgRet = Msg.gc.GC_ROLE_DAILY_GIFT_QUERY
+    msgRet.status = getPrizeState(human)
+    Grid.makeItem(msgRet.item, REWARD_ITEM_ID, REWARD_ITEM_CNT)
+    Msg.send(msgRet, human.fd)
+end
+
+function Get(human)
+    if not ModuleisOpen(human) then
+        return Broadcast.sendErr(human, Lang.COMMON_SYSTEM_READY)
+    end
+
+    ObjHuman.updateDaily(human)
+
+    if isClaimedToday(human) then
+        return Broadcast.sendErr(human, "今日已领取")
+    end
+
+    local itemArr = {{REWARD_ITEM_ID, REWARD_ITEM_CNT}}
+    BagLogic.addItemList(human, itemArr, LOGTYPE)
+
+    human.db.roleDailyGiftData = human.db.roleDailyGiftData or {}
+    human.db.roleDailyGiftData.getTime = os.time()
+
+    -- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_113)
+    Query(human)
+end

+ 1 - 0
script/module/topup/Proto.lua

@@ -21,6 +21,7 @@ BuyItem = {
 	{"voucher",		1,		"int"},			-- 代金券
 	{"nCanBuyNum",	1,		"byte"},		-- 可购买数量
 	{"productId",	1,		"string"},		-- 
+	{"disableVoucher",1,	"byte"},		-- 禁用代金券(1=禁用,0=可用)
 }
 
 TopupItemNet = {

+ 116 - 0
script/module/voucher/VoucherSpecialOffer.lua

@@ -0,0 +1,116 @@
+-- 代金券特惠
+-- 每日每档限购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 giftConfig = require("excel.VoucherSpecialOffer").gift
+
+local LOGTYPE = "VoucherSpecialOffer"
+local VOUCHERSHOP_ACTID = 27
+
+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)
+    return VoucherShopLogic.isOpen(human, YYInfo, funcConfig)
+end
+
+function isRed(human)
+    return false
+end
+
+function updateDaily(human)
+    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 Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
+    end
+
+    local giftCfg = getCfg(buyId)
+    if not giftCfg then
+        return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
+    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)
+    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