tg_zhanghu.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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.setZhanghuOfMain(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 current_time = os.date("%Y-%m-%d %H:%M:%S")
  37. msg_body.update_time = current_time
  38. for i = 1, #msg_body.id_list, 1 do
  39. local id = msg_body.id_list[i]
  40. local sql = string.format("UPDATE `advertiser` SET main_id = %d WHERE id = %d ",
  41. msg_body.main_id,id)
  42. skynet.error(sql)
  43. mysqldbx.query(sql)
  44. end
  45. return true,{}
  46. end
  47. function M.searchZhanghu(msg_body)
  48. local isok ,key = tools.checkData({"advertiser_id"},msg_body)
  49. if not isok then
  50. return false,string.format("缺少字段: %s.", key)
  51. end
  52. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_id = '%s' LIMIT 1 ", tostring(msg_body.advertiser_id))
  53. local res;
  54. res = mysqldbx.query(sql)
  55. local info = {}
  56. if #res>0 then
  57. info = res[1]
  58. end
  59. return true,info
  60. end
  61. function M.searchName(msg_body)
  62. local isok ,key = tools.checkData({"content","page_size","page_number"},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 sql = string.format(" SELECT COUNT(*) AS total FROM advertiser advertiser_name LIKE '%%%s%%' ", msg_body.content)
  70. local total = mysqldbx.query(sql)
  71. sql = string.format("SELECT * FROM advertiser WHERE advertiser_name LIKE '%%%s%%' ORDER BY id LIMIT %d OFFSET %d ", msg_body.content, page_size, offset)
  72. local res;
  73. res = mysqldbx.query(sql)
  74. return true,res,total[1].total
  75. end
  76. function M.switch(msg_body)
  77. local isok ,key = tools.checkData({"id_list","status"},msg_body)
  78. if not isok then
  79. return false,string.format("缺少字段: %s.", key)
  80. end
  81. for i = 1, #msg_body.id_list, 1 do
  82. local id = msg_body.id_list[i]
  83. local sql = string.format("UPDATE `advertiser` SET status = %d WHERE id = %d ",
  84. msg_body.status,id)
  85. local res;
  86. res = mysqldbx.query(sql)
  87. end
  88. return true,{}
  89. end
  90. function M.mainFilter(msg_body)
  91. local isok ,key = tools.checkData({"content","main_id","page_size","page_number"},msg_body)
  92. if not isok then
  93. return false,string.format("缺少字段: %s.", key)
  94. end
  95. local page_size = msg_body.page_size
  96. local page_number = msg_body.page_number
  97. local offset = (page_number - 1) * page_size
  98. local main_id_param = ""
  99. if msg_body.main_id ~= "" then
  100. main_id_param = " AND main_id = "..msg_body.main_id.." "
  101. end
  102. local content_param = ""
  103. if msg_body.content ~= "" then
  104. content_param = string.format(" AND (advertiser_name LIKE CONCAT( '%%%s%%')) OR (advertiser_id LIKE CONCAT('%%%s%%'))",msg_body.content,msg_body.content)
  105. end
  106. local sql = "SELECT COUNT(*) AS total FROM advertiser WHERE 1=1 "..main_id_param..content_param
  107. local total = mysqldbx.query(sql)
  108. sql = "SELECT * FROM advertiser WHERE 1=1 "..main_id_param..content_param..string.format(" ORDER BY id LIMIT %d OFFSET %d ",page_size, offset)
  109. local res;
  110. res = mysqldbx.query(sql)
  111. return true,res,total[1].total
  112. end
  113. function M.search(msg_body)
  114. local isok ,key = tools.checkData({"main_id","content","page_size","page_number","status"},msg_body)
  115. if not isok then
  116. return false,string.format("缺少字段: %s.", key)
  117. end
  118. local page_size = msg_body.page_size
  119. local page_number = msg_body.page_number
  120. local offset = (page_number - 1) * page_size
  121. local statuss_param = ""
  122. if msg_body.status~="" then
  123. statuss_param = "AND status = "..msg_body.status.." "
  124. end
  125. local main_id_param = ""
  126. if msg_body.main_id ~= "" then
  127. main_id_param = " AND main_id = "..msg_body.main_id.." "
  128. end
  129. local content_param = ""
  130. if msg_body.content ~= "" then
  131. content_param = string.format(" AND (advertiser_name LIKE CONCAT( '%%%s%%')) OR (advertiser_id LIKE CONCAT('%%%s%%'))",msg_body.content,msg_body.content)
  132. end
  133. local param = statuss_param..main_id_param..content_param
  134. local sql = "SELECT COUNT(*) AS total FROM advertiser WHERE 1=1 "..param
  135. local total = mysqldbx.query(sql)
  136. sql = "SELECT * FROM advertiser WHERE 1=1 "..param..string.format(" ORDER BY id LIMIT %d OFFSET %d ",page_size, offset)
  137. local res;
  138. res = mysqldbx.query(sql)
  139. return true,res,total[1].total
  140. end
  141. function M.search_info_by_id(msg_body)
  142. local isok ,key = tools.checkData({"query_list"},msg_body)
  143. if not isok then
  144. return false,string.format("缺少字段: %s.", key)
  145. end
  146. local temp = {}
  147. for i = 1, #msg_body.query_list, 1 do
  148. local zhang_hu_id = msg_body.query_list[i].zhang_hu_id..""
  149. local key = msg_body.query_list[i].id
  150. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_id = '%s' LIMIT 1",zhang_hu_id)
  151. local res = mysqldbx.query(sql)
  152. if #res >0 then
  153. table.insert(temp,#temp+1,res[1])
  154. end
  155. end
  156. return true,temp
  157. end
  158. function M.update_zhanghu(msg_body)
  159. httpc.dns() -- set dns server
  160. httpc.timeout = 100 -- set timeout 1 second
  161. local status, body = httpc.get('https://clipvideoup.s6kuwan.com/adoce/advertiser/sync_center_advertiser','',{})
  162. if status == 200 then
  163. return true,{}
  164. else
  165. return false,{}
  166. end
  167. return true,{}
  168. end
  169. function searchZhanghuName(name,id)
  170. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_name LIKE '%%%s%%'", name)
  171. local res;
  172. res = mysqldbx.query(sql)
  173. local id_list = {}
  174. for i = 1, #res, 1 do
  175. table.insert(id_list,i,res[i].id)
  176. end
  177. if #id_list> 0 then
  178. M.setZhanghuOfMain({id_list=id_list,main_id=id})
  179. end
  180. end
  181. function M.advertiserListOfMain(msg_body)
  182. local isok ,key = tools.checkData({"id_list","main_id"},msg_body)
  183. if not isok then
  184. return false,string.format("缺少字段: %s.", key)
  185. end
  186. local fail_list = {}
  187. for i = 1, #msg_body.id_list, 1 do
  188. local id = msg_body.id_list[i]
  189. local sql = string.format("SELECT * FROM advertiser where advertiser_id = '%s' and main_id = %d ", id,msg_body.main_id)
  190. local isok,res;
  191. res = mysqldbx.query(sql)
  192. if #res <1 then
  193. table.insert(fail_list,#fail_list+1,id)
  194. end
  195. end
  196. return true,fail_list
  197. end
  198. function M.init()
  199. local sql = string.format("select * from `tg_main` ")
  200. local isok,res;
  201. res = mysqldbx.query(sql)
  202. if #res > 0 then
  203. tools.dump(res)
  204. for i = 1, #res, 1 do
  205. local name = res[i].main_name
  206. searchZhanghuName(name,res[i].id)
  207. end
  208. end
  209. return true,{}
  210. end
  211. return M