Commit c582511001d8cafdfd79b0fb7901a6e5fbf59b98

Authored by saicom
1 parent 77b54f12

新增用户商城相关数据

src/GlobalVar.lua
... ... @@ -259,3 +259,17 @@ RedPointTags = {
259 259 PvpCR = 1,
260 260 PvpHR = 2,
261 261 }
  262 +
  263 +RefreshType = {
  264 + RefreshType_Daily = 1, -- 日刷新
  265 + RefreshType_Weekly = 2, -- 周刷新
  266 + RefreshType_Monthly = 3, -- 月刷新
  267 +}
  268 +
  269 +CardType = {
  270 + NormalMonthCard = 1, --普通月卡
  271 + SuperMonthCard = 2, --超级月卡
  272 + PrivilegeCard = 3, --特权卡
  273 + GrowFund = 4, --成长助力
  274 + BattleCard = 5, --赛季卡
  275 +}
262 276 \ No newline at end of file
... ...
src/ProtocolCode.lua
... ... @@ -183,6 +183,7 @@ actionCodes = {
183 183 Store_ayncPurchaseRpc = 555,
184 184 Store_myCardRechargeRpc = 556,
185 185 Store_iosRechargeRpc = 557,
  186 + Store_shopBuyRpc = 558,
186 187  
187 188  
188 189 Email_listRpc = 600,
... ...
src/RedisKeys.lua
... ... @@ -11,6 +11,7 @@ R_RUNEIDS = "role:%d:runeIds" -- 玩家拥有符文自增id
11 11 R_RUNE = "role:%d:rune:%d" -- 符文详细信息
12 12 R_EMAIL = "role:%d:emailIds" --邮件列表
13 13 R_EMAIL_ITEM = "email:%d:%d" --邮件
  14 +R_STORE = "role:%d:store" -- 商店
14 15  
15 16  
16 17 -- rank
... ...
src/actions/StoreAction.lua
... ... @@ -254,4 +254,52 @@ function _M.dinerBuyRpc(agent , data)
254 254 return true
255 255 end
256 256  
  257 +function _M.shopBuyRpc(agent , data)
  258 + local role = agent.role
  259 + local msg = MsgPack.unpack(data)
  260 + local id = msg.id
  261 + local count = msg.count or 1
  262 +
  263 + local dataSet = csvdb["shop_normalCsv"][id]
  264 + if not dataSet then return end
  265 +
  266 + local buyRecord = role.storeData:getProperty("Store_buyRecord")
  267 + if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (buyRecord[id] or 0))) then return 1 end
  268 +
  269 + local cost = {[dataSet.icon] = dataSet.cost * count}
  270 +
  271 + local desc = "unknown"
  272 + if dataSet.shop == 1 then -- 普通商店
  273 + desc = "dailyShop"
  274 + local dailySDD = role.dailyData:getProperty("dailySDD")
  275 + if dailySDD[id] then -- 折扣
  276 + cost = math.ceil(dataSet.cost * (1 - dataSet.disount / 100))
  277 + end
  278 + elseif dataSet.shop == 2 then -- 美食商店
  279 + desc = "dinerShop"
  280 + elseif dataSet.shop == 3 then -- 竞技场商店
  281 + desc = "pvpShop"
  282 + end
  283 +
  284 + if not role:checkItemEnough(cost) then return end
  285 +
  286 + if dataSet.limit ~= 0 then
  287 + buyRecord[id] = (buyRecord[id] or 0) + count
  288 + role.storeData:updateProperty({field = "Store_buyRecord", value = buyRecord})
  289 + end
  290 +
  291 + role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count}})
  292 +
  293 + local gift = {}
  294 + for _id, _count in pairs(dataSet.gift:toNumMap()) do
  295 + gift[_id] = _count * count
  296 + end
  297 + local reward = role:award(gift, {log = {desc = desc, int1 = id, int2 = count}})
  298 +
  299 + role:log("role_action", {desc = desc, int1 = id, int2 = count})
  300 +
  301 + SendPacket(actionCodes.Store_shopBuyRpc, MsgPack.pack({reward = reward}))
  302 + return true
  303 +end
  304 +
257 305 return _M
258 306 \ No newline at end of file
... ...
src/models/Daily.lua
... ... @@ -63,8 +63,8 @@ function Daily:refreshDailyData(notify)
63 63 -- 每日折扣搞一下
64 64 local dailySDD = {}
65 65 local sddPool = {}
66   - for id, data in pairs(csvdb["shop_diamondCsv"]) do
67   - if data.disount ~= 0 then
  66 + for id, data in pairs(csvdb["shop_normalCsv"]) do
  67 + if data.shop == 1 and data.disount ~= 0 then
