statistics_platform.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --统计平台
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. function M.add_platform(msg_body)
  7. local isok ,key = tools.checkData({"zd_boost_number","tg_platform_name","tg_platform_id"},msg_body)
  8. if not isok then
  9. return false,string.format("缺少字段: %s.", key)
  10. end
  11. 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)
  12. mysqldbx.query(sql)
  13. return true, {}
  14. end
  15. function M.modify(msg_body)
  16. local isok ,key = tools.checkData({"zd_boost_number","tg_platform_name","id","tg_platform_id"},msg_body)
  17. if not isok then
  18. return false,string.format("缺少字段: %s.", key)
  19. end
  20. 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)
  21. mysqldbx.query(sql)
  22. return true, {}
  23. end
  24. function M.search(msg_body)
  25. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  26. if not isok then
  27. return false,string.format("缺少字段: %s.", key)
  28. end
  29. local page_size = msg_body.page_size
  30. local page_number = msg_body.page_number
  31. local offset = (page_number - 1) * page_size
  32. local sql = "SELECT * FROM statistics_platform "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  33. local list = mysqldbx.query(sql)
  34. sql = "SELECT COUNT(*) AS total FROM statistics_platform "
  35. local total = mysqldbx.query(sql)
  36. return true,list,total[1].total
  37. end
  38. return M