tg_main.lua 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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({"tf_support_status","internal_advertiser_classify","tg_app_index_list","aigc_status","title_pay_type","is_boost","is_reservation","title_type_id","is_group_record","tf_time_interval","mini_program_platform_id","is_comment","material_rule_id","parent_main_id","tg_day","id","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 tf_support_status_param = ""
  70. if msg_body.tf_support_status~="" then
  71. tf_support_status_param = " AND tf_support_status = "..msg_body.tf_support_status
  72. end
  73. local internal_advertiser_classify_param = ""
  74. if msg_body.internal_advertiser_classify~="" then
  75. internal_advertiser_classify_param = string.format(" AND internal_advertiser_classify = '%s' ",msg_body.internal_advertiser_classify)
  76. end
  77. local tg_app_index_list_param = ""
  78. if msg_body.tg_app_index_list~="" then
  79. local idString = table.concat(msg_body.tg_app_index_list, ",")
  80. tg_app_index_list_param = string.format(" AND tg_app_index IN (%s) ",idString)
  81. end
  82. local aigc_status_param = ""
  83. if msg_body.aigc_status~="" then
  84. aigc_status_param = " AND aigc_status = "..msg_body.aigc_status
  85. end
  86. local title_pay_type_param = ""
  87. if msg_body.title_pay_type~="" then
  88. title_pay_type_param = " AND title_pay_type = "..msg_body.title_pay_type
  89. end
  90. local is_boost_param = ""
  91. if msg_body.is_boost~="" then
  92. is_boost_param = " AND is_boost = "..msg_body.is_boost
  93. end
  94. local is_reservation_param = ""
  95. if msg_body.is_reservation~="" then
  96. is_reservation_param = " AND is_reservation = "..msg_body.is_reservation
  97. end
  98. local title_type_id_param = ""
  99. if msg_body.title_type_id~="" then
  100. title_type_id_param = " AND title_type_id = "..msg_body.title_type_id
  101. end
  102. local is_group_record_param = ""
  103. if msg_body.is_group_record~="" then
  104. is_group_record_param = " AND is_group_record = "..msg_body.is_group_record
  105. end
  106. local tf_time_interval_param = ""
  107. if msg_body.tf_time_interval~="" then
  108. tf_time_interval_param = " AND tf_time_interval = "..msg_body.tf_time_interval
  109. end
  110. local mini_program_platform_id_param = ""
  111. if msg_body.mini_program_platform_id~="" then
  112. mini_program_platform_id_param = " AND mini_program_platform_id = "..msg_body.mini_program_platform_id
  113. end
  114. local is_comment_param = ""
  115. if msg_body.is_comment~="" then
  116. is_comment_param = " AND is_comment = "..msg_body.is_comment
  117. end
  118. local material_rule_id_param = ""
  119. if msg_body.material_rule_id~="" then
  120. material_rule_id_param = " AND material_rule_id = "..msg_body.material_rule_id
  121. end
  122. local parent_main_id_param = ""
  123. if msg_body.parent_main_id~="" then
  124. parent_main_id_param = " AND parent_main_id = "..msg_body.parent_main_id
  125. end
  126. local tg_day_param = ""
  127. if msg_body.tg_day~="" then
  128. tg_day_param = " AND tg_day = "..msg_body.tg_day
  129. end
  130. local id_param = ""
  131. if msg_body.id~="" then
  132. id_param = " AND id = "..msg_body.id
  133. end
  134. local ads_operation_status_param = ""
  135. if msg_body.ads_operation_status~="" then
  136. ads_operation_status_param = string.format(" AND ads_operation_status = '%s' ",msg_body.ads_operation_status)
  137. end
  138. local statistics_platform_id_param = ""
  139. if msg_body.statistics_platform_id~="" then
  140. statistics_platform_id_param = string.format(" AND statistics_platform_id = %d ",msg_body.statistics_platform_id)
  141. end
  142. local converted_time_duration_param = ""
  143. if msg_body.converted_time_duration~="" then
  144. converted_time_duration_param = string.format(" AND converted_time_duration = '%s' ",msg_body.converted_time_duration)
  145. end
  146. local infra_status_param = ""
  147. if msg_body.infra_status~="" then
  148. infra_status_param = string.format(" AND infra_status = %d ",msg_body.infra_status)
  149. end
  150. local cbo_script_status_param = ""
  151. if msg_body.cbo_script_status~="" then
  152. cbo_script_status_param = string.format(" AND cbo_script_status = %d ",msg_body.cbo_script_status)
  153. end
  154. local cbo_status_param = ""
  155. if msg_body.cbo_status~="" then
  156. cbo_status_param = string.format(" AND cbo_status = %d ",msg_body.cbo_status)
  157. end
  158. local project_type_param = ""
  159. if msg_body.project_type~="" then
  160. project_type_param = string.format(" AND project_type = %d ",msg_body.project_type)
  161. end
  162. local oce_product_id_param = ""
  163. if msg_body.oce_product_id~="" and msg_body.oce_product_id~=nil then
  164. oce_product_id_param = string.format(" AND oce_product_id = '%s' ",msg_body.oce_product_id)
  165. end
  166. local oce_product_platform_id_param = ""
  167. if msg_body.oce_product_platform_id~="" and msg_body.oce_oce_product_platform_idproduct_id~=nil then
  168. oce_product_platform_id_param = string.format(" AND oce_product_platform_id = '%s' ",msg_body.oce_product_platform_id)
  169. end
  170. local delivery_mode_param = ""
  171. if msg_body.delivery_mode~="" and msg_body.delivery_mode~=nil then
  172. delivery_mode_param = string.format(" AND delivery_mode = '%s' ",msg_body.delivery_mode)
  173. end
  174. local main_name_param = ""
  175. if msg_body.main_name~="" then
  176. main_name_param = string.format(" AND ( main_name LIKE CONCAT( '%%%s%%')) ",msg_body.main_name)
  177. end
  178. local wx_miniapp_create_status_param = ""
  179. if msg_body.wx_miniapp_create_status~="" then
  180. wx_miniapp_create_status_param = string.format(" AND wx_miniapp_create_status = %d ",msg_body.wx_miniapp_create_status)
  181. end
  182. local tg_platform_param = ""
  183. if msg_body.tg_platform_id~="" then
  184. tg_platform_param = string.format(" AND tg_platform_id = %d ",msg_body.tg_platform_id)
  185. end
  186. local material_platform_id_param = ""
  187. if msg_body.material_platform_id~="" then
  188. material_platform_id_param = string.format(" AND material_platform_id = %d ",msg_body.material_platform_id)
  189. end
  190. local running_status_param = ""
  191. if msg_body.running_status~="" then
  192. running_status_param = string.format(" AND running_status = %d ",msg_body.running_status)
  193. end
  194. local pay_type_param = ""
  195. if msg_body.pay_type~="" then
  196. pay_type_param = string.format(" AND pay_type = %d ",msg_body.pay_type)
  197. end
  198. local butler_id_param = ""
  199. if msg_body.butler_id~="" then
  200. butler_id_param = string.format(" AND butler_id = %d ",msg_body.butler_id)
  201. end
  202. local tg_app_index_param = ""
  203. if msg_body.tg_app_index~="" then
  204. tg_app_index_param = string.format(" AND tg_app_index = %d ",msg_body.tg_app_index)
  205. end
  206. local is_open_create_link_param = ""
  207. if msg_body.is_open_create_link~="" then
  208. is_open_create_link_param = string.format(" AND is_open_create_link = %d ",msg_body.is_open_create_link)
  209. end
  210. local is_delete_param = ""
  211. if msg_body.is_delete~="" then
  212. is_delete_param = string.format(" AND is_delete = %d ",msg_body.is_delete)
  213. end
  214. local custom_budget_param = ""
  215. if msg_body.custom_budget~="" then
  216. custom_budget_param = string.format(" AND custom_budget LIKE '%%%d%%' ", msg_body.custom_budget)
  217. end
  218. local cpa_bid_param = ""
  219. if msg_body.cpa_bid~="" then
  220. cpa_bid_param = string.format(" AND cpa_bid LIKE '%%%d%%' ", msg_body.cpa_bid)
  221. end
  222. local template_bid_param = ""
  223. if msg_body.template_bid~="" then
  224. template_bid_param = string.format(" AND template_bid LIKE '%%%d%%' ", msg_body.template_bid)
  225. end
  226. -- local genre_param = ""
  227. -- if msg_body.genre~="" then
  228. -- genre_param = string.format(" AND genre = %d ",msg_body.genre)
  229. -- end
  230. local param = internal_advertiser_classify_param..tf_support_status_param..tg_app_index_list_param..aigc_status_param..title_pay_type_param..is_boost_param..is_reservation_param..title_type_id_param..is_group_record_param..tf_time_interval_param..mini_program_platform_id_param..is_comment_param..material_rule_id_param..parent_main_id_param..tg_day_param..id_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;
  231. local sql = "SELECT * FROM tg_main where 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  232. local res = mysqldbx.query(sql)
  233. skynet.error("sql:",sql)
  234. sql = "SELECT COUNT(*) AS total FROM tg_main where 1=1 "..param
  235. local total = mysqldbx.query(sql)
  236. return true,res,total[1].total
  237. end
  238. -- `main_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '主体名称',
  239. -- `app_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '小程序ID',
  240. -- `running_status` tinyint(1) DEFAULT '1' COMMENT '运行状态 0-停止 1-运行中',
  241. -- `ad_quantity` int NOT NULL DEFAULT '40' COMMENT '广告数量',
  242. -- `cpa_bid` bigint NOT NULL DEFAULT '1750' COMMENT 'CPA出价(分), 默认17.5元',
  243. -- `bid_type` tinyint(1) DEFAULT '1' COMMENT '出价方式 0-常规 1-最大化 2 两种存储',
  244. -- `bid_ratio` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '1' COMMENT '出价方式比例(如 1:2)',
  245. -- `budget` bigint NOT NULL DEFAULT '9000000' COMMENT '预算金额(分), 默认9万元',
  246. -- `tg_platform_id` int NOT NULL DEFAULT '0' COMMENT '平台',
  247. -- `daily_new_limit` int DEFAULT '0' COMMENT '今天新上数量上限',
  248. function M.addMain(msg_body)
  249. local isok ,key = tools.checkData({"tf_support_status","internal_advertiser_classify","aigc_status","zy_conifg","title_pay_type","is_boost","is_reservation","title_type_id","is_group_record","tf_time_interval","mat_roi","reduce_roi","boost_high_price_end_time","boost_high_price_number","reduce_consume_amount","reduce_bid_amount","is_comment","convert_cnt","material_rule_id","material_rule_number","parent_main_id","valid_timer_like_num","tg_day","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)
  250. if not isok then
  251. return false,string.format("缺少字段: %s.", key)
  252. end
  253. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  254. msg_body.create_time = current_time
  255. local sql = string.format("INSERT INTO `tg_main` (tf_support_status,internal_advertiser_classify,aigc_status,zy_conifg,title_pay_type,is_boost,is_reservation,title_type_id,is_group_record,tf_time_interval,mat_roi,reduce_roi,boost_high_price_end_time,boost_high_price_number,reduce_consume_amount,reduce_bid_amount,is_comment,convert_cnt,material_rule_id,material_rule_number,parent_main_id,valid_timer_like_num,tg_day,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 ( %d,'%s',%d,'%s',%d,%d, %d,%d, %d,%d,%f,%f,%d,%d,%f,%f,%d,%d,%d,%d, %d,%d,%d,'%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')",
  256. msg_body.tf_support_status,
  257. msg_body.internal_advertiser_classify,
  258. msg_body.aigc_status,
  259. cjson.encode(msg_body.zy_conifg),
  260. msg_body.title_pay_type,
  261. msg_body.is_boost,
  262. msg_body.is_reservation,
  263. msg_body.title_type_id,
  264. msg_body.is_group_record,
  265. msg_body.tf_time_interval,
  266. msg_body.mat_roi,
  267. msg_body.reduce_roi,
  268. msg_body.boost_high_price_end_time,
  269. msg_body.boost_high_price_number,
  270. msg_body.reduce_consume_amount,
  271. msg_body.reduce_bid_amount,
  272. msg_body.is_comment,
  273. msg_body.convert_cnt,
  274. msg_body.material_rule_id,
  275. msg_body.material_rule_number,
  276. msg_body.parent_main_id,
  277. msg_body.valid_timer_like_num,
  278. msg_body.tg_day,
  279. msg_body.ads_operation_status,
  280. msg_body.statistics_platform_id,
  281. msg_body.hide_if_converted,
  282. msg_body.converted_time_duration,
  283. msg_body.cbo_script_time,
  284. msg_body.cbo_script_status,
  285. msg_body.cbo_status,
  286. msg_body.project_type,
  287. msg_body.tf_status,
  288. msg_body.tf_start_time,
  289. msg_body.stat_cost,
  290. msg_body.oce_product_id,
  291. msg_body.oce_product_platform_id,
  292. msg_body.material_platform_id,
  293. msg_body.strategy_config,
  294. msg_body.delivery_mode,
  295. msg_body.price,
  296. msg_body.pack_strategy_status,
  297. msg_body.start_chapter,
  298. msg_body.advertiser_id,
  299. msg_body.wx_miniapp_create_status,
  300. 0,
  301. msg_body.ad_act,
  302. msg_body.template_bid,
  303. msg_body.zh_id,
  304. msg_body.roi_goal,
  305. msg_body.ql_bid,
  306. msg_body.infra_status,
  307. msg_body.pay_type,
  308. msg_body.qm_id,
  309. msg_body.ldy_template_site_id,
  310. msg_body.yw_id,
  311. msg_body.parent_platform_id,
  312. msg_body.platform_shared_id,
  313. msg_body.distributor_id,
  314. msg_body.is_delete,
  315. msg_body.ad_convert_type,
  316. msg_body.aweme_id,
  317. msg_body.tg_app_index,
  318. msg_body.butler_id,
  319. msg_body.mini_program_platform_id,
  320. msg_body.landing_page,
  321. msg_body.valid_timer_time,
  322. msg_body.valid_timer_number,
  323. msg_body.channelId,
  324. msg_body.no_bid_budget,
  325. msg_body.max_ad_quantity,
  326. cjson.encode(msg_body.tg_link_config),
  327. msg_body.tg_platform_id,
  328. msg_body.app_id,
  329. msg_body.main_name,
  330. msg_body.running_status,
  331. msg_body.ad_quantity,
  332. msg_body.cpa_bid,
  333. msg_body.bid_type,
  334. msg_body.bid_ratio,
  335. msg_body.custom_budget,
  336. msg_body.daily_new_limit,
  337. msg_body.valid_time,
  338. msg_body.group_id)
  339. skynet.error(sql)
  340. tools.dump(mysqldbx.query(sql))
  341. if msg_body.parent_main_id ~= 0 then
  342. M.updateParentMain(msg_body.parent_main_id)
  343. end
  344. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateMainConfig"}))
  345. -- pushAddMainMsg(msg_body)
  346. return true
  347. end
  348. --此主体将书库的书都发布到小程序书籍
  349. function M.syncMain(msg_body)
  350. local isok ,key = tools.checkData({"id","min_stat_cost","max_stat_cost"},msg_body)
  351. if not isok then
  352. return false,string.format("缺少字段: %s.", key)
  353. end
  354. local sql = string.format("select * from `tg_main` where id = %d LIMIT 1 ",msg_body.id)
  355. local res = mysqldbx.query(sql)
  356. res[1].min_stat_cost = msg_body.min_stat_cost
  357. res[1].max_stat_cost = msg_body.max_stat_cost
  358. res[1].start_publish_time = ""
  359. res[1].end_publish_time = ""
  360. if msg_body.start_publish_time~="" and msg_body.start_publish_time~=nil then
  361. res[1].start_publish_time = msg_body.start_publish_time
  362. end
  363. if msg_body.end_publish_time~="" and msg_body.end_publish_time~=nil then
  364. res[1].end_publish_time = msg_body.end_publish_time
  365. end
  366. syncMainAppletProduct(res[1])
  367. return true,{}
  368. end
  369. function syncMainAppletProduct(main_info)
  370. -- local tg_platform_id = main_info.tg_platform_id
  371. -- local app_id = main_info.app_id
  372. -- local sql = string.format("SELECT * FROM video_product where book_platform = %d ",tg_platform_id)
  373. -- local video_product_list = mysqldtaskbx.Singleton().query(sql)
  374. -- function isHaveAppletProdut(product_id)
  375. -- 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)
  376. -- local r = mysqldtaskbx.Singleton().query(sql)
  377. -- return #r>0
  378. -- end
  379. -- local need_create_link_list = {}
  380. -- local verify_list = {}
  381. -- for i = 1, #video_product_list, 1 do
  382. -- local product = video_product_list[i]
  383. -- if not isHaveAppletProdut(product.product_id) and not verify_list[product.product_id] then
  384. -- verify_list[product.product_id] = true
  385. -- 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})
  386. -- end
  387. -- end
  388. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="syncMain",data={main_info=main_info}}))
  389. end
  390. function pushAddMainMsg(msg_body)
  391. 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)
  392. local isok,res;
  393. res = mysqldbx.query(sql)
  394. skynet.error("sql:",sql)
  395. tools.dump(res)
  396. if #res > 0 then
  397. local main_info = res[1]
  398. skynet.fork(function ()
  399. -- local getMainInfoByAppid = function(app_id)
  400. -- local temp_list = {}
  401. -- for i = 1, #main_list, 1 do
  402. -- local main_item = main_list[i]
  403. -- if (main_item.app_id==app_id) then
  404. -- table.insert(temp_list,#temp_list+1,main_item)
  405. -- end
  406. -- end
  407. -- return temp_list
  408. -- end
  409. --获取书籍小程序列表
  410. sql = string.format("SELECT * FROM video_applet_product ")
  411. res = mysqldtaskbx.Singleton().query(sql)
  412. local video_applet_product_list = {}
  413. if #res>0 then
  414. for i = 1, #res, 1 do
  415. table.insert(video_applet_product_list,i,res[i])
  416. end
  417. end
  418. local need_create_link_list = {}
  419. -- local isCreateLinkByMainIdAndProductId = function(main_id,product_id)
  420. -- local isCreate = false
  421. -- for i = 1, #video_applet_product_list, 1 do
  422. -- local item = video_applet_product_list[i]
  423. -- if (item.product_id==product_id and item.main_id == main_id) then
  424. -- isCreate = true
  425. -- break
  426. -- end
  427. -- end
  428. -- return isCreate
  429. -- end
  430. --根据小程序id 筛选出所有需要创建的书籍
  431. local video_applet_product_of_main_list = {}
  432. local verify_list = {}
  433. for i = 1, #video_applet_product_list, 1 do
  434. local applet_item = video_applet_product_list[i]
  435. if verify_list[applet_item.product_id]==nil then
  436. if applet_item.status == 1 and applet_item.dy_small_applet_app_id == main_info.app_id then
  437. verify_list[applet_item.product_id] = true
  438. 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})
  439. end
  440. end
  441. end
  442. skynet.error("找到所有小程序!",#video_applet_product_of_main_list)
  443. 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}}))
  444. end)
  445. end
  446. end
  447. local function combine_query_and_params(query, params)
  448. -- 将 params 中的值替换到 query 中的占位符 ?
  449. local combined_query = query:gsub("?", function()
  450. local param = table.remove(params, 1) -- 从 params 中取出第一个参数
  451. if type(param) == "string" then
  452. return "'" .. param .. "'" -- 如果是字符串,用单引号包裹
  453. else
  454. return tostring(param) -- 如果是数字或其他类型,直接转换为字符串
  455. end
  456. end)
  457. return combined_query
  458. end
  459. function M.modifyMain(msg_body)
  460. local isok ,key = tools.checkData({"tf_support_status","internal_advertiser_classify","aigc_status","zy_conifg","title_pay_type","is_boost","is_reservation","title_type_id","is_group_record","tf_time_interval","mat_roi","reduce_roi","boost_high_price_end_time","boost_high_price_number","reduce_consume_amount","reduce_bid_amount","is_comment","convert_cnt","material_rule_id","material_rule_number","valid_timer_like_num","tg_day","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)
  461. if not isok then
  462. return false,string.format("缺少字段: %s.", key)
  463. end
  464. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  465. msg_body.update_time = current_time
  466. local query = [[
  467. UPDATE `tg_main` SET
  468. tf_support_status =?,
  469. internal_advertiser_classify =?,
  470. aigc_status =?,
  471. zy_conifg =?,
  472. title_pay_type = ?,
  473. is_boost = ?,
  474. is_reservation = ?,
  475. title_type_id = ?,
  476. is_group_record = ?,
  477. tf_time_interval = ?,
  478. mat_roi = ?,
  479. reduce_roi = ?,
  480. boost_high_price_end_time = ?,
  481. boost_high_price_number = ?,
  482. reduce_consume_amount = ?,
  483. reduce_bid_amount = ?,
  484. is_comment = ?,
  485. convert_cnt = ?,
  486. material_rule_id = ?,
  487. material_rule_number = ?,
  488. valid_timer_like_num = ?,
  489. tg_day = ?,
  490. ads_operation_status = ?,
  491. statistics_platform_id = ?,
  492. hide_if_converted = ?,
  493. converted_time_duration = ?,
  494. cbo_script_time = ?,
  495. cbo_script_status = ?,
  496. cbo_status = ?,
  497. project_type = ?,
  498. tf_status = ?,
  499. tf_start_time = ?,
  500. stat_cost = ?,
  501. oce_product_id = ?,
  502. oce_product_platform_id = ?,
  503. material_platform_id = ?,
  504. strategy_config = ?,
  505. delivery_mode = ?,
  506. price = ?,
  507. pack_strategy_status = ?,
  508. start_chapter = ?,
  509. advertiser_id = ?,
  510. wx_miniapp_create_status = ?,
  511. genre = ?,
  512. ad_act = ?,
  513. template_bid = ?,
  514. zh_id = ?,
  515. roi_goal = ?,
  516. ql_bid = ?,
  517. infra_status = ?,
  518. pay_type = ?,
  519. qm_id = ?,
  520. ldy_template_site_id = ?,
  521. yw_id = ?,
  522. parent_platform_id = ?,
  523. platform_shared_id = ?,
  524. distributor_id = ?,
  525. is_delete = ?,
  526. ad_convert_type = ?,
  527. aweme_id = ?,
  528. tg_app_index = ?,
  529. butler_id = ?,
  530. mini_program_platform_id = ?,
  531. landing_page = ?,
  532. valid_timer_time = ?,
  533. valid_timer_number = ?,
  534. channelId = ?,
  535. no_bid_budget = ?,
  536. max_ad_quantity = ?,
  537. tg_platform_id = ?,
  538. app_id = ?,
  539. main_name = ?,
  540. update_time = ?,
  541. running_status = ?,
  542. ad_quantity = ?,
  543. cpa_bid = ?,
  544. bid_type = ?,
  545. bid_ratio = ?,
  546. custom_budget = ?,
  547. daily_new_limit = ?,
  548. valid_time = ?,
  549. tg_link_config = ?,
  550. group_id = ?
  551. WHERE id = ?
  552. ]]
  553. local params = {
  554. msg_body.tf_support_status,
  555. msg_body.internal_advertiser_classify,
  556. msg_body.aigc_status,
  557. cjson.encode(msg_body.zy_conifg),
  558. msg_body.title_pay_type,
  559. msg_body.is_boost,
  560. msg_body.is_reservation,
  561. msg_body.title_type_id,
  562. msg_body.is_group_record,
  563. msg_body.tf_time_interval,
  564. msg_body.mat_roi,
  565. msg_body.reduce_roi,
  566. msg_body.boost_high_price_end_time,
  567. msg_body.boost_high_price_number,
  568. msg_body.reduce_consume_amount,
  569. msg_body.reduce_bid_amount,
  570. msg_body.is_comment,
  571. msg_body.convert_cnt,
  572. msg_body.material_rule_id,
  573. msg_body.material_rule_number,
  574. msg_body.valid_timer_like_num,
  575. msg_body.tg_day,
  576. msg_body.ads_operation_status,
  577. msg_body.statistics_platform_id,
  578. msg_body.hide_if_converted,
  579. msg_body.converted_time_duration,
  580. msg_body.cbo_script_time,
  581. msg_body.cbo_script_status,
  582. msg_body.cbo_status,
  583. msg_body.project_type,
  584. msg_body.tf_status,
  585. msg_body.tf_start_time,
  586. msg_body.stat_cost,
  587. msg_body.oce_product_id,
  588. msg_body.oce_product_platform_id,
  589. msg_body.material_platform_id,
  590. msg_body.strategy_config,
  591. msg_body.delivery_mode,
  592. msg_body.price,
  593. msg_body.pack_strategy_status,
  594. msg_body.start_chapter,
  595. msg_body.advertiser_id,
  596. msg_body.wx_miniapp_create_status,
  597. 0,
  598. msg_body.ad_act,
  599. msg_body.template_bid,
  600. msg_body.zh_id,
  601. msg_body.roi_goal,
  602. msg_body.ql_bid,
  603. msg_body.infra_status,
  604. msg_body.pay_type,
  605. msg_body.qm_id,
  606. msg_body.ldy_template_site_id,
  607. msg_body.yw_id,
  608. msg_body.parent_platform_id,
  609. msg_body.platform_shared_id,
  610. msg_body.distributor_id,
  611. msg_body.is_delete,
  612. msg_body.ad_convert_type,
  613. msg_body.aweme_id,
  614. msg_body.tg_app_index,
  615. msg_body.butler_id,
  616. msg_body.mini_program_platform_id,
  617. msg_body.landing_page,
  618. tonumber(msg_body.valid_timer_time),
  619. tonumber(msg_body.valid_timer_number),
  620. msg_body.channelId,
  621. msg_body.no_bid_budget,
  622. msg_body.max_ad_quantity,
  623. msg_body.tg_platform_id,
  624. msg_body.app_id,
  625. msg_body.main_name,
  626. msg_body.update_time,
  627. msg_body.running_status,
  628. msg_body.ad_quantity,
  629. msg_body.cpa_bid,
  630. msg_body.bid_type,
  631. msg_body.bid_ratio,
  632. msg_body.custom_budget,
  633. tonumber(msg_body.daily_new_limit),
  634. tonumber(msg_body.valid_time),
  635. cjson.encode(msg_body.tg_link_config),
  636. msg_body.group_id,
  637. msg_body.id
  638. }
  639. local sql = combine_query_and_params(query,params)
  640. skynet.error("sql:",sql)
  641. -- 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 ",
  642. -- 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,
  643. -- 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)
  644. tools.dump(mysqldbx.query(sql))
  645. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateMainConfig"}))
  646. return true
  647. end
  648. --配置主体推广链接
  649. function M.tgLinkConfig(msg_body)
  650. local isok ,key = tools.checkData({"id","is_open","huichuan_id","chongzhi_id","kadian_id","f_chongzhi_id","site_id"},msg_body)
  651. if not isok then
  652. return false,string.format("缺少字段: %s.", key)
  653. end
  654. local sql = string.format("select tg_link_config from `tg_main` WHERE id = %d ",msg_body.id)
  655. local res = mysqldbx.query(sql)
  656. sql = string.format("UPDATE `tg_main` SET tg_link_config = '%s' WHERE id = %d ",
  657. cjson.encode(msg_body),msg_body.id)
  658. mysqldbx.query(sql)
  659. return true, {}
  660. end
  661. --设置创建链接状态
  662. function M.set_open_create_link_status(msg_body)
  663. local isok ,key = tools.checkData({"id","is_open_create_link"},msg_body)
  664. if not isok then
  665. return false,string.format("缺少字段: %s.", key)
  666. end
  667. local sql = string.format("UPDATE `tg_main` SET is_open_create_link = %d WHERE id = %d ",
  668. msg_body.is_open_create_link,msg_body.id)
  669. mysqldbx.query(sql)
  670. return true, {}
  671. end
  672. --获取主体下的运行总数
  673. function M.get_main_ad_run_number(msg_body)
  674. local isok ,key = tools.checkData({"main_id"},msg_body)
  675. if not isok then
  676. return false,string.format("缺少字段: %s.", key)
  677. end
  678. local sql ="SELECT * FROM advertiser WHERE main_id = " .. msg_body.main_id;
  679. local res = mysqldbx.query(sql)
  680. local all_run_number = 0
  681. for i = 1, #res, 1 do
  682. local run_number = res[i].ad_run_number
  683. all_run_number = all_run_number + run_number
  684. end
  685. local nums = #res
  686. sql = string.format("select * from `tg_main` where id = %d LIMIT 1 ",msg_body.main_id)
  687. res = mysqldbx.query(sql)
  688. local max = nums * res[1].max_ad_quantity
  689. return true,{all_run_number=all_run_number,max=max}
  690. end
  691. function M.search_info_by_id(msg_body)
  692. local isok ,key = tools.checkData({"query_list"},msg_body)
  693. if not isok then
  694. return false,string.format("缺少字段: %s.", key)
  695. end
  696. local idString = table.concat(msg_body.query_list, ",")
  697. local sql = string.format("SELECT * FROM tg_main WHERE id IN (%s)",idString)
  698. local res = mysqldbx.query(sql)
  699. return true,res
  700. end
  701. function M.search_info_by_tg_app_index(msg_body)
  702. local isok ,key = tools.checkData({"query_list"},msg_body)
  703. if not isok then
  704. return false,string.format("缺少字段: %s.", key)
  705. end
  706. local idString = table.concat(msg_body.query_list, ",")
  707. local sql = string.format("SELECT * FROM tg_main WHERE tg_app_index IN (%s)",idString)
  708. local res = mysqldbx.query(sql)
  709. return true,res
  710. end
  711. function M.updateParentMain(parent_main_id)
  712. local sql = string.format("select * from `tg_main` where id = '%s' LIMIT 1 ",parent_main_id)
  713. local res = mysqldbx.query(sql)
  714. local main_info = nil
  715. if #res>0 then
  716. main_info = res[1]
  717. end
  718. if main_info~=nil then
  719. sql = string.format("select * from `tg_main` where parent_main_id = %d LIMIT 500 ",parent_main_id)
  720. res = mysqldbx.query(sql)
  721. local child_list = nil
  722. local id_list = {}
  723. if #res>0 then
  724. child_list = res
  725. for i = 1, #child_list, 1 do
  726. table.insert(id_list,i,child_list[i].id)
  727. end
  728. end
  729. if child_list ~= nil then
  730. local idString = table.concat(id_list, ",")
  731. sql = string.format("UPDATE `tg_main` SET child_main_list = '%s' WHERE id = %d ",idString,parent_main_id)
  732. mysqldbx.query(sql)
  733. end
  734. end
  735. end
  736. function mysqldtaskbx.start()
  737. local function on_connect(db)
  738. db:query("set charset utf8mb4");
  739. end
  740. local conf = config.db_cnf.book_server.mysqldb_task_cnf
  741. db = mysql.connect{
  742. host=conf.ip,
  743. port=conf.port,
  744. database=conf.db,
  745. user=conf.user,
  746. password=conf.password,
  747. charset="utf8mb4",
  748. max_packet_size = 1024 * 1024,
  749. on_connect = on_connect
  750. }
  751. if not db then
  752. error("mysql connect fail")
  753. end
  754. end
  755. function mysqldtaskbx.Singleton()
  756. if db == nil then
  757. mysqldtaskbx.start()
  758. end
  759. return mysqldtaskbx
  760. end
  761. function mysqldtaskbx.query(sql)
  762. return db:query(sql)
  763. end
  764. return M