--投放产品卖点模版 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","selling_points","call_to_action_buttons","status"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("INSERT INTO `tf_product_selling_points_tpl` (name,selling_points,call_to_action_buttons,status) VALUES ('%s','%s','%s',%d)",msg_body.name,msg_body.selling_points,msg_body.call_to_action_buttons,msg_body.status) skynet.error(sql) mysqldbx.query(sql) return true, {} end function M.modify(msg_body) local isok ,key = tools.checkData({"name","selling_points","call_to_action_buttons","status","id"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("UPDATE tf_product_selling_points_tpl SET name = '%s' , selling_points = '%s' , call_to_action_buttons = '%s' , status = %d WHERE id = %d ",msg_body.name,msg_body.selling_points,msg_body.call_to_action_buttons,msg_body.status,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_product_selling_points_tpl "..string.format(" LIMIT %d OFFSET %d ",page_size, offset) local list = mysqldbx.query(sql) sql = "SELECT COUNT(*) AS total FROM tf_product_selling_points_tpl " local total = mysqldbx.query(sql) return true,list,total[1].total end return M