|
@@ -0,0 +1,75 @@
|
|
|
+--主体出价模版
|
|
|
+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({"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` (name,tg_main_id,cpa_bid,custom_budget,no_bid_budget,tg_main_name,status) "
|
|
|
+ local sql = sql_param..string.format(" VALUES ('%s',%d,%d,%d,%d,'%s',%d) ",
|
|
|
+ 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({"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 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.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({"page_size","page_number","name","status","tg_main_name","cpa_bid"},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 name_param = ""
|
|
|
+ if msg_body.name~="" then
|
|
|
+ name_param = string.format(" AND (tg_main_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 cpa_bid_param = ""
|
|
|
+ if msg_body.cpa_bid~="" then
|
|
|
+ cpa_bid_param = string.format(" AND cpa_bid = %d ",msg_body.cpa_bid)
|
|
|
+ end
|
|
|
+
|
|
|
+ local param = name_param..tg_main_name_param..status_param..cpa_bid_param
|
|
|
+
|
|
|
+ local sql = "SELECT * FROM tg_main_price_template WHERE 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
+
|
|
|
+ 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
|