Commit 2ca9397254f418e2cff5487421720942c35ab1f3
1 parent
913e070e
添加邮件表
Showing
9 changed files
with
100 additions
and
80 deletions
Show diff stats
src/actions/EmailAction.lua
| @@ -3,22 +3,32 @@ local tarr2tab = table.array2Table | @@ -3,22 +3,32 @@ local tarr2tab = table.array2Table | ||
| 3 | 3 | ||
| 4 | local function loadEmails(roleId) | 4 | local function loadEmails(roleId) |
| 5 | local emails = {} | 5 | local emails = {} |
| 6 | - local rds = string.format(R_EMAIL, roleId) | ||
| 7 | - local ids = redisproxy:lrange(rds, 0, EMAIL_LIMIT - 1) | ||
| 8 | - local redret = redisproxy:pipelining(function (red) | ||
| 9 | - for _, id in ipairs(ids) do | ||
| 10 | - red:hgetall(string.format("email:%d:%s", roleId, id)) | ||
| 11 | - end | ||
| 12 | - end) | ||
| 13 | - for index, id in ipairs(ids) do | ||
| 14 | - local email = require("models.Email").new({key = string.format("email:%d:%s", roleId, id)}) | ||
| 15 | - if email:load(tarr2tab(redret[index])) then | 6 | + local res = mysqlproxy:query(string.format("SELECT * FROM `Email` WHERE `roleId` = %s", roleId)) |
| 7 | + for _, data in ipairs(res) do | ||
| 8 | + local email = require("models.Email").new({key = string.format("%d",data.id), id=data.id}) | ||
| 9 | + if email:load(data) then | ||
| 16 | table.insert(emails, email) | 10 | table.insert(emails, email) |
| 17 | end | 11 | end |
| 18 | end | 12 | end |
| 19 | return emails | 13 | return emails |
| 20 | end | 14 | end |
| 21 | 15 | ||
| 16 | +local function delExpireEmails(roleId) | ||
| 17 | + local sql = [[ | ||
| 18 | + DELETE FROM Email | ||
| 19 | + WHERE id IN ( | ||
| 20 | + SELECT id FROM ( | ||
| 21 | + SELECT id | ||
| 22 | + FROM Email WHERE roleId=%s | ||
| 23 | + ORDER BY createtime DESC, id desc | ||
| 24 | + LIMIT %s, 100000 | ||
| 25 | + ) a | ||
| 26 | + ); | ||
| 27 | + ]] | ||
| 28 | + sql = string.format(sql, roleId, EMAIL_LIMIT) | ||
| 29 | + mysqlproxy:query(sql) | ||
| 30 | +end | ||
| 31 | + | ||
| 22 | function _M.listRpc(agent, data) | 32 | function _M.listRpc(agent, data) |
| 23 | local role = agent.role | 33 | local role = agent.role |
| 24 | local roleId = role:getProperty("id") | 34 | local roleId = role:getProperty("id") |
| @@ -51,7 +61,7 @@ function _M.listRpc(agent, data) | @@ -51,7 +61,7 @@ function _M.listRpc(agent, data) | ||
| 51 | if flag and ( not email.mid or tonum(email.mid) == mid ) | 61 | if flag and ( not email.mid or tonum(email.mid) == mid ) |
| 52 | and ( not email.endtime or tonum(email.endtime) > now )then | 62 | and ( not email.endtime or tonum(email.endtime) > now )then |
| 53 | local time = math.max(tonum(email.timestamp, 0) , tonum(email.createtime)) | 63 | local time = math.max(tonum(email.timestamp, 0) , tonum(email.createtime)) |
| 54 | - redisproxy:insertEmail({ | 64 | + mysqlproxy:insertEmail({ |
| 55 | roleId = roleId, | 65 | roleId = roleId, |
| 56 | emailId = 0, | 66 | emailId = 0, |
| 57 | createtime = time, | 67 | createtime = time, |
| @@ -64,6 +74,7 @@ function _M.listRpc(agent, data) | @@ -64,6 +74,7 @@ function _M.listRpc(agent, data) | ||
| 64 | end | 74 | end |
| 65 | end | 75 | end |
| 66 | end | 76 | end |
| 77 | + delExpireEmails(roleId) | ||
| 67 | 78 | ||
| 68 | local emails = loadEmails(roleId) | 79 | local emails = loadEmails(roleId) |
| 69 | for _, email in ipairs(emails) do | 80 | for _, email in ipairs(emails) do |
| @@ -120,9 +131,8 @@ function _M.drawAttachRpc(agent, data) | @@ -120,9 +131,8 @@ function _M.drawAttachRpc(agent, data) | ||
| 120 | local msg = MsgPack.unpack(data) | 131 | local msg = MsgPack.unpack(data) |
| 121 | local id = msg.id | 132 | local id = msg.id |
| 122 | 133 | ||
| 123 | - local rds = string.format(R_EMAIL_ITEM, roleId, id) | ||
| 124 | 134 | ||
| 125 | - local email = require("models.Email").new({key = rds}) | 135 | + local email = require("models.Email").new({key = string.format("%d", id), id = id}) |
| 126 | if not email:load() then return end | 136 | if not email:load() then return end |
| 127 | 137 | ||
| 128 | local attachments = getEmailAttachments(email) | 138 | local attachments = getEmailAttachments(email) |
| @@ -143,8 +153,7 @@ function _M.checkRpc(agent, data) | @@ -143,8 +153,7 @@ function _M.checkRpc(agent, data) | ||
| 143 | local msg = MsgPack.unpack(data) | 153 | local msg = MsgPack.unpack(data) |
| 144 | local id = msg.id | 154 | local id = msg.id |
| 145 | 155 | ||
| 146 | - local emailRds = string.format("email:%d:%s", roleId, id) | ||
| 147 | - local email = require("models.Email").new({key = emailRds}) | 156 | + local email = require("models.Email").new({key = string.format("%d", id), id = id}) |
| 148 | if not email:load() then return end | 157 | if not email:load() then return end |
| 149 | 158 | ||
| 150 | email:setProperty("status", 1) | 159 | email:setProperty("status", 1) |
| @@ -158,33 +167,21 @@ end | @@ -158,33 +167,21 @@ end | ||
| 158 | function _M.delRpc(agent, data) | 167 | function _M.delRpc(agent, data) |
| 159 | local role = agent.role | 168 | local role = agent.role |
| 160 | local roleId = role:getProperty("id") | 169 | local roleId = role:getProperty("id") |
| 161 | - | ||
| 162 | - local rds = string.format(R_EMAIL, roleId) | ||
| 163 | - local ids = redisproxy:lrange(rds, 0, EMAIL_LIMIT - 1) | ||
| 164 | - local now = skynet.timex() | ||
| 165 | local result = {} | 170 | local result = {} |
| 166 | - local emailSet = csvdb["emailCsv"] | ||
| 167 | - | ||
| 168 | - redisproxy:pipelining(function (red) | ||
| 169 | - for _, id in ipairs(ids) do | ||
| 170 | - local emailRds = string.format("email:%d:%s", roleId, id) | ||
| 171 | - local email = require("models.Email").new({key = emailRds}) | ||
| 172 | - if email:load() then | ||
| 173 | - local status = email:getProperty("status") | ||
| 174 | - local attachments = email:getProperty("attachments") | ||
| 175 | - local emailData = emailSet[email:getProperty("emailId")] | ||
| 176 | - if emailData and attachments:len() == 0 then | ||
| 177 | - attachments = emailData.attachment | ||
| 178 | - end | ||
| 179 | - if status == 2 or (status == 1 and attachments:len() == 0) then | ||
| 180 | - email:log(role, 3) | ||
| 181 | - red:lrem(rds, 0, id) | ||
| 182 | - red:del(emailRds) | ||
| 183 | - result[tonum(id)] = 1 | ||
| 184 | - end | ||
| 185 | - end | 171 | + local tmp = {} |
| 172 | + local emails = loadEmails(roleId) | ||
| 173 | + for _, email in ipairs(emails) do | ||
| 174 | + local attachments = getEmailAttachments(email) | ||
| 175 | + | ||
| 176 | + if email:getProperty("status") == 2 or (attachments == "" and email:getProperty("status") == 1) then | ||
| 177 | + result[email:getProperty("id")] = 1 | ||
| 178 | + email:log(role, 3) | ||
| 179 | + table.insert(tmp, email:getProperty("id")) | ||
| 186 | end | 180 | end |
| 187 | - end) | 181 | + end |
| 182 | + | ||
| 183 | + mysqlproxy:query(string.format("DELETE FROM `Email` WHERE `id` in (%s)", table.concat(tmp, ","))) | ||
| 184 | + | ||
| 188 | for delId, _ in ipairs(result) do | 185 | for delId, _ in ipairs(result) do |
| 189 | role:mylog("mail_action", {desc = "del_mail", int1 = delId}) | 186 | role:mylog("mail_action", {desc = "del_mail", int1 = delId}) |
| 190 | end | 187 | end |
src/actions/GmAction.lua
| @@ -498,7 +498,7 @@ table.insert(helpDes, {"发送邮件", "email", "id", "奖励"}) | @@ -498,7 +498,7 @@ table.insert(helpDes, {"发送邮件", "email", "id", "奖励"}) | ||
| 498 | function _M.email(role, pms) | 498 | function _M.email(role, pms) |
| 499 | local id = tonum(pms.pm1, 0) | 499 | local id = tonum(pms.pm1, 0) |
| 500 | local reward = pms.pm2 | 500 | local reward = pms.pm2 |
| 501 | - redisproxy:insertEmail({ | 501 | + mysqlproxy:insertEmail({ |
| 502 | roleId = role:getProperty("id"), | 502 | roleId = role:getProperty("id"), |
| 503 | emailId = id, | 503 | emailId = id, |
| 504 | createtime = skynet.timex(), | 504 | createtime = skynet.timex(), |
src/actions/RoleAction.lua
| @@ -14,6 +14,8 @@ local table_insert = table.insert | @@ -14,6 +14,8 @@ local table_insert = table.insert | ||
| 14 | local tconcat = table.concat | 14 | local tconcat = table.concat |
| 15 | local httpc = require("http.httpc") | 15 | local httpc = require("http.httpc") |
| 16 | 16 | ||
| 17 | +require "utils.MysqlUtil" | ||
| 18 | + | ||
| 17 | local WAVE_HERO_NUMS = 150 | 19 | local WAVE_HERO_NUMS = 150 |
| 18 | local WAVE_RUNE_NUMS = 150 | 20 | local WAVE_RUNE_NUMS = 150 |
| 19 | 21 | ||
| @@ -154,7 +156,8 @@ function _M.loginRpc( agent, data ) | @@ -154,7 +156,8 @@ function _M.loginRpc( agent, data ) | ||
| 154 | end | 156 | end |
| 155 | end | 157 | end |
| 156 | 158 | ||
| 157 | - SERV_OPEN = redisproxy:hget("autoincrement_set", "server_start") | 159 | + --SERV_OPEN = redisproxy:hget("autoincrement_set", "server_start") |
| 160 | + SERV_OPEN = getDbCfgVal("server_info", "server_start", "str_value") | ||
| 158 | 161 | ||
| 159 | role:changeStructVersion() -- 数据结构 版本更新 | 162 | role:changeStructVersion() -- 数据结构 版本更新 |
| 160 | role:getAdvData(true) -- 清掉不合格的数据 | 163 | role:getAdvData(true) -- 清掉不合格的数据 |
| @@ -364,7 +367,7 @@ function _M.createRpc(agent, data) | @@ -364,7 +367,7 @@ function _M.createRpc(agent, data) | ||
| 364 | 367 | ||
| 365 | newRole:award(globalCsv.birthItem, {log = {desc = "birth"}, notNotify = true}) | 368 | newRole:award(globalCsv.birthItem, {log = {desc = "birth"}, notNotify = true}) |
| 366 | -- 欢迎邮件 | 369 | -- 欢迎邮件 |
| 367 | - redisproxy:insertEmail({roleId = roleId, emailId = 1}) | 370 | + mysqlproxy:insertEmail({roleId = roleId, emailId = 1}) |
| 368 | 371 | ||
| 369 | if msg.newuser then | 372 | if msg.newuser then |
| 370 | newRole:log("onCreateAccount") | 373 | newRole:log("onCreateAccount") |
| @@ -394,9 +397,9 @@ function _M.createRpc(agent, data) | @@ -394,9 +397,9 @@ function _M.createRpc(agent, data) | ||
| 394 | reward = reward:setv(itemId, count) | 397 | reward = reward:setv(itemId, count) |
| 395 | end | 398 | end |
| 396 | if back.reward[70] then | 399 | if back.reward[70] then |
| 397 | - redisproxy:insertEmail({roleId = roleId, emailId = MailId.CBBackAward2, contentPms = {back.money}, createtime = skynet.timex(), attachments = reward}) | 400 | + mysqlproxy:insertEmail({roleId = roleId, emailId = MailId.CBBackAward2, contentPms = {back.money}, createtime = skynet.timex(), attachments = reward}) |
| 398 | else | 401 | else |
| 399 | - redisproxy:insertEmail({roleId = roleId, emailId = MailId.CBBackAward, contentPms = {back.money}, createtime = skynet.timex(), attachments = reward}) | 402 | + mysqlproxy:insertEmail({roleId = roleId, emailId = MailId.CBBackAward, contentPms = {back.money}, createtime = skynet.timex(), attachments = reward}) |
| 400 | end | 403 | end |
| 401 | newRole:mylog("cbback", {key1 = uid, int2 = roleId}) | 404 | newRole:mylog("cbback", {key1 = uid, int2 = roleId}) |
| 402 | end | 405 | end |
src/models/Email.lua
| 1 | -local Email = class("Email", require("shared.ModelBase")) | 1 | +local Email = class("Email", require("shared.ModelBaseMysql")) |
| 2 | 2 | ||
| 3 | function Email:ctor(properties) | 3 | function Email:ctor(properties) |
| 4 | Email.super.ctor(self, properties) | 4 | Email.super.ctor(self, properties) |
| 5 | end | 5 | end |
| 6 | 6 | ||
| 7 | Email.schema = { | 7 | Email.schema = { |
| 8 | - key = {"string"}, -- redis key | ||
| 9 | - id = {"number", 0}, -- 数据库ID | 8 | + id = {"number", 0, "pri_auto"}, -- 数据库ID |
| 9 | + roleId = {"number", 0, "index"}, -- 角色 ID | ||
| 10 | emailId = {"number", 0}, -- 邮件csv ID | 10 | emailId = {"number", 0}, -- 邮件csv ID |
| 11 | title = {"string", ""}, -- 邮件标题 | 11 | title = {"string", ""}, -- 邮件标题 |
| 12 | stitle = {"string", ""}, -- 小标题 | 12 | stitle = {"string", ""}, -- 小标题 |
| 13 | content = {"string", ""}, -- 邮件正文 | 13 | content = {"string", ""}, -- 邮件正文 |
| 14 | - attachments = {"string", ""}, | 14 | + attachments = {"string", "", 512}, |
| 15 | status = {"number", 0}, -- 邮件状态: 未读, 已读, 已领取 | 15 | status = {"number", 0}, -- 邮件状态: 未读, 已读, 已领取 |
| 16 | createtime = {"number", skynet.timex()}, | 16 | createtime = {"number", skynet.timex()}, |
| 17 | contentPms = {"table", {}}, | 17 | contentPms = {"table", {}}, |
src/models/RolePlugin.lua
| @@ -234,7 +234,7 @@ function RolePlugin.bind(Role) | @@ -234,7 +234,7 @@ function RolePlugin.bind(Role) | ||
| 234 | local headData = csvdb["player_iconCsv"][itemId] | 234 | local headData = csvdb["player_iconCsv"][itemId] |
| 235 | -- pvp 跨服竞技场奖励 | 235 | -- pvp 跨服竞技场奖励 |
| 236 | if headData and headData.path == 2 then | 236 | if headData and headData.path == 2 then |
| 237 | - redisproxy:insertEmail({roleId = self:getProperty("id"), emailId = 19}) | 237 | + mysqlproxy:insertEmail({roleId = self:getProperty("id"), emailId = 19}) |
| 238 | end | 238 | end |
| 239 | end | 239 | end |
| 240 | end | 240 | end |
| @@ -834,12 +834,14 @@ function RolePlugin.bind(Role) | @@ -834,12 +834,14 @@ function RolePlugin.bind(Role) | ||
| 834 | end | 834 | end |
| 835 | 835 | ||
| 836 | -- delete rune | 836 | -- delete rune |
| 837 | - redisproxy:pipelining(function (red) | ||
| 838 | - for _, runeId in pairs(bDel) do | ||
| 839 | - red:del(string.format(R_RUNE, roleId, runeId)) | ||
| 840 | - red:srem(string.format(R_RUNEIDS, roleId), runeId) | ||
| 841 | - end | ||
| 842 | - end) | 837 | + --redisproxy:pipelining(function (red) |
| 838 | + -- for _, runeId in pairs(bDel) do | ||
| 839 | + -- red:del(string.format(R_RUNE, roleId, runeId)) | ||
| 840 | + -- red:srem(string.format(R_RUNEIDS, roleId), runeId) | ||
| 841 | + -- end | ||
| 842 | + --end) | ||
| 843 | + mysqlproxy:query(string.format("DELETE FROM `Rune` WHERE `uid` in (%s)", table.concat(bDel, ","))) | ||
| 844 | + | ||
| 843 | local response = {} | 845 | local response = {} |
| 844 | for _, runeId in pairs(bDel) do | 846 | for _, runeId in pairs(bDel) do |
| 845 | table.insert(response, {uid = runeId, bDel = true}) | 847 | table.insert(response, {uid = runeId, bDel = true}) |
| @@ -1612,21 +1614,10 @@ function RolePlugin.bind(Role) | @@ -1612,21 +1614,10 @@ function RolePlugin.bind(Role) | ||
| 1612 | end | 1614 | end |
| 1613 | 1615 | ||
| 1614 | local roleId = self:getProperty("id") | 1616 | local roleId = self:getProperty("id") |
| 1615 | - local email_rds = string.format(R_EMAIL, roleId) | ||
| 1616 | - | ||
| 1617 | - local emailIds = redisproxy:lrange(email_rds, 0, EMAIL_LIMIT - 1) or {} | ||
| 1618 | - local redret = redisproxy:pipelining(function (red) | ||
| 1619 | - for _, id in ipairs(emailIds) do | ||
| 1620 | - red:hget(string.format(R_EMAIL_ITEM, roleId, id), "status") | ||
| 1621 | - end | ||
| 1622 | - end) | 1617 | + local res = mysqlproxy:query(string.format("SELECT `id` FROM `Email` WHERE `roleId` = %d AND `status` = 0;", roleId)) |
| 1623 | 1618 | ||
| 1624 | self.SendMailFlag = false | 1619 | self.SendMailFlag = false |
| 1625 | - for index, id in ipairs(emailIds) do | ||
| 1626 | - if tonumber(redret[index]) == 0 then | ||
| 1627 | - return true | ||
| 1628 | - end | ||
| 1629 | - end | 1620 | + return next(res) |
| 1630 | end | 1621 | end |
| 1631 | 1622 | ||
| 1632 | checks["pvphg"] = function() | 1623 | checks["pvphg"] = function() |
| @@ -1954,7 +1945,7 @@ function RolePlugin.bind(Role) | @@ -1954,7 +1945,7 @@ function RolePlugin.bind(Role) | ||
| 1954 | for k, v in pairs(tgift) do | 1945 | for k, v in pairs(tgift) do |
| 1955 | gift = gift .. k.."="..v.." " | 1946 | gift = gift .. k.."="..v.." " |
| 1956 | end | 1947 | end |
| 1957 | - redisproxy:insertEmail({roleId = self:getProperty("id"), emailId = mailId, createtime = createTime, attachments = gift, contentPms = contentPms}) | 1948 | + mysqlproxy:insertEmail({roleId = self:getProperty("id"), emailId = mailId, createtime = createTime, attachments = gift, contentPms = contentPms}) |
| 1958 | self.sendMailFlag = true | 1949 | self.sendMailFlag = true |
| 1959 | end | 1950 | end |
| 1960 | 1951 |
src/services/dbseed.lua
| @@ -102,7 +102,7 @@ local function initAdvSeasonTable() | @@ -102,7 +102,7 @@ local function initAdvSeasonTable() | ||
| 102 | end | 102 | end |
| 103 | 103 | ||
| 104 | local function checkRoleTables() | 104 | local function checkRoleTables() |
| 105 | - local list = {"Role", "Daily", "Activity", "Diner", "Store", "Hero", "RoleIncre", "Rune", "Order"} | 105 | + local list = {"Role", "Daily", "Activity", "Diner", "Store", "Hero", "RoleIncre", "Rune", "Order", "Email"} |
| 106 | for _, name in ipairs(list) do | 106 | for _, name in ipairs(list) do |
| 107 | local obj = require("models."..name).new({key = "key"}) | 107 | local obj = require("models."..name).new({key = "key"}) |
| 108 | print("check table [" .. name .. "] begin.") | 108 | print("check table [" .. name .. "] begin.") |
src/services/globald.lua
| @@ -135,7 +135,7 @@ local function check_battle_act_close() | @@ -135,7 +135,7 @@ local function check_battle_act_close() | ||
| 135 | rankIndex = rankIndex + 1 | 135 | rankIndex = rankIndex + 1 |
| 136 | for _, cfg in pairs(actData) do | 136 | for _, cfg in pairs(actData) do |
| 137 | if rankIndex <= cfg.rank then | 137 | if rankIndex <= cfg.rank then |
| 138 | - redisproxy:insertEmail({ | 138 | + mysqlproxy:insertEmail({ |
| 139 | roleId = roleId, | 139 | roleId = roleId, |
| 140 | emailId = cfg.email_1, | 140 | emailId = cfg.email_1, |
| 141 | attachments = cfg.reward_1, | 141 | attachments = cfg.reward_1, |
src/shared/ModelBaseMysql.lua
| @@ -53,7 +53,7 @@ end | @@ -53,7 +53,7 @@ end | ||
| 53 | function ModelBaseMysql:getPriKey() | 53 | function ModelBaseMysql:getPriKey() |
| 54 | for k, v in pairs(self.class.schema) do | 54 | for k, v in pairs(self.class.schema) do |
| 55 | local objType, def, keyType, length = table_unpack(v) | 55 | local objType, def, keyType, length = table_unpack(v) |
| 56 | - if keyType == "pri" then | 56 | + if keyType == "pri" or keyType == "pri_auto" then |
| 57 | self.pri_key = k | 57 | self.pri_key = k |
| 58 | break | 58 | break |
| 59 | end | 59 | end |
| @@ -310,7 +310,7 @@ end | @@ -310,7 +310,7 @@ end | ||
| 310 | function ModelBaseMysql:checkTableSchema() | 310 | function ModelBaseMysql:checkTableSchema() |
| 311 | -- 1.检测是否表存在 | 311 | -- 1.检测是否表存在 |
| 312 | local typeMap = { | 312 | local typeMap = { |
| 313 | - number = {"int", 0, 10}, | 313 | + number = {"int", 0}, |
| 314 | string = {"varchar", "", 128}, | 314 | string = {"varchar", "", 128}, |
| 315 | table = {"blob", "NULL"}, | 315 | table = {"blob", "NULL"}, |
| 316 | pri = {"bigint", 0}, | 316 | pri = {"bigint", 0}, |
| @@ -330,15 +330,16 @@ function ModelBaseMysql:checkTableSchema() | @@ -330,15 +330,16 @@ function ModelBaseMysql:checkTableSchema() | ||
| 330 | ) ; | 330 | ) ; |
| 331 | ]] | 331 | ]] |
| 332 | local field_tpl_str = "`%s` %s%s DEFAULT %s" | 332 | local field_tpl_str = "`%s` %s%s DEFAULT %s" |
| 333 | + local auto_increment_str = "`%s` %s NOT NULL AUTO_INCREMENT" | ||
| 333 | local field_str = "" | 334 | local field_str = "" |
| 334 | 335 | ||
| 335 | - local res = mysqlproxy:query("desc ".. tbName .. ";") | 336 | + local res = mysqlproxy:query("desc `".. tbName .. "`;") |
| 336 | local keyList = {} | 337 | local keyList = {} |
| 337 | if res["err"] then -- 表不存在 | 338 | if res["err"] then -- 表不存在 |
| 338 | local schema = {} | 339 | local schema = {} |
| 339 | for k, v in pairs(self.class.schema) do | 340 | for k, v in pairs(self.class.schema) do |
| 340 | local keyType = v[3] | 341 | local keyType = v[3] |
| 341 | - if keyType == "pri" then | 342 | + if keyType == "pri" or keyType == "pri_auto" then |
| 342 | self.pri_key = k | 343 | self.pri_key = k |
| 343 | table_insert(schema, 1, {k, v}) | 344 | table_insert(schema, 1, {k, v}) |
| 344 | else | 345 | else |
| @@ -351,9 +352,16 @@ function ModelBaseMysql:checkTableSchema() | @@ -351,9 +352,16 @@ function ModelBaseMysql:checkTableSchema() | ||
| 351 | for _, tbl in ipairs(schema) do | 352 | for _, tbl in ipairs(schema) do |
| 352 | local k, v = tbl[1], tbl[2] | 353 | local k, v = tbl[1], tbl[2] |
| 353 | local objType, def, keyType, length = table_unpack(v) | 354 | local objType, def, keyType, length = table_unpack(v) |
| 355 | + local isAutoPriKey = false | ||
| 354 | assert(typeMap[objType], string_format("schema invalid type, %s, %s", tbName, k)) | 356 | assert(typeMap[objType], string_format("schema invalid type, %s, %s", tbName, k)) |
| 355 | -- 主键使用bigint存储 | 357 | -- 主键使用bigint存储 |
| 356 | if keyType == "pri" then objType = "pri" end | 358 | if keyType == "pri" then objType = "pri" end |
| 359 | + if keyType == "pri" or keyType == "pri_auto" then | ||
| 360 | + objType = "pri" | ||
| 361 | + if keyType == "pri_auto" then | ||
| 362 | + isAutoPriKey = true | ||
| 363 | + end | ||
| 364 | + end | ||
| 357 | 365 | ||
| 358 | local info = typeMap[objType] | 366 | local info = typeMap[objType] |
| 359 | local suffix = "" | 367 | local suffix = "" |
| @@ -370,7 +378,11 @@ function ModelBaseMysql:checkTableSchema() | @@ -370,7 +378,11 @@ function ModelBaseMysql:checkTableSchema() | ||
| 370 | def = "NULL" | 378 | def = "NULL" |
| 371 | end | 379 | end |
| 372 | 380 | ||
| 373 | - field_str = field_str .. string.format(field_tpl_str..",", k, fieldType, suffix, def) | 381 | + if not isAutoPriKey then |
| 382 | + field_str = field_str .. string.format(field_tpl_str..",", k, fieldType, suffix, def) | ||
| 383 | + else | ||
| 384 | + field_str = field_str .. string.format(auto_increment_str..",", k, fieldType) | ||
| 385 | + end | ||
| 374 | end | 386 | end |
| 375 | 387 | ||
| 376 | assert(self.pri_key, string_format("table not include primary key, [%s]", tbName)) | 388 | assert(self.pri_key, string_format("table not include primary key, [%s]", tbName)) |
| @@ -379,6 +391,7 @@ function ModelBaseMysql:checkTableSchema() | @@ -379,6 +391,7 @@ function ModelBaseMysql:checkTableSchema() | ||
| 379 | index_key_str = index_key_str .. string_format(index_tpl_str, k, k) | 391 | index_key_str = index_key_str .. string_format(index_tpl_str, k, k) |
| 380 | end | 392 | end |
| 381 | -- 创建表格 | 393 | -- 创建表格 |
| 394 | + print(string_format(create_sql, tbName, field_str, self.pri_key, index_key_str)) | ||
| 382 | mysqlproxy:query(string_format(create_sql, tbName, field_str, self.pri_key, index_key_str)) | 395 | mysqlproxy:query(string_format(create_sql, tbName, field_str, self.pri_key, index_key_str)) |
| 383 | else -- 检测是否有添加新字段 | 396 | else -- 检测是否有添加新字段 |
| 384 | local addCol = {} | 397 | local addCol = {} |
| @@ -388,9 +401,6 @@ function ModelBaseMysql:checkTableSchema() | @@ -388,9 +401,6 @@ function ModelBaseMysql:checkTableSchema() | ||
| 388 | end | 401 | end |
| 389 | for k, v in pairs(self.class.schema) do | 402 | for k, v in pairs(self.class.schema) do |
| 390 | local objType, def, keyType, length = table_unpack(v) | 403 | local objType, def, keyType, length = table_unpack(v) |
| 391 | - if keyType == "pri" then | ||
| 392 | - self.pri_key = k | ||
| 393 | - end | ||
| 394 | if not curCols[k] then | 404 | if not curCols[k] then |
| 395 | print(string_format("table [%s] add new column [%s]", tbName, k)) | 405 | print(string_format("table [%s] add new column [%s]", tbName, k)) |
| 396 | assert(typeMap[objType], string_format("schema invalid type, [%s], [%s]", tbName, k)) | 406 | assert(typeMap[objType], string_format("schema invalid type, [%s], [%s]", tbName, k)) |
src/shared/mysqlproxy.lua
| @@ -31,4 +31,23 @@ setmetatable(mysqlproxy, { __index = function(t, k) | @@ -31,4 +31,23 @@ setmetatable(mysqlproxy, { __index = function(t, k) | ||
| 31 | return f | 31 | return f |
| 32 | end}) | 32 | end}) |
| 33 | 33 | ||
| 34 | +function mysqlproxy:insertEmail(params) | ||
| 35 | + local pms = { | ||
| 36 | + key = string.format("%s", 0), | ||
| 37 | + roleId = params.roleId, | ||
| 38 | + emailId = params.emailId, | ||
| 39 | + createtime = params.createtime or skynet.timex(), | ||
| 40 | + contentPms = params.contentPms or {}, | ||
| 41 | + rewardPms = params.rewardPms or {}, | ||
| 42 | + title = params.title or "", | ||
| 43 | + stitle = params.stitle or "", | ||
| 44 | + content = params.content or "", | ||
| 45 | + attachments = params.attachments or "", | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + local email = require("models.Email").new(pms) | ||
| 49 | + email:create() | ||
| 50 | + return true | ||
| 51 | +end | ||
| 52 | + | ||
| 34 | return mysqlproxy | 53 | return mysqlproxy |
| 35 | \ No newline at end of file | 54 | \ No newline at end of file |