Commit 3e20f499d99e9fa79f308bca77f153733b9a9957

Authored by saicom
1 parent 02abfcb2

完善商城相关协议

src/ProtocolCode.lua
@@ -184,6 +184,10 @@ actionCodes = { @@ -184,6 +184,10 @@ actionCodes = {
184 Store_myCardRechargeRpc = 556, 184 Store_myCardRechargeRpc = 556,
185 Store_iosRechargeRpc = 557, 185 Store_iosRechargeRpc = 557,
186 Store_shopBuyRpc = 558, 186 Store_shopBuyRpc = 558,
  187 + Store_updateproperty = 559,
  188 + Store_getFreeChectRpc = 559,
  189 + Store_getGrowFundRewardRpc = 560, --成长助力奖励
  190 + Store_getBattlePassRewardRpc = 561, --赛季卡奖励
187 191
188 192
189 Email_listRpc = 600, 193 Email_listRpc = 600,
src/actions/GmAction.lua
@@ -512,6 +512,14 @@ function _M.helpRpc(agent, data) @@ -512,6 +512,14 @@ function _M.helpRpc(agent, data)
512 return true 512 return true
513 end 513 end
514 514
  515 +table.insert(helpDes, {"测试", "test", ""})
  516 +function _M.test(role, pms)
  517 + local id = tonum(pms.pm1, 0)
  518 + local a = require("actions.StoreAction")
  519 + a.getGrowFundRewardRpc({role=role}, MsgPack.pack({id=id}))
  520 + return "成功"
  521 +end
  522 +
515 -- 充值回调 523 -- 充值回调
516 function _M.ayncPurchase(role, params) 524 function _M.ayncPurchase(role, params)
517 return role:handlePurchase(params) or "" 525 return role:handlePurchase(params) or ""
src/actions/RoleAction.lua
@@ -128,7 +128,7 @@ function _M.loginRpc( agent, data ) @@ -128,7 +128,7 @@ function _M.loginRpc( agent, data )
128 128
129 redisproxy:zadd(FRIEND_RECOMMEND, now, roleId) 129 redisproxy:zadd(FRIEND_RECOMMEND, now, roleId)
130 130
131 - for _, name in ipairs({"dailyData", "dinerData", "activity"}) do 131 + for _, name in ipairs({"dailyData", "dinerData", "activity", "storeData"}) do
132 response[name] = role[name]:data() 132 response[name] = role[name]:data()
133 end 133 end
134 134
src/actions/StoreAction.lua
@@ -263,8 +263,11 @@ function _M.shopBuyRpc(agent , data) @@ -263,8 +263,11 @@ function _M.shopBuyRpc(agent , data)
263 local dataSet = csvdb["shop_normalCsv"][id] 263 local dataSet = csvdb["shop_normalCsv"][id]
264 if not dataSet then return end 264 if not dataSet then return end
265 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 266 + local buyRecord = role.storeData:getProperty("buyR")
  267 + if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (buyRecord[id] or 0))) then
  268 + skynet.error(string.format("shop buy over limit, user_id:%d, goods_id:%d", role:getProperty("id"), id))
  269 + return 1
  270 + end
