video_applet_product.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. function mysqldtaskbx.start()
  22. local function on_connect(db)
  23. db:query("set charset utf8mb4");
  24. end
  25. local conf = config.db_cnf.book_server.mysqldb_task_cnf
  26. db = mysql.connect{
  27. host=conf.ip,
  28. port=conf.port,
  29. database=conf.db,
  30. user=conf.user,
  31. password=conf.password,
  32. charset="utf8mb4",
  33. max_packet_size = 1024 * 1024,
  34. on_connect = on_connect
  35. }
  36. if not db then
  37. skynet.error("mysql connect fail")
  38. end
  39. end
  40. function mysqldtaskbx.Singleton()
  41. if db == nil then
  42. mysqldtaskbx.start()
  43. end
  44. return mysqldtaskbx
  45. end
  46. function mysqldtaskbx.query(sql)
  47. return db:query(sql)
  48. end
  49. return M