904118851 8 сар өмнө
parent
commit
19f41eb4af

+ 79 - 3
service/backmgr/filter_data.lua

@@ -6,7 +6,8 @@ local skynet = require "skynet"
 local cjson = require "cjson"
 
 function M.search_filter_data(msg_body)
-    local isok ,key =  tools.checkData({"tg_platform_id","page_size","page_number"},msg_body)
+    local isok ,key =  tools.checkData({"tg_platform_id","page_size","page_number",
+    "d_z","comment","collect","forward","product_id","source","start_publish_time","end_publish_time"},msg_body)
     if not isok then
         return false,string.format("缺少字段: %s.", key)
     end
@@ -21,12 +22,87 @@ function M.search_filter_data(msg_body)
         tg_platform_id_param =  " tg_platform_id = "..msg_body.tg_platform_id.." "
     end
 
-    local param = tg_platform_id_param
+
+    local product_param = ""
+    if msg_body.product_id~="" then
+        if isFirst == true then
+            product_param =  string.format(" AND book_id = '%s' ",tonumber(msg_body.product_id))
+        else
+            isFirst = true
+            product_param =  string.format(" book_id = '%s' ",tonumber(msg_body.product_id))
+        end
+    end
+
+    local source_param = ""
+    if msg_body.source~="" then
+        if isFirst == true then
+            source_param =  string.format(" AND source = '%s' ",msg_body.source)
+        else
+            isFirst = true
+            source_param =  string.format(" source = '%s' ",msg_body.source)
+        end
+    end
+
+    local date_param = ""
+    if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then
+        if isFirst == true then
+            date_param = " AND DATE(publish_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_publish_time / 1000) .. ")) AND DATE(publish_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_publish_time / 1000) .. "))"
+        else
+            isFirst = true
+            date_param = " DATE(publish_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_publish_time / 1000) .. ")) AND DATE(publish_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_publish_time / 1000) .. "))"
+        end
+    end
+
+
+    local d_z_param = ""
+    if msg_body.d_z~="" then
+        if(msg_body.d_z == 0) then
+            d_z_param = " like_num ASC"
+        else
+            d_z_param = " like_num DESC"
+        end
+    end
+   
+    local comment_param = ""
+    if msg_body.comment~="" then
+        if(msg_body.comment == 0) then
+            comment_param = " comment_num ASC"
+        else
+            comment_param = " comment_num DESC"
+        end
+    end
+
+    local forward_param = ""
+    if msg_body.forward~="" then
+        if(msg_body.forward == 0) then
+            forward_param = " shared_num ASC"
+        else
+            forward_param = " shared_num DESC"
+        end
+    end
+    
+    local collect_param = ""
+    if msg_body.collect~="" then
+        if(msg_body.collect == 0) then
+            collect_param = " kepp_num ASC"
+        else
+            collect_param = " kepp_num DESC"
+        end
+    end
+    
+
+    local param = date_param..tg_platform_id_param..product_param..source_param
+
+    local up_down_param = d_z_param..comment_param..forward_param..collect_param
+
+    if up_down_param ~= "" then
+        up_down_param = " ORDER BY " ..up_down_param
+    end
 
     if param ~= "" then
         param = " WHERE "..param
     end
-    local sql = "SELECT * FROM filter_data "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
+    local sql = "SELECT * FROM filter_data "..param..up_down_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
 
     local res =  mysqldbx.query(sql)
 

+ 1 - 1
service/backmgr/filter_task.lua

@@ -570,7 +570,7 @@ function M.search_book_data(msg_body)
    
     end
 
-    local param = is_auto_param..product_param..product_name_param..tg_platform_param..is_store_param..genre_param;
+    local param = product_param..product_name_param..tg_platform_param..is_auto_param..is_store_param..genre_param;
 
     if param ~= "" then
         param = " WHERE "..param