268 271
269 local cost = {[dataSet.icon] = dataSet.cost * count} 272 local cost = {[dataSet.icon] = dataSet.cost * count}
270 273
@@ -285,9 +288,8 @@ function _M.shopBuyRpc(agent , data) @@ -285,9 +288,8 @@ function _M.shopBuyRpc(agent , data)
285 288
286 if dataSet.limit ~= 0 then 289 if dataSet.limit ~= 0 then
287 buyRecord[id] = (buyRecord[id] or 0) + count 290 buyRecord[id] = (buyRecord[id] or 0) + count
288 - role.storeData:updateProperty({field = "Store_buyRecord", value = buyRecord}) 291 + role.storeData:updateProperty({field = "buyR", value = buyRecord})
289 end 292 end
290 -  
291 role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count}}) 293 role:costItems(cost, {log = {desc = desc, int1 = id, int2 = count}})
292 294
293 local gift = {} 295 local gift = {}
@@ -302,4 +304,108 @@ function _M.shopBuyRpc(agent , data) @@ -302,4 +304,108 @@ function _M.shopBuyRpc(agent , data)
302 return true 304 return true
303 end 305 end
304 306
  307 +function _M.getFreeCheckRpc(agent, data)
  308 + local role = agent.role
  309 + local msg = MsgPack.unpack(data)
  310 + local id = msg.id
  311 +
  312 + local config = csvdb["shop_rechargeCsv"][id]
  313 + if not config then return end
  314 +
  315 + local rechargeRecord = role.storeData:getProperty("payR")
  316 + local getCount = (rechargeRecord[id] or 0)
  317 + if getCount >= config.limit then
  318 + return 1
  319 + end
  320 + local reward, _ = role:award(rechargeData.itemFirst, {log = {desc = "freeGift", int1 = id}})
  321 +
  322 + rechargeRecord[id] = getCount + 1
  323 + role.storeData:updateProperty({field = "payR", value = rechargeRecord})
  324 +
  325 + SendPacket(actionCodes.Store_getFreeChectRpc, MsgPack.pack({reward = reward}))
  326 +end
  327 +
  328 +function _M.getGrowFundRewardRpc(agent, data)
  329 + local role = agent.role
  330 + local msg = MsgPack.unpack(data)
  331 + local id = msg.id
  332 +
  333 + local config = csvdb["reward_newbeeCsv"][id]
  334 + if not config then return end
  335 +
  336 + local growFundFlag = role.storeData:getProperty("growFund")
  337 + local growFundRecord = role.storeData:getProperty("growFundR")
  338 +
  339 + if growFundFlag == 0 then
  340 + skynet.error("user do not buy grow fund")
  341 + return 1
  342 + end
  343 +
  344 + if not role:checkHangPass(config.condition) then
  345 + skynet.error(string.format("user do not finish hang pass, user_id:%d", role:getProperty("id")))
  346 + return 1
  347 + end
  348 +
  349 + local b = string.getbit(growFundRecord, id)
  350 + if string.char(b) == "1" then
  351 + return 1
  352 + end
  353 +
  354 + growFundRecord = string.setbit(growFundRecord, id)
  355 + role.storeData:updateProperty({field = "growFundR", value = growFundRecord})
  356 +
  357 + local gift = config.giftFree .. " " .. config.giftLimit
  358 + local reward, _ = role:award(gift, {log = {desc = "grownFund", int1 = id}})
  359 +
  360 + SendPacket(actionCodes.Store_getGrowFundRewardRpc, MsgPack.pack({reward = reward}))
  361 +end
  362 +
  363 +function _M.getBattlePassRewardRpc(agent, data)
  364 + local role = agent.role
  365 + local msg = MsgPack.unpack(data)
  366 + local id = msg.id
  367 +
  368 + local config = csvdb["reward_battlepassCsv"][id]
  369 + if not config then return end
  370 +
  371 + local timeNow = skynet.timex()
  372 + local battleCardExTs = role.storeData:getProperty("battleCardEx")
  373 + local battleCardFreeRecord = role.storeData:getProperty("battleFR")
  374 + local battleCardLimitRecord = role.storeData:getProperty("battleLR")
  375 +
  376 + local freeFlag = string.char(string.getbit(battleCardFreeRecord, id))
  377 + local limitFlag = string.char(string.getbit(battleCardLimitRecord, id))
  378 +
  379 + if freeFlag == "1" and limitFlag == "1" then
  380 + skynet.error("user already get battle pass reward")
  381 + return 1
  382 + end
  383 +
  384 + if battleCardExTs < timeNow and freeFlag == "1" then
  385 + return 1
  386 + end
  387 +
  388 + local gift = ""
  389 + if freeFlag == "0" then
  390 + gift = config.giftFree
  391 +
  392 + battleCardFreeRecord = string.setbit(battleCardFreeRecord, id)
  393 + role.storeData:updateProperty({field = "battleFR", value = battleCardFreeRecord})
  394 + end
  395 +
  396 + if battleCardExTs > timeNow and limitFlag == "0" then
  397 + if gift ~= "" then
  398 + gift = gift .. " "
  399 + end
  400 + gift = gift .. config.giftLimit
  401 +
  402 + battleCardLimitRecord = string.setbit(battleCardLimitRecord, id)
  403 + role.storeData:updateProperty({field = "battleFR", value = battleCardLimitRecord})
  404 + end
  405 +
  406 + local reward, _ = role:award(gift, {log = {desc = "battleCard", int1 = id}})
  407 +
  408 + SendPacket(actionCodes.Store_getBattlePassRewardRpc, MsgPack.pack({reward = reward}))
  409 +end
  410 +
