tg_main_price_template.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. function M.add_tg_main_price_template(msg_body)
  9. local isok ,key = tools.checkData({"roi_goal","tf_end_time","name","tg_main_id","cpa_bid","custom_budget","no_bid_budget","tg_main_name","status"},msg_body)
  10. if not isok then
  11. return false,string.format("缺少字段: %s.", key)
  12. end
  13. local sql_param = "INSERT INTO `tg_main_price_template` (roi_goal,tf_end_time,name,tg_main_id,cpa_bid,custom_budget,no_bid_budget,tg_main_name,status) "
  14. local sql = sql_param..string.format(" VALUES (%d,%d,'%s',%d,%d,%d,%d,'%s',%d) ",
  15. msg_body.roi_goal,msg_body.tf_end_time,msg_body.name,msg_body.tg_main_id,msg_body.cpa_bid,msg_body.custom_budget,msg_body.no_bid_budget,msg_body.tg_main_name,msg_body.status)
  16. mysqldbx.query(sql)
  17. return true
  18. end
  19. function M.modify_tg_main_price_template(msg_body)
  20. local isok ,key = tools.checkData({"roi_goal","tf_end_time","id","name","tg_main_id","cpa_bid","custom_budget","no_bid_budget","tg_main_name","status"},msg_body)
  21. if not isok then
  22. return false,string.format("缺少字段: %s.", key)
  23. end
  24. local sql = string.format("UPDATE `tg_main_price_template` SET roi_goal = %d , tf_end_time = %d , name = '%s' ,tg_main_id = %d , cpa_bid = %d , custom_budget = %d , no_bid_budget = %d , tg_main_name = '%s' , status = %d WHERE id = %d ",
  25. msg_body.roi_goal,msg_body.tf_end_time,msg_body.name,msg_body.tg_main_id,msg_body.cpa_bid,msg_body.custom_budget,msg_body.no_bid_budget
  26. ,msg_body.tg_main_name,msg_body.status,msg_body.id)
  27. mysqldbx.query(sql)
  28. return true
  29. end
  30. function M.search_tg_main_price_template(msg_body)
  31. local isok ,key = tools.checkData({"min_tf_end_time","max_tf_end_time","page_size","page_number","name","status","tg_main_name","cpa_bid","tg_main_id"},msg_body)
  32. if not isok then
  33. return false,string.format("缺少字段: %s.", key)
  34. end
  35. local page_size = msg_body.page_size
  36. local page_number = msg_body.page_number
  37. local offset = (page_number - 1) * page_size
  38. local tf_end_time_param = ""
  39. if msg_body.min_tf_end_time~="" and msg_body.max_tf_end_time~="" then
  40. tf_end_time_param = string.format(" AND tf_end_time >=%d AND tf_end_time <=%d ", msg_body.min_tf_end_time,msg_body.max_tf_end_time)
  41. end
  42. local name_param = ""
  43. if msg_body.name~="" then
  44. name_param = string.format(" AND (name LIKE '%%%s%%' ) ",msg_body.name)
  45. end
  46. local tg_main_name_param = ""
  47. if msg_body.tg_main_name~="" then
  48. tg_main_name_param = string.format(" AND (tg_main_name LIKE '%%%s%%' ) ",msg_body.tg_main_name)
  49. end
  50. local status_param = ""
  51. if msg_body.status~="" then
  52. status_param = string.format(" AND status = %d ",msg_body.status)
  53. end
  54. local tg_main_id_param = ""
  55. if msg_body.tg_main_id~="" then
  56. tg_main_id_param = string.format(" AND tg_main_id = %d ",msg_body.tg_main_id)
  57. end
  58. local cpa_bid_param = ""
  59. if msg_body.cpa_bid~="" then
  60. cpa_bid_param = string.format(" AND cpa_bid LIKE '%%%d%%' ", msg_body.cpa_bid)
  61. end
  62. local param = tf_end_time_param..name_param..tg_main_name_param..status_param..cpa_bid_param..tg_main_id_param
  63. local sql = "SELECT * FROM tg_main_price_template WHERE 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  64. skynet.error("sql:",sql)
  65. local list = mysqldbx.query(sql)
  66. sql = "SELECT COUNT(*) AS total FROM tg_main_price_template WHERE 1=1 "..param
  67. local total = mysqldbx.query(sql)
  68. return true,list,total[1].total
  69. end
  70. return M