项目初始化

This commit is contained in:
ray
2026-04-13 18:09:52 +08:00
commit aa67b0e37e
22 changed files with 2959 additions and 0 deletions

View File

@@ -0,0 +1,188 @@
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import dotenv from 'dotenv';
const rootDir = path.resolve(process.cwd());
dotenv.config({ path: path.join(rootDir, '.env') });
const toBool = (value, fallback) => {
if (value == null) return fallback;
return ['1', 'true', 'yes', 'y', 'on'].includes(String(value).trim().toLowerCase());
};
const ensureDir = (dirPath) => {
fs.mkdirSync(dirPath, { recursive: true });
return dirPath;
};
export const config = {
rootDir,
baseUrl: process.env.ALIYUN_APS_BASE_URL || 'https://aps.aliyun.com',
headless: toBool(process.env.ALIYUN_APS_HEADLESS, false),
timezone: process.env.ALIYUN_APS_TIMEZONE || 'Asia/Shanghai',
cron: process.env.ALIYUN_APS_CRON || '0 6 * * *',
orderStartDate: process.env.ALIYUN_APS_ORDER_START_DATE || '2024-01-01',
billStartMonth: process.env.ALIYUN_APS_BILL_START_MONTH || '2024-01',
smtp: {
host: process.env.ALIYUN_APS_SMTP_HOST || 'smtp.qq.com',
port: parseInt(process.env.ALIYUN_APS_SMTP_PORT || '465', 10),
secure: toBool(process.env.ALIYUN_APS_SMTP_SECURE, true),
user: process.env.ALIYUN_APS_SMTP_USER || '',
pass: process.env.ALIYUN_APS_SMTP_PASS || '',
},
notifyEmail: process.env.ALIYUN_APS_NOTIFY_EMAIL || '',
closeBrowser: toBool(process.env.ALIYUN_APS_CLOSE_BROWSER, true),
fullSync: toBool(process.env.ALIYUN_APS_FULL_SYNC, true),
resumeBillMonth: process.env.ALIYUN_APS_RESUME_BILL_MONTH || '',
resumeBillPage: Math.max(1, Number.parseInt(process.env.ALIYUN_APS_RESUME_BILL_PAGE || '1', 10) || 1),
dbSyncScript: process.env.ALIYUN_APS_DB_SYNC_SCRIPT || '../aps-aliyun-sync/aps_db_sync.py',
userDataDir: ensureDir(path.join(rootDir, '.browser')),
dataDir: ensureDir(path.join(rootDir, 'data')),
downloadDir: ensureDir(path.join(rootDir, 'downloads')),
};
export const datasets = {
customers: {
name: 'customers',
url: `${config.baseUrl}/#/detail/my_customer/~/customer/list`,
heading: '我的客户',
pageSize: 100,
uniqueKey: (record) => record.accountId || record.loginName || record.__hash,
normalize: (record) => {
const loginAndUid = record['登录名称/账号ID'] || '';
const [loginName = '', accountId = ''] = splitLines(loginAndUid);
return {
loginName: loginName.replace(/\s+/g, ''),
accountId,
realName: record['UID实名认证名称'] || '',
reportSource: record['报备来源'] || '',
reportType: record['报备类型'] || '',
tradeMode: record['交易模式'] || '',
authStatus: record['实名认证状态'] || '',
relationTime: record['关联日期'] || '',
owner: record['跟进员工'] || '',
cashBalanceCny: record['账户现金余额(CNY)'] || '',
invoicePendingCny: record['待开票金额(CNY)'] || '',
lastMonthConsumptionCny: record['上月消费金额(CNY)'] || '',
thisMonthConsumptionCny: record['本月消费金额(CNY)'] || '',
paymentNoticeStatus: record['代为支付告知状态'] || '',
inviteType: record['邀约注册类型'] || '',
isNewCustomer: record['是否新客户'] || '',
isPerformanceQualified: record['是否达成业绩起算点'] || '',
customerCategory: record['客户分类'] || '',
remark: record['备注'] || '',
inactiveMonths: record['客户无消费月数'] || '',
releasePlanTime: record['计划释放时间'] || '',
releasePlanReason: record['计划释放原因'] || '',
};
},
},
orders: {
name: 'orders',
url: `${config.baseUrl}/#/detail/order/~/costCenter/order`,
heading: '订单查询',
pageSize: 100,
uniqueKey: (record) => record.orderId || record.__hash,
normalize: (record, context) => ({
orderId: record['订单号'] || '',
customerAccount: (record['客户账号'] || '').replace(/\s+/g, ''),
customerCategory: record['客户分类'] || '',
orderType: record['订单类型'] || '',
orderOriginalPriceCny: record['订单原价 (CNY)'] || '',
actualPaidCny: record['实付金额 (CNY)'] || '',
orderStatus: record['订单状态'] || '',
createdAt: record['下单时间'] || '',
windowStart: context.windowStart || '',
windowEnd: context.windowEnd || '',
}),
},
orderDetails: {
name: 'orderDetails',
url: `${config.baseUrl}/#/detail/order/~/costCenter/order`,
heading: '订单详情',
pageSize: 100,
uniqueKey: (record) => record.orderId || record.__hash,
normalize: (record, context) => ({
orderId: record.orderId || '',
orderType: record.orderType || '',
status: record.status || '',
tradeType: record.tradeType || '',
customerCategory: record.customerCategory || '',
dealerName: record.dealerName || '',
dealerUid: record.dealerUid || '',
customerType: record.customerType || '',
opportunityId: record.opportunityId || '',
paymentTime: record.paymentTime || '',
orderTime: record.orderTime || '',
productName: record.productName || '',
productCode: record.productCode || '',
originalPriceCny: record.originalPriceCny || '',
paidAmountCny: record.paidAmountCny || '',
discount: record.discount || '',
payableAmountCny: record.payableAmountCny || '',
couponAmountCny: record.couponAmountCny || '',
windowStart: context.windowStart || '',
windowEnd: context.windowEnd || '',
}),
},
customerDetails: {
name: 'customerDetails',
url: `${config.baseUrl}/#/detail/my_customer/~/customer/list`,
heading: '详情',
pageSize: 100,
uniqueKey: (record) => record.accountId || record.__hash,
normalize: (record, context) => ({
accountId: context.accountId || '',
customerAccount: record.customerAccount || '',
customerName: record.customerName || '',
customerType: record.customerType || '',
tradeMode: record.tradeMode || '',
customerSource: record.customerSource || '',
realNameStatus: record.realNameStatus || '',
email: record.email || '',
relationDate: record.relationDate || '',
phone: record.phone || '',
remark: record.remark || '',
paymentNoticeStatus: record.paymentNoticeStatus || '',
department: record.department || '',
lastMonthPayableTotalCny: record.lastMonthPayableTotalCny || '',
lastMonthPrepayCny: record.lastMonthPrepayCny || '',
lastMonthPostpayCny: record.lastMonthPostpayCny || '',
currentMonthPayableTotalCny: record.currentMonthPayableTotalCny || '',
currentMonthPrepayCny: record.currentMonthPrepayCny || '',
currentMonthPostpayCny: record.currentMonthPostpayCny || '',
}),
},
bills: {
name: 'bills',
url: `${config.baseUrl}/#/detail/bill/~/costCenter/bill`,
heading: '账单查询',
pageSize: 100,
uniqueKey: (record) => record.__hash,
normalize: (record, context) => ({
billingMonth: record['账期'] || '',
consumeDate: record['消费时间'] || '',
customerAccount: (record['客户账号'] || '').replace(/\s+/g, ''),
customerCategory: record['客户分类'] || '',
productCategory: record['产品分类'] || '',
productName: record['产品名称'] || '',
originalPriceCny: record['原价 (CNY)'] || '',
customerPayableCny: record['客户应付金额 (CNY)'] || '',
billType: record['账单类型'] || '',
countsForPerformance: record['是否计入业绩'] || '',
commissionable: record['是否返佣'] || '',
commissionMonth: record['佣金月份'] || context.month || '',
inviteType: record['邀约注册类型'] || '',
serviceStartAt: record['服务开始时间'] || '',
serviceEndAt: record['服务结束时间'] || '',
}),
},
};
function splitLines(value) {
return String(value)
.split('\n')
.map((part) => part.trim())
.filter(Boolean);
}