fq_book.lua 2.5 KB

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