123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- --小程序书籍
- 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.add_applet_product(msg_body)
- local isok ,key = tools.checkData({"product_name","product_id","book_platform","dy_small_program_start","dy_small_program_start_data","dy_small_applet_app_id","check_url","main_id","status"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("INSERT INTO `video_applet_product` (product_name,product_id,book_platform,dy_small_program_start,dy_small_program_start_data,dy_small_applet_app_id,check_url,main_id,status,wait_status) VALUES ('%s','%s',%d,'%s','%s','%s','%s',%d,%d,%d)",
- msg_body.product_name,msg_body.product_id,msg_body.book_platform,msg_body.dy_small_program_start,msg_body.dy_small_program_start_data,msg_body.dy_small_applet_app_id,msg_body.check_url,msg_body.main_id,msg_body.status,2)
- mysqldtaskbx.Singleton().query(sql)
- return true, {}
- end
- --开启小程序书籍任务
- function M.open_app_book_task(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 res,sql,id;
- id = msg_body.id_list[i]
- sql = string.format("UPDATE video_applet_product SET status = 0 , wait_status = 0 ,is_close_execution = 1 WHERE id = %d ",id)
- res = mysqldtaskbx.Singleton().query(sql)
- end
- return true,{}
- 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
- return M
|