1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- --番茄
- local M = {}
- local mysqldbx = require "mysqldbx"
- local tools = require "tools"
- local skynet = require "skynet"
- local cjson = require "cjson"
- function M.get_all_fq_key()
- local sql = "SELECT * FROM fq_book_config "
- local res = mysqldbx.query(sql)
- return true,res
- end
- function M.add_fq_book_sid_tt(msg_body)
- local isok ,key = tools.checkData({"sid_tt","name"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("SELECT * FROM fq_book_config WHERE sid_tt = '%s' LIMIT 1", msg_body.sid_tt)
- local isok,res;
- res = mysqldbx.query(sql)
- if #res > 0 then
- return false ,"sid_tt :"..msg_body.sid_tt.." 已存在!"
- end
- sql = string.format("INSERT INTO `fq_book_config` (sid_tt,name) VALUES ('%s','%s')",msg_body.sid_tt,msg_body.name)
- mysqldbx.query(sql)
- skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateFqKeyList"}))
- return true, {}
- end
- function M.delete_fq_book_sid_tt(msg_body)
- local isok ,key = tools.checkData({"sid_tt"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("DELETE FROM fq_book_config WHERE sid_tt = '%s' ",msg_body.sid_tt)
- mysqldbx.query(sql)
- skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateFqKeyList"}))
- return true, {}
- end
- function M.set_use_status(msg_body)
- local isok ,key = tools.checkData({"canUse","id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("UPDATE fq_book_config SET canUse = %d WHERE id =%d ",msg_body.canUse,msg_body.id)
- mysqldbx.query(sql)
- skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateFqKeyList"}))
- return true, {}
- end
- function M.fq_book_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 fq_book_config "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
- local list = mysqldbx.query(sql)
- sql = "SELECT COUNT(*) AS total FROM fq_book_config "
- local total = mysqldbx.query(sql)
- return true,list,total[1].total
- end
- return M
|