tg_main.lua 43 KB

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