tg_main.lua 25 KB

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