--管家 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({"white_advertiser_id","advertiser_ids","oce_product_id","oce_product_platform_id","advertiser_id","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 white_advertiser_id = %d , advertiser_ids = '%s' , advertiser_id = %d ,name = '%s', cc_account_id = %d ,email = '%s' , tg_platform_ids = '%s' ,oce_product_id = '%s' , oce_product_platform_id = '%s' WHERE id = %d ", msg_body.white_advertiser_id,cjson.encode(msg_body.advertiser_ids),msg_body.advertiser_id,msg_body.butler_name,msg_body.cc_account_id,msg_body.mail,msg_body.tg_platform_ids,msg_body.oce_product_id,msg_body.oce_product_platform_id,msg_body.id) skynet.error("sql:",sql) mysqldbx.query(sql) return true end function M.search_butler(msg_body) local isok ,key = tools.checkData({"name","id","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 name_param = "" if msg_body.name~="" then name_param = string.format(" AND (name LIKE CONCAT( '%%%s%%')) ",msg_body.name) end local id_param = "" if msg_body.id~="" then id_param = string.format(" AND id = %d ",msg_body.id) end param = name_param..id_param local sql = "SELECT * FROM advertiser_butler WHERE 1=1 "..param..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 "..param skynet.error(sql) local total = mysqldbx.query(sql) return true,list,total[1].total end return M