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
|
buyR = {"table", {}}, -- 购买商品记录 {id=count}
payR = {"table", {}}, -- 充值记录 {id=count}
growFund = {"number", 0}, -- 成长基金
growFundR = {"string", ""}, -- 成长基金领取记录
monthCardEx = {"number", 0}, -- 月卡过期时间戳
smonthCardEx = {"number", 0}, -- 超级月卡过期时间戳
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
16
|
battleCard = {"number", 0}, -- 赛季卡
|
3e20f499
saicom
完善商城相关协议
|
17
18
|
battleFR = {"string", ""}, -- 免费赛季卡领取记录
battleLR = {"string", ""}, -- 付费赛季卡领取记录
|
317a46a9
liuzujun
添加特权卡
|
19
|
limitTPack = {"table", {}}, -- 限时礼包 {id=expire_ts}
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
20
21
22
|
privCardEx = {"number", 0}, -- 特权卡过期时间戳
getMailT1 = {"number",0}, -- 上次发送月卡福利邮件的时间
getMailT2 = {"number",0}, -- 上次发送超级月卡福利邮件的时间
|
9ea0c502
liuzujun
限时礼包
|
23
|
packTrigger = {"table", {}} -- 礼包触发记录 {关卡难度1={id, 通关关卡数,升级数,爬塔层数}, ...}
|
c5825110
saicom
新增用户商城相关数据
|
24
25
26
|
}
function Store:updateProperty(params)
|
3e20f499
saicom
完善商城相关协议
|
27
28
29
|
params = params or {}
if not self.schema[params.field] then
return
|
c5825110
saicom
新增用户商城相关数据
|
30
|
end
|
3e20f499
saicom
完善商城相关协议
|
31
|
local oldValue = self:getProperty(params.field)
|
c5825110
saicom
新增用户商城相关数据
|
32
33
|
if params.value then
self:setProperty(params.field, params.value)
|
3e20f499
saicom
完善商城相关协议
|
34
35
36
37
38
39
40
41
|
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
新增用户商城相关数据
|
42
|
end
|
c5825110
saicom
新增用户商城相关数据
|
43
44
|
end
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
45
46
47
|
function Store:onCrossDay()
self:sendMonthCardEmail()
self:deleteExpireLimitGoods()
|
c5825110
saicom
新增用户商城相关数据
|
48
49
|
end
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
50
51
52
53
54
55
56
57
|
-- 删除过期商品
function Store:deleteExpireLimitGoods()
local timeNow = skynet.timex()
local limitGoodsList = self:getProperty("limitTPack")
for k, v in pairs(limitGoodsList) do
if timeNow > v then
limitGoodsList[k] = nil
end
|
c5825110
saicom
新增用户商城相关数据
|
58
|
end
|
c5825110
saicom
新增用户商城相关数据
|
59
60
61
62
|
end
-- 发送月卡邮件
function Store:sendMonthCardEmail()
|
3e20f499
saicom
完善商城相关协议
|
63
|
local timeNow = skynet.timex()
|
9ea0c502
liuzujun
限时礼包
|
64
|
local tabs = {{ex="monthCardEx", t="getMailT1", mail=MailId.MonthCard, alert=MailId.MonthCardEx},
|
706b517e
liuzujun
翻倍掉落活动,商城免费宝箱
|
65
|
{ex="smonthCardEx", t="getMailT2", mail=MailId.SuperMonthCard, alert=MailId.SuperMonthCardEx}}
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
66
67
68
69
70
71
72
73
74
75
76
|
for _, v in ipairs(tabs) do
local ex = self:getProperty(v.ex)
local ts = self:getProperty(v.t) or 0
local mailId = v.mail
local alertId = v.alert
local alertTs = dayLater(ex) - DAY_SEC
if ex > timeNow then
local cnt = 0
if ts == 0 then
cnt = 1
else
|
70aa8660
liuzujun
发送多天邮件bug
|
77
|
local diff = math.floor((dayLater(timeNow) - dayLater(ts))/DAY_SEC)
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
diff = diff < 0 and 0 or diff
diff = diff > 31 and 31 or diff
cnt = diff
end
for i = cnt - 1, 0, -1 do
local createTs = timeNow - i * DAY_SEC
self.owner:sendMail(mailId, createTs)
-- 过期头一天发提醒邮件
if dayLater(createTs) == alertTs then
self.owner:sendMail(alertId, createTs)
end
end
if cnt > 0 then
self:updateProperty({field=v.t, value=timeNow})
end
end
|
3e20f499
saicom
完善商城相关协议
|
94
|
end
|
c5825110
saicom
新增用户商城相关数据
|
95
96
|
end
|
317a46a9
liuzujun
添加特权卡
|
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
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
|
317a46a9
liuzujun
添加特权卡
|
115
116
117
118
119
120
|
-- 挂机栏位 特权卡额外个数
function Store:getHangSlotExtraCount()
if self:isPrivCardExpire() then
return 0
end
|
d9d51454
liuzujun
修改特权卡引用配置错误bug
|
121
|
return globalCsv.shop_priv_card_hang_slot_cnt or 4
|
317a46a9
liuzujun
添加特权卡
|
122
123
124
125
126
127
128
|
end
-- 探索加速/餐厅加速 特权卡系数
function Store:getProduceItemSpeedCoef()
if self:isPrivCardExpire() then
return 1
end
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
129
130
|
local coef = (globalCsv.shop_priv_card_produce_coef or 25)/ 100
return 1 + coef
|
317a46a9
liuzujun
添加特权卡
|
131
132
133
134
135
136
137
138
|
end
-- 拆解室栏位 特权卡额外个数
function Store:getTimeBoxSlotExtraCount()
if self:isPrivCardExpire() then
return 0
end
|
d9d51454
liuzujun
修改特权卡引用配置错误bug
|
139
|
return globalCsv.shop_priv_time_box_slot_cnt or 3
|
317a46a9
liuzujun
添加特权卡
|
140
141
142
143
144
145
146
147
|
end
-- 齿轮兑换 特权卡系数
function Store:getGearExchangeCoef()
if self:isPrivCardExpire() then
return 1
end
|
7f9f002d
liuzujun
循环周活动
|
148
|
local coef = (globalCsv.shop_priv_exchange_gear_coef or 50)/ 100
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
149
|
return 1 + coef
|
317a46a9
liuzujun
添加特权卡
|
150
151
|
end
|
c5825110
saicom
新增用户商城相关数据
|
152
|
-- 购买通行证
|
3e20f499
saicom
完善商城相关协议
|
153
|
function Store:onBuyCard(type, duration)
|
c5825110
saicom
新增用户商城相关数据
|
154
|
local timeNow = skynet.timex()
|
3e20f499
saicom
完善商城相关协议
|
155
|
if type == CardType.NormalMonthCard then
|
317a46a9
liuzujun
添加特权卡
|
156
157
158
159
160
|
if self:isMonthCardExpire() then
self:updateProperty({field = "monthCardEx", value = timeNow + duration})
else
self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + duration})
end
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
161
|
self:sendMonthCardEmail()
|
3e20f499
saicom
完善商城相关协议
|
162
|
elseif type == CardType.SuperMonthCard then
|
317a46a9
liuzujun
添加特权卡
|
163
164
165
166
167
|
if self:isSuperMonthCardExpire() then
self:updateProperty({field = "smonthCardEx", value = timeNow + duration})
else
self:updateProperty({field = "smonthCardEx", value = self:getProperty("smonthCardEx") + duration})
end
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
168
|
self:sendMonthCardEmail()
|
3e20f499
saicom
完善商城相关协议
|
169
|
elseif type == CardType.PrivilegeCard then
|
317a46a9
liuzujun
添加特权卡
|
170
171
172
173
174
|
if self:isPrivCardExpire() then
self:updateProperty({field = "privCardEx", value = timeNow + duration})
else
self:updateProperty({field = "privCardEx", value = self:getProperty("privCardEx") + duration})
end
|
3e20f499
saicom
完善商城相关协议
|
175
176
177
|
elseif type == CardType.GrowFund then
self:updateProperty({field = "growFund", value = 1})
elseif type == CardType.BattleCard then
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
178
|
self:updateProperty({field = "battleCard", value = 1})
|
c5825110
saicom
新增用户商城相关数据
|
179
180
181
|
end
end
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
182
|
--检测购买是否超过限制数量
|
3e20f499
saicom
完善商城相关协议
|
183
184
|
function Store:checkRechargeRecord(limit, id)
local rechargeRecord = self:getProperty("payR")
|
c5825110
saicom
新增用户商城相关数据
|
185
186
187
188
|
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
完善商城相关协议
|
189
190
|
rechargeRecord[id] = (rechargeRecord[id] or 0) + 1
self:updateProperty({field = "payR", value = rechargeRecord})
|
c5825110
saicom
新增用户商城相关数据
|
191
192
193
|
return true
end
|
3e20f499
saicom
完善商城相关协议
|
194
195
196
197
198
199
200
201
202
|
function Store:notifyUpdateProperty(field, newValue, oldValue)
local datas = {
key = field,
newValue = newValue,
oldValue = oldValue,
}
SendPacket(actionCodes.Store_updateproperty, MsgPack.pack(datas))
end
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
203
204
|
-- 赛季卡重置 需要把未能领取的奖励通过邮件发送
function Store:onBattleCardReset()
|
706b517e
liuzujun
翻倍掉落活动,商城免费宝箱
|
205
|
local gift = {}
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
206
|
local function concatGift(data)
|
706b517e
liuzujun
翻倍掉落活动,商城免费宝箱
|
207
208
|
for key, v in pairs(data:toNumMap()) do
gift[key] = (gift[key] or 0) + v
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
209
210
211
212
213
214
215
216
217
218
219
|
end
end
local battleCardFlag = self:getProperty("battleCard")
local battleCardFreeRecord = self:getProperty("battleFR")
local battleCardLimitRecord = self:getProperty("battleLR")
local battlePoint = self.owner:getProperty("battlePoint")
for id, config in pairs(csvdb["reward_battlepassCsv"]) do
if config then
local freeFlag = string.char(string.getbit(battleCardFreeRecord, id))
local limitFlag = string.char(string.getbit(battleCardLimitRecord, id))
|
9ea0c502
liuzujun
限时礼包
|
220
|
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
221
222
223
224
225
226
227
228
229
230
|
if battlePoint < config.point then
break
end
if freeFlag == "0" then
concatGift(config.giftFree)
end
if limitFlag == "0" and battleCardFlag == 1 then
concatGift(config.giftLimit)
end
end
|
9ea0c502
liuzujun
限时礼包
|
231
|
end
|
706b517e
liuzujun
翻倍掉落活动,商城免费宝箱
|
232
|
self.owner:sendMail(MailId.BattleCardAward, nil, gift)
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
233
234
|
-- 计算剩余奖励
self:updateProperty({field = "battleCard", value=0})
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
235
236
237
238
239
240
|
self:updateProperty({field = "battleFR", value=""})
self:updateProperty({field = "battleLR", value=""})
self.owner:updateProperty({field = "battlePoint", value=0})
end
-- 重置购买记录
|
1a0b3c56
liuzujun
抽卡保底,切换定向卡池
|
241
242
243
244
245
246
247
248
|
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
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
249
250
251
252
253
254
|
--通行证商店
if config.shop == 2 then
if config.type == CardType.BattleCard then
self:onBattleCardReset()
end
end
|
1a0b3c56
liuzujun
抽卡保底,切换定向卡池
|
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
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
|
9ea0c502
liuzujun
限时礼包
|
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
--触发限时礼包
function Store:OnTriggerLimitTimePack(eventType, param)
local limitPack = self:getProperty("limitTPack")
local timeNow = skynet.timex()
local find = false
-- 有未过期的限时礼包不再推送
for k, v in pairs(limitPack) do
if v > timeNow then
find = true
break
end
end
if find == true then
return
end
limitPack = {}
local hangPass = self.owner:getProperty("hangPass")
local triggerRecord = self:getProperty("packTrigger")
local result = {}
local maxDiff = 0
-- 取满足限时礼包关卡要求的对应数据
for diff, maxCarbonId in pairs(hangPass) do
for id, cfg in pairs(csvdb["shop_packCsv"]) do
local range = cfg.showRange:toArray(true, "=")
local beginRange = range[1] or 0
local endRange = range[2] or 0
if maxCarbonId > beginRange and maxCarbonId <= endRange and cfg.type == eventType then
result[diff] = cfg
maxDiff = math.max(maxDiff, diff)
break
end
end
end
local shopGoodsId = 0
for diff, cfg in pairs(result) do
if diff == maxDiff then
local record = triggerRecord[diff] or {}
if (record[0] or 0) ~= cfg.id and next(record) then
record = {}
end
record[0] = cfg.id
record[eventType] = (record[eventType] or 0) + 1
|
93f6e69b
liuzujun
拾荒选择时间,抽卡增加sr保底
|
312
|
if record[eventType] > 0 and record[eventType] % 10 == 0 then
|
9ea0c502
liuzujun
限时礼包
|
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
local pool = cfg.packId:toArray(true, "=")
local idx = math.random(1, #pool)
shopGoodsId = pool[idx]
end
triggerRecord[diff] = record
end
end
if shopGoodsId ~= 0 then
local rechargeCfg = csvdb["shop_rechargeCsv"][shopGoodsId]
if rechargeCfg then
limitPack[rechargeCfg.id] = timeNow + rechargeCfg.time
self:updateProperty({field = "limitTPack", value = limitPack})
end
end
if next(result) then
self:updateProperty({field = "packTrigger", value = triggerRecord})
end
end
|
c5825110
saicom
新增用户商城相关数据
|
332
333
|
function Store:data()
return {
|
3e20f499
saicom
完善商城相关协议
|
334
335
336
337
338
339
|
buyR = self:getProperty("buyR"),
payR = self:getProperty("payR"),
growFund = self:getProperty("growFund"),
growFundR = self:getProperty("growFundR"),
monthCardEx = self:getProperty("monthCardEx"),
smonthCardEx = self:getProperty("smonthCardEx"),
|
fb3d084d
liuzujun
月卡赛季卡发送邮件奖励
|
340
341
342
|
battleCard = self:getProperty("battleCard"),
battleFR = self:getProperty("battleFR"),
battleLR = self:getProperty("battleLR"),
|
3e20f499
saicom
完善商城相关协议
|
343
|
limitTPack = self:getProperty("limitTPack"),
|
317a46a9
liuzujun
添加特权卡
|
344
|
privCardEx = self:getProperty("privCardEx"),
|
93f6e69b
liuzujun
拾荒选择时间,抽卡增加sr保底
|
345
|
packTrigger = self:getProperty("packTrigger")
|
c5825110
saicom
新增用户商城相关数据
|
346
347
348
349
|
}
end
return Store
|