tg_zhanghu.lua 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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({"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 property_status_param = ""
  139. if msg_body.property_status~="" then
  140. property_status_param = "AND property_status = "..msg_body.property_status.." "
  141. end
  142. local avatar_status_param = ""
  143. if msg_body.avatar_status~="" then
  144. avatar_status_param = "AND avatar_status = "..msg_body.avatar_status.." "
  145. end
  146. local statuss_param = ""
  147. if msg_body.status~="" then
  148. statuss_param = "AND status = "..msg_body.status.." "
  149. end
  150. local main_id_param = ""
  151. if msg_body.main_id ~= "" then
  152. main_id_param = " AND main_id = "..msg_body.main_id.." "
  153. end
  154. local content_param = ""
  155. if msg_body.content ~= "" then
  156. content_param = string.format(" AND (advertiser_name LIKE CONCAT( '%%%s%%')) OR (advertiser_id LIKE CONCAT('%%%s%%'))",msg_body.content,msg_body.content)
  157. end
  158. local param = avatar_status_param..property_status_param..statuss_param..main_id_param..content_param
  159. local sql = "SELECT COUNT(*) AS total FROM advertiser WHERE 1=1 "..param
  160. local total = mysqldbx.query(sql)
  161. sql = "SELECT * FROM advertiser WHERE 1=1 "..param..string.format(" ORDER BY id LIMIT %d OFFSET %d ",page_size, offset)
  162. local res;
  163. res = mysqldbx.query(sql)
  164. return true,res,total[1].total
  165. end
  166. function M.search_info_by_id(msg_body)
  167. local isok ,key = tools.checkData({"query_list"},msg_body)
  168. if not isok then
  169. return false,string.format("缺少字段: %s.", key)
  170. end
  171. local temp = {}
  172. for i = 1, #msg_body.query_list, 1 do
  173. local zhang_hu_id = msg_body.query_list[i].zhang_hu_id..""
  174. local key = msg_body.query_list[i].id
  175. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_id = '%s' LIMIT 1",zhang_hu_id)
  176. local res = mysqldbx.query(sql)
  177. if #res >0 then
  178. table.insert(temp,#temp+1,res[1])
  179. end
  180. end
  181. return true,temp
  182. end
  183. function M.update_zhanghu(msg_body)
  184. httpc.dns() -- set dns server
  185. httpc.timeout = 100 -- set timeout 1 second
  186. local status, body = httpc.get('https://clipvideoup.s6kuwan.com/adoce/advertiser/sync_center_advertiser','',{})
  187. if status == 200 then
  188. return true,{}
  189. else
  190. return false,{}
  191. end
  192. return true,{}
  193. end
  194. function searchZhanghuName(name,id)
  195. local sql = string.format("SELECT * FROM advertiser WHERE advertiser_name LIKE '%%%s%%'", name)
  196. local res;
  197. res = mysqldbx.query(sql)
  198. local id_list = {}
  199. for i = 1, #res, 1 do
  200. table.insert(id_list,i,res[i].id)
  201. end
  202. if #id_list> 0 then
  203. M.setZhanghuOfMain({id_list=id_list,main_id=id})
  204. end
  205. end
  206. function M.init()
  207. local sql = string.format("select * from `tg_main` ")
  208. local isok,res;
  209. res = mysqldbx.query(sql)
  210. if #res > 0 then
  211. tools.dump(res)
  212. for i = 1, #res, 1 do
  213. local name = res[i].main_name
  214. searchZhanghuName(name,res[i].id)
  215. end
  216. end
  217. return true,{}
  218. end
  219. return M