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