video_material.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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"},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 WHERE id =%d ",msg_body.artificial_status,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({"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"},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 product_param = ""
  69. if msg_body.product_id~="" then
  70. product_param = string.format(" AND product_id = %d ",tonumber(msg_body.product_id))
  71. end
  72. local product_name_param = ""
  73. if msg_body.product_name~="" then
  74. product_name_param = string.format("AND product_name = '%s' ",msg_body.product_name)
  75. end
  76. local is_auto_param = ""
  77. if msg_body.dy_id~="" then
  78. if msg_body.dy_id~=0 then
  79. is_auto_param = " AND dy_id != 0"
  80. else
  81. is_auto_param = " AND dy_id = 0"
  82. end
  83. end
  84. local material_id_param = ""
  85. if msg_body.material_id~="" then
  86. material_id_param = string.format(" AND id = %d ",tonumber(msg_body.material_id))
  87. end
  88. local oce_material_param = ""
  89. if msg_body.oce_material_id~="" then
  90. oce_material_param =string.format("AND oce_material_id = %d ",tonumber(msg_body.oce_material_id))
  91. end
  92. local tg_platform_param = ""
  93. if msg_body.tg_platform_id~="" then
  94. tg_platform_param = " AND book_platform = "..msg_body.tg_platform_id.." "
  95. end
  96. local date_param = ""
  97. if msg_body.start_time_date~="" and msg_body.end_time_date~="" then
  98. 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) .. "))"
  99. end
  100. local sync_status_param = ""
  101. if msg_body.sync_status~="" then
  102. sync_status_param = " AND sync_status = "..msg_body.sync_status.." "
  103. end
  104. local status_param = ""
  105. if msg_body.status~="" then
  106. status_param = " AND status = "..msg_body.status.." "
  107. end
  108. local artificial_status_param = ""
  109. if msg_body.artificial_status~="" then
  110. artificial_status_param = " AND artificial_status = "..msg_body.artificial_status.." "
  111. end
  112. local signature_param = ""
  113. if msg_body.signature~="" then
  114. signature_param = string.format("AND signature = '%s' ",msg_body.signature)
  115. end
  116. local dy_id_1_param = ""
  117. if msg_body.dy_id_1~="" then
  118. dy_id_1_param = " AND dy_id = "..tonumber(msg_body.dy_id_1)
  119. end
  120. local d_z_param = ""
  121. if msg_body.d_z~="" then
  122. if(msg_body.d_z == 0) then
  123. d_z_param = " d_z_number ASC"
  124. else
  125. d_z_param = " d_z_number DESC"
  126. end
  127. end
  128. local comment_param = ""
  129. if msg_body.comment~="" then
  130. if(msg_body.comment == 0) then
  131. comment_param = " comment_number ASC"
  132. else
  133. comment_param = " comment_number DESC"
  134. end
  135. end
  136. local forward_param = ""
  137. if msg_body.forward~="" then
  138. if(msg_body.forward == 0) then
  139. forward_param = " forward_number ASC"
  140. else
  141. forward_param = " forward_number DESC"
  142. end
  143. end
  144. local collect_param = ""
  145. if msg_body.collect~="" then
  146. if(msg_body.collect == 0) then
  147. collect_param = " collect_number ASC"
  148. else
  149. collect_param = " collect_number DESC"
  150. end
  151. end
  152. -----
  153. local stat_cost_param = ""
  154. if msg_body.stat_cost~="" then
  155. if(msg_body.stat_cost == 0) then
  156. stat_cost_param = " stat_cost ASC"
  157. else
  158. stat_cost_param = " stat_cost DESC"
  159. end
  160. end
  161. local show_cnt_param = ""
  162. if msg_body.show_cnt~="" then
  163. if(msg_body.show_cnt == 0) then
  164. show_cnt_param = " comment_number ASC"
  165. else
  166. show_cnt_param = " comment_number DESC"
  167. end
  168. end
  169. local click_cnt_param = ""
  170. if msg_body.click_cnt~="" then
  171. if(msg_body.click_cnt == 0) then
  172. click_cnt_param = " click_cnt ASC"
  173. else
  174. click_cnt_param = " click_cnt DESC"
  175. end
  176. end
  177. local convert_cnt_param = ""
  178. if msg_body.convert_cnt~="" then
  179. if(msg_body.convert_cnt == 0) then
  180. convert_cnt_param = " convert_cnt ASC"
  181. else
  182. convert_cnt_param = " convert_cnt DESC"
  183. end
  184. end
  185. local cvr_param = ""
  186. if msg_body.cvr~="" then
  187. if(msg_body.cvr == 0) then
  188. cvr_param = " cvr ASC"
  189. else
  190. cvr_param = " cvr DESC"
  191. end
  192. end
  193. local ctr_param = ""
  194. if msg_body.ctr~="" then
  195. if(msg_body.ctr == 0) then
  196. ctr_param = " ctr ASC"
  197. else
  198. ctr_param = " ctr DESC"
  199. end
  200. end
  201. local new_param = stat_cost_param..show_cnt_param..click_cnt_param..convert_cnt_param..cvr_param..ctr_param
  202. -----
  203. local 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
  204. local up_down_param = d_z_param..comment_param..forward_param..collect_param..new_param
  205. if up_down_param ~= "" then
  206. up_down_param = " ORDER BY " ..up_down_param
  207. else
  208. up_down_param = " ORDER BY id DESC "
  209. end
  210. local sql = "SELECT * FROM video_material WHERE 1=1 "..param..up_down_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  211. local res = mysqldbx.query(sql)
  212. skynet.error("sql:",sql)
  213. sql = "SELECT COUNT(*) AS total FROM video_material WHERE 1=1 "..param.." ORDER BY id DESC "
  214. local total = mysqldbx.query(sql)
  215. return true,res,total[1].total
  216. end
  217. return M