305 return _M 411 return _M
306 \ No newline at end of file 412 \ No newline at end of file
1 -Subproject commit a09b1fc2fc76e793675b45b1ab28a6c98b18ce9b 1 +Subproject commit 12409daded138b2934c0741b15b2e0de305bb109
src/models/RolePlugin.lua
@@ -145,7 +145,6 @@ function RolePlugin.bind(Role) @@ -145,7 +145,6 @@ function RolePlugin.bind(Role)
145 end 145 end
146 end 146 end
147 end 147 end
148 -  
149 return reward, allChange --实际获得的奖励 和 最高级奖励转化过程 148 return reward, allChange --实际获得的奖励 和 最高级奖励转化过程
150 end 149 end
151 150
@@ -1507,7 +1506,7 @@ function RolePlugin.bind(Role) @@ -1507,7 +1506,7 @@ function RolePlugin.bind(Role)
1507 return 1506 return
1508 end 1507 end
1509 1508
1510 - local diamond = self:recharge({ 1509 + local reward = self:recharge({
1511 id = orderObject:getProperty("rechargeId"), 1510 id = orderObject:getProperty("rechargeId"),
1512 transactionId = params.transactionId, 1511 transactionId = params.transactionId,
1513 pay_time = params.pay_time, 1512 pay_time = params.pay_time,
@@ -1518,7 +1517,7 @@ function RolePlugin.bind(Role) @@ -1518,7 +1517,7 @@ function RolePlugin.bind(Role)
1518 1517
1519 redisproxy:srem(string.format("role:%d:orders", roleId), partnerOrderStr) 1518 redisproxy:srem(string.format("role:%d:orders", roleId), partnerOrderStr)
1520 SendPacket(actionCodes.Store_ayncPurchaseRpc, MsgPack.pack({ order = partnerOrderStr, 1519 SendPacket(actionCodes.Store_ayncPurchaseRpc, MsgPack.pack({ order = partnerOrderStr,
1521 - result = "success", diamond = diamond})) 1520 + result = "success", reward = reward}))
1522 1521
1523 return orderObject:getProperty("rechargeId") 1522 return orderObject:getProperty("rechargeId")
1524 end 1523 end
@@ -1532,7 +1531,7 @@ function RolePlugin.bind(Role) @@ -1532,7 +1531,7 @@ function RolePlugin.bind(Role)
1532 return 1531 return
1533 end 1532 end
1534 1533
1535 - if not role.storeData:checkRechargeRecord(rechargeData.limit, id) then 1534 + if not self.storeData:checkRechargeRecord(rechargeData.limit, id) then
1536 return 1 1535 return 1
1537 end 1536 end
1538 1537
@@ -1547,25 +1546,27 @@ function RolePlugin.bind(Role) @@ -1547,25 +1546,27 @@ function RolePlugin.bind(Role)
1547 self:updateProperty({field = "rechargeF", value = rechargeF}) 1546 self:updateProperty({field = "rechargeF", value = rechargeF})
1548 end 1547 end
1549 self:gainDiamond({count = diamondCount, isRecharge = true, log = {desc = "recharge", int1 = id}}) 1548 self:gainDiamond({count = diamondCount, isRecharge = true, log = {desc = "recharge", int1 = id}})
1550 - elseif rechargeData.shop == 1 then --通行证商店  
1551 - reward = self:award(rechargeData.itemFirst, {log = {desc = "recharge", int1 = id}}) 1549 + elseif rechargeData.shop == 2 then --通行证商店
  1550 + reward, _ = self:award(rechargeData.itemFirst, {log = {desc = "recharge", int1 = id}})
1552 self.storeData:onBuyCard(rechargeData.type, rechargeData.time) 1551 self.storeData:onBuyCard(rechargeData.type, rechargeData.time)
1553 - return  
1554 - elseif rechargeData.shop == 2 then -- 礼包商店  
1555 - reward = self:award(rechargeData.itemFirst, {log = {desc = "recharge", int1 = id}})  
1556 - return 1552 + elseif rechargeData.shop == 3 then -- 礼包商店
  1553 + reward, _ = self:award(rechargeData.itemFirst, {log = {desc = "recharge", int1 = id}})
1557 else 1554 else
1558 skynet.error("invalid recharge shop type " .. id) 1555 skynet.error("invalid recharge shop type " .. id)
1559 return 1556 return
1560 end 1557 end
1561 1558
  1559 + if diamondCount > 0 then
  1560 + reward[Itemid.Diamond] = (reward[Itemid.Diamond] or 0) + diamondCount
  1561 + end
  1562 +
1562 -- 累充 1563 -- 累充
1563 local rmb = rechargeData.rmb 1564 local rmb = rechargeData.rmb
1564 self:updateProperty({field = "rmbC", delta = rmb}) 1565 self:updateProperty({field = "rmbC", delta = rmb})
1565 1566
1566 self:log("role_action", {desc = "recharge", int1 = id, int2 = rmb, key1 = params.transactionId, key2 = params.order, long1 = params.pay_time}) 1567 self:log("role_action", {desc = "recharge", int1 = id, int2 = rmb, key1 = params.transactionId, key2 = params.order, long1 = params.pay_time})
1567 1568
1568 - return diamondCount, reward 1569 + return reward
1569 end 1570 end
1570 1571
1571 end 1572 end
src/models/Store.lua
@@ -7,38 +7,39 @@ function Store:ctor(properties) @@ -7,38 +7,39 @@ function Store:ctor(properties)
7 end 7 end
8 8
9 Store.schema = { 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", {}}, -- 赛季卡领取记录 10 + buyR = {"table", {}}, -- 购买商品记录 {id=count}
  11 + payR = {"table", {}}, -- 充值记录 {id=count}
  12 + growFund = {"number", 0}, -- 成长基金
  13 + growFundR = {"string", ""}, -- 成长基金领取记录
  14 + monthCardEx = {"number", 0}, -- 月卡过期时间戳
  15 + smonthCardEx = {"number", 0}, -- 超级月卡过期时间戳
  16 + battleCardEx = {"number", 0}, -- 赛季卡过期时间戳
  17 + battleFR = {"string", ""}, -- 免费赛季卡领取记录
  18 + battleLR = {"string", ""}, -- 付费赛季卡领取记录
  19 + limitTPack = {"table", {}} -- 限时礼包 {id=expire_ts}
18 } 20 }
19 21
20 function Store:updateProperty(params) 22 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 23 + params = params or {}
  24 + if not self.schema[params.field] then
  25 + return
29 end 26 end
  27 + local oldValue = self:getProperty(params.field)
30 if params.value then 28 if params.value then
31 self:setProperty(params.field, params.value) 29 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 30 + elseif params.delta then
  31 + self:incrProperty(params.field, params.delta)
  32 + else
  33 + return
  34 + end
  35 + local newValue = self:getProperty(params.field)
  36 + if not params.notNotify then
  37 + self:notifyUpdateProperty(params.field, newValue, oldValue)
36 end 38 end
37 - return false  
38 end 39 end
39 40
40 function Store:refreshData(notify, refreshType) 41 function Store:refreshData(notify, refreshType)
41 - local buyRecord = self:getProperty("Store_buyRecord") 42 + local buyRecord = self:getProperty("buyR")
42 local result = {} 43 local result = {}
43 for id, data in pairs(csvdb["shop_normalCsv"]) do 44 for id, data in pairs(csvdb["shop_normalCsv"]) do
44 if data.shop == 1 and refreshType == RefreshType.RefreshType_Daily then 45 if data.shop == 1 and refreshType == RefreshType.RefreshType_Daily then
@@ -48,66 +49,85 @@ function Store:refreshData(notify, refreshType) @@ -48,66 +49,85 @@ function Store:refreshData(notify, refreshType)
48 buyRecord[id] = nil 49 buyRecord[id] = nil
49 end 50 end
50 end 51 end
51 - self:setProperty("Store_buyRecord", buyRecord) 52 + self:setProperty("buyR", buyRecord)
52 if notify then 53 if notify then
53 - --self.owner:notifyUpdateProperties(self:data())  
54 - self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord}) 54 + self:notifyUpdateProperty({field="buyR", value=buyRecord})
55 end 55 end
56 end 56 end
57 57
58 function Store:refreshPvpBuyRecord(notify) 58 function Store:refreshPvpBuyRecord(notify)
59 - local buyRecord = self:getProperty("Store_buyRecord") 59 + local buyRecord = self:getProperty("buyR")
60 for id, data in pairs(csvdb["shop_normalCsv"]) do 60 for id, data in pairs(csvdb["shop_normalCsv"]) do
61 if data.shop == 3 then 61 if data.shop == 3 then
62 buyRecord[id] = nil 62 buyRecord[id] = nil
63 end 63 end
64 end 64 end
65 - self:setProperty("Store_buyRecord", buyRecord) 65 + self:setProperty("buyR", buyRecord)
66 if notify then 66 if notify then
67 - self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord}) 67 + self:notifyUpdateProperty({field="buyR", value=buyRecord})
68 end 68 end
69 end 69 end
70 70
71 -- 发送月卡邮件 71 -- 发送月卡邮件
72 function Store:sendMonthCardEmail() 72 function Store:sendMonthCardEmail()
  73 + local monthCardEx = self:getProperty("monthCardEx")
  74 + local smonthCardEx = self:getProperty("smonthCardEx")
  75 + local timeNow = skynet.timex()
  76 + if monthCardEx < timeNow then
  77 + redisproxy:insertEmail({roleId = self.owner:getProperty("id"), emailId = 19})
  78 + end
  79 + if smonthCardEx < timeNow then
  80 + redisproxy:insertEmail({roleId = self.owner:getProperty("id"), emailId = 20})
  81 + end
