tf_region_tpl.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --投放地区模版
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. function M.add(msg_body)
  7. local isok ,key = tools.checkData({"name","city","location_type","region_version"},msg_body)
  8. if not isok then
  9. return false,string.format("缺少字段: %s.", key)
  10. end
  11. local sql = string.format("INSERT INTO `tf_region_tpl` (name,city,location_type,region_version) VALUES ('%s','%s','%s','%s')",msg_body.name,msg_body.city,msg_body.location_type,msg_body.region_version)
  12. mysqldbx.query(sql)
  13. return true, {}
  14. end
  15. function M.modify(msg_body)
  16. local isok ,key = tools.checkData({"name","city","location_type","region_version","id"},msg_body)
  17. if not isok then
  18. return false,string.format("缺少字段: %s.", key)
  19. end
  20. local sql = string.format("UPDATE tf_region_tpl SET name = '%s' , city = '%s' ,location_type = '%s' , region_version = '%s' WHERE id = %d ",msg_body.name,msg_body.city,msg_body.location_type,msg_body.region_version,msg_body.id)
  21. mysqldbx.query(sql)
  22. return true, {}
  23. end
  24. function M.search(msg_body)
  25. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  26. if not isok then
  27. return false,string.format("缺少字段: %s.", key)
  28. end
  29. local page_size = msg_body.page_size
  30. local page_number = msg_body.page_number
  31. local offset = (page_number - 1) * page_size
  32. local sql = "SELECT * FROM tf_region_tpl where 1=1 "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  33. local list = mysqldbx.query(sql)
  34. sql = "SELECT COUNT(*) AS total FROM tf_region_tpl "
  35. local total = mysqldbx.query(sql)
  36. return true,list,total[1].total
  37. end
  38. return M