tf_product_selling_points_tpl.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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","selling_points","call_to_action_buttons","status"},msg_body)
  8. if not isok then
  9. return false,string.format("缺少字段: %s.", key)
  10. end
  11. local sql = string.format("INSERT INTO `tf_product_selling_points_tpl` (name,selling_points,call_to_action_buttons,status) VALUES ('%s','%s','%s',%d)",msg_body.name,msg_body.selling_points,msg_body.call_to_action_buttons,msg_body.status)
  12. skynet.error(sql)
  13. mysqldbx.query(sql)
  14. return true, {}
  15. end
  16. function M.modify(msg_body)
  17. local isok ,key = tools.checkData({"name","selling_points","call_to_action_buttons","status","id"},msg_body)
  18. if not isok then
  19. return false,string.format("缺少字段: %s.", key)
  20. end
  21. local sql = string.format("UPDATE tf_product_selling_points_tpl SET name = '%s' , selling_points = '%s' , call_to_action_buttons = '%s' , status = %d WHERE id = %d ",msg_body.name,msg_body.selling_points,msg_body.call_to_action_buttons,msg_body.status,msg_body.id)
  22. mysqldbx.query(sql)
  23. return true, {}
  24. end
  25. function M.search(msg_body)
  26. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  27. if not isok then
  28. return false,string.format("缺少字段: %s.", key)
  29. end
  30. local page_size = msg_body.page_size
  31. local page_number = msg_body.page_number
  32. local offset = (page_number - 1) * page_size
  33. local sql = "SELECT * FROM tf_product_selling_points_tpl "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  34. local list = mysqldbx.query(sql)
  35. sql = "SELECT COUNT(*) AS total FROM tf_product_selling_points_tpl "
  36. local total = mysqldbx.query(sql)
  37. return true,list,total[1].total
  38. end
  39. return M