73 end 82 end
74 83
75 -- 购买通行证 84 -- 购买通行证
76 -function onBuyCard(type, duration) 85 +function Store:onBuyCard(type, duration)
  86 + duration = duration == "" and 0 or tonumber(duration)
77 local timeNow = skynet.timex() 87 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}) 88 + if type == CardType.NormalMonthCard then
  89 + self:updateProperty({field = "monthCardEx", value = timeNow + duration})
  90 + elseif type == CardType.SuperMonthCard then
  91 + self:updateProperty({field = "smonthCardEx", value = timeNow + duration})
  92 + elseif type == CardType.PrivilegeCard then
  93 + elseif type == CardType.GrowFund then
  94 + self:updateProperty({field = "growFund", value = 1})
  95 + elseif type == CardType.BattleCard then
  96 + self:updateProperty({field = "battleCardEx", value = timeNow + duration})
87 end 97 end
88 end 98 end
89 99
90 -function checkRechargeRecord(limit, id)  
91 - local rechargeRecord = self:getProperty("Store_rechargeRecord") 100 +function Store:checkRechargeRecord(limit, id)
  101 + local rechargeRecord = self:getProperty("payR")
92 if limit ~= 0 and limit <= (rechargeRecord[id] or 0) then 102 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"))) 103 skynet.error(string.format("recharge id:%d count over limit, user id:%d", id, self.owner:getProperty("id")))
94 return false 104 return false
95 end 105 end
96 - rechargeRecord[id] = rechargeRecord[id] + 1  
97 - self:updateProperty({field = "Store_rechargeRecord", value = rechargeRecord[id]}) 106 + rechargeRecord[id] = (rechargeRecord[id] or 0) + 1
  107 + self:updateProperty({field = "payR", value = rechargeRecord})
98 return true 108 return true
99 end 109 end
100 110
  111 +function Store:notifyUpdateProperty(field, newValue, oldValue)
  112 + local datas = {
  113 + key = field,
  114 + newValue = newValue,
  115 + oldValue = oldValue,
  116 + }
  117 + SendPacket(actionCodes.Store_updateproperty, MsgPack.pack(datas))
  118 +end
  119 +
101 function Store:data() 120 function Store:data()
102 return { 121 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"), 122 + buyR = self:getProperty("buyR"),
  123 + payR = self:getProperty("payR"),
  124 + growFund = self:getProperty("growFund"),
  125 + growFundR = self:getProperty("growFundR"),
  126 + monthCardEx = self:getProperty("monthCardEx"),
  127 + smonthCardEx = self:getProperty("smonthCardEx"),
  128 + battleCardEx = self:getProperty("battleCardEx"),
  129 + battleCardR = self:getProperty("battleCardR"),
  130 + limitTPack = self:getProperty("limitTPack"),
111 } 131 }
112 end 132 end
113 133