other_book.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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","product_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 product_id_param = ""
  28. if msg_body.product_id~="" then
  29. product_id_param = string.format(" AND product_id = '%s' " ,msg_body.product_id )
  30. end
  31. local tg_platform_id_param = ""
  32. if msg_body.tg_platform_id~="" then
  33. tg_platform_id_param = " AND tg_platform_id = "..msg_body.tg_platform_id.." "
  34. end
  35. local param = product_id_param..tg_platform_id_param
  36. local sql = "SELECT * FROM other_book where 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  37. local list = mysqldbx.query(sql)
  38. sql = "SELECT COUNT(*) AS total FROM other_book where 1=1 "..param
  39. local total = mysqldbx.query(sql)
  40. return true,list,total[1].total
  41. end
  42. return M