fq_book.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --番茄
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. function M.add_fq_book_sid_tt(msg_body)
  7. local isok ,key = tools.checkData({"sid_tt","name"},msg_body)
  8. if not isok then
  9. return false,string.format("缺少字段: %s.", key)
  10. end
  11. local sql = string.format("SELECT * FROM fq_book_config WHERE sid_tt = '%s' LIMIT 1", msg_body.sid_tt)
  12. local isok,res;
  13. res = mysqldbx.query(sql)
  14. if #res > 0 then
  15. return false ,"sid_tt :"..msg_body.sid_tt.." 已存在!"
  16. end
  17. sql = string.format("INSERT INTO `fq_book_config` (sid_tt,name) VALUES ('%s','%s')",msg_body.sid_tt,msg_body.name)
  18. mysqldbx.query(sql)
  19. return true, {}
  20. end
  21. function M.delete_fq_book_sid_tt(msg_body)
  22. local isok ,key = tools.checkData({"sid_tt"},msg_body)
  23. if not isok then
  24. return false,string.format("缺少字段: %s.", key)
  25. end
  26. local sql = string.format("DELETE FROM fq_book_config WHERE sid_tt = '%s' ",msg_body.sid_tt)
  27. mysqldbx.query(sql)
  28. return true, {}
  29. end
  30. function M.fq_book_list(msg_body)
  31. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  32. if not isok then
  33. return false,string.format("缺少字段: %s.", key)
  34. end
  35. local page_size = msg_body.page_size
  36. local page_number = msg_body.page_number
  37. local offset = (page_number - 1) * page_size
  38. local sql = "SELECT * FROM fq_book_config "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  39. local list = mysqldbx.query(sql)
  40. sql = "SELECT COUNT(*) AS total FROM fq_book_config "
  41. local total = mysqldbx.query(sql)
  42. return true,list,total[1].total
  43. end
  44. return M