mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
refactor: 订单生成改为流式迭代降低内存,新增删单模式(cleaner),批量插入(BATCH_SIZE),日期预设选择,CLI合并单入口
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
export async function deleteOrders(conn, { companyId, specIds, shopIds, startDate, endDate, verbose, dryRun }) {
|
||||
const conditions = ['company_id = ?'];
|
||||
const params = [companyId];
|
||||
|
||||
if (specIds && specIds.length > 0) {
|
||||
const placeholders = specIds.map(() => '?').join(',');
|
||||
conditions.push(`product_spec_id IN (${placeholders})`);
|
||||
params.push(...specIds);
|
||||
}
|
||||
|
||||
if (shopIds && shopIds.length > 0) {
|
||||
const placeholders = shopIds.map(() => '?').join(',');
|
||||
conditions.push(`shop_id IN (${placeholders})`);
|
||||
params.push(...shopIds);
|
||||
}
|
||||
|
||||
if (startDate) {
|
||||
conditions.push('order_time >= ?');
|
||||
params.push(startDate + ' 00:00:00');
|
||||
}
|
||||
|
||||
if (endDate) {
|
||||
conditions.push('order_time <= ?');
|
||||
params.push(endDate + ' 23:59:59');
|
||||
}
|
||||
|
||||
const where = conditions.join(' AND ');
|
||||
|
||||
if (dryRun) {
|
||||
const [rows] = await conn.execute(
|
||||
`SELECT COUNT(*) AS cnt FROM ec_order WHERE ${where}`,
|
||||
params
|
||||
);
|
||||
return { matched: rows[0].cnt, deleted: 0 };
|
||||
}
|
||||
|
||||
const [result] = await conn.execute(
|
||||
`DELETE FROM ec_order WHERE ${where}`,
|
||||
params
|
||||
);
|
||||
return { matched: result.affectedRows, deleted: result.affectedRows };
|
||||
}
|
||||
Reference in New Issue
Block a user