904118851 5 ay önce
ebeveyn
işleme
46421ae37c

+ 63 - 1
2_PRODUCT_FACTORY/qm_batch_factory.js

@@ -7,6 +7,9 @@ const redis_help = require('../src/use_redis');
 const config = require('../etc/config.json');
 const time_count = 1000;
 const task_queue = []
+const mysql = require('mysql2/promise');
+const dbConfig = config.isDebug?config.debug_mysql:config.release_mysql
+const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
 
 function getProductById(product_list,product_id){
     for (let index = 0; index < product_list.length; index++) {
@@ -316,13 +319,72 @@ CMD.update_filter_data = async function(FilterConfig,data) {
 
 
 CMD.insert_product = async function(data){
-    return await video_product_controllers.createProductData({
+    await video_product_controllers.createProductData({
         book_platform:data.tg_platform_id,
         product_name:data.book_name,
         genre:data.genre,
         product_id:data.book_id,
         words:data.words
     })
+
+    //如果七猫库里有对应的免费的书,那么检测是否有此免费的书,如果没有则插入
+    let connection  = null
+    try{
+        connection = await mysql.createConnection({
+            ...dbConfig,
+            multipleStatements: true
+        });
+        const [rows] = await connection.execute(
+            `SELECT * FROM qm_iap_lib WHERE book_id = ${data.book_id} AND is_have_iaa = 1  LIMIT 1`
+        );
+        if(rows.length<=0){
+
+        }else{
+            let qm_iap_book_info = rows[0]
+            let iaa_book_info = await CMD.getQMMFVideoProduct(qm_iap_book_info.iaa_book_id)
+            if(iaa_book_info==null){
+                await CMD.addQMMFVideoProduct(qm_iap_book_info.iaa_book_id,data.book_id)
+            }
+        }
+    }catch(e){
+        console.error("insert_product:",e)
+    }finally{
+        if(connection!=null){
+            await connection.end();
+        }
+    }
 }
 
+//插入
+CMD.addQMMFVideoProduct = async function(product_id,product_parent_id){
+    let connection = await mysql.createConnection({
+        ...taskdbConfig,
+        multipleStatements: true
+    });
+
+    let qm_book_data = await require('../src/api/qm_mf/qm_mf_search_book').search_id(product_id)
+    if(qm_book_data!=null){
+        await connection.execute(
+            `INSERT INTO video_product (product_name,product_id,book_platform,genre,words,product_parent_id)  VALUES ("${qm_book_data.book_name}",${product_id},${config.platform_qmmf},${qm_book_data.genre},"${qm_book_data.words}",${product_parent_id})`
+        );
+    }
+    await connection.end();
+}
+
+CMD.getQMMFVideoProduct = async function(product_id){
+    let connection = await mysql.createConnection({
+        ...taskdbConfig,
+        multipleStatements: true
+    });
+
+    const [rows] = await connection.execute(
+        `SELECT * FROM video_product WHERE product_id = ${product_id} AND book_platform = ${config.platform_qmmf}  LIMIT 1`
+    );
+    await connection.end();
+
+    if(rows.length<=0){
+        return null
+    }
+    return rows[0]
+}
 CMD.init()

+ 14 - 50
2_PRODUCT_FACTORY/qm_mf_batch_factory.js

@@ -319,75 +319,39 @@ CMD.update_filter_data = async function(FilterConfig,data) {
 
 
 CMD.insert_product = async function(data){
-    await video_product_controllers.createProductData({
+
+    //查找父id,如果找到就赋值,否则父id就是自己
+    let product_parent_id = data.book_id
+    let iap_book_info = await CMD.getIAPInfo(data.book_id)
+    if(iap_book_info!=null){
+        product_parent_id = iap_book_info.book_id
+    }
+    return await video_product_controllers.createProductData({
         book_platform:data.tg_platform_id,
         product_name:data.book_name,
         genre:data.genre,
         product_id:data.book_id,
-        words:data.words
+        words:data.words,
+        product_parent_id:product_parent_id
     })
-
-    //如果七猫库里有对应的免费的书,那么检测是否有此免费的书,如果没有则插入
-    let connection  = null
-    try{
-        connection = await mysql.createConnection({
-            ...dbConfig,
-            multipleStatements: true
-        });
-        const [rows] = await connection.execute(
-            `SELECT * FROM qm_iap_lib WHERE book_id = ${data.book_id} AND is_have_iaa = 1  LIMIT 1`
-        );
-        if(rows.length<=0){
-
-        }else{
-            let qm_iap_book_info = rows[0]
-            let iaa_book_info = await CMD.getQMMFVideoProduct(qm_iap_book_info.iaa_book_id)
-            if(iaa_book_info==null){
-                await CMD.addQMMFVideoProduct(qm_iap_book_info.iaa_book_id,data.book_id)
-            }
-        }
-    }catch(e){
-        console.error("insert_product:",e)
-    }finally{
-        if(connection!=null){
-            await connection.end();
-        }
-    }
-   
 }
 
-//插入
-CMD.addQMMFVideoProduct = async function(product_id,product_parent_id){
-    let connection = await mysql.createConnection({
-        ...taskdbConfig,
-        multipleStatements: true
-    });
-
-    let qm_book_data = await require('../src/api/qm_mf/qm_mf_search_book').search_id(product_id)
-    if(qm_book_data!=null){
-        await connection.execute(
-            `INSERT INTO video_product (product_name,product_id,book_platform,genre,words,product_parent_id)  VALUES (${qm_book_data.book_name},${product_id},${config.platform_qmmf},${qm_book_data.genre},${qm_book_data.words},${product_parent_id})`
-        );
-    }
-
-    await connection.end();
-}
-
-CMD.getQMMFVideoProduct = async function(product_id){
+CMD.getIAPInfo = async function(iaa_book_id){
     let connection = await mysql.createConnection({
         ...taskdbConfig,
         multipleStatements: true
     });
 
     const [rows] = await connection.execute(
-        `SELECT * FROM video_product WHERE product_id = ${product_id} AND book_platform = ${config.platform_qmmf}  LIMIT 1`
+        `SELECT * FROM qm_iap_lib WHERE iaa_book_id = ${iaa_book_id} AND is_have_iaa = 1  LIMIT 1`
     );
     await connection.end();
-
+    
     if(rows.length<=0){
         return null
     }
     return rows[0]
 }
 
+
 CMD.init()