123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- --账户
- local M = {}
- local mysqldbx = require "mysqldbx"
- local tools = require "tools"
- local skynet = require "skynet"
- local httpc = require "http.httpc"
- --page_size 是你想要在每页中显示的记录数。
- --page_number 页数
- --获取所有账户
- function M.getZhangHuList(msg_body)
- local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local page_size = msg_body.page_size
- local page_number = msg_body.page_number
- local offset = (page_number - 1) * page_size
- local sql = string.format("SELECT * FROM advertiser ORDER BY id LIMIT %d OFFSET %d", page_size, offset)
- local isok,res;
- res = mysqldbx.query(sql)
- if #res <= 0 then
- return true ,{}
- end
- return true, res
- end
- function M.getTotal()
- local sql = "SELECT COUNT(*) AS total FROM advertiser"
- local res = mysqldbx.query(sql)
- return true,res[1]
- end
- function M.setZhanghuOfMain(msg_body)
- local isok ,key = tools.checkData({"id_list","main_id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local current_time = os.date("%Y-%m-%d %H:%M:%S")
- msg_body.update_time = current_time
- for i = 1, #msg_body.id_list, 1 do
- local id = msg_body.id_list[i]
- local sql = string.format("UPDATE `advertiser` SET main_id = %d WHERE id = %d ",
- msg_body.main_id,id)
- skynet.error(sql)
- mysqldbx.query(sql)
- end
- return true,{}
- end
- function M.searchZhanghu(msg_body)
- local isok ,key = tools.checkData({"advertiser_id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("SELECT * FROM advertiser WHERE advertiser_id = '%s' LIMIT 1 ", tostring(msg_body.advertiser_id))
- local res;
- res = mysqldbx.query(sql)
- local info = {}
- if #res>0 then
- info = res[1]
- end
- return true,info
- end
- function M.searchName(msg_body)
- local isok ,key = tools.checkData({"content","page_size","page_number"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local page_size = msg_body.page_size
- local page_number = msg_body.page_number
- local offset = (page_number - 1) * page_size
- local sql = string.format(" SELECT COUNT(*) AS total FROM advertiser advertiser_name LIKE '%%%s%%' ", msg_body.content)
- local total = mysqldbx.query(sql)
- sql = string.format("SELECT * FROM advertiser WHERE advertiser_name LIKE '%%%s%%' ORDER BY id LIMIT %d OFFSET %d ", msg_body.content, page_size, offset)
- local res;
- res = mysqldbx.query(sql)
- return true,res,total[1].total
- end
- function M.switch(msg_body)
- local isok ,key = tools.checkData({"id_list","status"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- for i = 1, #msg_body.id_list, 1 do
- local id = msg_body.id_list[i]
- local sql = string.format("UPDATE `advertiser` SET status = %d WHERE id = %d ",
- msg_body.status,id)
- local res;
- res = mysqldbx.query(sql)
- end
- return true,{}
- end
- function M.mainFilter(msg_body)
- local isok ,key = tools.checkData({"main_id","page_size","page_number"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local page_size = msg_body.page_size
- local page_number = msg_body.page_number
- local offset = (page_number - 1) * page_size
- local sql = string.format(" SELECT COUNT(*) AS total FROM advertiser WHERE main_id = %d ", msg_body.main_id)
- local total = mysqldbx.query(sql)
-
- sql = string.format("SELECT * FROM advertiser WHERE main_id = %d ORDER BY id LIMIT %d OFFSET %d ", msg_body.main_id, page_size, offset)
- local res;
- res = mysqldbx.query(sql)
- return true,res,total[1].total
- end
- function M.search(msg_body)
- local isok ,key = tools.checkData({"content","page_size","page_number"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local page_size = msg_body.page_size
- local page_number = msg_body.page_number
- local offset = (page_number - 1) * page_size
-
- 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)
- local total = mysqldbx.query(sql)
- 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)
- local res;
- res = mysqldbx.query(sql)
- return true,res,total[1].total
- end
- function M.search_info_by_id(msg_body)
- local isok ,key = tools.checkData({"query_list"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local temp = {}
- for i = 1, #msg_body.query_list, 1 do
- local zhang_hu_id = msg_body.query_list[i].zhang_hu_id..""
- local key = msg_body.query_list[i].id
- local sql = string.format("SELECT * FROM advertiser WHERE advertiser_id = '%s' LIMIT 1",zhang_hu_id)
- local res = mysqldbx.query(sql)
- if #res >0 then
- temp[key] = res[1]
- end
- end
- return true,temp
- end
- function M.update_zhanghu(msg_body)
- httpc.dns() -- set dns server
- httpc.timeout = 100 -- set timeout 1 second
- local status, body = httpc.get('https://clipvideoup.s6kuwan.com/adoce/advertiser/sync_center_advertiser','',{})
- if status == 200 then
- return true,{}
- else
- return false,{}
- end
- return true,{}
- end
- function searchZhanghuName(name,id)
- local sql = string.format("SELECT * FROM advertiser WHERE advertiser_name LIKE '%%%s%%'", name)
- local res;
- res = mysqldbx.query(sql)
- local id_list = {}
- for i = 1, #res, 1 do
- table.insert(id_list,i,res[i].id)
- end
- if #id_list> 0 then
- M.setZhanghuOfMain({id_list=id_list,main_id=id})
- end
- end
- function M.init()
- local sql = string.format("select * from `tg_main` ")
- local isok,res;
- res = mysqldbx.query(sql)
- if #res > 0 then
- tools.dump(res)
- for i = 1, #res, 1 do
- local name = res[i].main_name
- searchZhanghuName(name,res[i].id)
- end
- end
- return true,{}
- end
- return M
|