yw_book.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.get_all_yw_key()
  8. local sql = "SELECT * FROM yw_book_config "
  9. local res = mysqldbx.query(sql)
  10. return true,res
  11. end
  12. function M.add_yw_book_open_sessid(msg_body)
  13. local isok ,key = tools.checkData({"open_sessid","name"},msg_body)
  14. if not isok then
  15. return false,string.format("缺少字段: %s.", key)
  16. end
  17. local sql = string.format("SELECT * FROM yw_book_config WHERE open_sessid = '%s' LIMIT 1", msg_body.open_sessid)
  18. local isok,res;
  19. res = mysqldbx.query(sql)
  20. if #res > 0 then
  21. return false ,"open_sessid :"..msg_body.open_sessid.." 已存在!"
  22. end
  23. sql = string.format("INSERT INTO `yw_book_config` (open_sessid,name) VALUES ('%s','%s')",msg_body.open_sessid,msg_body.name)
  24. mysqldbx.query(sql)
  25. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateYwKeyList"}))
  26. return true, {}
  27. end
  28. function M.modify_yw_book_open_sessid(msg_body)
  29. local isok ,key = tools.checkData({"open_sessid","id","name"},msg_body)
  30. if not isok then
  31. return false,string.format("缺少字段: %s.", key)
  32. end
  33. local sql = string.format("UPDATE yw_book_config SET open_sessid = '%s' , name = '%s' WHERE id =%d ",msg_body.open_sessid,msg_body.name,msg_body.id)
  34. mysqldbx.query(sql)
  35. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateYwKeyList"}))
  36. return true, {}
  37. end
  38. function M.get_list(msg_body)
  39. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  40. if not isok then
  41. return false,string.format("缺少字段: %s.", key)
  42. end
  43. local page_size = msg_body.page_size
  44. local page_number = msg_body.page_number
  45. local offset = (page_number - 1) * page_size
  46. local sql = "SELECT * FROM yw_book_config "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  47. local list = mysqldbx.query(sql)
  48. sql = "SELECT COUNT(*) AS total FROM yw_book_config "
  49. local total = mysqldbx.query(sql)
  50. return true,list,total[1].total
  51. end
  52. return M