run_zy_iap_match_7day.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //同步掌阅付费的匹配书籍
  2. const config = require("../etc/config.json");
  3. const mysql = require('mysql2/promise');
  4. const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
  5. const redis_help = require('../src/use_redis');
  6. const video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
  7. const helper = require("../src/helper");
  8. const schedule = require('node-schedule');
  9. const CMD = {}
  10. async function processTask(){
  11. let right_status = true
  12. let connection = null
  13. try{
  14. connection = await mysql.createConnection({
  15. ...taskdbConfig,
  16. multipleStatements: true
  17. });
  18. const [records] = await connection.execute(
  19. `SELECT * FROM video_product WHERE create_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND create_at <= CURDATE()
  20. AND book_platform = ${config.platform_zy} AND match_book = "NONE" LIMIT 1000 ;`
  21. );
  22. if(records.length<=0){
  23. console.log("完成所有七猫付费的匹配")
  24. throw 0
  25. }
  26. for (let index = 0; index < records.length; index++) {
  27. const element = records[index];
  28. let iaa_book_info = await require('../src/api/zy_mf/zy_mf_search_book').new_search_name(element.product_name)
  29. if(iaa_book_info!=null){
  30. iaa_book_info = await require('../src/api/zy_mf/zy_mf_search_book').new_search_id(iaa_book_info.book_id)
  31. if(iaa_book_info!=null){
  32. let book_info = await video_product_controllers.getProductData({book_id:iaa_book_info.book_id})
  33. if(!book_info.success){
  34. //创建一个免费书籍
  35. await video_product_controllers.createProductData({
  36. book_platform:config.platform_zymf,
  37. product_name:iaa_book_info.book_name,
  38. genre:iaa_book_info.genre,
  39. product_id:iaa_book_info.book_id,
  40. words:iaa_book_info.words,
  41. totalChapterNum:iaa_book_info.totalChapterNum,
  42. publish_time:iaa_book_info.publish_time,
  43. default_pay_section:iaa_book_info.default_pay_section,
  44. default_price:iaa_book_info.default_price,
  45. fee_unit:iaa_book_info.fee_unit,
  46. product_parent_id:element.product_id,
  47. match_book:element.product_id,
  48. gender:iaa_book_info.gender
  49. })
  50. }else{
  51. await video_product_controllers.updateData({id:book_info.data.id},{
  52. match_book:element.product_id
  53. })
  54. }
  55. await connection.execute(
  56. `UPDATE video_product
  57. SET match_book = ? WHERE id = ?`,
  58. [iaa_book_info.book_id, element.id]
  59. );
  60. }
  61. }
  62. }
  63. }catch(e){
  64. if(e==0){
  65. right_status = false
  66. }
  67. console.error("processTask error:",e)
  68. } finally{
  69. if(connection!=null){
  70. connection.end()
  71. }
  72. }
  73. }
  74. CMD.init = async function(){
  75. redis_help.connect((results)=>{
  76. if(results){
  77. const job = schedule.scheduleJob('0 09,21 * * *', async function() {
  78. await processTask();
  79. });
  80. }
  81. })
  82. }
  83. CMD.init()