video_applet_product.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. --搜索小程序书
  36. --tg_platform_id 平台id
  37. --product_id 书id
  38. --product_name 书名
  39. --main_id 主体ID
  40. --dy_small_applet_app_id 小程序ID
  41. function M.search_app_book_data(msg_body)
  42. local isok ,key = tools.checkData({
  43. "status",
  44. "product_name",
  45. "product_id",
  46. "tg_platform_id",
  47. "main_id",
  48. "app_id",
  49. "page_size",
  50. "page_number"},msg_body)
  51. if not isok then
  52. return false,string.format("缺少字段: %s.", key)
  53. end
  54. local page_size = msg_body.page_size
  55. local page_number = msg_body.page_number
  56. local offset = (page_number - 1) * page_size
  57. local product_param = ""
  58. if msg_body.product_id~="" then
  59. product_param =string.format(" AND product_id = '%s' ",msg_body.product_id)
  60. end
  61. local product_name_param = ""
  62. if msg_body.product_name~="" then
  63. product_name_param = string.format("AND product_name = '%s' ",msg_body.product_name)
  64. end
  65. local tg_platform_param = ""
  66. if msg_body.tg_platform_id~="" then
  67. tg_platform_param = "AND book_platform = "..msg_body.tg_platform_id.." "
  68. end
  69. local main_param = ""
  70. if msg_body.main_id~="" then
  71. main_param = "AND main_id = "..msg_body.main_id.." "
  72. end
  73. local app_param = ""
  74. if msg_body.app_id~="" then
  75. app_param = string.format("AND dy_small_applet_app_id = '%s' ",msg_body.app_id)
  76. end
  77. local status_param = ""
  78. if msg_body.status~="" then
  79. status_param = " AND status = "..msg_body.status.." "
  80. end
  81. local param = product_param..product_name_param..tg_platform_param..main_param..app_param..status_param;
  82. local sql = "SELECT * FROM video_applet_product WHERE 1=1 "..param.." ORDER BY id DESC "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  83. local list = mysqldtaskbx.Singleton().query(sql)
  84. sql = "SELECT COUNT(*) AS total FROM video_applet_product WHERE 1=1 "..param.." ORDER BY id DESC "
  85. local total = mysqldtaskbx.Singleton().query(sql)
  86. return true,list,total[1].total
  87. end
  88. function mysqldtaskbx.start()
  89. local function on_connect(db)
  90. db:query("set charset utf8mb4");
  91. end
  92. local conf = config.db_cnf.book_server.mysqldb_task_cnf
  93. db = mysql.connect{
  94. host=conf.ip,
  95. port=conf.port,
  96. database=conf.db,
  97. user=conf.user,
  98. password=conf.password,
  99. charset="utf8mb4",
  100. max_packet_size = 1024 * 1024,
  101. on_connect = on_connect
  102. }
  103. if not db then
  104. skynet.error("mysql connect fail")
  105. end
  106. end
  107. function mysqldtaskbx.Singleton()
  108. if db == nil then
  109. mysqldtaskbx.start()
  110. end
  111. return mysqldtaskbx
  112. end
  113. function mysqldtaskbx.query(sql)
  114. return db:query(sql)
  115. end
  116. return M