video_material.lua 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. for i = 1, #res, 1 do
  38. local id = res[i].id
  39. sql = string.format("UPDATE video_material SET artificial_status = %d , exe_review_person_id = %d WHERE id =%d ",msg_body.artificial_status,msg_body.user_id,id)
  40. mysqldbx.query(sql)
  41. end
  42. return true,{}
  43. end
  44. --搜索推广数据
  45. --oce_material_id 推广素材id
  46. --book_platform 平台id
  47. --product_id 书id
  48. --sync_status 状态
  49. function M.search(msg_body)
  50. local isok ,key = tools.checkData({"publish_time","min_book_word","max_book_word","genre","end_time_date",
  51. "start_time_date",
  52. "sync_status",
  53. "product_id",
  54. "tg_platform_id",
  55. "oce_material_id",
  56. "product_name",
  57. "material_id",
  58. "page_size",
  59. "page_number",
  60. "dy_id",
  61. "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)
  62. if not isok then
  63. return false,string.format("缺少字段: %s.", key)
  64. end
  65. local page_size = msg_body.page_size
  66. local page_number = msg_body.page_number
  67. local offset = (page_number - 1) * page_size
  68. local user_id_param = ""
  69. if msg_body.user_id~="" then
  70. user_id_param = string.format(" AND user_id = %d ",tonumber(msg_body.user_id))
  71. end
  72. local word_param = ""
  73. if msg_body.min_book_word~="" and msg_body.max_book_word~="" then
  74. 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)
  75. end
  76. local product_param = ""
  77. if msg_body.product_id~="" then
  78. product_param = string.format(" AND product_id = %d ",tonumber(msg_body.product_id))
  79. end
  80. local product_name_param = ""
  81. if msg_body.product_name~="" then
  82. product_name_param = string.format("AND product_name = '%s' ",msg_body.product_name)
  83. end
  84. local is_auto_param = ""
  85. if msg_body.dy_id~="" then
  86. if msg_body.dy_id~=0 then
  87. is_auto_param = " AND dy_id != 0"
  88. else
  89. is_auto_param = " AND dy_id = 0"
  90. end
  91. end
  92. local genre_param = ""
  93. if msg_body.genre~="" then
  94. genre_param = string.format(" AND genre = %d ",tonumber(msg_body.genre))
  95. end
  96. local material_id_param = ""
  97. if msg_body.material_id~="" then
  98. material_id_param = string.format(" AND id = %d ",tonumber(msg_body.material_id))
  99. end
  100. local oce_material_param = ""
  101. if msg_body.oce_material_id~="" then
  102. oce_material_param =string.format("AND oce_material_id = %d ",tonumber(msg_body.oce_material_id))
  103. end
  104. local tg_platform_param = ""
  105. if msg_body.tg_platform_id~="" then
  106. tg_platform_param = " AND book_platform = "..msg_body.tg_platform_id.." "
  107. end
  108. local publish_time_param = ""
  109. if msg_body.publish_time~="" then
  110. publish_time_param = string.format(" AND publish_time = '%s' ",msg_body.publish_time)
  111. end
  112. local date_param = ""
  113. if msg_body.start_time_date~="" and msg_body.end_time_date~="" then
  114. 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) .. "))"
  115. end
  116. local sync_status_param = ""
  117. if msg_body.sync_status~="" then
  118. sync_status_param = " AND sync_status = "..msg_body.sync_status.." "
  119. end
  120. local status_param = ""
  121. if msg_body.status~="" then
  122. status_param = " AND status = "..msg_body.status.." "
  123. end
  124. local artificial_status_param = ""
  125. if msg_body.artificial_status~="" then
  126. artificial_status_param = " AND artificial_status = "..msg_body.artificial_status.." "
  127. end
  128. local machine_review_status_param = ""
  129. if msg_body.machine_review_status~="" then
  130. machine_review_status_param = " AND machine_review_status = "..msg_body.machine_review_status.." "
  131. end
  132. local is_sexual_inducement_content_param = ""
  133. if msg_body.is_sexual_inducement_content~="" then
  134. is_sexual_inducement_content_param = " AND is_sexual_inducement_content = "..msg_body.is_sexual_inducement_content.." "
  135. end
  136. local is_bad_value_view_param = ""
  137. if msg_body.is_bad_value_view~="" then
  138. is_bad_value_view_param = " AND is_bad_value_view = "..msg_body.is_bad_value_view.." "
  139. end
  140. local signature_param = ""
  141. if msg_body.signature~="" then
  142. signature_param = string.format("AND signature = '%s' ",msg_body.signature)
  143. end
  144. local dy_id_1_param = ""
  145. if msg_body.dy_id_1~="" then
  146. dy_id_1_param = " AND dy_id = "..tonumber(msg_body.dy_id_1)
  147. end
  148. local d_z_param = ""
  149. if msg_body.d_z~="" then
  150. if(msg_body.d_z == 0) then
  151. d_z_param = " d_z_number ASC"
  152. else
  153. d_z_param = " d_z_number DESC"
  154. end
  155. end
  156. local comment_param = ""
  157. if msg_body.comment~="" then
  158. if(msg_body.comment == 0) then
  159. comment_param = " comment_number ASC"
  160. else
  161. comment_param = " comment_number DESC"
  162. end
  163. end
  164. local forward_param = ""
  165. if msg_body.forward~="" then
  166. if(msg_body.forward == 0) then
  167. forward_param = " forward_number ASC"
  168. else
  169. forward_param = " forward_number DESC"
  170. end
  171. end
  172. local collect_param = ""
  173. if msg_body.collect~="" then
  174. if(msg_body.collect == 0) then
  175. collect_param = " collect_number ASC"
  176. else
  177. collect_param = " collect_number DESC"
  178. end
  179. end
  180. -----
  181. local stat_cost_param = ""
  182. if msg_body.stat_cost~="" then
  183. if(msg_body.stat_cost == 0) then
  184. stat_cost_param = " stat_cost ASC"
  185. else
  186. stat_cost_param = " stat_cost DESC"
  187. end
  188. end
  189. local show_cnt_param = ""
  190. if msg_body.show_cnt~="" then
  191. if(msg_body.show_cnt == 0) then
  192. show_cnt_param = " comment_number ASC"
  193. else
  194. show_cnt_param = " comment_number DESC"
  195. end
  196. end
  197. local click_cnt_param = ""
  198. if msg_body.click_cnt~="" then
  199. if(msg_body.click_cnt == 0) then
  200. click_cnt_param = " click_cnt ASC"
  201. else
  202. click_cnt_param = " click_cnt DESC"
  203. end
  204. end
  205. local convert_cnt_param = ""
  206. if msg_body.convert_cnt~="" then
  207. if(msg_body.convert_cnt == 0) then
  208. convert_cnt_param = " convert_cnt ASC"
  209. else
  210. convert_cnt_param = " convert_cnt DESC"
  211. end
  212. end
  213. local cvr_param = ""
  214. if msg_body.cvr~="" then
  215. if(msg_body.cvr == 0) then
  216. cvr_param = " cvr ASC"
  217. else
  218. cvr_param = " cvr DESC"
  219. end
  220. end
  221. local ctr_param = ""
  222. if msg_body.ctr~="" then
  223. if(msg_body.ctr == 0) then
  224. ctr_param = " ctr ASC"
  225. else
  226. ctr_param = " ctr DESC"
  227. end
  228. end
  229. local new_param = stat_cost_param..show_cnt_param..click_cnt_param..convert_cnt_param..cvr_param..ctr_param
  230. -----
  231. local param = publish_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
  232. local up_down_param = d_z_param..comment_param..forward_param..collect_param..new_param
  233. if up_down_param ~= "" then
  234. up_down_param = " ORDER BY " ..up_down_param
  235. else
  236. up_down_param = " ORDER BY id DESC "
  237. end
  238. local sql = "SELECT * FROM video_material WHERE 1=1 "..param..up_down_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  239. local res = mysqldbx.query(sql)
  240. skynet.error("sql:",sql)
  241. sql = "SELECT COUNT(*) AS total FROM video_material WHERE 1=1 "..param.." ORDER BY id DESC "
  242. local total = mysqldbx.query(sql)
  243. return true,res,total[1].total
  244. end
  245. return M