video_titles.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.add_video_title(msg_body)
  8. local isok ,key = tools.checkData({"title_list","pay_type","title_type_id"},msg_body)
  9. if not isok then
  10. return false,string.format("缺少字段: %s.", key)
  11. end
  12. local pay_type = msg_body.pay_type
  13. local title_type_id = msg_body.title_type_id
  14. for i = 1, #msg_body.title_list, 1 do
  15. local title = msg_body.title_list[i].title
  16. local md5_tag = msg_body.title_list[i].md5_tag
  17. local sql = string.format("SELECT * FROM video_titles WHERE md5_tag = '%s' LIMIT 1", md5_tag)
  18. local isok,res;
  19. res = mysqldbx.query(sql)
  20. if #res > 0 then
  21. -- return false, string.format("没有这个md5 %s.", md5_tag)
  22. else
  23. sql = string.format("INSERT INTO `video_titles` (title,md5_tag,pay_type,title_type_id) VALUES ('%s','%s',%d,%d)",title,md5_tag,pay_type,title_type_id)
  24. res = mysqldbx.query(sql)
  25. end
  26. end
  27. return true, {}
  28. end
  29. function M.delete_video_title(msg_body)
  30. local isok ,key = tools.checkData({"id_list"},msg_body)
  31. if not isok then
  32. return false,string.format("缺少字段: %s.", key)
  33. end
  34. for i = 1, #msg_body.id_list, 1 do
  35. local id = msg_body.id_list[i]
  36. local sql = string.format("DELETE FROM video_titles WHERE id = %d ",id)
  37. mysqldbx.query(sql)
  38. end
  39. return true, {}
  40. end
  41. function M.modify_video_title(msg_body)
  42. local isok ,key = tools.checkData({"title","md5_tag","id","pay_type","title_type_id"},msg_body)
  43. if not isok then
  44. return false,string.format("缺少字段: %s.", key)
  45. end
  46. local sql = string.format("UPDATE video_titles SET title_type_id = %d , pay_type = %d , title = '%s' , md5_tag = '%s' WHERE id = %d ",msg_body.title_type_id,msg_body.pay_type,msg_body.title,msg_body.md5_tag,msg_body.id)
  47. mysqldbx.query(sql)
  48. return true, {}
  49. end
  50. function M.modify_pay_type(msg_body)
  51. local isok ,key = tools.checkData({"id_list","pay_type"},msg_body)
  52. if not isok then
  53. return false,string.format("缺少字段: %s.", key)
  54. end
  55. local idString = table.concat(msg_body.id_list, ",")
  56. sql = string.format("UPDATE `video_titles` SET pay_type = %d WHERE id IN (%s) ",msg_body.pay_type,idString)
  57. mysqldbx.query(sql)
  58. return true, {}
  59. end
  60. function M.modify_title_type_id(msg_body)
  61. local isok ,key = tools.checkData({"id_list","title_type_id"},msg_body)
  62. if not isok then
  63. return false,string.format("缺少字段: %s.", key)
  64. end
  65. local idString = table.concat(msg_body.id_list, ",")
  66. sql = string.format("UPDATE `video_titles` SET title_type_id = %d WHERE id IN (%s) ",msg_body.title_type_id,idString)
  67. mysqldbx.query(sql)
  68. return true, {}
  69. end
  70. function M.search_video_title(msg_body)
  71. local isok ,key = tools.checkData({"page_size","page_number","content","pay_type","title_type_id"},msg_body)
  72. if not isok then
  73. return false,string.format("缺少字段: %s.", key)
  74. end
  75. local page_size = msg_body.page_size
  76. local page_number = msg_body.page_number
  77. local offset = (page_number - 1) * page_size
  78. local content_param = ""
  79. if msg_body.content~=""then
  80. content_param = string.format(" AND (title LIKE CONCAT( '%%%s%%')) ",msg_body.content)
  81. end
  82. local pay_type_param = ""
  83. if msg_body.pay_type~=""then
  84. pay_type_param = string.format(" AND pay_type = %d ",msg_body.pay_type)
  85. end
  86. local title_type_id_param = ""
  87. if msg_body.title_type_id~=""then
  88. title_type_id_param = string.format(" AND title_type_id = %d ",msg_body.title_type_id)
  89. end
  90. local param = content_param..pay_type_param..title_type_id_param
  91. local sql = "SELECT * FROM video_titles WHERE 1=1 "..param.." ORDER BY id DESC ".. string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  92. local list = mysqldbx.query(sql)
  93. sql = "SELECT COUNT(*) AS total FROM video_titles WHERE 1=1 "..param
  94. local total = mysqldbx.query(sql)
  95. return true,list,total[1].total
  96. end
  97. function M.initAll()
  98. local sql = "SELECT * FROM video_titles "
  99. local list = mysqldbx.query(sql)
  100. for i = 1, #list, 1 do
  101. if (list[i].md5_tag==nil) then
  102. local id = list[i].id
  103. local md5_tag =md5.sumhexa(list[i].title)
  104. skynet.error("md5_tag:",md5_tag)
  105. sql = string.format("UPDATE video_titles SET md5_tag = '%s' WHERE id = %d ",md5_tag,id)
  106. mysqldbx.query(sql)
  107. end
  108. end
  109. return true,{}
  110. end
  111. return M