diff --git a/src/models/Store.lua b/src/models/Store.lua index dd3a1ae..02d26ac 100644 --- a/src/models/Store.lua +++ b/src/models/Store.lua @@ -98,37 +98,67 @@ local SuperMonthCard = {} SuperMonthCard["buy"] = function(self, id) local smonthCards = self:getProperty("smonthCards") or {} + local buyLimitFunc = function(buylimit) + for k, v in pairs(buylimit) do + if k == 1 then + if v == 101 then + if self:isMonthCardExpire() then + skynet.error("月卡过期") + return false + end + else + if smonthCards[v] == nil then + skynet.error("没有购买增刊里的条件, %d", v) + return false + end + end + elseif k == 2 then + if smonthCards[v] == nil and v ~= 101 then + skynet.error("没有购买增刊里的条件, %d", v) + return false + end + if SuperMonthCard["isExpired"](self, v) == false and v ~= 101 then + skynet.error("上期特刊奖励没有领取完") + return false + end + end + end + return true + end + local BuyMonthCard = {} BuyMonthCard["renewal"]= function() --续刊 - if self:isMonthCardExpire() then return false end + local card = csvdb["shop_cardCsv"][id] or {} + if card["buyLimit"] and card["buyLimit"] ~= "" then + if buyLimitFunc(card["buyLimit"]:toNumMap()) == false then + skynet.error("不满足购买条件") + return false + end + end local smonthCard = smonthCards[id] or {} if next(smonthCard) then - smonthCard["buyCount"] = (smonthCard["buyCount"] or 0) + 1 - - local card = csvdb["shop_cardCsv"][id] or {} - local periods = SuperMonthCard["periods"](self, id) + (card["cardPlusPeriods"] or 30) + local periods = SuperMonthCard["periods"](self, id) + (card["amount"] or 30) smonthCard["periods"] = periods - self:updateProperty({filed = "smonthCards", value = smonthCards}) + self:updateProperty({field = "smonthCards", value = smonthCards}) return true end end BuyMonthCard["order"] = function() --增刊条件 local card = csvdb["shop_cardCsv"][id] or {} - --判断是否购买过增刊条件里的特刊 - local cardId = card["cardPlusCondition"] or 0 - if self:isMonthCardExpire() or smonthCards[cardId] == nil then return false end - - --如果上期特刊奖励没有领取玩,则不能购买这期特刊。 - if SuperMonthCard["isExpired"](self, cardId) == false and cardId ~= 101 then return false end - - smonthCards[id] = {["periods"] = (card["cardPlusPeriods"] or 30), ["buyCount"] = 1} + if card["buyLimit"] and card["buyLimit"] ~= "" then + if buyLimitFunc(card["buyLimit"]:toNumMap()) == false then + skynet.error("不满足增刊条件") + return false + end + end + smonthCards[id] = {["periods"] = (card["amount"] or 30), ["buyCount"] = 1} - self:updateProperty({filed = "smonthCards", value = smonthCards}) + self:updateProperty({field= "smonthCards", value = smonthCards}) return true end @@ -171,6 +201,12 @@ SuperMonthCard["itemDaily"] = function(self, id) return reward, change, cur_ex end +SuperMonthCard["itemFirst"] = function(self, id) + local card = csvdb["shop_cardCsv"][id] or {} + local reward, _ = self.owner:award(card["itemFirst"], {isRecharge = true, log = {desc = "recharge", int1 = id}}) + return reward +end + -- 删除过期商品 function Store:deleteExpireLimitGoods() local timeNow = skynet.timex() @@ -313,7 +349,7 @@ function Store:getMonthCardDailyReward(id) self:updateProperty({field = "monthCardEx", delta = -1}) local cur_ex = self:getProperty("monthCardEx") - local actCfg = csvdb["shop_card"][id] or {} + local actCfg = csvdb["shop_cardCsv"][id] or {} local award = actCfg.itemDaily:toNumMap() local reward, change = self.owner:award(award, {log = {desc = "monthCardReward", int1 = id, int2 = cur_ex}}) @@ -354,7 +390,7 @@ function Store:firstBuyMonthCard(id) if self:getProperty("firstMonthCard") == 1 then self:updateProperty({field = "firstMonthCard", value = 0}) local card = csvdb["shop_cardCsv"][id] or {} - return self:award(card["cardFirst"], {log = {desc = "monthCardReward", int1 = id, int2 = 30}}) + return self.owner:award(card["itemOnce"], {log = {desc = "monthCardReward", int1 = id, int2 = 30}}) end return nil end @@ -377,9 +413,8 @@ function Store:onBuyCard(type, duration, id, actid) end end - --签收奖励 - tmpreward, _= self:getMonthCardDailyReward(id) - if tmpreward then + tmpreward = SuperMonthCard["itemFirst"](self, id) + if next(tmpreward) then for k, v in pairs(tmpreward) do reward[k] = (reward[k] or 0) + v end @@ -387,9 +422,10 @@ function Store:onBuyCard(type, duration, id, actid) return reward elseif type == CardType.SuperMonthCard then if SuperMonthCard["buy"](self, id) then - return self:getSMonthCardDailyReward(id) + skynet.error("特刊购买成功:"..id) + return SuperMonthCard["itemFirst"](self, id) end - return nil, nil + return nil elseif type == CardType.NormalMonthCardLevelUp then if self:isMonthCardExpire() then skynet.error(string.format("month card expired, can not level up,%d,%d",self.owner:getProperty("id"), id)) -- libgit2 0.21.2