68 68 table.insert(sddPool, id)
69 69 end
70 70 end
... ...
src/models/RolePlugin.lua
... ... @@ -11,6 +11,7 @@ function RolePlugin.bind(Role)
11 11 self:loadHeros()
12 12 self:loadDiner()
13 13 self:loadActivity()
  14 + self:loadStoreInfo()
14 15 end
15 16  
16 17 function Role:reloadWhenLogin()
... ... @@ -529,6 +530,18 @@ function RolePlugin.bind(Role)
529 530 -- 放role 里面了
530 531 end
531 532  
  533 + function Role:loadStoreInfo()
  534 + local roleId = self:getProperty("id")
  535 + local dataKey = string.format(R_STORE, roleId)
  536 + self.storeData = require("models.Store").new({key = dataKey})
  537 + self.storeData.owner = self
  538 + if not redisproxy:exists(dataKey) then
  539 + self.storeData:create()
  540 + else
  541 + self.storeData:load()
  542 + end
  543 + end
  544 +
532 545 function Role:addEquip(equipType, equipLv, count, pms)
533 546 pms = pms or {}
534 547 if count ~= count then return end
... ... @@ -1511,8 +1524,13 @@ function RolePlugin.bind(Role)
1511 1524 return
1512 1525 end
1513 1526  
  1527 + if not role.storeData:checkRechargeRecord(rechargeData.limit, id) then
  1528 + return 1
  1529 + end
  1530 +
1514 1531 local diamondCount = 0
1515   - if rechargeData.type == 0 then -- 钻石
  1532 + local reward = {}
  1533 + if rechargeData.shop == 1 then -- 钻石
1516 1534 local rechargeF = self:getProperty("rechargeF")
1517 1535 diamondCount = rechargeData.diamond + rechargeData.diamondExtra
1518 1536 if not rechargeF[id] then
... ... @@ -1521,11 +1539,15 @@ function RolePlugin.bind(Role)
1521 1539 self:updateProperty({field = "rechargeF", value = rechargeF})
1522 1540 end
1523 1541 self:gainDiamond({count = diamondCount, isRecharge = true, log = {desc = "recharge", int1 = id}})
1524   - elseif rechargeData.type == 1 then --月卡
  1542 + elseif rechargeData.shop == 1 then --通行证商店
  1543 + reward = self:award(rechargeData.itemFirst, {log = {desc = "recharge", int1 = id}})
  1544 + self.storeData:onBuyCard(rechargeData.type, rechargeData.time)
1525 1545 return
1526   - elseif rechargeData.type == 2 then -- 赛季通行证
  1546 + elseif rechargeData.shop == 2 then -- 礼包商店
  1547 + reward = self:award(rechargeData.itemFirst, {log = {desc = "recharge", int1 = id}})
1527 1548 return
1528 1549 else
  1550 + skynet.error("invalid recharge shop type " .. id)
1529 1551 return
1530 1552 end
1531 1553  
... ... @@ -1535,7 +1557,7 @@ function RolePlugin.bind(Role)
1535 1557  
1536 1558 self:log("role_action", {desc = "recharge", int1 = id, int2 = rmb, key1 = params.transactionId, key2 = params.order, long1 = params.pay_time})
1537 1559  
1538   - return diamondCount
  1560 + return diamondCount, reward
