123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- --视频标题
- local M = {}
- local mysqldbx = require "mysqldbx"
- local tools = require "tools"
- local skynet = require "skynet"
- local md5 = require "md5"
- function M.add_video_title(msg_body)
- local isok ,key = tools.checkData({"title_list","pay_type","title_type_id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local pay_type = msg_body.pay_type
- local title_type_id = msg_body.title_type_id
- for i = 1, #msg_body.title_list, 1 do
- local title = msg_body.title_list[i].title
- local md5_tag = msg_body.title_list[i].md5_tag
- local sql = string.format("SELECT * FROM video_titles WHERE md5_tag = '%s' LIMIT 1", md5_tag)
- local isok,res;
- res = mysqldbx.query(sql)
- if #res > 0 then
- -- return false, string.format("没有这个md5 %s.", md5_tag)
- else
- 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)
- res = mysqldbx.query(sql)
- end
- end
- return true, {}
- end
- function M.delete_video_title(msg_body)
- local isok ,key = tools.checkData({"id_list"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- for i = 1, #msg_body.id_list, 1 do
- local id = msg_body.id_list[i]
- local sql = string.format("DELETE FROM video_titles WHERE id = %d ",id)
- mysqldbx.query(sql)
- end
- return true, {}
- end
- function M.modify_video_title(msg_body)
- local isok ,key = tools.checkData({"title","md5_tag","id","pay_type","title_type_id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- 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)
- mysqldbx.query(sql)
- return true, {}
- end
- function M.modify_pay_type(msg_body)
- local isok ,key = tools.checkData({"id_list","pay_type"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local idString = table.concat(msg_body.id_list, ",")
- sql = string.format("UPDATE `video_titles` SET pay_type = %d WHERE id IN (%s) ",msg_body.pay_type,idString)
- mysqldbx.query(sql)
- return true, {}
- end
- function M.modify_title_type_id(msg_body)
- local isok ,key = tools.checkData({"id_list","title_type_id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local idString = table.concat(msg_body.id_list, ",")
- sql = string.format("UPDATE `video_titles` SET title_type_id = %d WHERE id IN (%s) ",msg_body.title_type_id,idString)
- mysqldbx.query(sql)
- return true, {}
- end
- function M.search_video_title(msg_body)
- local isok ,key = tools.checkData({"page_size","page_number","content","pay_type","title_type_id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local page_size = msg_body.page_size
- local page_number = msg_body.page_number
- local offset = (page_number - 1) * page_size
- local content_param = ""
- if msg_body.content~=""then
- content_param = string.format(" AND (title LIKE CONCAT( '%%%s%%')) ",msg_body.content)
- end
- local pay_type_param = ""
- if msg_body.pay_type~=""then
- pay_type_param = string.format(" AND pay_type = %d ",msg_body.pay_type)
- end
- local title_type_id_param = ""
- if msg_body.title_type_id~=""then
- title_type_id_param = string.format(" AND title_type_id = %d ",msg_body.title_type_id)
- end
- local param = content_param..pay_type_param..title_type_id_param
- local sql = "SELECT * FROM video_titles WHERE 1=1 "..param.." ORDER BY id DESC ".. string.format(" LIMIT %d OFFSET %d ",page_size, offset)
- local list = mysqldbx.query(sql)
- sql = "SELECT COUNT(*) AS total FROM video_titles WHERE 1=1 "..param
- local total = mysqldbx.query(sql)
- return true,list,total[1].total
- end
- function M.initAll()
- local sql = "SELECT * FROM video_titles "
- local list = mysqldbx.query(sql)
- for i = 1, #list, 1 do
- if (list[i].md5_tag==nil) then
- local id = list[i].id
- local md5_tag =md5.sumhexa(list[i].title)
- skynet.error("md5_tag:",md5_tag)
- sql = string.format("UPDATE video_titles SET md5_tag = '%s' WHERE id = %d ",md5_tag,id)
- mysqldbx.query(sql)
- end
- end
- return true,{}
- end
- return M
|