origin_video_titles.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. sql = string.format("DELETE FROM origin_video_titles WHERE id = %d ",title_tab.id)
  31. mysqldbx.query(sql)
  32. end
  33. return true, {}
  34. end
  35. function M.search_origin_video_titles(msg_body)
  36. local isok ,key = tools.checkData({"page_size","page_number","content","start_create_time",
  37. "end_create_time"},msg_body)
  38. if not isok then
  39. return false,string.format("缺少字段: %s.", key)
  40. end
  41. local page_size = msg_body.page_size
  42. local page_number = msg_body.page_number
  43. local offset = (page_number - 1) * page_size
  44. local content_param = ""
  45. if msg_body.content~="" then
  46. content_param = string.format(" AND ( title LIKE CONCAT( '%%%s%%')) ",msg_body.content)
  47. end
  48. local create_date_param = ""
  49. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  50. 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) .. "))"
  51. end
  52. 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)
  53. local list = mysqldbx.query(sql)
  54. 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)
  55. local total = mysqldbx.query(sql)
  56. return true,list,total[1].total
  57. end
  58. return M