如何获取产品销售总量?节点

How to get the total quantity of products sold? Node

在产品table中添加一个字段,如sellcounter,按照下面的操作

下订单后在产品中进行一次更新查询Table喜欢...

await productModel.updateAll({
          id: product.id
        }, {
          sellcounter: product.sellcounter + 1
        });

以上代码用于环回节点

这里的想法是将特定产品的销售数量增加一。

为此,您需要使用方法 findOnefindById 来更新特定产品。

结果代码应如下所示(假设您有产品对象及其 ID):

const productToUpdate = await productModel.findById(product.id);
await productToUpdate.updateAttributes({ sellcounter: product.sellcounter + 1 });