other_book.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --失败书籍
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. local cjson = require "cjson"
  7. function M.delete_other_book(msg_body)
  8. local isok ,key = tools.checkData({"id_list"},msg_body)
  9. if not isok then
  10. return false,string.format("缺少字段: %s.", key)
  11. end
  12. for i = 1, #msg_body.id_list, 1 do
  13. local id = msg_body.id_list[i]
  14. local sql = string.format("DELETE FROM other_book WHERE id = %d ",id)
  15. mysqldbx.query(sql)
  16. end
  17. return true, {}
  18. end
  19. function M.search_other_book(msg_body)
  20. local isok ,key = tools.checkData({"page_size","page_number","tg_platform_id"},msg_body)
  21. if not isok then
  22. return false,string.format("缺少字段: %s.", key)
  23. end
  24. local page_size = msg_body.page_size
  25. local page_number = msg_body.page_number
  26. local offset = (page_number - 1) * page_size
  27. local tg_platform_id_param = ""
  28. if msg_body.tg_platform_id~="" then
  29. tg_platform_id_param = " AND tg_platform_id = "..msg_body.tg_platform_id.." "
  30. end
  31. local sql = "SELECT * FROM other_book "..tg_platform_id_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  32. local list = mysqldbx.query(sql)
  33. sql = "SELECT COUNT(*) AS total FROM other_book "..tg_platform_id_param
  34. local total = mysqldbx.query(sql)
  35. return true,list,total[1].total
  36. end
  37. return M