video_material.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. --推广
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. local cjson = require "cjson"
  7. local config = require "run_config"
  8. local db
  9. --设置推广状态
  10. function M.set_tui_guang_status(msg_body)
  11. local isok ,key = tools.checkData({"id_list","status"},msg_body)
  12. if not isok then
  13. return false,string.format("缺少字段: %s.", key)
  14. end
  15. local idString = table.concat(msg_body.id_list, ",")
  16. local sql = string.format("SELECT * FROM video_material WHERE id IN (%s)",idString)
  17. local isok,res;
  18. res = mysqldbx.query(sql)
  19. for i = 1, #res, 1 do
  20. local id = res[i].id
  21. local material_id = res[i].material_id
  22. sql = string.format("UPDATE video_material SET status = %d WHERE id =%d ",msg_body.status,id)
  23. mysqldbx.query(sql)
  24. end
  25. return true,{}
  26. end
  27. --设置审核状态
  28. function M.set_artificial_status(msg_body)
  29. local isok ,key = tools.checkData({"id_list","artificial_status","user_id"},msg_body)
  30. if not isok then
  31. return false,string.format("缺少字段: %s.", key)
  32. end
  33. local idString = table.concat(msg_body.id_list, ",")
  34. local sql = string.format("SELECT * FROM video_material WHERE id IN (%s)",idString)
  35. local isok,res;
  36. res = mysqldbx.query(sql)
  37. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  38. for i = 1, #res, 1 do
  39. local id = res[i].id
  40. sql = string.format("UPDATE video_material SET opt_time = '%s' ,artificial_status = %d , exe_review_person_id = %d WHERE id =%d ",current_time,msg_body.artificial_status,msg_body.user_id,id)
  41. mysqldbx.query(sql)
  42. end
  43. return true,{}
  44. end
  45. --搜索推广数据
  46. --oce_material_id 推广素材id
  47. --book_platform 平台id
  48. --product_id 书id
  49. --sync_status 状态
  50. function M.search(msg_body)
  51. local isok ,key = tools.checkData({
  52. "id_list",
  53. "material_id_list",
  54. "material_platform",
  55. "bl_status",
  56. "start_publish_time",
  57. "end_publish_time",
  58. "start_yun_fabu_time",
  59. "end_yun_fabu_time",
  60. "start_opt_time",
  61. "end_opt_time",
  62. "exe_review_person_id","min_book_word","max_book_word","genre","end_time_date",
  63. "start_time_date",
  64. "sync_status",
  65. "product_id",
  66. "tg_platform_id",
  67. "oce_material_id_list",
  68. "product_name",
  69. "material_id",
  70. "page_size",
  71. "page_number",
  72. "dy_id",
  73. "d_z",
  74. "comment",
  75. "collect",
  76. "forward",
  77. "status",
  78. "signature",
  79. "dy_id_1","artificial_status","machine_review_status","is_sexual_inducement_content","is_bad_value_view","user_id"},msg_body)
  80. if not isok then
  81. return false,string.format("缺少字段: %s.", key)
  82. end
  83. local page_size = msg_body.page_size
  84. local page_number = msg_body.page_number
  85. local offset = (page_number - 1) * page_size
  86. local material_platform_param = ""
  87. if msg_body.material_platform~="" then
  88. material_platform_param = string.format(" AND material_platform = %d ",tonumber(msg_body.material_platform))
  89. end
  90. local bl_status_param = ""
  91. if msg_body.bl_status~="" then
  92. bl_status_param = string.format(" AND bl_status = %d ",tonumber(msg_body.bl_status))
  93. end
  94. local publish_time_param = ""
  95. if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then
  96. publish_time_param = " AND DATE(publish_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_publish_time / 1000) .. ")) AND DATE(publish_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_publish_time / 1000) .. ")) "
  97. end
  98. local yun_fabu_time_param = ""
  99. if msg_body.start_yun_fabu_time~="" and msg_body.end_yun_fabu_time~="" then
  100. yun_fabu_time_param = " AND DATE(yun_fabu_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_yun_fabu_time / 1000) .. ")) AND DATE(yun_fabu_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_yun_fabu_time / 1000) .. "))"
  101. end
  102. local opt_time_param = ""
  103. if msg_body.start_opt_time~="" and msg_body.end_opt_time~="" then
  104. opt_time_param = " AND DATE(opt_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_opt_time / 1000) .. ")) AND DATE(opt_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_opt_time / 1000) .. "))"
  105. end
  106. local exe_review_person_id_param = ""
  107. if msg_body.exe_review_person_id~="" then
  108. exe_review_person_id_param = string.format(" AND exe_review_person_id = %d ",tonumber(msg_body.exe_review_person_id))
  109. end
  110. local user_id_param = ""
  111. if msg_body.user_id~="" then
  112. user_id_param = string.format(" AND user_id = %d ",tonumber(msg_body.user_id))
  113. end
  114. local word_param = ""
  115. if msg_body.min_book_word~="" and msg_body.max_book_word~="" then
  116. word_param = string.format(" AND CAST(words AS UNSIGNED) >= %f AND CAST(words AS UNSIGNED) <= %f ",msg_body.min_book_word,msg_body.max_book_word)
  117. end
  118. local product_param = ""
  119. if msg_body.product_id~="" then
  120. product_param = string.format(" AND product_id = %d ",tonumber(msg_body.product_id))
  121. end
  122. local product_name_param = ""
  123. if msg_body.product_name~="" then
  124. product_name_param = string.format("AND product_name = '%s' ",msg_body.product_name)
  125. end
  126. local is_auto_param = ""
  127. if msg_body.dy_id~="" then
  128. if msg_body.dy_id~=0 then
  129. is_auto_param = " AND dy_id != 0"
  130. else
  131. is_auto_param = " AND dy_id = 0"
  132. end
  133. end
  134. local genre_param = ""
  135. if msg_body.genre~="" then
  136. genre_param = string.format(" AND genre = %d ",tonumber(msg_body.genre))
  137. end
  138. local material_id_param = ""
  139. if msg_body.material_id~="" then
  140. material_id_param = string.format(" AND id = %d ",tonumber(msg_body.material_id))
  141. end
  142. local id_list_param = ""
  143. if msg_body.id_list~="" then
  144. local idString = table.concat(msg_body.id_list, ",")
  145. id_list_param =string.format(" AND id IN (%s) ",idString)
  146. end
  147. local material_id_list_param = ""
  148. if msg_body.material_id_list~="" then
  149. local idString = table.concat(msg_body.material_id_list, ",")
  150. material_id_list_param =string.format(" AND material_id IN (%s) ",idString)
  151. end
  152. local oce_material_id_list_param = ""
  153. if msg_body.oce_material_id_list~="" then
  154. local idString = table.concat(msg_body.oce_material_id_list, ",")
  155. oce_material_id_list_param =string.format(" AND oce_material_id IN (%s) ",idString)
  156. end
  157. local tg_platform_param = ""
  158. if msg_body.tg_platform_id~="" then
  159. tg_platform_param = " AND book_platform = "..msg_body.tg_platform_id.." "
  160. end
  161. local date_param = ""
  162. if msg_body.start_time_date~="" and msg_body.end_time_date~="" then
  163. date_param = " AND DATE(create_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_time_date / 1000) .. ")) AND DATE(create_at) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_time_date / 1000) .. "))"
  164. end
  165. local sync_status_param = ""
  166. if msg_body.sync_status~="" then
  167. sync_status_param = " AND sync_status = "..msg_body.sync_status.." "
  168. end
  169. local status_param = ""
  170. if msg_body.status~="" then
  171. status_param = " AND status = "..msg_body.status.." "
  172. end
  173. local artificial_status_param = ""
  174. if msg_body.artificial_status~="" then
  175. artificial_status_param = " AND artificial_status = "..msg_body.artificial_status.." "
  176. end
  177. local machine_review_status_param = ""
  178. if msg_body.machine_review_status~="" then
  179. machine_review_status_param = " AND machine_review_status = "..msg_body.machine_review_status.." "
  180. end
  181. local is_sexual_inducement_content_param = ""
  182. if msg_body.is_sexual_inducement_content~="" then
  183. is_sexual_inducement_content_param = " AND is_sexual_inducement_content = "..msg_body.is_sexual_inducement_content.." "
  184. end
  185. local is_bad_value_view_param = ""
  186. if msg_body.is_bad_value_view~="" then
  187. is_bad_value_view_param = " AND is_bad_value_view = "..msg_body.is_bad_value_view.." "
  188. end
  189. local signature_param = ""
  190. if msg_body.signature~="" then
  191. signature_param = string.format("AND signature = '%s' ",msg_body.signature)
  192. end
  193. local dy_id_1_param = ""
  194. if msg_body.dy_id_1~="" then
  195. dy_id_1_param = " AND dy_id = "..tonumber(msg_body.dy_id_1)
  196. end
  197. local d_z_param = ""
  198. if msg_body.d_z~="" then
  199. if(msg_body.d_z == 0) then
  200. d_z_param = " d_z_number ASC"
  201. else
  202. d_z_param = " d_z_number DESC"
  203. end
  204. end
  205. local comment_param = ""
  206. if msg_body.comment~="" then
  207. if(msg_body.comment == 0) then
  208. comment_param = " comment_number ASC"
  209. else
  210. comment_param = " comment_number DESC"
  211. end
  212. end
  213. local forward_param = ""
  214. if msg_body.forward~="" then
  215. if(msg_body.forward == 0) then
  216. forward_param = " forward_number ASC"
  217. else
  218. forward_param = " forward_number DESC"
  219. end
  220. end
  221. local collect_param = ""
  222. if msg_body.collect~="" then
  223. if(msg_body.collect == 0) then
  224. collect_param = " collect_number ASC"
  225. else
  226. collect_param = " collect_number DESC"
  227. end
  228. end
  229. -----
  230. local stat_cost_param = ""
  231. if msg_body.stat_cost~="" then
  232. if(msg_body.stat_cost == 0) then
  233. stat_cost_param = " stat_cost ASC"
  234. else
  235. stat_cost_param = " stat_cost DESC"
  236. end
  237. end
  238. local show_cnt_param = ""
  239. if msg_body.show_cnt~="" then
  240. if(msg_body.show_cnt == 0) then
  241. show_cnt_param = " comment_number ASC"
  242. else
  243. show_cnt_param = " comment_number DESC"
  244. end
  245. end
  246. local click_cnt_param = ""
  247. if msg_body.click_cnt~="" then
  248. if(msg_body.click_cnt == 0) then
  249. click_cnt_param = " click_cnt ASC"
  250. else
  251. click_cnt_param = " click_cnt DESC"
  252. end
  253. end
  254. local convert_cnt_param = ""
  255. if msg_body.convert_cnt~="" then
  256. if(msg_body.convert_cnt == 0) then
  257. convert_cnt_param = " convert_cnt ASC"
  258. else
  259. convert_cnt_param = " convert_cnt DESC"
  260. end
  261. end
  262. local cvr_param = ""
  263. if msg_body.cvr~="" then
  264. if(msg_body.cvr == 0) then
  265. cvr_param = " cvr ASC"
  266. else
  267. cvr_param = " cvr DESC"
  268. end
  269. end
  270. local ctr_param = ""
  271. if msg_body.ctr~="" then
  272. if(msg_body.ctr == 0) then
  273. ctr_param = " ctr ASC"
  274. else
  275. ctr_param = " ctr DESC"
  276. end
  277. end
  278. local new_param = stat_cost_param..show_cnt_param..click_cnt_param..convert_cnt_param..cvr_param..ctr_param
  279. -----
  280. local param = material_platform_param..bl_status_param..publish_time_param..yun_fabu_time_param..opt_time_param..exe_review_person_id_param..word_param..genre_param..date_param..product_param..id_list_param..material_id_list_param..oce_material_id_list_param..status_param..tg_platform_param..sync_status_param..product_name_param..is_auto_param..material_id_param..signature_param..dy_id_1_param..artificial_status_param..machine_review_status_param..is_sexual_inducement_content_param..is_bad_value_view_param..user_id_param
  281. local up_down_param = d_z_param..comment_param..forward_param..collect_param..new_param
  282. if up_down_param ~= "" then
  283. up_down_param = " ORDER BY " ..up_down_param
  284. else
  285. up_down_param = " ORDER BY id DESC "
  286. end
  287. local sql = "SELECT * FROM video_material WHERE 1=1 "..param..up_down_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  288. local res = mysqldbx.query(sql)
  289. skynet.error("sql:",sql)
  290. sql = "SELECT COUNT(*) AS total FROM video_material WHERE 1=1 "..param.." ORDER BY id DESC "
  291. local total = mysqldbx.query(sql)
  292. return true,res,total[1].total
  293. end
  294. return M