123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- --共享平台
- local M = {}
- local mysqldbx = require "mysqldbx"
- local tools = require "tools"
- local skynet = require "skynet"
- local cjson = require "cjson"
- --获取所有平台
- function M.gePlatformSharedList()
- local sql = string.format("select * from `platform_shared` ")
- local isok,res;
- res = mysqldbx.query(sql)
- if #res <= 0 then
- return true , {}
- end
- return true, res
- end
- function M.addPlatformShared(msg_body)
- local isok ,key = tools.checkData({"name","info"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("INSERT INTO `platform_shared` (name,info) VALUES ('%s','%s')",msg_body.name,cjson.encode(msg_body.info))
- mysqldbx.query(sql)
- skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
- return true, {}
- end
- function M.modifyPlatformShared(msg_body)
- local isok ,key = tools.checkData({"name","info","id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("UPDATE `platform_shared` SET name = '%s' , info = '%s' WHERE id = %d ",
- msg_body.name,
- cjson.encode(msg_body.info),
- msg_body.id)
- mysqldbx.query(sql)
- skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
- return true, {}
- end
- function M.search_platform_shared(msg_body)
- local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local page_size = msg_body.page_size
- local page_number = msg_body.page_number
- local offset = (page_number - 1) * page_size
-
- local param = ""
- local sql = "SELECT * FROM platform_shared where 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
- local list = mysqldbx.query(sql)
- sql = "SELECT COUNT(*) AS total FROM platform_shared where 1=1 "..param
- local total = mysqldbx.query(sql)
- return true,list,total[1].total
- end
- return M
|