mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
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 };
|
|
}
|