Ver Fonte

1、分类下商品列表接口补充分类父级ID信息;

Lawsun_M há 1 ano atrás
pai
commit
ad9d413b0d

+ 8 - 2
app/controller/home/productCategory.js

@@ -100,7 +100,7 @@ module.exports = class ProductCategoryController extends shopController {
       const data = await that.ctx.validate(that.categoryValidate, await that.ctx.getParse());
       const options = {
         where: { category_id: data.category_id, is_sale: 1 },
-        order: [[ 'is_hot', 'desc' ], [ 'is_new', 'desc' ]], // , [ 'product_stock', 'desc' ], [ 'product_id', 'asc' ]
+        order: [[ 'is_hot', 'desc' ], [ 'is_new', 'desc' ], [ 'sale_count', 'desc' ]], // , [ 'product_stock', 'desc' ]
         // offset: (data.page - 1) * data.limit, limit: data.limit,
         attributes: [ 'product_id', 'category_id', 'product_name', 'product_image', 'shop_price', 'market_price', 'is_new', 'is_hot' ],
       };
@@ -108,7 +108,13 @@ module.exports = class ProductCategoryController extends shopController {
       if (data.sale_sort) options.order.push([ 'sale_count', data.sale_sort == 1 ? 'asc' : 'desc' ]);
       const selectBean = await that.app.comoBean.instance(data, options);
       const result = await that.service.manager.select(selectBean, that.app.model.Products, '商品列表查看失败,请重试', true, true);
-      return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
+      // 2023/10/18  查询家具父级ID pid
+      const categoryResult = await that.app.model.ProductCategory.findOne({
+        where: { category_id: data.category_id },
+      });
+      const jsonResult = JSON.parse(JSON.stringify(result));
+      jsonResult.pid = categoryResult.pid;
+      return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', jsonResult, false));
     } catch (err) {
       return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
     }

+ 1 - 1
app/controller/home/products.js

@@ -100,7 +100,7 @@ module.exports = class ProductsController extends shopController {
         offset: 0, limit: 100,
         where: { is_home: 1, product_stock: { [seq.Op.gte]: 1 }, is_sale: 1, category_id: { [seq.Op.in]: cate } },
         attributes: [ 'product_id', 'category_id', 'product_name', 'product_image', 'shop_price', 'market_price', 'is_new', 'is_hot' ],
-        order: [[ 'is_hot', 'desc' ], [ 'is_new', 'desc' ], [ 'sale_count', 'desc' ], [ 'product_stock', 'desc' ], [ 'category_id', 'asc' ]],
+        order: [[ 'is_hot', 'desc' ], [ 'is_new', 'desc' ], [ 'sale_count', 'desc' ]],
       });
       return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
     } catch (err) {