origin_video_titles.lua 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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","pay_type","title_type_id"},msg_body)
  21. if not isok then
  22. return false,string.format("缺少字段: %s.", key)
  23. end
  24. local pay_type = msg_body.pay_type
  25. local title_type_id = msg_body.title_type_id
  26. for i = 1, #msg_body.title_list, 1 do
  27. local title_tab = msg_body.title_list[i]
  28. local sql = string.format("INSERT INTO `video_titles` (title,md5_tag,pay_type,title_type_id) VALUES ('%s','%s' ,%d,%d)",title_tab.title,title_tab.md5_tag,pay_type,title_type_id)
  29. mysqldbx.query(sql)
  30. skynet.error("sql:",sql)
  31. sql = string.format("DELETE FROM origin_video_titles WHERE id = %d ",title_tab.id)
  32. mysqldbx.query(sql)
  33. end
  34. return true, {}
  35. end
  36. function M.search_origin_video_titles(msg_body)
  37. local isok ,key = tools.checkData({"page_size","page_number","content","start_create_time",
  38. "end_create_time"},msg_body)
  39. if not isok then
  40. return false,string.format("缺少字段: %s.", key)
  41. end
  42. local page_size = msg_body.page_size
  43. local page_number = msg_body.page_number
  44. local offset = (page_number - 1) * page_size
  45. local content_param = ""
  46. if msg_body.content~="" then
  47. content_param = string.format(" AND ( title LIKE CONCAT( '%%%s%%')) ",msg_body.content)
  48. end
  49. local create_date_param = ""
  50. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  51. 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) .. "))"
  52. end
  53. 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)
  54. local list = mysqldbx.query(sql)
  55. 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)
  56. local total = mysqldbx.query(sql)
  57. return true,list,total[1].total
  58. end
  59. return M