1539 1561 end
1540 1562  
1541 1563 end
... ...
src/models/Store.lua 0 → 100644
... ... @@ -0,0 +1,114 @@
  1 +-- 商店数据
  2 +
  3 +local Store = class("Store", require("shared.ModelBase"))
  4 +
  5 +function Store:ctor(properties)
  6 + Store.super.ctor(self, properties)
  7 +end
  8 +
  9 +Store.schema = {
  10 + Store_buyRecord = {"table", {}}, -- 购买商品记录 {id=count}
  11 + Store_rechargeRecord = {"table", {}}, -- 充值记录 {id=count}
  12 + Store_growFund = {"number", 0}, -- 成长基金
  13 + Store_growFundRecord = {"table", {}}, -- 成长基金领取记录
  14 + Store_monthCardExTs = {"number", 0}, -- 月卡过期时间戳
  15 + Store_smonthCardExTs = {"number", 0}, -- 超级月卡过期时间戳
  16 + Store_battleCardExTs = {"number", 0}, -- 赛季卡过期时间戳
  17 + Store_battleCardRecord = {"table", {}}, -- 赛季卡领取记录
  18 +}
  19 +
  20 +function Store:updateProperty(params)
  21 + local type, default = table.unpack(self.schema[params.field])
  22 +
  23 + if params.delta then
  24 + self:incrProperty(params.field, params.delta)
  25 + if not params.notNotify then
  26 + self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
  27 + end
  28 + return true
  29 + end
  30 + if params.value then
  31 + self:setProperty(params.field, params.value)
  32 + if not params.notNotify then
  33 + self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
  34 + end
  35 + return true
  36 + end
  37 + return false
  38 +end
  39 +
  40 +function Store:refreshData(notify, refreshType)
  41 + local buyRecord = self:getProperty("Store_buyRecord")
  42 + local result = {}
  43 + for id, data in pairs(csvdb["shop_normalCsv"]) do
  44 + if data.shop == 1 and refreshType == RefreshType.RefreshType_Daily then
  45 + buyRecord[id] = nil
  46 + end
  47 + if data.shop == 2 and refreshType == RefreshType.RefreshType_Weekly then
  48 + buyRecord[id] = nil
  49 + end
  50 + end
  51 + self:setProperty("Store_buyRecord", buyRecord)
  52 + if notify then
  53 + --self.owner:notifyUpdateProperties(self:data())
  54 + self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord})
  55 + end
  56 +end
  57 +
  58 +function Store:refreshPvpBuyRecord(notify)
  59 + local buyRecord = self:getProperty("Store_buyRecord")
  60 + for id, data in pairs(csvdb["shop_normalCsv"]) do
  61 + if data.shop == 3 then
  62 + buyRecord[id] = nil
  63 + end
  64 + end
  65 + self:setProperty("Store_buyRecord", buyRecord)
  66 + if notify then
  67 + self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord})
  68 + end
  69 +end
  70 +
  71 +-- 发送月卡邮件
  72 +function Store:sendMonthCardEmail()
  73 +end
  74 +
  75 +-- 购买通行证
  76 +function onBuyCard(type, duration)
  77 + local timeNow = skynet.timex()
  78 + if rechargeData.type == CardType.NormalMonthCard then
  79 + self:updateProperty({field = "Store_monthCardExTs", value = timeNow + duration})
  80 + elseif rechargeData.type == CardType.SuperMonthCard then
  81 + self:updateProperty({field = "Store_smonthCardExTs", value = timeNow + duration})
  82 + elseif rechargeData.type == CardType.PrivilegeCard then
  83 + elseif rechargeData.type == CardType.GrowFund then
  84 + self:updateProperty({field = "Store_growFundRecord", 1})
  85 + elseif rechargeData.type == CardType.BattleCard then
  86 + self:updateProperty({field = "Store_battleCardRecord", 1})
  87 + end
  88 +end
  89 +
  90 +function checkRechargeRecord(limit, id)
  91 + local rechargeRecord = self:getProperty("Store_rechargeRecord")
  92 + if limit ~= 0 and limit <= (rechargeRecord[id] or 0) then
  93 + skynet.error(string.format("recharge id:%d count over limit, user id:%d", id, self.owner:getProperty("id")))
  94 + return false
  95 + end
  96 + rechargeRecord[id] = rechargeRecord[id] + 1
  97 + self:updateProperty({field = "Store_rechargeRecord", value = rechargeRecord[id]})
  98 + return true
  99 +end
  100 +
  101 +function Store:data()
  102 + return {
  103 + Store_buyRecord = self:getProperty("Store_buyRecord"),
  104 + Store_rechargeRecord = self:getProperty("Store_rechargeRecord"),
  105 + Store_growFund = self:getProperty("Store_growFund"),
  106 + Store_growFundRecord = self:getProperty("Store_growFundRecord"),
  107 + Store_monthCardExTs = self:getProperty("Store_monthCardExTs"),
  108 + Store_smonthCardExTs = self:getProperty("Store_smonthCardExTs"),
  109 + Store_battleCardExTs = self:getProperty("Store_battleCardExTs"),
  110 + Store_battleCardRecord = self:getProperty("Store_battleCardRecord"),
  111 + }
  112 +end
  113 +
  114 +return Store
0 115 \ No newline at end of file
... ...