tg_zhanghu.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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({"content","page_size","page_number"},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 sql = string.format("SELECT COUNT(*) AS total FROM advertiser WHERE (advertiser_name LIKE CONCAT( '%%%s%%')) OR (advertiser_id LIKE CONCAT('%%%s%%')) ", msg_body.content,msg_body.content)
  122. local total = mysqldbx.query(sql)
  123. sql = string.format("SELECT * FROM advertiser WHERE (advertiser_name LIKE CONCAT( '%%%s%%')) OR (advertiser_id LIKE CONCAT('%%%s%%')) ORDER BY id LIMIT %d OFFSET %d", msg_body.content, msg_body.content, page_size, offset)
  124. local res;
  125. res = mysqldbx.query(sql)
  126. return true,res,total[1].total
  127. end
  128. function M.search_info_by_id(msg_body)
  129. local isok ,key = tools.checkData({"query_list"},msg_body)
  130. if not isok then
  131. return false,string.format("缺少字段: %s.", key)
  132. end
  133. local temp = {}
  134. for i = 1, #msg_body.query_list, 1 do
  135. local zhang_hu_id = msg_body.query_list[i].zhang_hu_id..""
  136. local key = msg_body.query_list[i].id
  137. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_id = '%s' LIMIT 1",zhang_hu_id)
  138. local res = mysqldbx.query(sql)
  139. if #res >0 then
  140. table.insert(temp,#temp+1,res[1])
  141. end
  142. end
  143. return true,temp
  144. end
  145. function M.update_zhanghu(msg_body)
  146. httpc.dns() -- set dns server
  147. httpc.timeout = 100 -- set timeout 1 second
  148. local status, body = httpc.get('https://clipvideoup.s6kuwan.com/adoce/advertiser/sync_center_advertiser','',{})
  149. if status == 200 then
  150. return true,{}
  151. else
  152. return false,{}
  153. end
  154. return true,{}
  155. end
  156. function searchZhanghuName(name,id)
  157. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_name LIKE '%%%s%%'", name)
  158. local res;
  159. res = mysqldbx.query(sql)
  160. local id_list = {}
  161. for i = 1, #res, 1 do
  162. table.insert(id_list,i,res[i].id)
  163. end
  164. if #id_list> 0 then
  165. M.setZhanghuOfMain({id_list=id_list,main_id=id})
  166. end
  167. end
  168. function M.init()
  169. local sql = string.format("select * from `tg_main` ")
  170. local isok,res;
  171. res = mysqldbx.query(sql)
  172. if #res > 0 then
  173. tools.dump(res)
  174. for i = 1, #res, 1 do
  175. local name = res[i].main_name
  176. searchZhanghuName(name,res[i].id)
  177. end
  178. end
  179. return true,{}
  180. end
  181. return M