--主体出价模版 local M = {} local mysqldbx = require "mysqldbx" local tools = require "tools" local skynet = require "skynet" local cjson = require "cjson" local config = require "run_config" function M.add_tg_main_price_template(msg_body) 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) if not isok then return false,string.format("缺少字段: %s.", key) end 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) " local sql = sql_param..string.format(" VALUES (%d,%d,'%s',%d,%d,%d,%d,'%s',%d) ", 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) mysqldbx.query(sql) return true end function M.modify_tg_main_price_template(msg_body) 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) if not isok then return false,string.format("缺少字段: %s.", key) end 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 ", 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,msg_body.id) mysqldbx.query(sql) return true end function M.search_tg_main_price_template(msg_body) 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) if not isok then return false,string.format("缺少字段: %s.", key) end local page_size = msg_body.page_size local page_number = msg_body.page_number local offset = (page_number - 1) * page_size local tf_end_time_param = "" if msg_body.min_tf_end_time~="" and msg_body.max_tf_end_time~="" then 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) end local name_param = "" if msg_body.name~="" then name_param = string.format(" AND (name LIKE '%%%s%%' ) ",msg_body.name) end local tg_main_name_param = "" if msg_body.tg_main_name~="" then tg_main_name_param = string.format(" AND (tg_main_name LIKE '%%%s%%' ) ",msg_body.tg_main_name) end local status_param = "" if msg_body.status~="" then status_param = string.format(" AND status = %d ",msg_body.status) end local tg_main_id_param = "" if msg_body.tg_main_id~="" then tg_main_id_param = string.format(" AND tg_main_id = %d ",msg_body.tg_main_id) end local cpa_bid_param = "" if msg_body.cpa_bid~="" then cpa_bid_param = string.format(" AND cpa_bid LIKE '%%%d%%' ", msg_body.cpa_bid) end local param = tf_end_time_param..name_param..tg_main_name_param..status_param..cpa_bid_param..tg_main_id_param local sql = "SELECT * FROM tg_main_price_template WHERE 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset) skynet.error("sql:",sql) local list = mysqldbx.query(sql) sql = "SELECT COUNT(*) AS total FROM tg_main_price_template WHERE 1=1 "..param local total = mysqldbx.query(sql) return true,list,total[1].total end return M