tg_zhanghu.lua 6.4 KB

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