fix(shop-product): 「待绑定」只统计待审核/异常的订单,避免绑定后数字清不掉
现象:店铺商品已绑定系统商品,列表仍显示「N 单待绑定」。 原因:「待处理订单数」把 order_status_items 里所有 parse_status=2 的订单都算进去了, 但绑定只对「待审核 / 异常」的订单重建明细(syncOrderItemsOf → rebuildOrderItems 的状态白名单), 已流转(待推送/委外中/配送/历史/作废)的明细不会跟着变 → 数字永远清不掉。 - attachUnboundOrderCount:只统计 current_status ∈ (pending, exception) 的订单 - 「有订单未绑定」筛选(列表 + 导出)同口径,保证筛选结果与徽标一致 - 抽出 editableOrderIdsSql 复用 本地验证:店铺商品 59 的未绑定单从 8 → 7(其中 1 单已作废);其余不变。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
d5b4298c86
commit
cf0d984224
@ -101,13 +101,14 @@ class ShopProductController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 有订单未绑定:店铺商品自身未绑定,且被「未绑定系统商品」的订单明细引用
|
// 有订单未绑定:店铺商品自身未绑定,且被「未绑定系统商品」的订单明细引用
|
||||||
|
// (只算待审核/异常的单:已流转的单不会因绑定而重建,算进来会让筛选结果与徽标一直清不掉)
|
||||||
const onlyUnboundOrder = String(hasUnboundOrder) === '1';
|
const onlyUnboundOrder = String(hasUnboundOrder) === '1';
|
||||||
if (onlyUnboundOrder) {
|
if (onlyUnboundOrder) {
|
||||||
where.bind_type = 0;
|
where.bind_type = 0;
|
||||||
where.id = {
|
where.id = {
|
||||||
[Op.in]: ctx.app.Sequelize.literal(
|
[Op.in]: ctx.app.Sequelize.literal(
|
||||||
`(SELECT DISTINCT shop_product_id FROM order_status_items WHERE principal_id = ${principalId} ` +
|
`(SELECT DISTINCT shop_product_id FROM order_status_items WHERE principal_id = ${principalId} ` +
|
||||||
'AND parse_status = 2 AND shop_product_id IS NOT NULL)'
|
`AND parse_status = 2 AND shop_product_id IS NOT NULL AND order_id IN ${this.editableOrderIdsSql(principalId)})`
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -147,6 +148,20 @@ class ShopProductController extends Controller {
|
|||||||
return access.ownCompanyIds.map(Number).includes(Number(item.subsidiary_id));
|
return access.ownCompanyIds.map(Number).includes(Number(item.subsidiary_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 「还能通过绑定解决的未绑定明细」口径
|
||||||
|
*
|
||||||
|
* 只有待审核 / 异常的单在绑定时会重建明细(见 syncOrderItemsOf → rebuildOrderItems),
|
||||||
|
* 已流转(待推送/委外中/配送/历史…)的单不会跟着变,若把它们也算进来,
|
||||||
|
* 绑定后数字永远清不掉,看起来像「绑定了还是待绑定」。
|
||||||
|
* @param {number} principalId 主体ID
|
||||||
|
* @return {string} SQL 子查询(order_status_items.order_id 限定在这些订单上)
|
||||||
|
*/
|
||||||
|
editableOrderIdsSql(principalId) {
|
||||||
|
const statuses = EDITABLE_ORDER_STATUSES.map(status => `'${status}'`).join(', ');
|
||||||
|
return `(SELECT id FROM order_index WHERE principal_id = ${Number(principalId)} AND current_status IN (${statuses}))`;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回填每个店铺商品的「待处理订单数」(未绑定系统商品的订单明细按订单去重计数),
|
* 回填每个店铺商品的「待处理订单数」(未绑定系统商品的订单明细按订单去重计数),
|
||||||
* 便于列表上直接看出哪些商品还有订单等绑定
|
* 便于列表上直接看出哪些商品还有订单等绑定
|
||||||
@ -161,7 +176,13 @@ class ShopProductController extends Controller {
|
|||||||
|
|
||||||
const Op = this.app.Sequelize.Op;
|
const Op = this.app.Sequelize.Op;
|
||||||
const rows = await ctx.model.OrderStatusItem.findAll({
|
const rows = await ctx.model.OrderStatusItem.findAll({
|
||||||
where: { principal_id: principalId, parse_status: 2, shop_product_id: { [Op.in]: ids } },
|
where: {
|
||||||
|
principal_id: principalId,
|
||||||
|
parse_status: 2,
|
||||||
|
shop_product_id: { [Op.in]: ids },
|
||||||
|
// 只算「绑定后能自动补上」的单(待审核 / 异常)
|
||||||
|
order_id: { [Op.in]: ctx.app.Sequelize.literal(this.editableOrderIdsSql(principalId)) },
|
||||||
|
},
|
||||||
attributes: [
|
attributes: [
|
||||||
'shop_product_id',
|
'shop_product_id',
|
||||||
[ ctx.app.Sequelize.fn('COUNT', ctx.app.Sequelize.fn('DISTINCT', ctx.app.Sequelize.col('order_id'))), 'order_count' ],
|
[ ctx.app.Sequelize.fn('COUNT', ctx.app.Sequelize.fn('DISTINCT', ctx.app.Sequelize.col('order_id'))), 'order_count' ],
|
||||||
|
|||||||
@ -1016,12 +1016,16 @@ const EXPORT_TYPES = {
|
|||||||
whereIn(wh, 't.shop_id', csvValues(f.shop_ids).map(Number).filter(id => Number.isInteger(id) && id > 0));
|
whereIn(wh, 't.shop_id', csvValues(f.shop_ids).map(Number).filter(id => Number.isInteger(id) && id > 0));
|
||||||
whereIn(wh, 't.platform_type', csvValues(f.platform_types));
|
whereIn(wh, 't.platform_type', csvValues(f.platform_types));
|
||||||
whereIn(wh, 't.outer_code', csvValues(f.outer_codes));
|
whereIn(wh, 't.outer_code', csvValues(f.outer_codes));
|
||||||
// 有订单未绑定:与列表接口同口径(未绑定 + 被未解析的订单明细引用)
|
// 有订单未绑定:与列表接口同口径(未绑定 + 被未解析的订单明细引用;
|
||||||
|
// 只算待审核/异常的单,已流转的单不会因绑定而重建)
|
||||||
if (String(f.has_unbound_order) === '1') {
|
if (String(f.has_unbound_order) === '1') {
|
||||||
wh.raw('t.bind_type = 0');
|
wh.raw('t.bind_type = 0');
|
||||||
|
const editableStatuses = [ ORDER_STATUS.PENDING, ORDER_STATUS.EXCEPTION ].map(status => `'${status}'`).join(', ');
|
||||||
wh.raw(
|
wh.raw(
|
||||||
`t.id IN (SELECT DISTINCT shop_product_id FROM order_status_items WHERE principal_id = ${Number(ctx.principalId)} ` +
|
`t.id IN (SELECT DISTINCT shop_product_id FROM order_status_items WHERE principal_id = ${Number(ctx.principalId)} ` +
|
||||||
'AND parse_status = 2 AND shop_product_id IS NOT NULL)'
|
'AND parse_status = 2 AND shop_product_id IS NOT NULL ' +
|
||||||
|
`AND order_id IN (SELECT id FROM order_index WHERE principal_id = ${Number(ctx.principalId)} ` +
|
||||||
|
`AND current_status IN (${editableStatuses})))`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// 所在公司权限:只能导出自己所属公司(货主)的店铺商品
|
// 所在公司权限:只能导出自己所属公司(货主)的店铺商品
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user