video_applet_product.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --小程序书籍
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. local cjson = require "cjson"
  7. local config = require "run_config"
  8. local mysql = require "skynet.db.mysql"
  9. local db
  10. local mysqldtaskbx = {}
  11. function M.add_applet_product(msg_body)
  12. 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)
  13. if not isok then
  14. return false,string.format("缺少字段: %s.", key)
  15. end
  16. 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)",
  17. 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)
  18. mysqldtaskbx.Singleton().query(sql)
  19. return true, {}
  20. end
  21. --开启小程序书籍任务
  22. function M.open_app_book_task(msg_body)
  23. local isok ,key = tools.checkData({"id_list"},msg_body)
  24. if not isok then
  25. return false,string.format("缺少字段: %s.", key)
  26. end
  27. for i = 1, #msg_body.id_list, 1 do
  28. local res,sql,id;
  29. id = msg_body.id_list[i]
  30. sql = string.format("UPDATE video_applet_product SET status = 0 , wait_status = 0 ,is_close_execution = 1 WHERE id = %d ",id)
  31. res = mysqldtaskbx.Singleton().query(sql)
  32. end
  33. return true,{}
  34. end
  35. function mysqldtaskbx.start()
  36. local function on_connect(db)
  37. db:query("set charset utf8mb4");
  38. end
  39. local conf = config.db_cnf.book_server.mysqldb_task_cnf
  40. db = mysql.connect{
  41. host=conf.ip,
  42. port=conf.port,
  43. database=conf.db,
  44. user=conf.user,
  45. password=conf.password,
  46. charset="utf8mb4",
  47. max_packet_size = 1024 * 1024,
  48. on_connect = on_connect
  49. }
  50. if not db then
  51. skynet.error("mysql connect fail")
  52. end
  53. end
  54. function mysqldtaskbx.Singleton()
  55. if db == nil then
  56. mysqldtaskbx.start()
  57. end
  58. return mysqldtaskbx
  59. end
  60. function mysqldtaskbx.query(sql)
  61. return db:query(sql)
  62. end
  63. return M