tg_main.lua 30 KB

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