c5825110
saicom
新增用户商城相关数据
|
1
2
3
4
5
6
7
8
9
|
-- 商店数据
local Store = class("Store", require("shared.ModelBase"))
function Store:ctor(properties)
Store.super.ctor(self, properties)
end
Store.schema = {
|
3e20f499
saicom
完善商城相关协议
|
10
11
12
13
14
15
16
17
18
|
buyR = {"table", {}}, -- 购买商品记录 {id=count}
payR = {"table", {}}, -- 充值记录 {id=count}
growFund = {"number", 0}, -- 成长基金
growFundR = {"string", ""}, -- 成长基金领取记录
monthCardEx = {"number", 0}, -- 月卡过期时间戳
smonthCardEx = {"number", 0}, -- 超级月卡过期时间戳
battleCardEx = {"number", 0}, -- 赛季卡过期时间戳
battleFR = {"string", ""}, -- 免费赛季卡领取记录
battleLR = {"string", ""}, -- 付费赛季卡领取记录
|
317a46a9
liuzujun
添加特权卡
|
19
20
|
limitTPack = {"table", {}}, -- 限时礼包 {id=expire_ts}
privCardEx = {"number", 0} -- 特权卡过期时间戳
|
c5825110
saicom
新增用户商城相关数据
|
21
22
23
|
}
function Store:updateProperty(params)
|
3e20f499
saicom
完善商城相关协议
|
24
25
26
|
params = params or {}
if not self.schema[params.field] then
return
|
c5825110
saicom
新增用户商城相关数据
|
27
|
end
|
3e20f499
saicom
完善商城相关协议
|
28
|
local oldValue = self:getProperty(params.field)
|
c5825110
saicom
新增用户商城相关数据
|
29
30
|
if params.value then
self:setProperty(params.field, params.value)
|
3e20f499
saicom
完善商城相关协议
|
31
32
33
34
35
36
37
38
|
elseif params.delta then
self:incrProperty(params.field, params.delta)
else
return
end
local newValue = self:getProperty(params.field)
if not params.notNotify then
self:notifyUpdateProperty(params.field, newValue, oldValue)
|
c5825110
saicom
新增用户商城相关数据
|
39
|
end
|
c5825110
saicom
新增用户商城相关数据
|
40
41
42
|
end
function Store:refreshData(notify, refreshType)
|
3e20f499
saicom
完善商城相关协议
|
43
|
local buyRecord = self:getProperty("buyR")
|
c5825110
saicom
新增用户商城相关数据
|
44
45
46
47
48
49
50
51
52
|
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
|
3e20f499
saicom
完善商城相关协议
|
53
|
self:setProperty("buyR", buyRecord)
|
c5825110
saicom
新增用户商城相关数据
|
54
|
if notify then
|
3e20f499
saicom
完善商城相关协议
|
55
|
self:notifyUpdateProperty({field="buyR", value=buyRecord})
|
c5825110
saicom
新增用户商城相关数据
|
56
57
58
59
|
end
end
function Store:refreshPvpBuyRecord(notify)
|
3e20f499
saicom
完善商城相关协议
|
60
|
local buyRecord = self:getProperty("buyR")
|
c5825110
saicom
新增用户商城相关数据
|
61
62
63
64
65
|
for id, data in pairs(csvdb["shop_normalCsv"]) do
if data.shop == 3 then
buyRecord[id] = nil
end
end
|
3e20f499
saicom
完善商城相关协议
|
66
|
self:setProperty("buyR", buyRecord)
|
c5825110
saicom
新增用户商城相关数据
|
67
|
if notify then
|
3e20f499
saicom
完善商城相关协议
|
68
|
self:notifyUpdateProperty({field="buyR", value=buyRecord})
|
c5825110
saicom
新增用户商城相关数据
|
69
70
71
72
73
|
end
end
-- 发送月卡邮件
function Store:sendMonthCardEmail()
|
3e20f499
saicom
完善商城相关协议
|
74
75
76
77
78
79
80
81
82
|
local monthCardEx = self:getProperty("monthCardEx")
local smonthCardEx = self:getProperty("smonthCardEx")
local timeNow = skynet.timex()
if monthCardEx < timeNow then
redisproxy:insertEmail({roleId = self.owner:getProperty("id"), emailId = 19})
end
if smonthCardEx < timeNow then
redisproxy:insertEmail({roleId = self.owner:getProperty("id"), emailId = 20})
end
|
c5825110
saicom
新增用户商城相关数据
|
83
84
|
end
|
317a46a9
liuzujun
添加特权卡
|
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
function Store:isMonthCardExpire()
local timeNow = skynet.timex()
local ts = self:getProperty("monthCardEx")
return ts < timeNow
end
function Store:isSuperMonthCardExpire()
local timeNow = skynet.timex()
local ts = self:getProperty("smonthCardEx")
return ts < timeNow
end
function Store:isPrivCardExpire()
local timeNow = skynet.timex()
local ts = self:getProperty("privCardEx")
return ts < timeNow
end
function Store:isBattleCardExpire()
local timeNow = skynet.timex()
local ts = self:getProperty("battleCardEx")
return ts < timeNow
end
-- 挂机栏位 特权卡额外个数
function Store:getHangSlotExtraCount()
if self:isPrivCardExpire() then
return 0
end
return 4
end
-- 探索加速/餐厅加速 特权卡系数
function Store:getProduceItemSpeedCoef()
if self:isPrivCardExpire() then
return 1
end
return 1 + 0.25
end
-- 拆解室栏位 特权卡额外个数
function Store:getTimeBoxSlotExtraCount()
if self:isPrivCardExpire() then
return 0
end
return 3
end
-- 齿轮兑换 特权卡系数
function Store:getGearExchangeCoef()
if self:isPrivCardExpire() then
return 1
end
return 1 + 0.5
end
|
c5825110
saicom
新增用户商城相关数据
|
145
|
-- 购买通行证
|
3e20f499
saicom
完善商城相关协议
|
146
|
function Store:onBuyCard(type, duration)
|
c5825110
saicom
新增用户商城相关数据
|
147
|
local timeNow = skynet.timex()
|
3e20f499
saicom
完善商城相关协议
|
148
|
if type == CardType.NormalMonthCard then
|
317a46a9
liuzujun
添加特权卡
|
149
150
151
152
153
|
if self:isMonthCardExpire() then
self:updateProperty({field = "monthCardEx", value = timeNow + duration})
else
self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + duration})
end
|
3e20f499
saicom
完善商城相关协议
|
154
|
elseif type == CardType.SuperMonthCard then
|
317a46a9
liuzujun
添加特权卡
|
155
156
157
158
159
|
if self:isSuperMonthCardExpire() then
self:updateProperty({field = "smonthCardEx", value = timeNow + duration})
else
self:updateProperty({field = "smonthCardEx", value = self:getProperty("smonthCardEx") + duration})
end
|
3e20f499
saicom
完善商城相关协议
|
160
|
elseif type == CardType.PrivilegeCard then
|
317a46a9
liuzujun
添加特权卡
|
161
162
163
164
165
|
if self:isPrivCardExpire() then
self:updateProperty({field = "privCardEx", value = timeNow + duration})
else
self:updateProperty({field = "privCardEx", value = self:getProperty("privCardEx") + duration})
end
|
3e20f499
saicom
完善商城相关协议
|
166
167
168
|
elseif type == CardType.GrowFund then
self:updateProperty({field = "growFund", value = 1})
elseif type == CardType.BattleCard then
|
317a46a9
liuzujun
添加特权卡
|
169
170
171
172
173
|
if self:isBattleCardExpire() then
self:updateProperty({field = "battleCardEx", value = timeNow + duration})
else
self:updateProperty({field = "battleCardEx", value = self:getProperty("battleCardEx") + duration})
end
|
c5825110
saicom
新增用户商城相关数据
|
174
175
176
|
end
end
|
3e20f499
saicom
完善商城相关协议
|
177
178
|
function Store:checkRechargeRecord(limit, id)
local rechargeRecord = self:getProperty("payR")
|
c5825110
saicom
新增用户商城相关数据
|
179
180
181
182
|
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
|
3e20f499
saicom
完善商城相关协议
|
183
184
|
rechargeRecord[id] = (rechargeRecord[id] or 0) + 1
self:updateProperty({field = "payR", value = rechargeRecord})
|
c5825110
saicom
新增用户商城相关数据
|
185
186
187
|
return true
end
|
3e20f499
saicom
完善商城相关协议
|
188
189
190
191
192
193
194
195
196
|
function Store:notifyUpdateProperty(field, newValue, oldValue)
local datas = {
key = field,
newValue = newValue,
oldValue = oldValue,
}
SendPacket(actionCodes.Store_updateproperty, MsgPack.pack(datas))
end
|
1a0b3c56
liuzujun
抽卡保底,切换定向卡池
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
function Store:resetStoreReored(resetId)
local payRecord = self:getProperty("payR") or {}
local buyRecord = self:getProperty("buyR") or {}
for k, v in pairs(payRecord) do
local config = csvdb["shop_rechargeCsv"][k]
if config then
if config.resetTime == resetId then
payRecord[k] = nil
end
end
end
self:updateProperty({field = "payR", value = payRecord})
for k, v in pairs(buyRecord) do
local config = csvdb["shop_normalCsv"][k]
if config then
if config.resetTime == resetId then
buyRecord[k] = nil
end
end
end
self:updateProperty({field = "buyR", value = buyRecord})
end
|
c5825110
saicom
新增用户商城相关数据
|
220
221
|
function Store:data()
return {
|
3e20f499
saicom
完善商城相关协议
|
222
223
224
225
226
227
228
229
230
|
buyR = self:getProperty("buyR"),
payR = self:getProperty("payR"),
growFund = self:getProperty("growFund"),
growFundR = self:getProperty("growFundR"),
monthCardEx = self:getProperty("monthCardEx"),
smonthCardEx = self:getProperty("smonthCardEx"),
battleCardEx = self:getProperty("battleCardEx"),
battleCardR = self:getProperty("battleCardR"),
limitTPack = self:getProperty("limitTPack"),
|
317a46a9
liuzujun
添加特权卡
|
231
|
privCardEx = self:getProperty("privCardEx"),
|
c5825110
saicom
新增用户商城相关数据
|
232
233
234
235
|
}
end
return Store
|