904118851 3 тижнів тому
батько
коміт
def8a06c4c

+ 3 - 0
service/backmgr/init.lua

@@ -48,6 +48,7 @@ local data_manager = require "data_manager"
 local statistics_platform = require "statistics_platform"
 local review_user = require "review_user"
 local log = require "log"
+local product_task = require "product_task"
 local status_200 = 200
 local CMD = {
     
@@ -94,6 +95,8 @@ CMD["data_manager"] = data_manager;
 CMD["statistics_platform"] = statistics_platform;
 CMD["review_user"] = review_user;
 CMD["log"] = log;
+CMD["product_task"] = product_task;
+
 function run(target,fun,msg_body,fd)
     if target~=nil and fun~=nil and target[fun]~=nil then
         local isok,data,total = target[fun](msg_body)

+ 91 - 0
service/backmgr/product_task.lua

@@ -0,0 +1,91 @@
+--书籍任务
+local M = {}
+local mysqldbx = require "mysqldbx"
+local tools = require "tools"
+local skynet = require "skynet"
+local cjson = require "cjson"
+local config = require "run_config"
+local mysql = require "skynet.db.mysql"
+local db
+local mysqldtaskbx = {}
+function M.task()
+
+    skynet.error("执行一次task")
+
+    local sql = string.format("SELECT * FROM video_product where status = 10 AND list_time is not null ")
+
+    local res = mysqldtaskbx.Singleton().query(sql)
+
+    -- 获取当前服务器时间戳
+    local current_timestamp = os.time()
+
+    if #res >0 then
+        -- tools.dump(res)
+        for i = 1, #res, 1 do
+            local mysql_time_str = res[i].list_time
+            local id = res[i].id
+            -- 将MySQL时间字符串转换为时间戳
+            local pattern = "(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)"
+            local year, month, day, hour, min, sec = mysql_time_str:match(pattern)
+            local mysql_timestamp = os.time({
+                year = year,
+                month = month,
+                day = day,
+                hour = hour,
+                min = min,
+                sec = sec
+            })
+   
+            if mysql_timestamp < current_timestamp then
+                -- skynet.error("mysql_timestamp:",mysql_timestamp)
+                -- skynet.error("current_timestamp:",current_timestamp)
+                sql = string.format("UPDATE  video_product SET status = 1  WHERE id = %d ",id)
+                -- skynet.error("sql:",sql) 
+                -- tools.dump(res[i])
+                mysqldtaskbx.Singleton().query(sql)
+            else
+                --还没到时间
+            end
+        end
+    end
+
+
+    skynet.timeout(500, M.task)
+end
+
+
+function mysqldtaskbx.start()
+    local function on_connect(db)
+        db:query("set charset utf8mb4");
+    end
+    local conf = config.db_cnf.book_server.mysqldb_task_cnf
+    db = mysql.connect{
+        host=conf.ip,
+        port=conf.port,
+        database=conf.db,
+        user=conf.user,
+        password=conf.password,
+        charset="utf8mb4",
+        max_packet_size = 1024 * 1024,
+        on_connect = on_connect
+    }
+    if not db then
+       skynet.error("mysql connect fail")
+    end
+end
+
+function mysqldtaskbx.Singleton()
+    if db == nil then
+        mysqldtaskbx.start()
+    end
+    return mysqldtaskbx
+end
+function mysqldtaskbx.query(sql)
+    return db:query(sql)
+end
+
+skynet.start(function ()  --skynet.start启动一个timeout来执行function,创建了一个协程
+    skynet.timeout(500, M.task) --由于function函数还没用完协程,所有这个timeout又创建了一个协程
+end)
+
+return M

+ 15 - 2
service/backmgr/video_product.lua

@@ -353,6 +353,18 @@ function M.set_fee_unit(msg_body)
     return true, {}
 end
 
+--设置上架时间
+function M.set_list_time(msg_body)
+    local isok ,key =  tools.checkData({"list_time","id_list"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local idString = table.concat(msg_body.id_list, ",")
+    local sql = string.format("UPDATE  video_product SET list_time = '%s' WHERE id IN (%s) ",msg_body.list_time,idString)
+    mysqldtaskbx.Singleton().query(sql)
+    return true, {}
+end
+
 --设置 专辑链接 album_link
 function M.set_album_link(msg_body)
     local isok ,key =  tools.checkData({"album_link","id_list"},msg_body)
@@ -384,7 +396,7 @@ end
 
 --添加书籍数据
 function M.add_book_data(msg_body)
-    local isok ,key =  tools.checkData({"words","author","fee_unit","default_price","default_pay_section","publish_time","status","product_parent_id","tg_platform_id","product_id","product_name"
+    local isok ,key =  tools.checkData({"list_time","words","author","fee_unit","default_price","default_pay_section","publish_time","status","product_parent_id","tg_platform_id","product_id","product_name"
     ,"genre","is_store"},msg_body)
     if not isok then
         return false,string.format("缺少字段: %s.", key)
@@ -412,7 +424,8 @@ function M.add_book_data(msg_body)
         return false,"书籍已存在!"
     end
 
-    sql = string.format("INSERT INTO `video_product` (totalChapterNum,match_book,words,author,album_link,fee_unit,default_price,default_pay_section,publish_time,status,product_parent_id,book_platform,product_id, product_name, genre,is_store,is_auto)  VALUES (%d,'%s','%s','%s','%s',%d,%f,%d,'%s',%d,'%s',%d,'%s','%s',%d,%d,0)",
+    sql = string.format("INSERT INTO `video_product` (list_time,totalChapterNum,match_book,words,author,album_link,fee_unit,default_price,default_pay_section,publish_time,status,product_parent_id,book_platform,product_id, product_name, genre,is_store,is_auto)  VALUES ('%s',%d,'%s','%s','%s','%s',%d,%f,%d,'%s',%d,'%s',%d,'%s','%s',%d,%d,0)",
+        msg_body.list_time,
         totalChapterNum,
         match_book,
         msg_body.words,