material_review.lua 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --素材审核表
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. local mysql = require "skynet.db.mysql"
  7. local config = require "run_config"
  8. local cjson = require "cjson"
  9. local db
  10. local mysqldtaskbx = {}
  11. function M.search(msg_body)
  12. local isok ,key = tools.checkData({"page_size","page_number","material_id","oce_material_id",
  13. "is_sexual_inducement_content","is_bad_value_view","start_time_date","end_time_date"},msg_body)
  14. if not isok then
  15. return false,string.format("缺少字段: %s.", key)
  16. end
  17. local page_size = msg_body.page_size
  18. local page_number = msg_body.page_number
  19. local offset = (page_number - 1) * page_size
  20. local material_id_param = ""
  21. if msg_body.material_id~="" then
  22. material_id_param = string.format(" AND material_id = %d ",tonumber(msg_body.material_id))
  23. end
  24. local oce_material_param = ""
  25. if msg_body.oce_material_id~="" then
  26. oce_material_param =string.format("AND oce_material_id = %d ",tonumber(msg_body.oce_material_id))
  27. end
  28. local is_sexual_inducement_content_param = ""
  29. if msg_body.is_sexual_inducement_content~="" then
  30. is_sexual_inducement_content_param = "AND is_sexual_inducement_content = "..msg_body.is_sexual_inducement_content.." "
  31. end
  32. local is_bad_value_view_param = ""
  33. if msg_body.is_bad_value_view~="" then
  34. is_bad_value_view_param = "AND is_bad_value_view = "..msg_body.is_bad_value_view.." "
  35. end
  36. local date_param = ""
  37. if msg_body.start_time_date~="" and msg_body.end_time_date~="" then
  38. date_param = " AND DATE(create_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_time_date / 1000) .. ")) AND DATE(create_at) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_time_date / 1000) .. "))"
  39. end
  40. local param = material_id_param..oce_material_param..is_sexual_inducement_content_param..is_bad_value_view_param..date_param
  41. local sql = "SELECT * FROM video_material_review where 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  42. skynet.error("sql:",sql)
  43. local list = mysqldtaskbx.Singleton().query(sql)
  44. sql = "SELECT COUNT(*) AS total FROM video_material_review where 1=1 "..param
  45. local total = mysqldtaskbx.Singleton().query(sql)
  46. return true,list,total[1].total
  47. end
  48. function mysqldtaskbx.start()
  49. local function on_connect(db)
  50. db:query("set charset utf8mb4");
  51. end
  52. local conf = config.db_cnf.book_server.mysqldb_material_review_cnf
  53. db = mysql.connect{
  54. host=conf.ip,
  55. port=conf.port,
  56. database=conf.db,
  57. user=conf.user,
  58. password=conf.password,
  59. charset="utf8mb4",
  60. max_packet_size = 1024 * 1024,
  61. on_connect = on_connect
  62. }
  63. if not db then
  64. skynet.error("mysql connect fail")
  65. end
  66. end
  67. function mysqldtaskbx.Singleton()
  68. if db == nil then
  69. mysqldtaskbx.start()
  70. end
  71. return mysqldtaskbx
  72. end
  73. function mysqldtaskbx.query(sql)
  74. return db:query(sql)
  75. end
  76. return M