904118851 8 månader sedan
förälder
incheckning
36ed8ff14c
3 ändrade filer med 110 tillägg och 21 borttagningar
  1. 68 0
      service/backmgr/fq_mf_book.lua
  2. 40 21
      service/backmgr/origin_data.lua
  3. 2 0
      service/doc/cmd_sql.sql

+ 68 - 0
service/backmgr/fq_mf_book.lua

@@ -0,0 +1,68 @@
+--番茄免费
+local M = {}
+local mysqldbx = require "mysqldbx"
+local tools = require "tools"
+local skynet = require "skynet"
+local cjson = require "cjson"
+
+function M.get_all_fq_mf_key()
+    local sql = "SELECT * FROM fq_mf_book_config "
+    local res = mysqldbx.query(sql)
+    return true,res
+end
+
+function M.add_fq_mf_book_sid_tt(msg_body)
+    local isok ,key =  tools.checkData({"sid_tt","name"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local sql = string.format("SELECT * FROM fq_mf_book_config WHERE sid_tt = '%s' LIMIT 1", msg_body.sid_tt)
+    local isok,res;
+    res = mysqldbx.query(sql)
+    if #res > 0 then
+        return false ,"sid_tt :"..msg_body.sid_tt.." 已存在!"
+    end
+    sql = string.format("INSERT INTO `fq_mf_book_config` (sid_tt,name)  VALUES ('%s','%s')",msg_body.sid_tt,msg_body.name)
+    mysqldbx.query(sql)
+    skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateFqMfKeyList"}))
+    return true, {}
+end
+
+function M.delete_fq_mf_book_sid_tt(msg_body)
+    local isok ,key =  tools.checkData({"sid_tt"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local sql = string.format("DELETE FROM fq_mf_book_config WHERE sid_tt = '%s' ",msg_body.sid_tt)
+    mysqldbx.query(sql)
+    skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateFqMfKeyList"}))
+    return true, {}
+end
+
+
+function M.set_use_status(msg_body)
+    local isok ,key =  tools.checkData({"canUse","id"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local sql = string.format("UPDATE  fq_mf_book_config SET canUse = %d WHERE id =%d ",msg_body.canUse,msg_body.id)
+    mysqldbx.query(sql)
+    skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateFqMfKeyList"}))
+    return true, {}
+end
+
+function M.fq_mf_book_list(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 = "SELECT * FROM fq_mf_book_config "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
+    local list = mysqldbx.query(sql)
+    sql = "SELECT   COUNT(*) AS total  FROM fq_mf_book_config "
+    local total = mysqldbx.query(sql)
+    return true,list,total[1].total
+end
+return M

+ 40 - 21
service/backmgr/origin_data.lua

@@ -23,39 +23,58 @@ function M.search_origin_data(msg_body)
     local page_number = msg_body.page_number
     local offset = (page_number - 1) * page_size
 
-    local create_date_param = ""
-    if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
-        create_date_param = " AND DATE(create_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_create_time / 1000) .. ")) AND DATE(create_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_create_time / 1000) .. "))"
+    -- 使用数组构建查询条件,避免字符串拼接
+    local conditions = {"1=1"}
+    local params = {}
+
+    -- 创建时间条件
+    if msg_body.start_create_time ~= "" and msg_body.end_create_time ~= "" then
+        table.insert(conditions, "DATE(create_time) BETWEEN DATE(FROM_UNIXTIME(?)) AND DATE(FROM_UNIXTIME(?))")
+        table.insert(params, msg_body.start_create_time / 1000)
+        table.insert(params, msg_body.end_create_time / 1000)
     end
 
-    local date_param = ""
-    if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" 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) .. "))"
+    -- 发布时间条件
+    if msg_body.start_publish_time ~= "" and msg_body.end_publish_time ~= "" then
+        table.insert(conditions, "DATE(publish_time) BETWEEN DATE(FROM_UNIXTIME(?)) AND DATE(FROM_UNIXTIME(?))")
+        table.insert(params, msg_body.start_publish_time / 1000)
+        table.insert(params, msg_body.end_publish_time / 1000)
     end
 
-
-    local guajian_info_param = ""
-    if msg_body.guajian_info~="" then
-        guajian_info_param =  string.format(" AND  ( guajian_link LIKE CONCAT( '%%%s%%')) ",msg_body.guajian_info)
+    -- 挂件信息条件
+    if msg_body.guajian_info ~= "" then
+        table.insert(conditions, "guajian_link LIKE ?")
+        table.insert(params, "%" .. msg_body.guajian_info .. "%")
     end
 
-    local materialId_param = ""
-    if msg_body.materialId~="" then
-        materialId_param =  string.format(" AND materialId = '%s' ",msg_body.materialId)
+    -- 材料ID条件
+    if msg_body.materialId ~= "" then
+        table.insert(conditions, "materialId = ?")
+        table.insert(params, msg_body.materialId)
     end
 
-    local param = date_param..create_date_param..guajian_info_param..materialId_param
-
-
-    local sql = "SELECT * FROM origin_data WHERE 1=1 "..param.."ORDER BY id DESC"..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
+    -- 构建WHERE子句
+    local where_clause = table.concat(conditions, " AND ")
 
-    local res =  mysqldbx.query(sql)
+    -- 使用子查询优化分页
+    local sql = string.format([[
+        SELECT * FROM (
+            SELECT id FROM origin_data 
+            WHERE %s 
+            ORDER BY id DESC 
+            LIMIT %d OFFSET %d
+        ) AS tmp 
+        JOIN origin_data USING(id)
+    ]], where_clause, page_size, offset)
 
-    sql =  "SELECT  COUNT(*) AS total  FROM origin_data WHERE 1=1 "..param
+    -- 使用 COUNT(*) 优化总数查询
+    local count_sql = string.format("SELECT COUNT(*) AS total FROM origin_data WHERE %s", where_clause)
 
-    local total = mysqldbx.query(sql)
+    -- 执行查询
+    local res = mysqldbx.query(sql, table.unpack(params))
+    local total = mysqldbx.query(count_sql, table.unpack(params))
 
-    return true,res,total[1].total
+    return true, res, total[1].total
 end
 
 return M

+ 2 - 0
service/doc/cmd_sql.sql

@@ -196,3 +196,5 @@ create table tg_mini_program_platform (
 	mini_program_platform_id  int,	
 	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
 primary key (id));
+
+