origin_video_titles.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --视频标题
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. local md5 = require "md5"
  7. function M.delete_origin_video_titles(msg_body)
  8. local isok ,key = tools.checkData({"id_list"},msg_body)
  9. if not isok then
  10. return false,string.format("缺少字段: %s.", key)
  11. end
  12. for i = 1, #msg_body.id_list, 1 do
  13. local id = msg_body.id_list[i]
  14. local sql = string.format("DELETE FROM origin_video_titles WHERE id = %d ",id)
  15. mysqldbx.query(sql)
  16. end
  17. return true, {}
  18. end
  19. function M.publish_origin_video_titles(msg_body)
  20. local isok ,key = tools.checkData({"id_list"},msg_body)
  21. if not isok then
  22. return false,string.format("缺少字段: %s.", key)
  23. end
  24. for i = 1, #msg_body.title_list, 1 do
  25. local title_tab = msg_body.title_list[i]
  26. local sql = string.format("INSERT INTO `video_titles` (title,md5_tag) VALUES ('%s','%s')",title_tab.title,title_tab.md5_tag)
  27. mysqldbx.query(sql)
  28. sql = string.format("DELETE FROM origin_video_titles WHERE id = %d ",title_tab.id)
  29. mysqldbx.query(sql)
  30. end
  31. return true, {}
  32. end
  33. function M.search_origin_video_titles(msg_body)
  34. local isok ,key = tools.checkData({"page_size","page_number","content","start_create_time","end_create_time"},msg_body)
  35. if not isok then
  36. return false,string.format("缺少字段: %s.", key)
  37. end
  38. local page_size = msg_body.page_size
  39. local page_number = msg_body.page_number
  40. local offset = (page_number - 1) * page_size
  41. local create_date_param = ""
  42. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  43. create_date_param = " AND DATE(create_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_create_time / 1000) .. ")) AND DATE(create_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_create_time / 1000) .. "))"
  44. end
  45. local sql = "SELECT * FROM origin_video_titles WHERE 1=1 "..create_date_param..string.format(" AND (title LIKE CONCAT( '%%%s%%')) ",msg_body.content)..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  46. local list = mysqldbx.query(sql)
  47. sql = "SELECT COUNT(*) AS total FROM origin_video_titles WHERE 1=1 "..create_date_param..string.format(" AND (title LIKE CONCAT( '%%%s%%')) ",msg_body.content)
  48. local total = mysqldbx.query(sql)
  49. return true,list,total[1].total
  50. end
  51. return M