const db = require('../db');
const moment = require('moment');
async function task(argument) {
	const bills = await db.getCollection('bills');
	const urlTask = await db.getCollection('urlTask');
	const arrs = bills.find({type:"urlbuynumber",taskID:null})
	
	let count = 0;
	arrs.forEach( async ( item ) => {
		
		let task = await urlTask.find({accountID:item.accountID + ''}).limit(1000).toArray();
		
		for( var k in task ) {
			let x = task[k];

			if( moment(x.createdAt).format('YYYYMMDDHHmmss') === moment(item.createdAt).format('YYYYMMDDHHmmss')) {
				console.dir(x.total);
				console.dir(item.number);
				let rep = await bills.update({_id:item._id},{$set:{ taskID:x._id }});
				console.dir(rep.result);
			}
		}

	});
}

task();


