Store.lua
4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
-- 商店数据
local Store = class("Store", require("shared.ModelBase"))
function Store:ctor(properties)
Store.super.ctor(self, properties)
end
Store.schema = {
Store_buyRecord = {"table", {}}, -- 购买商品记录 {id=count}
Store_rechargeRecord = {"table", {}}, -- 充值记录 {id=count}
Store_growFund = {"number", 0}, -- 成长基金
Store_growFundRecord = {"table", {}}, -- 成长基金领取记录
Store_monthCardExTs = {"number", 0}, -- 月卡过期时间戳
Store_smonthCardExTs = {"number", 0}, -- 超级月卡过期时间戳
Store_battleCardExTs = {"number", 0}, -- 赛季卡过期时间戳
Store_battleCardRecord = {"table", {}}, -- 赛季卡领取记录
}
function Store:updateProperty(params)
local type, default = table.unpack(self.schema[params.field])
if params.delta then
self:incrProperty(params.field, params.delta)
if not params.notNotify then
self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
end
return true
end
if params.value then
self:setProperty(params.field, params.value)
if not params.notNotify then
self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
end
return true
end
return false
end
function Store:refreshData(notify, refreshType)
local buyRecord = self:getProperty("Store_buyRecord")
local result = {}
for id, data in pairs(csvdb["shop_normalCsv"]) do
if data.shop == 1 and refreshType == RefreshType.RefreshType_Daily then
buyRecord[id] = nil
end
if data.shop == 2 and refreshType == RefreshType.RefreshType_Weekly then
buyRecord[id] = nil
end
end
self:setProperty("Store_buyRecord", buyRecord)
if notify then
--self.owner:notifyUpdateProperties(self:data())
self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord})
end
end
function Store:refreshPvpBuyRecord(notify)
local buyRecord = self:getProperty("Store_buyRecord")
for id, data in pairs(csvdb["shop_normalCsv"]) do
if data.shop == 3 then
buyRecord[id] = nil
end
end
self:setProperty("Store_buyRecord", buyRecord)
if notify then
self:notifyUpdateProperty({field="Store_buyRecord", value=buyRecord})
end
end
-- 发送月卡邮件
function Store:sendMonthCardEmail()
end
-- 购买通行证
function onBuyCard(type, duration)
local timeNow = skynet.timex()
if rechargeData.type == CardType.NormalMonthCard then
self:updateProperty({field = "Store_monthCardExTs", value = timeNow + duration})
elseif rechargeData.type == CardType.SuperMonthCard then
self:updateProperty({field = "Store_smonthCardExTs", value = timeNow + duration})
elseif rechargeData.type == CardType.PrivilegeCard then
elseif rechargeData.type == CardType.GrowFund then
self:updateProperty({field = "Store_growFundRecord", 1})
elseif rechargeData.type == CardType.BattleCard then
self:updateProperty({field = "Store_battleCardRecord", 1})
end
end
function checkRechargeRecord(limit, id)
local rechargeRecord = self:getProperty("Store_rechargeRecord")
if limit ~= 0 and limit <= (rechargeRecord[id] or 0) then
skynet.error(string.format("recharge id:%d count over limit, user id:%d", id, self.owner:getProperty("id")))
return false
end
rechargeRecord[id] = rechargeRecord[id] + 1
self:updateProperty({field = "Store_rechargeRecord", value = rechargeRecord[id]})
return true
end
function Store:data()
return {
Store_buyRecord = self:getProperty("Store_buyRecord"),
Store_rechargeRecord = self:getProperty("Store_rechargeRecord"),
Store_growFund = self:getProperty("Store_growFund"),
Store_growFundRecord = self:getProperty("Store_growFundRecord"),
Store_monthCardExTs = self:getProperty("Store_monthCardExTs"),
Store_smonthCardExTs = self:getProperty("Store_smonthCardExTs"),
Store_battleCardExTs = self:getProperty("Store_battleCardExTs"),
Store_battleCardRecord = self:getProperty("Store_battleCardRecord"),
}
end
return Store