|
@@ -200,24 +200,70 @@ function M.search_tg_data(msg_body)
|
|
|
if not isok then
|
|
|
return false,string.format("缺少字段: %s.", key)
|
|
|
end
|
|
|
+ local isFirst = false
|
|
|
local page_size = msg_body.page_size
|
|
|
local page_number = msg_body.page_number
|
|
|
local offset = (page_number - 1) * page_size
|
|
|
local product_param = ""
|
|
|
if msg_body.product_id~="" then
|
|
|
- product_param = "AND product_id = "..msg_body.product_id.." "
|
|
|
+ isFirst = true
|
|
|
+ product_param = string.format(" product_id = %d ",tonumber(msg_body.product_id))
|
|
|
end
|
|
|
local oce_material_param = ""
|
|
|
if msg_body.oce_material_id~="" then
|
|
|
- oce_material_param = "AND oce_material_id = "..msg_body.oce_material_id.." "
|
|
|
+ if isFirst == true then
|
|
|
+ oce_material_param =string.format("AND oce_material_id = %d ",tonumber(msg_body.oce_material_id))
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ oce_material_param =string.format(" oce_material_id = %d ",tonumber(msg_body.oce_material_id))
|
|
|
+ end
|
|
|
end
|
|
|
local tg_platform_param = ""
|
|
|
if msg_body.tg_platform_id~="" then
|
|
|
- tg_platform_param = "AND book_platform = "..msg_body.tg_platform_id.." "
|
|
|
+ if isFirst == true then
|
|
|
+ tg_platform_param = "AND book_platform = "..msg_body.tg_platform_id.." "
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ tg_platform_param = " book_platform = "..msg_body.tg_platform_id.." "
|
|
|
+ end
|
|
|
end
|
|
|
- local sql = "SELECT id FROM video_material ORDER BY id DESC WHERE DATE(create_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_time_date / 1000) .. ")) AND DATE(create_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_time_date / 1000) .. "))"..product_param..oce_material_param..tg_platform_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
+
|
|
|
+ local date_param = ""
|
|
|
+ if msg_body.start_time_date~="" and msg_body.end_time_date~="" then
|
|
|
+ if isFirst == true then
|
|
|
+ date_param = " AND DATE(create_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_time_date / 1000) .. ")) AND DATE(create_at) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_time_date / 1000) .. "))"
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ date_param = " DATE(create_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_time_date / 1000) .. ")) AND DATE(create_at) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_time_date / 1000) .. "))"
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ local sync_status_param = ""
|
|
|
+
|
|
|
+ if msg_body.sync_status~="" then
|
|
|
+ if isFirst == true then
|
|
|
+ sync_status_param = "AND sync_status = "..msg_body.sync_status.." "
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ sync_status_param = " sync_status = "..msg_body.sync_status.." "
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ local param = date_param..product_param..oce_material_param..tg_platform_param..sync_status_param
|
|
|
+
|
|
|
+ if param ~= "" then
|
|
|
+ param = " WHERE "..param
|
|
|
+ end
|
|
|
+
|
|
|
+ local sql = "SELECT * FROM video_material "..param.." ORDER BY id DESC "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
+
|
|
|
local res = mysqldbx.query(sql)
|
|
|
- return true,res
|
|
|
+
|
|
|
+
|
|
|
+ sql = "SELECT COUNT(*) AS total FROM video_material "..param.." ORDER BY id DESC "
|
|
|
+ local total = mysqldbx.query(sql)
|
|
|
+
|
|
|
+ return true,res,total[1].total
|
|
|
end
|
|
|
|
|
|
|
|
@@ -251,12 +297,12 @@ end
|
|
|
--product_name 书名
|
|
|
--oce_material_id 巨量素材ID
|
|
|
function M.search_bao_liang_data(msg_body)
|
|
|
- local isok ,key = tools.checkData({"end_time_date",
|
|
|
- "start_time_date",
|
|
|
+ local isok ,key = tools.checkData({
|
|
|
"product_name",
|
|
|
"product_id",
|
|
|
"tg_platform_id",
|
|
|
"oce_material_id",
|
|
|
+ "tg_main_id",
|
|
|
"page_size",
|
|
|
"page_number"},msg_body)
|
|
|
if not isok then
|
|
@@ -265,21 +311,55 @@ function M.search_bao_liang_data(msg_body)
|
|
|
local page_size = msg_body.page_size
|
|
|
local page_number = msg_body.page_number
|
|
|
local offset = (page_number - 1) * page_size
|
|
|
+ local isFirst = false
|
|
|
local product_param = ""
|
|
|
if msg_body.product_id~="" then
|
|
|
- product_param = "AND product_id = "..msg_body.product_id.." "
|
|
|
+ isFirst = true
|
|
|
+ product_param = string.format(" product_id = %d ",tonumber(msg_body.product_id))
|
|
|
+ end
|
|
|
+ local main_param = ""
|
|
|
+ if msg_body.tg_main_id~="" then
|
|
|
+ if isFirst == true then
|
|
|
+ main_param = string.format("AND tg_main_id = %d ",tonumber(msg_body.tg_main_id))
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ main_param = string.format(" tg_main_id = %d ",tonumber(msg_body.tg_main_id))
|
|
|
+ end
|
|
|
end
|
|
|
+
|
|
|
local oce_material_param = ""
|
|
|
if msg_body.oce_material_id~="" then
|
|
|
- oce_material_param = "AND oce_material_id = "..msg_body.oce_material_id.." "
|
|
|
+ if isFirst == true then
|
|
|
+ oce_material_param = string.format("AND oce_material_id = %d ",tonumber(msg_body.oce_material_id))
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ oce_material_param = string.format(" oce_material_id = %d ",tonumber(msg_body.oce_material_id))
|
|
|
+ end
|
|
|
+
|
|
|
end
|
|
|
local tg_platform_param = ""
|
|
|
if msg_body.tg_platform_id~="" then
|
|
|
- tg_platform_param = "AND book_platform = "..msg_body.tg_platform_id.." "
|
|
|
+ if isFirst == true then
|
|
|
+ tg_platform_param = " AND tg_platform_id = "..msg_body.tg_platform_id.." "
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ tg_platform_param = " tg_platform_id = "..msg_body.tg_platform_id.." "
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ local param = product_param..oce_material_param..tg_platform_param..main_param;
|
|
|
+
|
|
|
+ if param ~= "" then
|
|
|
+ param = " WHERE "..param
|
|
|
end
|
|
|
- local sql = "SELECT id FROM video_material ORDER BY id DESC WHERE DATE(create_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_time_date / 1000) .. ")) AND DATE(create_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_time_date / 1000) .. "))"..product_param..oce_material_param..tg_platform_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
+
|
|
|
+ local sql = "SELECT * FROM boost_material_history "..param.." ORDER BY id DESC ".. string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
local res = mysqldbx.query(sql)
|
|
|
- return true,res
|
|
|
+ sql = "SELECT COUNT(*) AS total FROM boost_material_history "..param .." ORDER BY id DESC "
|
|
|
+ local total = mysqldbx.query(sql)
|
|
|
+
|
|
|
+ return true,res,total[1].total
|
|
|
end
|
|
|
|
|
|
--搜索书
|
|
@@ -293,7 +373,7 @@ function M.search_book_data(msg_body)
|
|
|
"tg_platform_id",
|
|
|
"oce_material_id",
|
|
|
"page_size",
|
|
|
- "page_number"},msg_body)
|
|
|
+ "page_number","is_auto"},msg_body)
|
|
|
if not isok then
|
|
|
return false,string.format("缺少字段: %s.", key)
|
|
|
end
|
|
@@ -301,20 +381,55 @@ function M.search_book_data(msg_body)
|
|
|
local page_number = msg_body.page_number
|
|
|
local offset = (page_number - 1) * page_size
|
|
|
local product_param = ""
|
|
|
+ local isFirst = false
|
|
|
+ local and_param = " AND "
|
|
|
if msg_body.product_id~="" then
|
|
|
- product_param = "AND product_id = "..msg_body.product_id.." "
|
|
|
+ isFirst = true;
|
|
|
+ product_param = string.format(" product_id = '%s' ",msg_body.product_id)
|
|
|
end
|
|
|
local product_name_param = ""
|
|
|
if msg_body.product_name~="" then
|
|
|
- product_name_param = "AND product_name = "..msg_body.product_name.." "
|
|
|
+ if isFirst==true then
|
|
|
+ product_name_param = string.format("AND product_name = '%s' ",msg_body.product_name)
|
|
|
+ else
|
|
|
+ isFirst = true;
|
|
|
+ product_name_param = string.format(" product_name = '%s' ",msg_body.product_name)
|
|
|
+ end
|
|
|
end
|
|
|
local tg_platform_param = ""
|
|
|
if msg_body.tg_platform_id~="" then
|
|
|
- tg_platform_param = "AND book_platform = "..msg_body.tg_platform_id.." "
|
|
|
- end
|
|
|
- local sql = "SELECT id FROM video_product ORDER BY id DESC WHERE "..product_param..product_name_param..tg_platform_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
- local res = mysqldbx.query(sql)
|
|
|
- return true,res
|
|
|
+ if isFirst==true then
|
|
|
+ tg_platform_param = string.format("AND book_platform = %d ",msg_body.tg_platform_id)
|
|
|
+ else
|
|
|
+ isFirst = true;
|
|
|
+ tg_platform_param = string.format(" book_platform = %d ",msg_body.tg_platform_id)
|
|
|
+ end
|
|
|
+
|
|
|
+ end
|
|
|
+ local is_auto_param = ""
|
|
|
+ if msg_body.is_auto~="" then
|
|
|
+ if isFirst==true then
|
|
|
+ is_auto_param = "AND is_auto = "..msg_body.is_auto.." "
|
|
|
+ else
|
|
|
+ isFirst = true;
|
|
|
+ is_auto_param = " is_auto = "..msg_body.is_auto.." "
|
|
|
+ end
|
|
|
+
|
|
|
+ end
|
|
|
+
|
|
|
+ local param = is_auto_param..product_param..product_name_param..tg_platform_param;
|
|
|
+
|
|
|
+ if param ~= "" then
|
|
|
+ param = " WHERE "..param
|
|
|
+ end
|
|
|
+ local sql = "SELECT * FROM video_product "..param.." ORDER BY id DESC "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
+ local res = mysqldtaskbx.Singleton().query(sql)
|
|
|
+
|
|
|
+ sql = "SELECT COUNT(*) AS total FROM video_product "..param.."ORDER BY id DESC"
|
|
|
+
|
|
|
+ local total = mysqldtaskbx.Singleton().query(sql)
|
|
|
+ tools.dump(total)
|
|
|
+ return true,res,total[1].total
|
|
|
end
|
|
|
|
|
|
--搜索小程序书
|
|
@@ -338,29 +453,149 @@ function M.search_app_book_data(msg_body)
|
|
|
local page_size = msg_body.page_size
|
|
|
local page_number = msg_body.page_number
|
|
|
local offset = (page_number - 1) * page_size
|
|
|
+ local isFirst = false
|
|
|
local product_param = ""
|
|
|
if msg_body.product_id~="" then
|
|
|
- product_param = "AND product_id = "..msg_body.product_id.." "
|
|
|
+ isFirst = true
|
|
|
+ product_param =string.format(" product_id = '%s' ",msg_body.product_id)
|
|
|
end
|
|
|
local product_name_param = ""
|
|
|
if msg_body.product_name~="" then
|
|
|
- product_name_param = "AND product_name = "..msg_body.product_name.." "
|
|
|
+ if isFirst ==true then
|
|
|
+ product_name_param = string.format("AND product_name = '%s' ",msg_body.product_name)
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ product_name_param = string.format(" product_name = '%s' ",msg_body.product_name)
|
|
|
+ end
|
|
|
+
|
|
|
end
|
|
|
local tg_platform_param = ""
|
|
|
if msg_body.tg_platform_id~="" then
|
|
|
- tg_platform_param = "AND book_platform = "..msg_body.tg_platform_id.." "
|
|
|
+ if isFirst ==true then
|
|
|
+ tg_platform_param = "AND book_platform = "..msg_body.tg_platform_id.." "
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ tg_platform_param = " book_platform = "..msg_body.tg_platform_id.." "
|
|
|
+ end
|
|
|
+
|
|
|
end
|
|
|
local main_param = ""
|
|
|
if msg_body.main_id~="" then
|
|
|
- main_param = "AND main_id = "..msg_body.main_id.." "
|
|
|
+ if isFirst == true then
|
|
|
+ main_param = "AND main_id = "..msg_body.main_id.." "
|
|
|
+ else
|
|
|
+ isFirst = true
|
|
|
+ main_param = " main_id = "..msg_body.main_id.." "
|
|
|
+ end
|
|
|
end
|
|
|
local app_param = ""
|
|
|
if msg_body.app_id~="" then
|
|
|
- app_param = "AND dy_small_applet_app_id = "..msg_body.app_id.." "
|
|
|
+ if isFirst == true then
|
|
|
+ app_param = string.format("AND dy_small_applet_app_id = '%s' ",msg_body.app_id)
|
|
|
+ else
|
|
|
+ app_param = string.format(" dy_small_applet_app_id = '%s' ",msg_body.app_id)
|
|
|
+ end
|
|
|
+
|
|
|
end
|
|
|
- local sql = "SELECT id FROM video_product ORDER BY id DESC WHERE "..product_param..product_name_param..tg_platform_param..main_param..app_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
- local res = mysqldbx.query(sql)
|
|
|
- return true,res
|
|
|
+
|
|
|
+ local param = product_param..product_name_param..tg_platform_param..main_param..app_param;
|
|
|
+
|
|
|
+ if param ~= "" then
|
|
|
+ param = " WHERE "..param
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ local sql = "SELECT * FROM video_applet_product "..param.." ORDER BY id DESC "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
+ local list = mysqldtaskbx.Singleton().query(sql)
|
|
|
+
|
|
|
+ sql = "SELECT COUNT(*) AS total FROM video_applet_product "..param.." ORDER BY id DESC "
|
|
|
+
|
|
|
+ local total = mysqldtaskbx.Singleton().query(sql)
|
|
|
+
|
|
|
+ return true,list,total[1].total
|
|
|
+end
|
|
|
+
|
|
|
+--添加书籍数据
|
|
|
+function M.add_book_data(msg_body)
|
|
|
+ local isok ,key = tools.checkData({"tg_platform_id","product_id","product_name"
|
|
|
+ ,"genre","is_store"},msg_body)
|
|
|
+ if not isok then
|
|
|
+ return false,string.format("缺少字段: %s.", key)
|
|
|
+ end
|
|
|
+ local sql ;
|
|
|
+ local isok,res;
|
|
|
+ local sql = string.format("SELECT * FROM video_product where product_id = '%s' LIMIT 1 ",msg_body.product_id)
|
|
|
+ res = mysqldtaskbx.Singleton().query(sql)
|
|
|
+
|
|
|
+ if #res>0 then
|
|
|
+ return false,"书籍已存在!"
|
|
|
+ end
|
|
|
+
|
|
|
+ sql = string.format("INSERT INTO `video_product` (book_platform,product_id, product_name, genre,is_store,is_auto) VALUES (%d,'%s','%s',%d,%d,0)",
|
|
|
+ msg_body.tg_platform_id,
|
|
|
+ msg_body.product_id,
|
|
|
+ msg_body.product_name,
|
|
|
+ msg_body.genre,msg_body.is_store)
|
|
|
+
|
|
|
+ res = mysqldtaskbx.Singleton().query(sql)
|
|
|
+ return true,{}
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+--发送书籍数据到主体
|
|
|
+function M.send_book_data(msg_body)
|
|
|
+ local isok ,key = tools.checkData({"tg_platform_id","app_id","id_list","main_id"},msg_body)
|
|
|
+ if not isok then
|
|
|
+ return false,string.format("缺少字段: %s.", key)
|
|
|
+ end
|
|
|
+ local idString = table.concat(msg_body.id_list, ",")
|
|
|
+ local sql ;
|
|
|
+ local isok,res;
|
|
|
+ local sql = string.format("SELECT * FROM video_product WHERE id IN (%s)",idString)
|
|
|
+ res = mysqldtaskbx.Singleton().query(sql)
|
|
|
+ for i = 1, #res, 1 do
|
|
|
+ local product_id = res[i].product_id
|
|
|
+ local product_name = res[i].product_name
|
|
|
+ local sql = string.format("SELECT * FROM video_applet_product where product_id = '%s' and book_platform = %d and dy_small_applet_app_id = '%s' ",product_id,msg_body.tg_platform_id,msg_body.app_id)
|
|
|
+ res = mysqldtaskbx.Singleton().query(sql)
|
|
|
+ if #res<=0 then
|
|
|
+ sql = string.format("INSERT INTO `video_applet_product` (product_id,product_name,book_platform,dy_small_applet_app_id,main_id,wait_status,status) VALUES ('%s','%s',%d,'%s',%d,%d,%d)",
|
|
|
+ product_id,product_name,msg_body.tg_platform_id,msg_body.app_id,msg_body.main_id,0,0)
|
|
|
+ res = mysqldtaskbx.Singleton().query(sql)
|
|
|
+ end
|
|
|
+ end
|
|
|
+ return true,{}
|
|
|
+end
|
|
|
+--删除书籍
|
|
|
+function M.delete_book_data(msg_body)
|
|
|
+ local isok ,key = tools.checkData({"id_list"},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("DELETE FROM video_product WHERE id = %d ",id)
|
|
|
+ local res = mysqldtaskbx.Singleton().query(sql)
|
|
|
+ tools.dump(res)
|
|
|
+ end
|
|
|
+
|
|
|
+ return true,{}
|
|
|
+end
|
|
|
+
|
|
|
+--书籍入库
|
|
|
+function M.set_book_data_is_store(msg_body)
|
|
|
+ local isok ,key = tools.checkData({"id_list"},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 video_product SET is_store = %d WHERE id = %d ",1,id)
|
|
|
+ local res = mysqldtaskbx.Singleton().query(sql)
|
|
|
+ end
|
|
|
+ return true,{}
|
|
|
end
|
|
|
|
|
|
function mysqldtaskbx.start()
|