Commit fa992c94622292185c9782d8d4a2a0f6844e7e13
1 parent
e4ff71cd
添加daily,diner,activity,store
Showing
7 changed files
with
46 additions
and
92 deletions
Show diff stats
src/models/Activity.lua
1 | -local Activity = class("Activity", require("shared.ModelBase")) | |
1 | +local Activity = class("Activity", require("shared.ModelBaseMysql")) | |
2 | 2 | local string_format = string.format |
3 | 3 | |
4 | 4 | -- activity_ctr showType |
... | ... | @@ -64,6 +64,7 @@ end |
64 | 64 | |
65 | 65 | |
66 | 66 | Activity.schema = { |
67 | + id = {"number", 0, "pri"}, -- 角色id | |
67 | 68 | actime = {"table", {}}, -- 最近检查某项活动的开始时间 {id = time} |
68 | 69 | round = {"table", {}}, -- 记录活动到了第几轮 {id = roundnum} |
69 | 70 | act4 = {"table", {}}, -- {0 = day, 1= -1, 2 = -1} == 签到活动 | ... | ... |
src/models/Daily.lua
1 | 1 | -- 日常数据 |
2 | 2 | |
3 | -local Daily = class("Daily", require("shared.ModelBase")) | |
3 | +local Daily = class("Daily", require("shared.ModelBaseMysql")) | |
4 | 4 | |
5 | 5 | function Daily:ctor(properties) |
6 | 6 | Daily.super.ctor(self, properties) |
7 | 7 | end |
8 | 8 | |
9 | 9 | Daily.schema = { |
10 | - commentHero = {"string", ""}, -- 单日评论食灵记录 type=1 | |
10 | + id = {"number", 0, "pri"}, -- 角色id | |
11 | + commentHero = {"string", "", "blob"}, -- 单日评论食灵记录 type=1 | |
11 | 12 | hangQC = {"number", 0}, -- 挂机快速次数 |
12 | 13 | dinerQC = {"number", 0}, -- 贩卖加速次数 |
13 | 14 | advElC = {"number", 0}, -- 无尽次数(消耗体力) | ... | ... |
src/models/Diner.lua
1 | -local Diner = class("Diner", require("shared.ModelBase")) | |
1 | +local Diner = class("Diner", require("shared.ModelBaseMysql")) | |
2 | 2 | |
3 | 3 | function Diner:ctor(properties) |
4 | 4 | Diner.super.ctor(self, properties) |
5 | 5 | end |
6 | 6 | |
7 | 7 | Diner.schema = { |
8 | + id = {"number", 0, "pri"}, -- 角色id | |
8 | 9 | buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 |
9 | - order = {"string", "[]"}, -- 特殊订单 | |
10 | - sells = {"string", "[]"}, -- 贩卖位置 | |
10 | + order = {"string", "[]", 1024}, -- 特殊订单 | |
11 | + sells = {"string", "[]", "", 1024}, -- 贩卖位置 | |
11 | 12 | dishTree = {"string", "1=1 101=1 201=1"}, -- 料理天赋 |
12 | 13 | skillTree = {"string", ""}, -- 支援天赋 |
13 | 14 | popular = {"number",0}, -- 累计人气 | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -628,10 +628,10 @@ function RolePlugin.bind(Role) |
628 | 628 | |
629 | 629 | function Role:loadDaily() |
630 | 630 | local roleId = self:getProperty("id") |
631 | - local dataKey = string.format(R_DAILY, roleId) | |
632 | - self.dailyData = require("models.Daily").new({key = dataKey}) | |
631 | + local dataKey = string.format("%d", roleId) | |
632 | + self.dailyData = require("models.Daily").new({key = dataKey, id = roleId}) | |
633 | 633 | self.dailyData.owner = self |
634 | - if not redisproxy:exists(dataKey) then | |
634 | + if not self.dailyData:checkKeyExists(dataKey) then | |
635 | 635 | self.dailyData:create() |
636 | 636 | else |
637 | 637 | self.dailyData:load() |
... | ... | @@ -640,10 +640,10 @@ function RolePlugin.bind(Role) |
640 | 640 | |
641 | 641 | function Role:loadActivity() |
642 | 642 | local roleId = self:getProperty("id") |
643 | - local dataKey = string.format(R_ACTIVITY, roleId) | |
644 | - self.activity = require("models.Activity").new({key = dataKey}) | |
643 | + local dataKey = string.format("%d", roleId) | |
644 | + self.activity = require("models.Activity").new({key = dataKey, id = roleId}) | |
645 | 645 | self.activity.owner = self |
646 | - if not redisproxy:exists(dataKey) then | |
646 | + if not self.activity:checkKeyExists(dataKey) then | |
647 | 647 | self.activity:create() |
648 | 648 | else |
649 | 649 | self.activity:load() |
... | ... | @@ -652,10 +652,10 @@ function RolePlugin.bind(Role) |
652 | 652 | |
653 | 653 | function Role:loadDiner() |
654 | 654 | local roleId = self:getProperty("id") |
655 | - local dataKey = string.format(R_DINER, roleId) | |
656 | - self.dinerData = require("models.Diner").new({key = dataKey}) | |
655 | + local dataKey = string.format("%d", roleId) | |
656 | + self.dinerData = require("models.Diner").new({key = dataKey, id = roleId}) | |
657 | 657 | self.dinerData.owner = self |
658 | - if not redisproxy:exists(dataKey) then | |
658 | + if not self.dinerData:checkKeyExists(dataKey) then | |
659 | 659 | self.dinerData:create() |
660 | 660 | else |
661 | 661 | self.dinerData:load() |
... | ... | @@ -669,10 +669,10 @@ function RolePlugin.bind(Role) |
669 | 669 | |
670 | 670 | function Role:loadStoreInfo() |
671 | 671 | local roleId = self:getProperty("id") |
672 | - local dataKey = string.format(R_STORE, roleId) | |
673 | - self.storeData = require("models.Store").new({key = dataKey}) | |
672 | + local dataKey = string.format("%d", roleId) | |
673 | + self.storeData = require("models.Store").new({key = dataKey, id = roleId}) | |
674 | 674 | self.storeData.owner = self |
675 | - if not redisproxy:exists(dataKey) then | |
675 | + if not self.storeData:checkKeyExists(dataKey) then | |
676 | 676 | self.storeData:create() |
677 | 677 | else |
678 | 678 | self.storeData:load() | ... | ... |
src/models/Store.lua
1 | 1 | -- 商店数据 |
2 | 2 | |
3 | -local Store = class("Store", require("shared.ModelBase")) | |
3 | +local Store = class("Store", require("shared.ModelBaseMysql")) | |
4 | 4 | |
5 | 5 | function Store:ctor(properties) |
6 | 6 | Store.super.ctor(self, properties) |
... | ... | @@ -11,6 +11,7 @@ ActGoodsType = { |
11 | 11 | } |
12 | 12 | |
13 | 13 | Store.schema = { |
14 | + id = {"number", 0, "pri"}, -- 角色id | |
14 | 15 | buyR = {"table", {}}, -- 购买商品记录 {id=count} |
15 | 16 | payR = {"table", {}}, -- 充值记录 {id=count} |
16 | 17 | growFund = {"number", 0}, -- 成长基金 | ... | ... |
src/services/dbseed.lua
... | ... | @@ -89,8 +89,13 @@ local function initAdvSeasonTable() |
89 | 89 | end |
90 | 90 | |
91 | 91 | local function checkRoleTables() |
92 | - local role = require("models.Role").new({key = "key"}) | |
93 | - role:checkTableSchema() | |
92 | + local list = {"Role", "Daily", "Activity", "Diner", "Store"} | |
93 | + for _, name in ipairs(list) do | |
94 | + local obj = require("models."..name).new({key = "key"}) | |
95 | + print("check table [" .. name .. "] begin.") | |
96 | + obj:checkTableSchema() | |
97 | + print("check table [" .. name .. "] end.") | |
98 | + end | |
94 | 99 | end |
95 | 100 | |
96 | 101 | local steps = { |
... | ... | @@ -117,7 +122,6 @@ local steps = { |
117 | 122 | } |
118 | 123 | |
119 | 124 | skynet.start(function () |
120 | - redisproxy = require("shared.redisproxy") | |
121 | 125 | --local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 |
122 | 126 | --if not new then |
123 | 127 | -- print("server has been initialized...") | ... | ... |
src/shared/ModelBaseMysql.lua
... | ... | @@ -35,51 +35,6 @@ function ModelBaseMysql:ctor(properties) |
35 | 35 | self:getPriKey() |
36 | 36 | end |
37 | 37 | |
38 | --- startCache 和 endCache 在恰当的时候*配对使用* 嵌套使用多次增加引用计数 直到引用计数为0 写入 | |
39 | -function ModelBaseMysql:startCache( ... ) | |
40 | - for _, field in ipairs({ ... }) do | |
41 | - if self.class.schema[field] then | |
42 | - self.cacheFields[field] = (self.cacheFields[field] or 0) + 1 | |
43 | - end | |
44 | - end | |
45 | -end | |
46 | - | |
47 | ---减少缓存引用计数 为时写入, 无参数 强制刷新所有缓存 | |
48 | -function ModelBaseMysql:endCache( ... ) | |
49 | - local args = { ... } | |
50 | - local params = {} | |
51 | - | |
52 | - local function doOneCache(field) | |
53 | - local propname = field .. "_" | |
54 | - table_insert(params, field) | |
55 | - if self.class.schema[field][1] == "table" then | |
56 | - table_insert(params, MsgPack.pack(self[propname])) | |
57 | - else | |
58 | - table_insert(params, self[propname]) | |
59 | - end | |
60 | - end | |
61 | - | |
62 | - if not next(args) then | |
63 | - for field, _ in pairs(self.cacheFields) do | |
64 | - doOneCache(field) | |
65 | - end | |
66 | - self.cacheFields = {} | |
67 | - else | |
68 | - for _, field in ipairs(args) do | |
69 | - if self.cacheFields[field] then | |
70 | - self.cacheFields[field] = self.cacheFields[field] - 1 | |
71 | - if self.cacheFields[field] <= 0 then | |
72 | - self.cacheFields[field] = nil | |
73 | - doOneCache(field) | |
74 | - end | |
75 | - end | |
76 | - end | |
77 | - end | |
78 | - | |
79 | - if next(params) then | |
80 | - redisproxy:hmset(self:getKey(), table_unpack(params)) | |
81 | - end | |
82 | -end | |
83 | 38 | --[[-- |
84 | 39 | |
85 | 40 | 返回对象的 ID 值。 |
... | ... | @@ -100,6 +55,7 @@ function ModelBaseMysql:getPriKey() |
100 | 55 | local objType, def, keyType, length = table_unpack(v) |
101 | 56 | if keyType == "pri" then |
102 | 57 | self.pri_key = k |
58 | + break | |
103 | 59 | end |
104 | 60 | end |
105 | 61 | end |
... | ... | @@ -172,9 +128,9 @@ function ModelBaseMysql:save() |
172 | 128 | update_list = update_list .. "," |
173 | 129 | end |
174 | 130 | |
175 | - key_list = key_list .. k | |
131 | + key_list = key_list .. "`" .. k .. "`" | |
176 | 132 | value_list = value_list .. v |
177 | - update_list = update_list .. k .. "=" .. v | |
133 | + update_list = update_list .. "`" .. k .. "`=" .. v | |
178 | 134 | end |
179 | 135 | sql = string_format(sql, tbName, key_list, value_list, update_list) |
180 | 136 | mysqlproxy:query(sql) |
... | ... | @@ -284,14 +240,7 @@ function ModelBaseMysql:setProperty(property, value) |
284 | 240 | tostring(self), self.class.__cname, property, typ, type(value))) |
285 | 241 | self[propname] = value |
286 | 242 | |
287 | - if not self.cacheFields[property] then | |
288 | - -- table 使用msgpack | |
289 | - if typ == "table" then | |
290 | - value = MsgPack.pack(value) | |
291 | - end | |
292 | - --redisproxy:hset(self:getKey(), property, value) | |
293 | - self:save() | |
294 | - end | |
243 | + self:save() | |
295 | 244 | end |
296 | 245 | |
297 | 246 | function ModelBaseMysql:setProperties(fields) |
... | ... | @@ -312,20 +261,15 @@ function ModelBaseMysql:setProperties(fields) |
312 | 261 | tostring(self), self.class.__cname, property, typ, type(value))) |
313 | 262 | self[propname] = value |
314 | 263 | |
315 | - if not self.cacheFields[property] then | |
316 | - table_insert(result, property) | |
317 | - if typ == "table" then | |
318 | - table_insert(result, MsgPack.pack(self[propname])) | |
319 | - else | |
320 | - table_insert(result, self[propname]) | |
321 | - end | |
264 | + table_insert(result, property) | |
265 | + if typ == "table" then | |
266 | + table_insert(result, MsgPack.pack(self[propname])) | |
267 | + else | |
268 | + table_insert(result, self[propname]) | |
322 | 269 | end |
323 | 270 | end |
324 | 271 | end |
325 | - if next(result) then | |
326 | - --redisproxy:hmset(self:getKey(), table_unpack(result)) | |
327 | - self:save() | |
328 | - end | |
272 | + self:save() | |
329 | 273 | end |
330 | 274 | |
331 | 275 | function ModelBaseMysql:incrProperty(property, value) |
... | ... | @@ -346,10 +290,7 @@ function ModelBaseMysql:incrProperty(property, value) |
346 | 290 | tostring(self), self.class.__cname, property, typ, type(value))) |
347 | 291 | self[propname] = self[propname] + value |
348 | 292 | |
349 | - if not self.cacheFields[property] then | |
350 | - --return redisproxy:hincrby(self:getKey(), property, value) | |
351 | - self:save() | |
352 | - end | |
293 | + self:save() | |
353 | 294 | end |
354 | 295 | |
355 | 296 | function ModelBaseMysql:onLoad() |
... | ... | @@ -358,6 +299,11 @@ end |
358 | 299 | function ModelBaseMysql:onCreate() |
359 | 300 | end |
360 | 301 | |
302 | +function ModelBaseMysql:checkKeyExists(key) | |
303 | + local res = mysqlproxy:query(string_format("SELECT * FROM `%s` WHERE `%s` = %s", self.class.__cname, self.pri_key, key)) | |
304 | + return next(res) | |
305 | +end | |
306 | + | |
361 | 307 | function ModelBaseMysql:checkTableSchema() |
362 | 308 | -- 1.检测是否表存在 |
363 | 309 | local typeMap = { | ... | ... |