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
19
|
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", ""}, -- 付费赛季卡领取记录
limitTPack = {"table", {}} -- 限时礼包 {id=expire_ts}
|
c5825110
saicom
新增用户商城相关数据
|
20
21
22
|
}
function Store:updateProperty(params)
|
3e20f499
saicom
完善商城相关协议
|
23
24
25
|
params = params or {}
if not self.schema[params.field] then
return
|
c5825110
saicom
新增用户商城相关数据
|
26
|
end
|
3e20f499
saicom
完善商城相关协议
|
27
|
local oldValue = self:getProperty(params.field)
|
c5825110
saicom
新增用户商城相关数据
|
28
29
|
if params.value then
self:setProperty(params.field, params.value)
|
3e20f499
saicom
完善商城相关协议
|
30
31
32
33
34
35
36
37
|
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
新增用户商城相关数据
|
38
|
end
|
c5825110
saicom
新增用户商城相关数据
|
39
40
41
|
end
function Store:refreshData(notify, refreshType)
|
3e20f499
saicom
完善商城相关协议
|
42
|
local buyRecord = self:getProperty("buyR")
|
c5825110
saicom
新增用户商城相关数据
|
43
44
45
46
47
48
49
50
51
|
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
完善商城相关协议
|
52
|
self:setProperty("buyR", buyRecord)
|
c5825110
saicom
新增用户商城相关数据
|
53
|
if notify then
|
3e20f499
saicom
完善商城相关协议
|
54
|
self:notifyUpdateProperty({field="buyR", value=buyRecord})
|
c5825110
saicom
新增用户商城相关数据
|
55
56
57
58
|
end
end
function Store:refreshPvpBuyRecord(notify)
|
3e20f499
saicom
完善商城相关协议
|
59
|
local buyRecord = self:getProperty("buyR")
|
c5825110
saicom
新增用户商城相关数据
|
60
61
62
63
64
|
for id, data in pairs(csvdb["shop_normalCsv"]) do
if data.shop == 3 then
buyRecord[id] = nil
end
end
|
3e20f499
saicom
完善商城相关协议
|
65
|
self:setProperty("buyR", buyRecord)
|
c5825110
saicom
新增用户商城相关数据
|
66
|
if notify then
|
3e20f499
saicom
完善商城相关协议
|
67
|
self:notifyUpdateProperty({field="buyR", value=buyRecord})
|
c5825110
saicom
新增用户商城相关数据
|
68
69
70
71
72
|
end
end
-- 发送月卡邮件
function Store:sendMonthCardEmail()
|
3e20f499
saicom
完善商城相关协议
|
73
74
75
76
77
78
79
80
81
|
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
新增用户商城相关数据
|
82
83
84
|
end
-- 购买通行证
|
3e20f499
saicom
完善商城相关协议
|
85
86
|
function Store:onBuyCard(type, duration)
duration = duration == "" and 0 or tonumber(duration)
|
c5825110
saicom
新增用户商城相关数据
|
87
|
local timeNow = skynet.timex()
|
3e20f499
saicom
完善商城相关协议
|
88
89
90
91
92
93
94
95
96
|
if type == CardType.NormalMonthCard then
self:updateProperty({field = "monthCardEx", value = timeNow + duration})
elseif type == CardType.SuperMonthCard then
self:updateProperty({field = "smonthCardEx", value = timeNow + duration})
elseif type == CardType.PrivilegeCard then
elseif type == CardType.GrowFund then
self:updateProperty({field = "growFund", value = 1})
elseif type == CardType.BattleCard then
self:updateProperty({field = "battleCardEx", value = timeNow + duration})
|
c5825110
saicom
新增用户商城相关数据
|
97
98
99
|
end
end
|
3e20f499
saicom
完善商城相关协议
|
100
101
|
function Store:checkRechargeRecord(limit, id)
local rechargeRecord = self:getProperty("payR")
|
c5825110
saicom
新增用户商城相关数据
|
102
103
104
105
|
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
完善商城相关协议
|
106
107
|
rechargeRecord[id] = (rechargeRecord[id] or 0) + 1
self:updateProperty({field = "payR", value = rechargeRecord})
|
c5825110
saicom
新增用户商城相关数据
|
108
109
110
|
return true
end
|
3e20f499
saicom
完善商城相关协议
|
111
112
113
114
115
116
117
118
119
|
function Store:notifyUpdateProperty(field, newValue, oldValue)
local datas = {
key = field,
newValue = newValue,
oldValue = oldValue,
}
SendPacket(actionCodes.Store_updateproperty, MsgPack.pack(datas))
end
|
c5825110
saicom
新增用户商城相关数据
|
120
121
|
function Store:data()
return {
|
3e20f499
saicom
完善商城相关协议
|
122
123
124
125
126
127
128
129
130
|
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"),
|
c5825110
saicom
新增用户商城相关数据
|
131
132
133
134
|
}
end
return Store
|