tg_zhanghu.lua 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. --账户
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. local httpc = require "http.httpc"
  7. --page_size 是你想要在每页中显示的记录数。
  8. --page_number 页数
  9. --获取所有账户
  10. function M.getZhangHuList(msg_body)
  11. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  12. if not isok then
  13. return false,string.format("缺少字段: %s.", key)
  14. end
  15. local page_size = msg_body.page_size
  16. local page_number = msg_body.page_number
  17. local offset = (page_number - 1) * page_size
  18. local sql = string.format("SELECT * FROM advertiser ORDER BY id LIMIT %d OFFSET %d", page_size, offset)
  19. local isok,res;
  20. res = mysqldbx.query(sql)
  21. if #res <= 0 then
  22. return true ,{}
  23. end
  24. return true, res
  25. end
  26. function M.getTotal()
  27. local sql = "SELECT COUNT(*) AS total FROM advertiser"
  28. local res = mysqldbx.query(sql)
  29. return true,res[1]
  30. end
  31. function M.advertiserListOfMain(msg_body)
  32. local isok ,key = tools.checkData({"id_list","main_id"},msg_body)
  33. if not isok then
  34. return false,string.format("缺少字段: %s.", key)
  35. end
  36. local fail_list = {}
  37. for i = 1, #msg_body.id_list, 1 do
  38. local id = msg_body.id_list[i]
  39. local sql = string.format("SELECT * FROM advertiser where advertiser_id = '%s' and main_id = %d ", id,msg_body.main_id)
  40. local isok,res;
  41. res = mysqldbx.query(sql)
  42. if #res <1 then
  43. table.insert(fail_list,#fail_list+1,id)
  44. end
  45. end
  46. return true,fail_list
  47. end
  48. function M.setZhanghuOfMain(msg_body)
  49. local isok ,key = tools.checkData({"id_list","main_id"},msg_body)
  50. if not isok then
  51. return false,string.format("缺少字段: %s.", key)
  52. end
  53. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  54. msg_body.update_time = current_time
  55. for i = 1, #msg_body.id_list, 1 do
  56. local id = msg_body.id_list[i]
  57. local sql = string.format("UPDATE `advertiser` SET main_id = %d WHERE id = %d ",
  58. msg_body.main_id,id)
  59. skynet.error(sql)
  60. mysqldbx.query(sql)
  61. end
  62. return true,{}
  63. end
  64. function M.searchZhanghu(msg_body)
  65. local isok ,key = tools.checkData({"advertiser_id"},msg_body)
  66. if not isok then
  67. return false,string.format("缺少字段: %s.", key)
  68. end
  69. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_id = '%s' LIMIT 1 ", tostring(msg_body.advertiser_id))
  70. local res;
  71. res = mysqldbx.query(sql)
  72. local info = {}
  73. if #res>0 then
  74. info = res[1]
  75. end
  76. return true,info
  77. end
  78. function M.searchName(msg_body)
  79. local isok ,key = tools.checkData({"content","page_size","page_number"},msg_body)
  80. if not isok then
  81. return false,string.format("缺少字段: %s.", key)
  82. end
  83. local page_size = msg_body.page_size
  84. local page_number = msg_body.page_number
  85. local offset = (page_number - 1) * page_size
  86. local sql = string.format(" SELECT COUNT(*) AS total FROM advertiser advertiser_name LIKE '%%%s%%' ", msg_body.content)
  87. local total = mysqldbx.query(sql)
  88. sql = string.format("SELECT * FROM advertiser WHERE advertiser_name LIKE '%%%s%%' ORDER BY id LIMIT %d OFFSET %d ", msg_body.content, page_size, offset)
  89. local res;
  90. res = mysqldbx.query(sql)
  91. return true,res,total[1].total
  92. end
  93. function M.switch(msg_body)
  94. local isok ,key = tools.checkData({"id_list","status"},msg_body)
  95. if not isok then
  96. return false,string.format("缺少字段: %s.", key)
  97. end
  98. for i = 1, #msg_body.id_list, 1 do
  99. local id = msg_body.id_list[i]
  100. local sql = string.format("UPDATE `advertiser` SET status = %d WHERE id = %d ",
  101. msg_body.status,id)
  102. local res;
  103. res = mysqldbx.query(sql)
  104. end
  105. return true,{}
  106. end
  107. function M.mainFilter(msg_body)
  108. local isok ,key = tools.checkData({"content","main_id","page_size","page_number"},msg_body)
  109. if not isok then
  110. return false,string.format("缺少字段: %s.", key)
  111. end
  112. local page_size = msg_body.page_size
  113. local page_number = msg_body.page_number
  114. local offset = (page_number - 1) * page_size
  115. local main_id_param = ""
  116. if msg_body.main_id ~= "" then
  117. main_id_param = " AND main_id = "..msg_body.main_id.." "
  118. end
  119. local content_param = ""
  120. if msg_body.content ~= "" then
  121. content_param = string.format(" AND (advertiser_name LIKE CONCAT( '%%%s%%')) OR (advertiser_id LIKE CONCAT('%%%s%%'))",msg_body.content,msg_body.content)
  122. end
  123. local sql = "SELECT COUNT(*) AS total FROM advertiser WHERE 1=1 "..main_id_param..content_param
  124. local total = mysqldbx.query(sql)
  125. sql = "SELECT * FROM advertiser WHERE 1=1 "..main_id_param..content_param..string.format(" ORDER BY id LIMIT %d OFFSET %d ",page_size, offset)
  126. local res;
  127. res = mysqldbx.query(sql)
  128. return true,res,total[1].total
  129. end
  130. function M.search(msg_body)
  131. local isok ,key = tools.checkData({"advertiser_id_list","avatar_status","property_status","main_id","content","page_size","page_number","status"},msg_body)
  132. if not isok then
  133. return false,string.format("缺少字段: %s.", key)
  134. end
  135. local page_size = msg_body.page_size
  136. local page_number = msg_body.page_number
  137. local offset = (page_number - 1) * page_size
  138. local advertiser_id_list_param = ""
  139. if msg_body.advertiser_id_list~="" then
  140. local idString = table.concat(msg_body.advertiser_id_list, ",")
  141. advertiser_id_list_param = string.format(" AND advertiser_id IN (%s) ",idString)
  142. end
  143. local property_status_param = ""
  144. if msg_body.property_status~="" then
  145. property_status_param = "AND property_status = "..msg_body.property_status.." "
  146. end
  147. local avatar_status_param = ""
  148. if msg_body.avatar_status~="" then
  149. avatar_status_param = "AND avatar_status = "..msg_body.avatar_status.." "
  150. end
  151. local statuss_param = ""
  152. if msg_body.status~="" then
  153. statuss_param = "AND status = "..msg_body.status.." "
  154. end
  155. local main_id_param = ""
  156. if msg_body.main_id ~= "" then
  157. main_id_param = " AND main_id = "..msg_body.main_id.." "
  158. end
  159. local content_param = ""
  160. if msg_body.content ~= "" then
  161. content_param = string.format(" AND (advertiser_name LIKE CONCAT( '%%%s%%')) OR (advertiser_id LIKE CONCAT('%%%s%%'))",msg_body.content,msg_body.content)
  162. end
  163. local param = advertiser_id_list_param..avatar_status_param..property_status_param..statuss_param..main_id_param..content_param
  164. local sql = "SELECT COUNT(*) AS total FROM advertiser WHERE 1=1 "..param
  165. local total = mysqldbx.query(sql)
  166. sql = "SELECT * FROM advertiser WHERE 1=1 "..param..string.format(" ORDER BY id LIMIT %d OFFSET %d ",page_size, offset)
  167. local res;
  168. res = mysqldbx.query(sql)
  169. return true,res,total[1].total
  170. end
  171. function M.search_info_by_id(msg_body)
  172. local isok ,key = tools.checkData({"query_list"},msg_body)
  173. if not isok then
  174. return false,string.format("缺少字段: %s.", key)
  175. end
  176. local temp = {}
  177. for i = 1, #msg_body.query_list, 1 do
  178. local zhang_hu_id = msg_body.query_list[i].zhang_hu_id..""
  179. local key = msg_body.query_list[i].id
  180. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_id = '%s' LIMIT 1",zhang_hu_id)
  181. local res = mysqldbx.query(sql)
  182. if #res >0 then
  183. table.insert(temp,#temp+1,res[1])
  184. end
  185. end
  186. return true,temp
  187. end
  188. function M.update_zhanghu(msg_body)
  189. httpc.dns() -- set dns server
  190. httpc.timeout = 100 -- set timeout 1 second
  191. local status, body = httpc.get('https://clipvideoup.s6kuwan.com/adoce/advertiser/sync_center_advertiser','',{})
  192. if status == 200 then
  193. return true,{}
  194. else
  195. return false,{}
  196. end
  197. return true,{}
  198. end
  199. function searchZhanghuName(name,id)
  200. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_name LIKE '%%%s%%'", name)
  201. local res;
  202. res = mysqldbx.query(sql)
  203. local id_list = {}
  204. for i = 1, #res, 1 do
  205. table.insert(id_list,i,res[i].id)
  206. end
  207. if #id_list> 0 then
  208. M.setZhanghuOfMain({id_list=id_list,main_id=id})
  209. end
  210. end
  211. function M.init()
  212. local sql = string.format("select * from `tg_main` ")
  213. local isok,res;
  214. res = mysqldbx.query(sql)
  215. if #res > 0 then
  216. tools.dump(res)
  217. for i = 1, #res, 1 do
  218. local name = res[i].main_name
  219. searchZhanghuName(name,res[i].id)
  220. end
  221. end
  222. return true,{}
  223. end
  224. return M