12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //同步掌阅免费的匹配书籍
- const config = require("../etc/config.json");
- const mysql = require('mysql2/promise');
- const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
- const redis_help = require('../src/use_redis');
- const video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
- const helper = require("../src/helper");
- const schedule = require('node-schedule');
- const CMD = {}
- async function processTask(){
- let right_status = true
- let connection = null
- try{
- connection = await mysql.createConnection({
- ...taskdbConfig,
- multipleStatements: true
- });
- const [records] = await connection.execute(
- `SELECT * FROM video_product WHERE create_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND create_at <= CURDATE()
- AND book_platform = ${config.platform_zymf} AND match_book = "NONE" LIMIT 1000 ;`
- );
- if(records.length<=0){
- console.log("完成所有七猫免费的匹配")
- throw 0
- }
- for (let index = 0; index < records.length; index++) {
- const element = records[index];
- let iap_book_info = await require('../src/api/zy/zy_search_book').new_search_name(element.product_name)
- if(iap_book_info!=null){
- iap_book_info = await require('../src/api/zy/zy_search_book').new_search_id(iap_book_info.book_id)
- if(iap_book_info!=null){
- let book_info = await video_product_controllers.getProductData({book_id:iap_book_info.book_id})
- if(!book_info.success){
- //创建一个付费书籍
- await video_product_controllers.createProductData({
- book_platform:config.platform_zy,
- product_name:iap_book_info.book_name,
- genre:iap_book_info.genre,
- product_id:iap_book_info.book_id,
- words:iap_book_info.words,
- totalChapterNum:iap_book_info.totalChapterNum,
- publish_time:iap_book_info.publish_time,
- default_pay_section:iap_book_info.default_pay_section,
- default_price:iap_book_info.default_price,
- fee_unit:iap_book_info.fee_unit,
- match_book:element.product_id
- })
- }else{
- await video_product_controllers.updateData({id:book_info.data.id},{
- match_book:element.product_id
- })
- }
-
- await connection.execute(
- `UPDATE video_product
- SET match_book = ?,
- product_parent_id = ?
- WHERE id = ?`,
- [iap_book_info.book_id, iap_book_info.book_id, element.id]
- );
- }
-
- }
- }
- }catch(e){
- if(e==0){
- right_status = false
- }
- console.error("processTask error:",e)
- } finally{
- if(connection!=null){
- connection.end()
- }
- if(right_status){
- global.setTimeout(processTask, 2000);
- }
- }
- }
- CMD.init = async function(){
- redis_help.connect((results)=>{
- if(results){
- const job = schedule.scheduleJob('0 03,15 * * *', async function() {
- await processTask();
- });
- }
- })
- }
- CMD.init()
|