--管家 local M = {} local mysqldbx = require "mysqldbx" local tools = require "tools" local skynet = require "skynet" local cjson = require "cjson" -- function M.add_butler(msg_body) -- local isok ,key = tools.checkData({"butler_name","butler_id","mail"},msg_body) -- if not isok then -- return false,string.format("缺少字段: %s.", key) -- end -- local sql = string.format("INSERT INTO `tg_butler` (butler_name,butler_id,mail) VALUES ('%s',%d,'%s')", -- msg_body.butler_name, msg_body.butler_id, msg_body.mail) -- mysqldbx.query(sql) -- return true -- end function M.modify_butler(msg_body) local isok ,key = tools.checkData({"butler_name","cc_account_id","mail","id","tg_platform_ids"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("UPDATE `advertiser_butler` SET name = '%s', cc_account_id = %d ,email = '%s' , tg_platform_ids = '%s' WHERE id = %d ", msg_body.butler_name,msg_body.cc_account_id,msg_body.mail,msg_body.tg_platform_ids,msg_body.id) skynet.error("sql:",sql) mysqldbx.query(sql) return true end function M.search_butler(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 advertiser_butler WHERE 1=1 "..string.format(" LIMIT %d OFFSET %d ",page_size, offset) local list = mysqldbx.query(sql) sql = "SELECT COUNT(*) AS total FROM advertiser_butler WHERE 1=1 " local total = mysqldbx.query(sql) return true,list,total[1].total end return M