tg_main.lua 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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 mysql = require "skynet.db.mysql"
  8. local config = require "run_config"
  9. local mysqldtaskbx = {}
  10. local db
  11. function M.getOpenMainList()
  12. local sql = string.format("select * from `tg_main` where running_status = 1 ")
  13. local isok,res;
  14. res = mysqldbx.query(sql)
  15. if #res <= 0 then
  16. return true , {}
  17. end
  18. return true, res
  19. end
  20. function M.getCloseMainList()
  21. local sql = string.format("select * from `tg_main` where running_status = 0 ")
  22. local isok,res;
  23. res = mysqldbx.query(sql)
  24. if #res <= 0 then
  25. return true , {}
  26. end
  27. return true, res
  28. end
  29. function M.getOpenCreateLinkMainList()
  30. local sql = string.format("select * from `tg_main` where is_open_create_link = 1 ")
  31. local isok,res;
  32. res = mysqldbx.query(sql)
  33. if #res <= 0 then
  34. return true , {}
  35. end
  36. return true, res
  37. end
  38. function M.getCloseCreateLinkMainList()
  39. local sql = string.format("select * from `tg_main` where is_open_create_link = 0 ")
  40. local isok,res;
  41. res = mysqldbx.query(sql)
  42. if #res <= 0 then
  43. return true , {}
  44. end
  45. return true, res
  46. end
  47. --page_size 是你想要在每页中显示的记录数。
  48. --page_number 页数
  49. --获取所有主体
  50. function M.getMainList()
  51. local sql = string.format("select * from `tg_main` ")
  52. local isok,res;
  53. res = mysqldbx.query(sql)
  54. if #res <= 0 then
  55. return true , {}
  56. end
  57. return true, res
  58. end
  59. function M.search(msg_body)
  60. local isok ,key = tools.checkData({"ads_operation_status","statistics_platform_id","converted_time_duration","cbo_status","project_type","oce_product_id",
  61. "oce_product_platform_id",
  62. "delivery_mode","material_platform_id","wx_miniapp_create_status","template_bid","cpa_bid","page_size","page_number","main_name","running_status","custom_budget","pay_type","tg_platform_id","butler_id","tg_app_index","is_open_create_link","is_delete"},msg_body)
  63. if not isok then
  64. return false,string.format("缺少字段: %s.", key)
  65. end
  66. local page_size = msg_body.page_size
  67. local page_number = msg_body.page_number
  68. local offset = (page_number - 1) * page_size
  69. local ads_operation_status_param = ""
  70. if msg_body.ads_operation_status~="" then
  71. ads_operation_status_param = string.format(" AND ads_operation_status = '%s' ",msg_body.ads_operation_status)
  72. end
  73. local statistics_platform_id_param = ""
  74. if msg_body.statistics_platform_id~="" then
  75. statistics_platform_id_param = string.format(" AND statistics_platform_id = %d ",msg_body.statistics_platform_id)
  76. end
  77. local converted_time_duration_param = ""
  78. if msg_body.converted_time_duration~="" then
  79. converted_time_duration_param = string.format(" AND converted_time_duration = '%s' ",msg_body.converted_time_duration)
  80. end
  81. local infra_status_param = ""
  82. if msg_body.infra_status~="" then
  83. infra_status_param = string.format(" AND infra_status = %d ",msg_body.infra_status)
  84. end
  85. local cbo_script_status_param = ""
  86. if msg_body.cbo_script_status~="" then
  87. cbo_script_status_param = string.format(" AND cbo_script_status = %d ",msg_body.cbo_script_status)
  88. end
  89. local cbo_status_param = ""
  90. if msg_body.cbo_status~="" then
  91. cbo_status_param = string.format(" AND cbo_status = %d ",msg_body.cbo_status)
  92. end
  93. local project_type_param = ""
  94. if msg_body.project_type~="" then
  95. project_type_param = string.format(" AND project_type = %d ",msg_body.project_type)
  96. end
  97. local oce_product_id_param = ""
  98. if msg_body.oce_product_id~="" and msg_body.oce_product_id~=nil then
  99. oce_product_id_param = string.format(" AND oce_product_id = '%s' ",msg_body.oce_product_id)
  100. end
  101. local oce_product_platform_id_param = ""
  102. if msg_body.oce_product_platform_id~="" and msg_body.oce_oce_product_platform_idproduct_id~=nil then
  103. oce_product_platform_id_param = string.format(" AND oce_product_platform_id = '%s' ",msg_body.oce_product_platform_id)
  104. end
  105. local delivery_mode_param = ""
  106. if msg_body.delivery_mode~="" and msg_body.delivery_mode~=nil then
  107. delivery_mode_param = string.format(" AND delivery_mode = '%s' ",msg_body.delivery_mode)
  108. end
  109. local main_name_param = ""
  110. if msg_body.main_name~="" then
  111. main_name_param = string.format(" AND ( main_name LIKE CONCAT( '%%%s%%')) ",msg_body.main_name)
  112. end
  113. local wx_miniapp_create_status_param = ""
  114. if msg_body.wx_miniapp_create_status~="" then
  115. wx_miniapp_create_status_param = string.format(" AND wx_miniapp_create_status = %d ",msg_body.wx_miniapp_create_status)
  116. end
  117. local tg_platform_param = ""
  118. if msg_body.tg_platform_id~="" then
  119. tg_platform_param = string.format(" AND tg_platform_id = %d ",msg_body.tg_platform_id)
  120. end
  121. local material_platform_id_param = ""
  122. if msg_body.material_platform_id~="" then
  123. material_platform_id_param = string.format(" AND material_platform_id = %d ",msg_body.material_platform_id)
  124. end
  125. local running_status_param = ""
  126. if msg_body.running_status~="" then
  127. running_status_param = string.format(" AND running_status = %d ",msg_body.running_status)
  128. end
  129. local pay_type_param = ""
  130. if msg_body.pay_type~="" then
  131. pay_type_param = string.format(" AND pay_type = %d ",msg_body.pay_type)
  132. end
  133. local butler_id_param = ""
  134. if msg_body.butler_id~="" then
  135. butler_id_param = string.format(" AND butler_id = %d ",msg_body.butler_id)
  136. end
  137. local tg_app_index_param = ""
  138. if msg_body.tg_app_index~="" then
  139. tg_app_index_param = string.format(" AND tg_app_index = %d ",msg_body.tg_app_index)
  140. end
  141. local is_open_create_link_param = ""
  142. if msg_body.is_open_create_link~="" then
  143. is_open_create_link_param = string.format(" AND is_open_create_link = %d ",msg_body.is_open_create_link)
  144. end
  145. local is_delete_param = ""
  146. if msg_body.is_delete~="" then
  147. is_delete_param = string.format(" AND is_delete = %d ",msg_body.is_delete)
  148. end
  149. local custom_budget_param = ""
  150. if msg_body.custom_budget~="" then
  151. custom_budget_param = string.format(" AND custom_budget LIKE '%%%d%%' ", msg_body.custom_budget)
  152. end
  153. local cpa_bid_param = ""
  154. if msg_body.cpa_bid~="" then
  155. cpa_bid_param = string.format(" AND cpa_bid LIKE '%%%d%%' ", msg_body.cpa_bid)
  156. end
  157. local template_bid_param = ""
  158. if msg_body.template_bid~="" then
  159. template_bid_param = string.format(" AND template_bid LIKE '%%%d%%' ", msg_body.template_bid)
  160. end
  161. -- local genre_param = ""
  162. -- if msg_body.genre~="" then
  163. -- genre_param = string.format(" AND genre = %d ",msg_body.genre)
  164. -- end
  165. local param = ads_operation_status_param..statistics_platform_id_param..converted_time_duration_param..infra_status_param..cbo_script_status_param..cbo_status_param..project_type_param..oce_product_platform_id_param..oce_product_id_param..delivery_mode_param..main_name_param..tg_platform_param..running_status_param..pay_type_param..butler_id_param..tg_app_index_param..is_open_create_link_param..is_delete_param..custom_budget_param..cpa_bid_param..template_bid_param..wx_miniapp_create_status_param..material_platform_id_param;
  166. local sql = "SELECT * FROM tg_main where 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  167. local res = mysqldbx.query(sql)
  168. skynet.error("sql:",sql)
  169. sql = "SELECT COUNT(*) AS total FROM tg_main where 1=1 "..param
  170. local total = mysqldbx.query(sql)
  171. return true,res,total[1].total
  172. end
  173. -- `main_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '主体名称',
  174. -- `app_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '小程序ID',
  175. -- `running_status` tinyint(1) DEFAULT '1' COMMENT '运行状态 0-停止 1-运行中',
  176. -- `ad_quantity` int NOT NULL DEFAULT '40' COMMENT '广告数量',
  177. -- `cpa_bid` bigint NOT NULL DEFAULT '1750' COMMENT 'CPA出价(分), 默认17.5元',
  178. -- `bid_type` tinyint(1) DEFAULT '1' COMMENT '出价方式 0-常规 1-最大化 2 两种存储',
  179. -- `bid_ratio` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '1' COMMENT '出价方式比例(如 1:2)',
  180. -- `budget` bigint NOT NULL DEFAULT '9000000' COMMENT '预算金额(分), 默认9万元',
  181. -- `tg_platform_id` int NOT NULL DEFAULT '0' COMMENT '平台',
  182. -- `daily_new_limit` int DEFAULT '0' COMMENT '今天新上数量上限',
  183. function M.addMain(msg_body)
  184. local isok ,key = tools.checkData({"ads_operation_status","statistics_platform_id","hide_if_converted","converted_time_duration","cbo_script_time","cbo_script_status","cbo_status","project_type","tf_status","tf_start_time","stat_cost","oce_product_id","oce_product_platform_id","material_platform_id","strategy_config","delivery_mode","price","pack_strategy_status","start_chapter","advertiser_id","wx_miniapp_create_status","ad_act","template_bid","zh_id","roi_goal","ql_bid","infra_status","pay_type","qm_id","ldy_template_site_id","yw_id","parent_platform_id","platform_shared_id","distributor_id","is_delete","ad_convert_type","aweme_id","tg_app_index","butler_id","mini_program_platform_id","landing_page","valid_timer_time","valid_timer_number","channelId","no_bid_budget","max_ad_quantity","tg_link_config","tg_platform_id","app_id","main_name","running_status","ad_quantity","cpa_bid","bid_type","bid_ratio","custom_budget","daily_new_limit","valid_time","group_id"},msg_body)
  185. if not isok then
  186. return false,string.format("缺少字段: %s.", key)
  187. end
  188. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  189. msg_body.create_time = current_time
  190. local sql = string.format("INSERT INTO `tg_main` (ads_operation_status,statistics_platform_id,hide_if_converted,converted_time_duration,cbo_script_time,cbo_script_status,cbo_status,project_type,tf_status,tf_start_time,stat_cost,oce_product_id,oce_product_platform_id,material_platform_id,strategy_config,delivery_mode,price,pack_strategy_status,start_chapter,advertiser_id,wx_miniapp_create_status,genre,ad_act,template_bid,zh_id,roi_goal,ql_bid,infra_status,pay_type,qm_id,ldy_template_site_id,yw_id,parent_platform_id,platform_shared_id,distributor_id,is_delete,ad_convert_type,aweme_id,tg_app_index,butler_id,mini_program_platform_id,landing_page,valid_timer_time,valid_timer_number,channelId,no_bid_budget,max_ad_quantity,tg_link_config,tg_platform_id,app_id,main_name,running_status,ad_quantity,cpa_bid,bid_type,bid_ratio,custom_budget,daily_new_limit,valid_time,group_id) VALUES ('%s',%d, '%s','%s','%s',%d,%d,%d,%d,'%s',%d,'%s','%s',%d,'%s','%s',%d,%d,%d,%s,%d,%d,%d,%d,'%s',%d,%d,%d,%d,'%s','%s','%s',%d,%d,'%s',%d,'%s','%s', %d, %d, %d,'%s', %d, '%s', '%s',%d, %d, '%s', %d, '%s', '%s', %d, %d, %d,%d, '%s', %d, %d, '%s', '%s')",
  191. msg_body.ads_operation_status,
  192. msg_body.statistics_platform_id,
  193. msg_body.hide_if_converted,
  194. msg_body.converted_time_duration,
  195. msg_body.cbo_script_time,
  196. msg_body.cbo_script_status,
  197. msg_body.cbo_status,
  198. msg_body.project_type,
  199. msg_body.tf_status,
  200. msg_body.tf_start_time,
  201. msg_body.stat_cost,
  202. msg_body.oce_product_id,
  203. msg_body.oce_product_platform_id,
  204. msg_body.material_platform_id,
  205. msg_body.strategy_config,
  206. msg_body.delivery_mode,
  207. msg_body.price,
  208. msg_body.pack_strategy_status,
  209. msg_body.start_chapter,
  210. msg_body.advertiser_id,
  211. msg_body.wx_miniapp_create_status,
  212. 0,
  213. msg_body.ad_act,
  214. msg_body.template_bid,
  215. msg_body.zh_id,
  216. msg_body.roi_goal,
  217. msg_body.ql_bid,
  218. msg_body.infra_status,
  219. msg_body.pay_type,
  220. msg_body.qm_id,
  221. msg_body.ldy_template_site_id,
  222. msg_body.yw_id,
  223. msg_body.parent_platform_id,
  224. msg_body.platform_shared_id,
  225. msg_body.distributor_id,
  226. msg_body.is_delete,
  227. msg_body.ad_convert_type,
  228. msg_body.aweme_id,
  229. msg_body.tg_app_index,
  230. msg_body.butler_id,
  231. msg_body.mini_program_platform_id,
  232. msg_body.landing_page,
  233. msg_body.valid_timer_time,
  234. msg_body.valid_timer_number,
  235. msg_body.channelId,
  236. msg_body.no_bid_budget,
  237. msg_body.max_ad_quantity,
  238. cjson.encode(msg_body.tg_link_config),
  239. msg_body.tg_platform_id,
  240. msg_body.app_id,
  241. msg_body.main_name,
  242. msg_body.running_status,
  243. msg_body.ad_quantity,
  244. msg_body.cpa_bid,
  245. msg_body.bid_type,
  246. msg_body.bid_ratio,
  247. msg_body.custom_budget,
  248. msg_body.daily_new_limit,
  249. msg_body.valid_time,
  250. msg_body.group_id)
  251. skynet.error(sql)
  252. tools.dump(mysqldbx.query(sql))
  253. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateMainConfig"}))
  254. -- pushAddMainMsg(msg_body)
  255. return true
  256. end
  257. --此主体将书库的书都发布到小程序书籍
  258. function M.syncMain(msg_body)
  259. local isok ,key = tools.checkData({"id","min_stat_cost","max_stat_cost"},msg_body)
  260. if not isok then
  261. return false,string.format("缺少字段: %s.", key)
  262. end
  263. local sql = string.format("select * from `tg_main` where id = %d LIMIT 1 ",msg_body.id)
  264. local res = mysqldbx.query(sql)
  265. res[1].min_stat_cost = msg_body.min_stat_cost
  266. res[1].max_stat_cost = msg_body.max_stat_cost
  267. syncMainAppletProduct(res[1])
  268. return true,{}
  269. end
  270. function syncMainAppletProduct(main_info)
  271. -- local tg_platform_id = main_info.tg_platform_id
  272. -- local app_id = main_info.app_id
  273. -- local sql = string.format("SELECT * FROM video_product where book_platform = %d ",tg_platform_id)
  274. -- local video_product_list = mysqldtaskbx.Singleton().query(sql)
  275. -- function isHaveAppletProdut(product_id)
  276. -- local s = string.format("SELECT * FROM video_applet_product where dy_small_applet_app_id = '%s' and product_id = '%s' and main_id = %d and book_platform = %d LIMIT 1",app_id,product_id,main_info.id,tg_platform_id)
  277. -- local r = mysqldtaskbx.Singleton().query(sql)
  278. -- return #r>0
  279. -- end
  280. -- local need_create_link_list = {}
  281. -- local verify_list = {}
  282. -- for i = 1, #video_product_list, 1 do
  283. -- local product = video_product_list[i]
  284. -- if not isHaveAppletProdut(product.product_id) and not verify_list[product.product_id] then
  285. -- verify_list[product.product_id] = true
  286. -- table.insert(need_create_link_list,#need_create_link_list+1,{product_name=product.product_name,product_id=product.product_id,book_platform=product.book_platform})
  287. -- end
  288. -- end
  289. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="syncMain",data={main_info=main_info}}))
  290. end
  291. function pushAddMainMsg(msg_body)
  292. local sql = string.format("select * from `tg_main` where main_name = '%s' and app_id = '%s' LIMIT 1 ",msg_body.main_name,msg_body.app_id)
  293. local isok,res;
  294. res = mysqldbx.query(sql)
  295. skynet.error("sql:",sql)
  296. tools.dump(res)
  297. if #res > 0 then
  298. local main_info = res[1]
  299. skynet.fork(function ()
  300. -- local getMainInfoByAppid = function(app_id)
  301. -- local temp_list = {}
  302. -- for i = 1, #main_list, 1 do
  303. -- local main_item = main_list[i]
  304. -- if (main_item.app_id==app_id) then
  305. -- table.insert(temp_list,#temp_list+1,main_item)
  306. -- end
  307. -- end
  308. -- return temp_list
  309. -- end
  310. --获取书籍小程序列表
  311. sql = string.format("SELECT * FROM video_applet_product ")
  312. res = mysqldtaskbx.Singleton().query(sql)
  313. local video_applet_product_list = {}
  314. if #res>0 then
  315. for i = 1, #res, 1 do
  316. table.insert(video_applet_product_list,i,res[i])
  317. end
  318. end
  319. local need_create_link_list = {}
  320. -- local isCreateLinkByMainIdAndProductId = function(main_id,product_id)
  321. -- local isCreate = false
  322. -- for i = 1, #video_applet_product_list, 1 do
  323. -- local item = video_applet_product_list[i]
  324. -- if (item.product_id==product_id and item.main_id == main_id) then
  325. -- isCreate = true
  326. -- break
  327. -- end
  328. -- end
  329. -- return isCreate
  330. -- end
  331. --根据小程序id 筛选出所有需要创建的书籍
  332. local video_applet_product_of_main_list = {}
  333. local verify_list = {}
  334. for i = 1, #video_applet_product_list, 1 do
  335. local applet_item = video_applet_product_list[i]
  336. if verify_list[applet_item.product_id]==nil then
  337. if applet_item.status == 1 and applet_item.dy_small_applet_app_id == main_info.app_id then
  338. verify_list[applet_item.product_id] = true
  339. table.insert(video_applet_product_of_main_list,#video_applet_product_of_main_list+1,{product_name=applet_item.product_name,product_id=applet_item.product_id,book_platform=applet_item.book_platform,dy_small_applet_app_id=applet_item.dy_small_applet_app_id})
  340. end
  341. end
  342. end
  343. skynet.error("找到所有小程序!",#video_applet_product_of_main_list)
  344. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="addMain",data={list=video_applet_product_of_main_list,main_info=main_info}}))
  345. end)
  346. end
  347. end
  348. local function combine_query_and_params(query, params)
  349. -- 将 params 中的值替换到 query 中的占位符 ?
  350. local combined_query = query:gsub("?", function()
  351. local param = table.remove(params, 1) -- 从 params 中取出第一个参数
  352. if type(param) == "string" then
  353. return "'" .. param .. "'" -- 如果是字符串,用单引号包裹
  354. else
  355. return tostring(param) -- 如果是数字或其他类型,直接转换为字符串
  356. end
  357. end)
  358. return combined_query
  359. end
  360. function M.modifyMain(msg_body)
  361. local isok ,key = tools.checkData({"ads_operation_status" ,"statistics_platform_id","hide_if_converted","converted_time_duration","cbo_script_time","cbo_script_status","cbo_status","project_type","tf_status","tf_start_time","stat_cost","oce_product_id","oce_product_platform_id","material_platform_id","strategy_config","delivery_mode","price","pack_strategy_status","start_chapter","advertiser_id","wx_miniapp_create_status","ad_act","template_bid","zh_id","roi_goal","ql_bid","infra_status","pay_type","pay_type","qm_id","ldy_template_site_id","yw_id","parent_platform_id","platform_shared_id","distributor_id","is_delete","ad_convert_type","aweme_id","tg_app_index","butler_id","mini_program_platform_id","landing_page","valid_timer_time","valid_timer_number","channelId","no_bid_budget","max_ad_quantity","tg_link_config","id","tg_platform_id","app_id","main_name","running_status","ad_quantity","cpa_bid","bid_type","bid_ratio","custom_budget","daily_new_limit","valid_time","group_id"},msg_body)
  362. if not isok then
  363. return false,string.format("缺少字段: %s.", key)
  364. end
  365. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  366. msg_body.update_time = current_time
  367. local query = [[
  368. UPDATE `tg_main` SET
  369. ads_operation_status = ?,
  370. statistics_platform_id = ?,
  371. hide_if_converted = ?,
  372. converted_time_duration = ?,
  373. cbo_script_time = ?,
  374. cbo_script_status = ?,
  375. cbo_status = ?,
  376. project_type = ?,
  377. tf_status = ?,
  378. tf_start_time = ?,
  379. stat_cost = ?,
  380. oce_product_id = ?,
  381. oce_product_platform_id = ?,
  382. material_platform_id = ?,
  383. strategy_config = ?,
  384. delivery_mode = ?,
  385. price = ?,
  386. pack_strategy_status = ?,
  387. start_chapter = ?,
  388. advertiser_id = ?,
  389. wx_miniapp_create_status = ?,
  390. genre = ?,
  391. ad_act = ?,
  392. template_bid = ?,
  393. zh_id = ?,
  394. roi_goal = ?,
  395. ql_bid = ?,
  396. infra_status = ?,
  397. pay_type = ?,
  398. qm_id = ?,
  399. ldy_template_site_id = ?,
  400. yw_id = ?,
  401. parent_platform_id = ?,
  402. platform_shared_id = ?,
  403. distributor_id = ?,
  404. is_delete = ?,
  405. ad_convert_type = ?,
  406. aweme_id = ?,
  407. tg_app_index = ?,
  408. butler_id = ?,
  409. mini_program_platform_id = ?,
  410. landing_page = ?,
  411. valid_timer_time = ?,
  412. valid_timer_number = ?,
  413. channelId = ?,
  414. no_bid_budget = ?,
  415. max_ad_quantity = ?,
  416. tg_platform_id = ?,
  417. app_id = ?,
  418. main_name = ?,
  419. update_time = ?,
  420. running_status = ?,
  421. ad_quantity = ?,
  422. cpa_bid = ?,
  423. bid_type = ?,
  424. bid_ratio = ?,
  425. custom_budget = ?,
  426. daily_new_limit = ?,
  427. valid_time = ?,
  428. tg_link_config = ?,
  429. group_id = ?
  430. WHERE id = ?
  431. ]]
  432. local params = {
  433. msg_body.ads_operation_status,
  434. msg_body.statistics_platform_id,
  435. msg_body.hide_if_converted,
  436. msg_body.converted_time_duration,
  437. msg_body.cbo_script_time,
  438. msg_body.cbo_script_status,
  439. msg_body.cbo_status,
  440. msg_body.project_type,
  441. msg_body.tf_status,
  442. msg_body.tf_start_time,
  443. msg_body.stat_cost,
  444. msg_body.oce_product_id,
  445. msg_body.oce_product_platform_id,
  446. msg_body.material_platform_id,
  447. msg_body.strategy_config,
  448. msg_body.delivery_mode,
  449. msg_body.price,
  450. msg_body.pack_strategy_status,
  451. msg_body.start_chapter,
  452. msg_body.advertiser_id,
  453. msg_body.wx_miniapp_create_status,
  454. 0,
  455. msg_body.ad_act,
  456. msg_body.template_bid,
  457. msg_body.zh_id,
  458. msg_body.roi_goal,
  459. msg_body.ql_bid,
  460. msg_body.infra_status,
  461. msg_body.pay_type,
  462. msg_body.qm_id,
  463. msg_body.ldy_template_site_id,
  464. msg_body.yw_id,
  465. msg_body.parent_platform_id,
  466. msg_body.platform_shared_id,
  467. msg_body.distributor_id,
  468. msg_body.is_delete,
  469. msg_body.ad_convert_type,
  470. msg_body.aweme_id,
  471. msg_body.tg_app_index,
  472. msg_body.butler_id,
  473. msg_body.mini_program_platform_id,
  474. msg_body.landing_page,
  475. tonumber(msg_body.valid_timer_time),
  476. tonumber(msg_body.valid_timer_number),
  477. msg_body.channelId,
  478. msg_body.no_bid_budget,
  479. msg_body.max_ad_quantity,
  480. msg_body.tg_platform_id,
  481. msg_body.app_id,
  482. msg_body.main_name,
  483. msg_body.update_time,
  484. msg_body.running_status,
  485. msg_body.ad_quantity,
  486. msg_body.cpa_bid,
  487. msg_body.bid_type,
  488. msg_body.bid_ratio,
  489. msg_body.custom_budget,
  490. tonumber(msg_body.daily_new_limit),
  491. tonumber(msg_body.valid_time),
  492. cjson.encode(msg_body.tg_link_config),
  493. msg_body.group_id,
  494. msg_body.id
  495. }
  496. local sql = combine_query_and_params(query,params)
  497. skynet.error("sql:",sql)
  498. -- local sql = string.format("UPDATE `tg_main` SET strategy_config = '%s' , delivery_mode = '%s' , price = %d , pack_strategy_status = %d , start_chapter = %d , advertiser_id = '%s' ,wx_miniapp_create_status = %d , genre = %d , ad_act = %d ,template_bid = %d , zh_id = '%s', roi_goal = %d , ql_bid = %d, infra_status = %d , pay_type = %d ,qm_id = '%s' , ldy_template_site_id = '%s' , yw_id = '%s' , parent_platform_id = %d , platform_shared_id = %d ,distributor_id = '%s' , is_delete = %d , ad_convert_type = '%s', aweme_id = '%s' ,tg_app_index = %d , butler_id = %d , mini_program_platform_id = %d , landing_page = '%s' , valid_timer_time = %d , valid_timer_number = %d ,channelId = '%s' , no_bid_budget = %d , max_ad_quantity = %d ,tg_platform_id = %d , app_id = '%s' ,main_name = '%s' , update_time = '%s' , running_status = %d ,ad_quantity = %d ,cpa_bid = %d ,bid_type = %d ,bid_ratio = '%s' ,custom_budget = %d ,daily_new_limit = %d ,valid_time = %d ,tg_link_config = '%s' ,group_id = '%s' ,advertiser_id = '%s' ,wx_miniapp_create_status = %d , genre = %d , ad_act = %d ,template_bid = %d , zh_id = '%s', roi_goal = %d , ql_bid = %d, infra_status = %d , pay_type = %d ,qm_id = '%s' , ldy_template_site_id = '%s' , yw_id = '%s' , parent_platform_id = %d , platform_shared_id = %d ,distributor_id = '%s' , is_delete = %d , ad_convert_type = '%s', aweme_id = '%s' ,tg_app_index = %d , butler_id = %d , mini_program_platform_id = %d , landing_page = '%s' , valid_timer_time = %d , valid_timer_number = %d ,channelId = '%s' , no_bid_budget = %d , max_ad_quantity = %d ,tg_platform_id = %d , app_id = '%s' ,main_name = '%s' , update_time = '%s' , running_status = %d ,ad_quantity = %d ,cpa_bid = %d ,bid_type = %d ,bid_ratio = '%s' ,custom_budget = %d ,daily_new_limit = %d ,valid_time = %d ,tg_link_config = '%s' ,group_id = '%s' WHERE id = %d ",
  499. -- msg_body.strategy_config,msg_body.delivery_mode,msg_body.price,msg_body.pack_strategy_status,msg_body.start_chapter,msg_body.advertiser_id,msg_body.wx_miniapp_create_status,msg_body.genre,msg_body.ad_act,msg_body.template_bid,msg_body.zh_id,msg_body.roi_goal,msg_body.ql_bid,msg_body.infra_status,msg_body.pay_type,msg_body.qm_id,msg_body.ldy_template_site_id,msg_body.yw_id,msg_body.parent_platform_id,msg_body.platform_shared_id,msg_body.distributor_id,msg_body.is_delete,msg_body.ad_convert_type,msg_body.aweme_id,msg_body.tg_app_index,msg_body.butler_id,msg_body.mini_program_platform_id,msg_body.landing_page,tonumber(msg_body.valid_timer_time),tonumber(msg_body.valid_timer_number),msg_body.channelId,msg_body.no_bid_budget,msg_body.max_ad_quantity,msg_body.tg_platform_id,msg_body.app_id,msg_body.main_name,msg_body.update_time,msg_body.running_status,msg_body.ad_quantity,msg_body.cpa_bid,msg_body.bid_type,msg_body.bid_ratio,msg_body.custom_budget,
  500. -- tonumber(msg_body.daily_new_limit),tonumber(msg_body.valid_time),cjson.encode(msg_body.tg_link_config),msg_body.group_id,msg_body.id)
  501. tools.dump(mysqldbx.query(sql))
  502. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateMainConfig"}))
  503. return true
  504. end
  505. --配置主体推广链接
  506. function M.tgLinkConfig(msg_body)
  507. local isok ,key = tools.checkData({"id","is_open","huichuan_id","chongzhi_id","kadian_id","f_chongzhi_id","site_id"},msg_body)
  508. if not isok then
  509. return false,string.format("缺少字段: %s.", key)
  510. end
  511. local sql = string.format("select tg_link_config from `tg_main` WHERE id = %d ",msg_body.id)
  512. local res = mysqldbx.query(sql)
  513. sql = string.format("UPDATE `tg_main` SET tg_link_config = '%s' WHERE id = %d ",
  514. cjson.encode(msg_body),msg_body.id)
  515. mysqldbx.query(sql)
  516. return true, {}
  517. end
  518. --设置创建链接状态
  519. function M.set_open_create_link_status(msg_body)
  520. local isok ,key = tools.checkData({"id","is_open_create_link"},msg_body)
  521. if not isok then
  522. return false,string.format("缺少字段: %s.", key)
  523. end
  524. local sql = string.format("UPDATE `tg_main` SET is_open_create_link = %d WHERE id = %d ",
  525. msg_body.is_open_create_link,msg_body.id)
  526. mysqldbx.query(sql)
  527. return true, {}
  528. end
  529. --获取主体下的运行总数
  530. function M.get_main_ad_run_number(msg_body)
  531. local isok ,key = tools.checkData({"main_id"},msg_body)
  532. if not isok then
  533. return false,string.format("缺少字段: %s.", key)
  534. end
  535. local sql ="SELECT * FROM advertiser WHERE main_id = " .. msg_body.main_id;
  536. local res = mysqldbx.query(sql)
  537. local all_run_number = 0
  538. for i = 1, #res, 1 do
  539. local run_number = res[i].ad_run_number
  540. all_run_number = all_run_number + run_number
  541. end
  542. local nums = #res
  543. sql = string.format("select * from `tg_main` where id = %d LIMIT 1 ",msg_body.main_id)
  544. res = mysqldbx.query(sql)
  545. local max = nums * res[1].max_ad_quantity
  546. return true,{all_run_number=all_run_number,max=max}
  547. end
  548. function M.search_info_by_id(msg_body)
  549. local isok ,key = tools.checkData({"query_list"},msg_body)
  550. if not isok then
  551. return false,string.format("缺少字段: %s.", key)
  552. end
  553. local idString = table.concat(msg_body.query_list, ",")
  554. local sql = string.format("SELECT * FROM tg_main WHERE id IN (%s)",idString)
  555. local res = mysqldbx.query(sql)
  556. return true,res
  557. end
  558. function M.search_info_by_tg_app_index(msg_body)
  559. local isok ,key = tools.checkData({"query_list"},msg_body)
  560. if not isok then
  561. return false,string.format("缺少字段: %s.", key)
  562. end
  563. local idString = table.concat(msg_body.query_list, ",")
  564. local sql = string.format("SELECT * FROM tg_main WHERE tg_app_index IN (%s)",idString)
  565. local res = mysqldbx.query(sql)
  566. return true,res
  567. end
  568. function mysqldtaskbx.start()
  569. local function on_connect(db)
  570. db:query("set charset utf8mb4");
  571. end
  572. local conf = config.db_cnf.book_server.mysqldb_task_cnf
  573. db = mysql.connect{
  574. host=conf.ip,
  575. port=conf.port,
  576. database=conf.db,
  577. user=conf.user,
  578. password=conf.password,
  579. charset="utf8mb4",
  580. max_packet_size = 1024 * 1024,
  581. on_connect = on_connect
  582. }
  583. if not db then
  584. error("mysql connect fail")
  585. end
  586. end
  587. function mysqldtaskbx.Singleton()
  588. if db == nil then
  589. mysqldtaskbx.start()
  590. end
  591. return mysqldtaskbx
  592. end
  593. function mysqldtaskbx.query(sql)
  594. return db:query(sql)
  595. end
  596. return M