platform_shared.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. --获取所有平台
  8. function M.gePlatformSharedList()
  9. local sql = string.format("select * from `platform_shared` ")
  10. local isok,res;
  11. res = mysqldbx.query(sql)
  12. if #res <= 0 then
  13. return true , {}
  14. end
  15. return true, res
  16. end
  17. function M.addPlatformShared(msg_body)
  18. local isok ,key = tools.checkData({"name","info"},msg_body)
  19. if not isok then
  20. return false,string.format("缺少字段: %s.", key)
  21. end
  22. local sql = string.format("INSERT INTO `platform_shared` (name,info) VALUES ('%s','%s')",msg_body.name,cjson.encode(msg_body.info))
  23. mysqldbx.query(sql)
  24. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
  25. return true, {}
  26. end
  27. function M.modifyPlatformShared(msg_body)
  28. local isok ,key = tools.checkData({"name","info","id"},msg_body)
  29. if not isok then
  30. return false,string.format("缺少字段: %s.", key)
  31. end
  32. local sql = string.format("UPDATE `platform_shared` SET name = '%s' , info = '%s' WHERE id = %d ",
  33. msg_body.name,
  34. cjson.encode(msg_body.info),
  35. msg_body.id)
  36. mysqldbx.query(sql)
  37. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
  38. return true, {}
  39. end
  40. function M.search_platform_shared(msg_body)
  41. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  42. if not isok then
  43. return false,string.format("缺少字段: %s.", key)
  44. end
  45. local page_size = msg_body.page_size
  46. local page_number = msg_body.page_number
  47. local offset = (page_number - 1) * page_size
  48. local param = ""
  49. local sql = "SELECT * FROM platform_shared where 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  50. local list = mysqldbx.query(sql)
  51. sql = "SELECT COUNT(*) AS total FROM platform_shared where 1=1 "..param
  52. local total = mysqldbx.query(sql)
  53. return true,list,total[1].total
  54. end
  55. return M