tg_mini_program_platform.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.add_tg_mini_program_platform(msg_body)
  8. local isok ,key = tools.checkData({"mini_program_platform_name","mini_program_platform_id"},msg_body)
  9. if not isok then
  10. return false,string.format("缺少字段: %s.", key)
  11. end
  12. local sql = string.format("INSERT INTO `tg_mini_program_platform` (mini_program_platform_name,mini_program_platform_id) VALUES ('%s',%d)",
  13. msg_body.mini_program_platform_name, msg_body.mini_program_platform_id)
  14. mysqldbx.query(sql)
  15. return true
  16. end
  17. function M.modify_tg_mini_program_platform(msg_body)
  18. local isok ,key = tools.checkData({"mini_program_platform_name","mini_program_platform_id","id"},msg_body)
  19. if not isok then
  20. return false,string.format("缺少字段: %s.", key)
  21. end
  22. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  23. msg_body.update_time = current_time
  24. local sql = string.format("UPDATE `tg_mini_program_platform` SET mini_program_platform_name = '%s' , mini_program_platform_id = %d WHERE id = %d ",
  25. msg_body.mini_program_platform_name,msg_body.mini_program_platform_id,msg_body.id)
  26. mysqldbx.query(sql)
  27. return true
  28. end
  29. function M.search_tg_mini_program_platform(msg_body)
  30. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  31. if not isok then
  32. return false,string.format("缺少字段: %s.", key)
  33. end
  34. local page_size = msg_body.page_size
  35. local page_number = msg_body.page_number
  36. local offset = (page_number - 1) * page_size
  37. local sql = "SELECT * FROM tg_mini_program_platform WHERE 1=1 "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  38. local list = mysqldbx.query(sql)
  39. sql = "SELECT COUNT(*) AS total FROM tg_mini_program_platform WHERE 1=1 "
  40. local total = mysqldbx.query(sql)
  41. return true,list,total[1].total
  42. end
  43. return M