promotion_audit_suggestions.lua 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. function M.set_status(msg_body)
  8. local isok ,key = tools.checkData({"id_list","status"},msg_body)
  9. if not isok then
  10. return false,string.format("缺少字段: %s.", key)
  11. end
  12. local idString = table.concat(msg_body.id_list, ",")
  13. local sql = string.format("SELECT * FROM promotion_audit_suggestions WHERE id IN (%s)",idString)
  14. local isok,res;
  15. res = mysqldbx.query(sql)
  16. for i = 1, #res, 1 do
  17. local id = res[i].id
  18. sql = string.format("UPDATE promotion_audit_suggestions SET status = %d WHERE id =%d ",msg_body.status,id)
  19. mysqldbx.query(sql)
  20. end
  21. return true,{}
  22. end
  23. function M.search_promotion_audit_suggestions(msg_body)
  24. local isok ,key = tools.checkData({"butler_id","page_size","page_number","start_create_time","end_create_time",
  25. "advertiser_id","promotion_id","material_type","material_item","status"},msg_body)
  26. if not isok then
  27. return false,string.format("缺少字段: %s.", key)
  28. end
  29. local page_size = msg_body.page_size
  30. local page_number = msg_body.page_number
  31. local offset = (page_number - 1) * page_size
  32. local butler_id_param = ""
  33. if msg_body.butler_id~="" then
  34. butler_id_param = " AND butler_id = "..msg_body.butler_id
  35. end
  36. local advertiser_id_param = ""
  37. if msg_body.advertiser_id~="" then
  38. advertiser_id_param = " AND advertiser_id = "..msg_body.advertiser_id
  39. end
  40. local promotion_id_param = ""
  41. if msg_body.promotion_id~="" then
  42. promotion_id_param = " AND promotion_id = "..tonumber(msg_body.promotion_id)
  43. end
  44. local material_type_param = ""
  45. if msg_body.material_type~="" then
  46. material_type_param = string.format( " AND material_type = '%s' ",msg_body.material_type)
  47. end
  48. local material_item_param = ""
  49. if msg_body.material_item~="" then
  50. material_item_param = string.format(" AND ( material_item LIKE CONCAT( '%%%s%%')) ",msg_body.material_item)
  51. end
  52. local status_param = ""
  53. if msg_body.status~="" then
  54. status_param = " AND status = "..msg_body.status
  55. end
  56. local product_id_param = ""
  57. if msg_body.product_id~="" then
  58. product_id_param = " AND product_id = "..tonumber(msg_body.product_id)
  59. end
  60. local product_library_id_param = ""
  61. if msg_body.product_library_id~="" then
  62. product_library_id_param = " AND product_library_id = "..tonumber(msg_body.product_library_id)
  63. end
  64. local create_date_param = ""
  65. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  66. create_date_param = " AND DATE(created_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_create_time / 1000) .. ")) AND DATE(created_at) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_create_time / 1000) .. "))"
  67. end
  68. local param = create_date_param..advertiser_id_param..promotion_id_param..material_type_param..material_item_param..status_param..product_id_param..product_library_id_param..butler_id_param
  69. local sql = "SELECT * FROM promotion_audit_suggestions WHERE 1=1 "..param.. " ORDER BY cost DESC "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  70. local list = mysqldbx.query(sql)
  71. sql = "SELECT COUNT(*) AS total FROM promotion_audit_suggestions WHERE 1=1 "..param
  72. local total = mysqldbx.query(sql)
  73. return true,list,total[1].total
  74. end
  75. return M