forked from yoone/API
fix: 销售统计总数
This commit is contained in:
parent
e4e4ceb7c1
commit
b2cddad10a
|
|
@ -853,9 +853,17 @@ export class OrderService {
|
||||||
// 4. 总量统计(时间段 + siteId)
|
// 4. 总量统计(时间段 + siteId)
|
||||||
// -------------------------
|
// -------------------------
|
||||||
const totalParams: any[] = [startDate, endDate];
|
const totalParams: any[] = [startDate, endDate];
|
||||||
|
const yooneParams: any[] = [startDate, endDate];
|
||||||
let totalSql = `
|
let totalSql = `
|
||||||
SELECT
|
SELECT
|
||||||
SUM(os.quantity) AS totalQuantity,
|
SUM(os.quantity) AS totalQuantity
|
||||||
|
FROM order_sale os
|
||||||
|
INNER JOIN \`order\` o ON o.id = os.orderId
|
||||||
|
WHERE o.date_paid BETWEEN ? AND ?
|
||||||
|
AND o.status IN ('completed','processing')
|
||||||
|
`;
|
||||||
|
let yooneSql = `
|
||||||
|
SELECT
|
||||||
SUM(CASE WHEN os.isYoone = 1 AND os.size = 3 THEN os.quantity ELSE 0 END) AS yoone3Quantity,
|
SUM(CASE WHEN os.isYoone = 1 AND os.size = 3 THEN os.quantity ELSE 0 END) AS yoone3Quantity,
|
||||||
SUM(CASE WHEN os.isYoone = 1 AND os.size = 6 THEN os.quantity ELSE 0 END) AS yoone6Quantity,
|
SUM(CASE WHEN os.isYoone = 1 AND os.size = 6 THEN os.quantity ELSE 0 END) AS yoone6Quantity,
|
||||||
SUM(CASE WHEN os.isYoone = 1 AND os.size = 9 THEN os.quantity ELSE 0 END) AS yoone9Quantity,
|
SUM(CASE WHEN os.isYoone = 1 AND os.size = 9 THEN os.quantity ELSE 0 END) AS yoone9Quantity,
|
||||||
|
|
@ -869,24 +877,34 @@ export class OrderService {
|
||||||
WHERE o.date_paid BETWEEN ? AND ?
|
WHERE o.date_paid BETWEEN ? AND ?
|
||||||
AND o.status IN ('completed','processing')
|
AND o.status IN ('completed','processing')
|
||||||
`;
|
`;
|
||||||
|
|
||||||
if (siteId) {
|
if (siteId) {
|
||||||
totalSql += ' AND os.siteId = ?';
|
totalSql += ' AND os.siteId = ?';
|
||||||
totalParams.push(siteId);
|
totalParams.push(siteId);
|
||||||
|
yooneSql += ' AND os.siteId = ?';
|
||||||
|
yooneParams.push(siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nameKeywords.length > 0) {
|
||||||
|
totalSql += ' AND (' + nameKeywords.map(() => 'os.name LIKE ?').join(' AND ') + ')';
|
||||||
|
totalParams.push(...nameKeywords.map(w => `%${w}%`));
|
||||||
|
}
|
||||||
|
|
||||||
const [totalResult] = await this.orderSaleModel.query(totalSql, totalParams);
|
const [totalResult] = await this.orderSaleModel.query(totalSql, totalParams);
|
||||||
|
const [yooneResult] = await this.orderSaleModel.query(yooneSql, yooneParams);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items,
|
items,
|
||||||
total: totalCount, // ✅ 总条数
|
total: totalCount, // ✅ 总条数
|
||||||
totalQuantity: Number(totalResult.totalQuantity || 0),
|
totalQuantity: Number(totalResult.totalQuantity || 0),
|
||||||
yoone3Quantity: Number(totalResult.yoone3Quantity || 0),
|
yoone3Quantity: Number(yooneResult.yoone3Quantity || 0),
|
||||||
yoone6Quantity: Number(totalResult.yoone6Quantity || 0),
|
yoone6Quantity: Number(yooneResult.yoone6Quantity || 0),
|
||||||
yoone9Quantity: Number(totalResult.yoone9Quantity || 0),
|
yoone9Quantity: Number(yooneResult.yoone9Quantity || 0),
|
||||||
yoone12Quantity: Number(totalResult.yoone12Quantity || 0),
|
yoone12Quantity: Number(yooneResult.yoone12Quantity || 0),
|
||||||
yoone12QuantityNew: Number(totalResult.yoone12QuantityNew || 0),
|
yoone12QuantityNew: Number(yooneResult.yoone12QuantityNew || 0),
|
||||||
yoone15Quantity: Number(totalResult.yoone15Quantity || 0),
|
yoone15Quantity: Number(yooneResult.yoone15Quantity || 0),
|
||||||
yoone18Quantity: Number(totalResult.yoone18Quantity || 0),
|
yoone18Quantity: Number(yooneResult.yoone18Quantity || 0),
|
||||||
zexQuantity: Number(totalResult.zexQuantity || 0),
|
zexQuantity: Number(yooneResult.zexQuantity || 0),
|
||||||
current,
|
current,
|
||||||
pageSize,
|
pageSize,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue