add 获取营业数据分析表指标卡数据

This commit is contained in:
wenpeng 2024-07-25 18:16:54 +08:00
parent e0d531ad82
commit e8672ed25e
4 changed files with 74 additions and 9 deletions

16
businessData.json Normal file
View File

@ -0,0 +1,16 @@
["78,720.00","137,014.00","467","497.0","244","38000"]
[" 11 营业天数 "," 12,455.82 日均营业额 "," -254,501.00 卡销差额 "," -23,136.45 日均卡销差额 "," 86.69% 会员卡实际折扣 "," 87.20% 会员卡消费折扣 "," 11 充卡数量 "," 29,000 充卡金额 "," 228,184.00 会员消费额 "," 3 开卡数量 "," 9,000 开卡金额 "," 0.00% 加钟率 "," 4,381.85 技师人均产值 "," 0.82 翻台率 "," 0 加钟数 "," 243 会员客流 "," 136 会员客数 "," 237.53 会员客单价 "," 212.02 客单价 "," 19.84% 会员卡销比 "]
["168,619.01","370,879.00","1480","1,626.0","846","52000"]
[" 30 营业天数 "," 12,362.63 日均营业额 "," -1,143,542.00 卡销差额 "," -38,118.07 日均卡销差额 "," 89.37% 会员卡实际折扣 "," 87.73% 会员卡消费折扣 "," 32 充卡数量 "," 48,000 充卡金额 "," 841,348.00 会员消费额 "," 3 开卡数量 "," 4,000 开卡金额 "," 0.00% 加钟率 "," 6,625.22 技师人均产值 "," 0.95 翻台率 "," 0 加钟数 "," 871 会员客流 "," 275 会员客数 "," 232.18 会员客单价 "," 215.41 客单价 "," 12.00% 会员卡销比 "]
["248,112.67","473,645.00","1551","1,625.0","875","132999"]
[" 31 营业天数 "," 15,278.87 日均营业额 "," -961,434.00 卡销差额 "," -31,014.00 日均卡销差额 "," 91.26% 会员卡实际折扣 "," 87.36% 会员卡消费折扣 "," 64 充卡数量 "," 132,999 充卡金额 "," 899,846.00 会员消费额 "," 0 开卡数量 "," 0 开卡金额 "," 0.00% 加钟率 "," 9,243.00 技师人均产值 "," 0.96 翻台率 "," 0 加钟数 "," 954 会员客流 "," 338 会员客数 "," 233.10 会员客单价 "," 219.14 客单价 "," 20.57% 会员卡销比 "]
["0.00","0","0.0"]
[" 0 营业天数 "," 0 日均营业额 "," 0 卡销差额 "," 0 日均卡销差额 "," 0 会员卡实际折扣 "," 0 会员卡消费折扣 "," 0 充卡数量 "," 0 充卡金额 "," 0 会员消费额 "," 0 开卡数量 "," 0 开卡金额 "," 0 加钟率 "," 0 技师人均产值 "," 0 翻台率 "," 0 加钟数 "," 0 会员客流 "," 0 会员客数 "," 0 会员客单价 "," 0 客单价 "," 0 会员卡销比 "]

33
businessDataUtil.js Normal file
View File

@ -0,0 +1,33 @@
export async function getDate(page, fs) {
await new Promise(r => setTimeout(r, 2000));
await page.waitForSelector('.ai_custome');
const aiCustome = await page.$$('.ai_custome .ai_custome_item .amount');
let ai = new Set();
for (const e of aiCustome) {
let str = await page.evaluate(element => element.textContent, e);
ai.add(str);
}
let importStorage = '\n' + JSON.stringify(Array.from(ai)) + '\n';
const file = 'businessData.json';//获取file
fs.appendFileSync(file, importStorage, 'utf-8');
const elementHandle = await page.waitForSelector('.bi_warp iframe');
const frame = await elementHandle.contentFrame();
await frame.waitForSelector('#label-content');
const items = await frame.$$('#label-content'); // Use $$ to get all matching elements
let its = new Set();
if (items.length > 0) { // Check if items array is not empty
for (const e of items) {
let str = await frame.evaluate(element => element.textContent, e); // Use frame.evaluate() here
its.add(str.replace(/\s+/g, ' '));
}
} else {
console.log('#label-content not found in the iframe');
}
importStorage = '\n' + JSON.stringify(Array.from(its)) + '\n';
fs.appendFileSync(file, importStorage, 'utf-8');
// console.log(its);
}

View File

@ -1,13 +1,15 @@
import { launch } from 'puppeteer';
import fs from 'fs';
import 'dotenv/config.js'
import { setLocalStorage } from './utils/userUtils.js';
import { getDate } from './businessDataUtil.js';
(async () => {
const browser = await launch({ headless: true, args: [`--window-size=1920,1080`], defaultViewport: { width: 1920, height: 1080 } });
const page = await browser.newPage();
setLocalStorage(page, 'user.json');
await page.goto('https://dev-dmp.meiguanjia.net/report/businessData');
await page.waitForSelector('.menu-list-second');
const childElements = await page.$$('.menu-list-second .menu-list-second-item');
await new Promise(r => setTimeout(r, 1000));
@ -15,12 +17,26 @@ import { setLocalStorage } from './utils/userUtils.js';
const str = await page.evaluate(node => node.textContent.trim(), childElements[1]);
console.log(str);
await new Promise(r => setTimeout(r, 1000));
await page.waitForSelector('.ai_custome');
const aiCustome = await page.$$('.ai_custome .ai_custome_item');
for (const e of aiCustome) {
let str = await page.evaluate(element => element.textContent.trim(), e);
console.log(str);
}
const file = 'businessData.json';//获取file
fs.writeFileSync(file, '', 'utf-8');
await getDate(page, fs);
console.log('========');
const time = await page.$('.arco-picker-start-time');
await time.click({ clickCount: 3 });
await time.type('2024-06', { delay: 100 });
await getDate(page, fs);
console.log('========');
await time.click({ clickCount: 3 });
await time.type('2024-05', { delay: 100 });
await getDate(page, fs);
console.log('========');
await time.click({ clickCount: 3 });
await time.type('2024-04', { delay: 100 });
await getDate(page, fs);
console.log('========');
await browser.close();
})();

File diff suppressed because one or more lines are too long