|
@@ -0,0 +1,192 @@
|
|
|
+const CMD = {}
|
|
|
+const time_count = 2000;
|
|
|
+const redis_help = require('../src/use_redis');
|
|
|
+const video_applet_product_controllers = require('../src/data_manager/Controllers/video_applet_product_controllers');
|
|
|
+var fq_mf_create_link_task_list = []
|
|
|
+const config = require('../etc/config.json')
|
|
|
+let finish_call_back = async function(new_data,error_info=null){
|
|
|
+ try{
|
|
|
+ if(new_data.start_page != null && error_info==null){
|
|
|
+ const result = await video_applet_product_controllers.updateData({id:new_data.id},{
|
|
|
+ dy_small_program_start:new_data.start_page,
|
|
|
+ dy_small_program_start_data:new_data.start_param,
|
|
|
+ promotion_id:new_data.promotion_id,
|
|
|
+ wait_status:1,
|
|
|
+ status:0
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ const result = await video_applet_product_controllers.updateData({id:new_data.id},{
|
|
|
+ status:2,
|
|
|
+ wait_status:2,
|
|
|
+ error_info:JSON.stringify(error_info)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch(e){
|
|
|
+ console.log("finish_call_back error:",e)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+CMD.isBlackBook = function(all_black_books,book_id){
|
|
|
+ if(all_black_books==null){
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ for (let index = 0; index < all_black_books.length; index++) {
|
|
|
+ const black_book = all_black_books[index];
|
|
|
+ if(black_book.product_id==book_id){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+CMD.getPlatformInfo = function(PlatformConfig,tg_platform_id){
|
|
|
+ for (let index = 0; index < PlatformConfig.length; index++) {
|
|
|
+ const element = PlatformConfig[index];
|
|
|
+ if(element.tg_platform_id==tg_platform_id){
|
|
|
+ return element
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+CMD.getSharedPlatform = function(PlatformShared,platform_shared_id){
|
|
|
+ for (let index = 0; index < PlatformShared.length; index++) {
|
|
|
+ const element = PlatformShared[index];
|
|
|
+ if(element.id==platform_shared_id){
|
|
|
+ return JSON.parse(element.info)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function processTask(){
|
|
|
+ try{
|
|
|
+ let MainConfig = await redis_help.getKeyValue("MainConfig")
|
|
|
+ MainConfig = JSON.parse(MainConfig)
|
|
|
+ let PlatformConfig = await redis_help.getKeyValue("PlatformConfig")
|
|
|
+ PlatformConfig = JSON.parse(PlatformConfig)
|
|
|
+
|
|
|
+
|
|
|
+ let black_books = await redis_help.getKeyValue("all_black_books")
|
|
|
+
|
|
|
+ if(black_books!=null){
|
|
|
+ black_books = JSON.parse(black_books)
|
|
|
+ }
|
|
|
+
|
|
|
+ let PlatformShared = await redis_help.getKeyValue("PlatformShared")
|
|
|
+
|
|
|
+ PlatformShared = JSON.parse(PlatformShared)
|
|
|
+
|
|
|
+ let platform_fanqie_info = CMD.getPlatformInfo(PlatformConfig,config.platform_fanqiemf)
|
|
|
+
|
|
|
+ let all_platform_list = CMD.getSharedPlatform(PlatformShared,platform_fanqie_info.platform_shared_id)
|
|
|
+
|
|
|
+ let result = null
|
|
|
+
|
|
|
+ for (let index = 0; index < all_platform_list.length; index++) {
|
|
|
+ const tg_platform_id = all_platform_list[index];
|
|
|
+ let temp_result = await video_applet_product_controllers.getAppletProductDataByStatus({status:0,wait_status:0,book_platform:tg_platform_id})
|
|
|
+ if(temp_result.success){
|
|
|
+ result = temp_result
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(result==null){
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if(result.success){
|
|
|
+
|
|
|
+ if(CMD.isBlackBook(black_books,result.data.product_id)){
|
|
|
+ await video_applet_product_controllers.updateData({id:result.data.id},{
|
|
|
+ status:2,
|
|
|
+ wait_status:2,
|
|
|
+ error_info:JSON.stringify({msg:"当前书在黑名单"})
|
|
|
+ })
|
|
|
+ throw "当前书在黑名单"
|
|
|
+ }
|
|
|
+ let main_info = CMD.getMainInfoById(MainConfig,result.data.main_id)
|
|
|
+
|
|
|
+ let PlatformInfo = null
|
|
|
+
|
|
|
+ PlatformInfo = CMD.getPlatformInfoById(PlatformConfig,main_info.tg_platform_id)
|
|
|
+ if(PlatformInfo==null){
|
|
|
+ await video_applet_product_controllers.updateData({id:result.data.id},{
|
|
|
+ status:2,
|
|
|
+ wait_status:2,
|
|
|
+ error_info:JSON.stringify({msg:"平台配置错误:"})
|
|
|
+ })
|
|
|
+ console.error("平台配置错误:",result)
|
|
|
+ throw "平台配置错误:"
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(main_info==null&&result.data.is_close_execution==1){
|
|
|
+ let CloseMainConfig = await redis_help.getKeyValue("CloseMainConfig")
|
|
|
+ CloseMainConfig = JSON.parse(CloseMainConfig)
|
|
|
+ main_info = CMD.getMainInfoById(CloseMainConfig,result.data.main_id)
|
|
|
+ }
|
|
|
+
|
|
|
+ if(main_info==null){
|
|
|
+ await video_applet_product_controllers.updateData({id:result.data.id},{
|
|
|
+ status:2,
|
|
|
+ wait_status:2,
|
|
|
+ error_info:JSON.stringify({msg:"主体配置错误:"})
|
|
|
+ })
|
|
|
+ console.error("主体配置错误:",result)
|
|
|
+ throw "主体配置错误:"
|
|
|
+ }
|
|
|
+
|
|
|
+ fq_mf_create_link_task_list.push({
|
|
|
+ n_data:result.data,
|
|
|
+ main_info:main_info,
|
|
|
+ PlatformInfo:PlatformInfo
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fq_mf_create_link_task_list.length>0){
|
|
|
+ let fq_create_link_task = fq_mf_create_link_task_list.pop()
|
|
|
+ require('./fqmf_create_link').runTask(fq_create_link_task.n_data
|
|
|
+ ,fq_create_link_task.main_info,
|
|
|
+ fq_create_link_task.PlatformInfo,finish_call_back)
|
|
|
+ }
|
|
|
+
|
|
|
+ await new Promise(resolve => setTimeout(resolve,100));
|
|
|
+
|
|
|
+ }catch(e){
|
|
|
+ console.log("CREATE_LINK_FACTORY error:",e)
|
|
|
+ finish_call_back(null,{"MESSAGE":"CREATE_LINK_FACTORY error:"})
|
|
|
+ } finally{
|
|
|
+ global.setTimeout(processTask,time_count)
|
|
|
+ }
|
|
|
+}
|
|
|
+CMD.init = function(){
|
|
|
+ redis_help.connect((results)=>{
|
|
|
+ if(results){
|
|
|
+ }
|
|
|
+ })
|
|
|
+ processTask()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+CMD.getPlatformInfoById = function(PlatformConfig,tg_platform_id){
|
|
|
+ for (let index = 0; index < PlatformConfig.length; index++) {
|
|
|
+ const element = PlatformConfig[index];
|
|
|
+ if(element.tg_platform_id==tg_platform_id){
|
|
|
+ return element
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+}
|
|
|
+
|
|
|
+CMD.getMainInfoById = function(MainConfig,main_id){
|
|
|
+ // console.log("MainConfig:",MainConfig)
|
|
|
+ for (let index = 0; index < MainConfig.length; index++) {
|
|
|
+ const element = MainConfig[index];
|
|
|
+ if(element.id==main_id){
|
|
|
+ return element
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+}
|
|
|
+CMD.init()
|