--投放地区模版 local M = {} local mysqldbx = require "mysqldbx" local tools = require "tools" local skynet = require "skynet" function M.add(msg_body) local isok ,key = tools.checkData({"name","city","location_type","region_version"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("INSERT INTO `tf_region_tpl` (name,city,location_type,region_version) VALUES ('%s','%s','%s','%s')",msg_body.name,msg_body.city,msg_body.location_type,msg_body.region_version) mysqldbx.query(sql) return true, {} end function M.modify(msg_body) local isok ,key = tools.checkData({"name","city","location_type","region_version","id"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("UPDATE tf_region_tpl SET name = '%s' , city = '%s' ,location_type = '%s' , region_version = '%s' WHERE id = %d ",msg_body.name,msg_body.city,msg_body.location_type,msg_body.region_version,msg_body.id) mysqldbx.query(sql) return true, {} end function M.search(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 tf_region_tpl where 1=1 "..string.format(" LIMIT %d OFFSET %d ",page_size, offset) local list = mysqldbx.query(sql) sql = "SELECT COUNT(*) AS total FROM tf_region_tpl " local total = mysqldbx.query(sql) return true,list,total[1].total end return M