qm_mf_get_parent_id.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }
  43. }
  44. CMD.getIAPInfo = async function(iaa_book_id){
  45. let connection = await mysql.createConnection({
  46. ...dbConfig,
  47. multipleStatements: true
  48. });
  49. const [rows] = await connection.execute(
  50. `SELECT * FROM qm_iap_lib WHERE iaa_book_id = ${iaa_book_id} AND is_have_iaa = 1 LIMIT 1`
  51. );
  52. await connection.end();
  53. if(rows.length<=0){
  54. return null
  55. }
  56. return rows[0]
  57. }
  58. CMD.init = async function(){
  59. redis_help.connect((results)=>{
  60. if(results){
  61. processTask();
  62. }
  63. })
  64. }
  65. CMD.init()