123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- --素材平台
- local M = {}
- local mysqldbx = require "mysqldbx"
- local tools = require "tools"
- local skynet = require "skynet"
- function M.add_platform(msg_body)
- local isok ,key = tools.checkData({"name","qc_num"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("INSERT INTO `material_platform` (name,qc_num) VALUES ('%s',%d)",msg_body.name,msg_body.qc_num)
- mysqldbx.query(sql)
- return true, {}
- end
- function M.modify(msg_body)
- local isok ,key = tools.checkData({"name","id","qc_num"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("UPDATE material_platform SET qc_num = %d , name = '%s' WHERE id = %d ",msg_body.qc_num,msg_body.name,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 material_platform "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
- local list = mysqldbx.query(sql)
- sql = "SELECT COUNT(*) AS total FROM material_platform "
- local total = mysqldbx.query(sql)
- return true,list,total[1].total
- end
- return M
|