video_material.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. "start_opt_time",
  53. "end_opt_time",
  54. "start_yun_fabu_time",
  55. "end_yun_fabu_time",
  56. "exe_review_person_id",
  57. "start_publish_time",
  58. "end_publish_time",
  59. "min_book_word","max_book_word","genre",
  60. "end_time_date",
  61. "start_time_date",
  62. "sync_status",
  63. "product_id",
  64. "tg_platform_id",
  65. "oce_material_id",
  66. "product_name",
  67. "material_id",
  68. "page_size",
  69. "page_number",
  70. "dy_id",
  71. "d_z","comment","collect","forward","status","signature","dy_id_1","artificial_status","machine_review_status","is_sexual_inducement_content","is_bad_value_view","user_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 yun_fabu_time_param = ""
  79. if msg_body.start_yun_fabu_time~="" and msg_body.end_yun_fabu_time~="" then
  80. 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) .. "))"
  81. end
  82. local publish_time_param = ""
  83. if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then
  84. 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) .. ")) "
  85. end
  86. local opt_time_param = ""
  87. if msg_body.start_opt_time~="" and msg_body.end_opt_time~="" then
  88. 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) .. "))"
  89. end
  90. local exe_review_person_id_param = ""
  91. if msg_body.exe_review_person_id~="" then
  92. exe_review_person_id_param = string.format(" AND exe_review_person_id = %d ",tonumber(msg_body.exe_review_person_id))
  93. end
  94. local user_id_param = ""
  95. if msg_body.user_id~="" then
  96. user_id_param = string.format(" AND user_id = %d ",tonumber(msg_body.user_id))
  97. end
  98. local word_param = ""
  99. if msg_body.min_book_word~="" and msg_body.max_book_word~="" then
  100. 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)
  101. end
  102. local product_param = ""
  103. if msg_body.product_id~="" then
  104. product_param = string.format(" AND product_id = %d ",tonumber(msg_body.product_id))
  105. end
  106. local product_name_param = ""
  107. if msg_body.product_name~="" then
  108. product_name_param = string.format("AND product_name = '%s' ",msg_body.product_name)
  109. end
  110. local is_auto_param = ""
  111. if msg_body.dy_id~="" then
  112. if msg_body.dy_id~=0 then
  113. is_auto_param = " AND dy_id != 0"
  114. else
  115. is_auto_param = " AND dy_id = 0"
  116. end
  117. end
  118. local genre_param = ""
  119. if msg_body.genre~="" then
  120. genre_param = string.format(" AND genre = %d ",tonumber(msg_body.genre))
  121. end
  122. local material_id_param = ""
  123. if msg_body.material_id~="" then
  124. material_id_param = string.format(" AND id = %d ",tonumber(msg_body.material_id))
  125. end
  126. local oce_material_param = ""
  127. if msg_body.oce_material_id~="" then
  128. oce_material_param =string.format("AND oce_material_id = %d ",tonumber(msg_body.oce_material_id))
  129. end
  130. local tg_platform_param = ""
  131. if msg_body.tg_platform_id~="" then
  132. tg_platform_param = " AND book_platform = "..msg_body.tg_platform_id.." "
  133. end
  134. local date_param = ""
  135. if msg_body.start_time_date~="" and msg_body.end_time_date~="" then
  136. 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) .. "))"
  137. end
  138. local sync_status_param = ""
  139. if msg_body.sync_status~="" then
  140. sync_status_param = " AND sync_status = "..msg_body.sync_status.." "
  141. end
  142. local status_param = ""
  143. if msg_body.status~="" then
  144. status_param = " AND status = "..msg_body.status.." "
  145. end
  146. local artificial_status_param = ""
  147. if msg_body.artificial_status~="" then
  148. artificial_status_param = " AND artificial_status = "..msg_body.artificial_status.." "
  149. end
  150. local machine_review_status_param = ""
  151. if msg_body.machine_review_status~="" then
  152. machine_review_status_param = " AND machine_review_status = "..msg_body.machine_review_status.." "
  153. end
  154. local is_sexual_inducement_content_param = ""
  155. if msg_body.is_sexual_inducement_content~="" then
  156. is_sexual_inducement_content_param = " AND is_sexual_inducement_content = "..msg_body.is_sexual_inducement_content.." "
  157. end
  158. local is_bad_value_view_param = ""
  159. if msg_body.is_bad_value_view~="" then
  160. is_bad_value_view_param = " AND is_bad_value_view = "..msg_body.is_bad_value_view.." "
  161. end
  162. local signature_param = ""
  163. if msg_body.signature~="" then
  164. signature_param = string.format("AND signature = '%s' ",msg_body.signature)
  165. end
  166. local dy_id_1_param = ""
  167. if msg_body.dy_id_1~="" then
  168. dy_id_1_param = " AND dy_id = "..tonumber(msg_body.dy_id_1)
  169. end
  170. local d_z_param = ""
  171. if msg_body.d_z~="" then
  172. if(msg_body.d_z == 0) then
  173. d_z_param = " d_z_number ASC"
  174. else
  175. d_z_param = " d_z_number DESC"
  176. end
  177. end
  178. local comment_param = ""
  179. if msg_body.comment~="" then
  180. if(msg_body.comment == 0) then
  181. comment_param = " comment_number ASC"
  182. else
  183. comment_param = " comment_number DESC"
  184. end
  185. end
  186. local forward_param = ""
  187. if msg_body.forward~="" then
  188. if(msg_body.forward == 0) then
  189. forward_param = " forward_number ASC"
  190. else
  191. forward_param = " forward_number DESC"
  192. end
  193. end
  194. local collect_param = ""
  195. if msg_body.collect~="" then
  196. if(msg_body.collect == 0) then
  197. collect_param = " collect_number ASC"
  198. else
  199. collect_param = " collect_number DESC"
  200. end
  201. end
  202. -----
  203. local stat_cost_param = ""
  204. if msg_body.stat_cost~="" then
  205. if(msg_body.stat_cost == 0) then
  206. stat_cost_param = " stat_cost ASC"
  207. else
  208. stat_cost_param = " stat_cost DESC"
  209. end
  210. end
  211. local show_cnt_param = ""
  212. if msg_body.show_cnt~="" then
  213. if(msg_body.show_cnt == 0) then
  214. show_cnt_param = " comment_number ASC"
  215. else
  216. show_cnt_param = " comment_number DESC"
  217. end
  218. end
  219. local click_cnt_param = ""
  220. if msg_body.click_cnt~="" then
  221. if(msg_body.click_cnt == 0) then
  222. click_cnt_param = " click_cnt ASC"
  223. else
  224. click_cnt_param = " click_cnt DESC"
  225. end
  226. end
  227. local convert_cnt_param = ""
  228. if msg_body.convert_cnt~="" then
  229. if(msg_body.convert_cnt == 0) then
  230. convert_cnt_param = " convert_cnt ASC"
  231. else
  232. convert_cnt_param = " convert_cnt DESC"
  233. end
  234. end
  235. local cvr_param = ""
  236. if msg_body.cvr~="" then
  237. if(msg_body.cvr == 0) then
  238. cvr_param = " cvr ASC"
  239. else
  240. cvr_param = " cvr DESC"
  241. end
  242. end
  243. local ctr_param = ""
  244. if msg_body.ctr~="" then
  245. if(msg_body.ctr == 0) then
  246. ctr_param = " ctr ASC"
  247. else
  248. ctr_param = " ctr DESC"
  249. end
  250. end
  251. local new_param = stat_cost_param..show_cnt_param..click_cnt_param..convert_cnt_param..cvr_param..ctr_param
  252. -----
  253. local param = publish_time_param..yun_fabu_time_param..exe_review_person_id_param..opt_time_param..word_param..genre_param..date_param..product_param..oce_material_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
  254. local up_down_param = d_z_param..comment_param..forward_param..collect_param..new_param
  255. if up_down_param ~= "" then
  256. up_down_param = " ORDER BY " ..up_down_param
  257. else
  258. up_down_param = " ORDER BY id DESC "
  259. end
  260. local sql = "SELECT * FROM video_material WHERE 1=1 "..param..up_down_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  261. local res = mysqldbx.query(sql)
  262. skynet.error("sql:",sql)
  263. sql = "SELECT COUNT(*) AS total FROM video_material WHERE 1=1 "..param.." ORDER BY id DESC "
  264. local total = mysqldbx.query(sql)
  265. return true,res,total[1].total
  266. end
  267. return M