12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- --阅文
- local M = {}
- local mysqldbx = require "mysqldbx"
- local tools = require "tools"
- local skynet = require "skynet"
- local cjson = require "cjson"
- function M.get_all_yw_key()
- local sql = "SELECT * FROM yw_book_config "
- local res = mysqldbx.query(sql)
- return true,res
- end
- function M.add_yw_book_open_sessid(msg_body)
- local isok ,key = tools.checkData({"open_sessid","name"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("SELECT * FROM yw_book_config WHERE open_sessid = '%s' LIMIT 1", msg_body.open_sessid)
- local isok,res;
- res = mysqldbx.query(sql)
- if #res > 0 then
- return false ,"open_sessid :"..msg_body.open_sessid.." 已存在!"
- end
- sql = string.format("INSERT INTO `yw_book_config` (open_sessid,name) VALUES ('%s','%s')",msg_body.open_sessid,msg_body.name)
- mysqldbx.query(sql)
- skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateYwKeyList"}))
- return true, {}
- end
- function M.modify_yw_book_open_sessid(msg_body)
- local isok ,key = tools.checkData({"open_sessid","id","name"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("UPDATE yw_book_config SET open_sessid = '%s' , name = '%s' WHERE id =%d ",msg_body.open_sessid,msg_body.name,msg_body.id)
- mysqldbx.query(sql)
- skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateYwKeyList"}))
- return true, {}
- end
- function M.get_list(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 sql = "SELECT * FROM yw_book_config "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
- local list = mysqldbx.query(sql)
- sql = "SELECT COUNT(*) AS total FROM yw_book_config "
- local total = mysqldbx.query(sql)
- return true,list,total[1].total
- end
- return M
|