qm_mf_get_parent_id.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const config = require("../etc/config.json");
  2. const mysql = require('mysql2/promise');
  3. const dbConfig = config.isDebug?config.debug_mysql:config.release_mysql
  4. const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
  5. const redis_help = require('../src/use_redis');
  6. const CMD = {}
  7. async function processTask(){
  8. let right_status = true
  9. let connection = null
  10. try{
  11. connection = await mysql.createConnection({
  12. ...taskdbConfig,
  13. multipleStatements: true
  14. });
  15. //先获取所有没有父id的七猫免费书籍
  16. const [rows] = await connection.execute(
  17. `SELECT * FROM video_product WHERE book_platform = 19 AND product_parent_id ="" LIMIT 323`
  18. );
  19. if(rows.length<=0){
  20. throw 0
  21. }
  22. for (let index = 0; index < rows.length; index++) {
  23. let video_product_info = rows[index]
  24. let product_parent_id = video_product_info.product_id
  25. let iap_book_info = await CMD.getIAPInfo(video_product_info.product_id)
  26. if(iap_book_info!=null){
  27. product_parent_id = iap_book_info.book_id
  28. }
  29. await connection.execute(
  30. `UPDATE video_product SET product_parent_id = "${product_parent_id}" WHERE id = ${video_product_info.id} `
  31. );
  32. }
  33. }catch(e){
  34. if(e==0){
  35. right_status = false
  36. }
  37. console.error("processTask error:",e)
  38. } finally{
  39. if(right_status){
  40. // global.setTimeout(processTask, 1000);
  41. }
  42. if(connection){
  43. connection.end()
  44. }
  45. }
  46. }
  47. CMD.getIAPInfo = async function(iaa_book_id){
  48. let connection = await mysql.createConnection({
  49. ...dbConfig,
  50. multipleStatements: true
  51. });
  52. const [rows] = await connection.execute(
  53. `SELECT * FROM qm_iap_lib WHERE iaa_book_id = ${iaa_book_id} AND is_have_iaa = 1 LIMIT 1`
  54. );
  55. await connection.end();
  56. if(rows.length<=0){
  57. return null
  58. }
  59. return rows[0]
  60. }
  61. CMD.init = async function(){
  62. redis_help.connect((results)=>{
  63. if(results){
  64. processTask();
  65. }
  66. })
  67. }
  68. CMD.init()