origin_video_titles.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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({"title_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",
  35. "end_create_time"},msg_body)
  36. if not isok then
  37. return false,string.format("缺少字段: %s.", key)
  38. end
  39. local page_size = msg_body.page_size
  40. local page_number = msg_body.page_number
  41. local offset = (page_number - 1) * page_size
  42. local content_param = ""
  43. if msg_body.content~="" then
  44. content_param = string.format(" AND ( title LIKE CONCAT( '%%%s%%')) ",msg_body.content)
  45. end
  46. local create_date_param = ""
  47. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  48. 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) .. "))"
  49. end
  50. local sql = "SELECT * FROM origin_video_titles WHERE 1=1 "..create_date_param..content_param..string.format(" AND (title LIKE CONCAT( '%%%s%%')) ",msg_body.content).." ORDER BY id DESC "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  51. local list = mysqldbx.query(sql)
  52. sql = "SELECT COUNT(*) AS total FROM origin_video_titles WHERE 1=1 "..create_date_param..content_param..string.format(" AND (title LIKE CONCAT( '%%%s%%')) ",msg_body.content)
  53. local total = mysqldbx.query(sql)
  54. return true,list,total[1].total
  55. end
  56. return M