Browse Source

1、商品置顶;2、办公/民用分类搜索子分类;

Lawsun_M 1 year ago
parent
commit
9ca9456482

+ 5 - 3
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' ]],
+        order: [[ 'is_top', 'desc' ], [ 'is_hot', 'desc' ], [ 'is_new', 'desc' ], [ 'sale_count', 'desc' ]],
       });
       return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
     } catch (err) {
@@ -130,7 +130,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_top', 'desc' ], [ 'is_hot', 'desc' ], [ 'is_new', 'desc' ], [ 'sale_count', 'desc' ], [ 'product_stock', 'desc' ], [ 'category_id', 'asc' ]],
       });
       return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
     } catch (err) {
@@ -148,7 +148,9 @@ module.exports = class ProductsController extends shopController {
     try {
       const data = await that.ctx.validate(that.searchValidate, await that.ctx.getParse());
       const result = await that.useModel.findAll({
-        offset: 0, limit: 100, order: [[ 'product_id', 'desc' ]],
+        offset: 0,
+        limit: 100,
+        order: [[ 'is_top', 'desc' ], [ 'is_hot', 'desc' ], [ 'is_new', 'desc' ], [ 'product_id', 'desc' ]],
         where: { product_name: { [that.app.Sequelize.Op.regexp]: data.keyword }, is_sale: 1 },
         attributes: [ 'product_id', 'category_id', 'product_name', 'product_image', 'shop_price', 'market_price', 'is_new', 'is_hot' ],
       });

+ 15 - 1
app/controller/manager/shops/products.js

@@ -96,6 +96,8 @@ module.exports = class ProductsController extends ManagerController {
         .number(),
       is_new: that.ctx.rules.default(0)
         .number(),
+      is_top: that.ctx.rules.default(0)
+        .number(),
       is_hot: that.ctx.rules.default(0)
         .number(),
       is_best: that.ctx.rules.default(0)
@@ -179,6 +181,8 @@ module.exports = class ProductsController extends ManagerController {
         .number(),
       is_new: that.ctx.rules.default('')
         .required(),
+      is_top: that.ctx.rules.default('')
+        .required(),
       is_hot: that.ctx.rules.default('')
         .required(),
       is_best: that.ctx.rules.default('')
@@ -367,10 +371,20 @@ module.exports = class ProductsController extends ManagerController {
           ],
         }, order: [[ 'product_id', 'desc' ]],
       };
-      if (data.category_id) options.where.category_id = data.category_id;
+      if (data.category_id === 1 || data.category_id === 4) {
+        const categoryIds = [];
+        const resultTemp = await that.app.model.ProductCategory.findAll({ where: { pid: data.category_id } });
+        for (const item of resultTemp) {
+          categoryIds.push(item.category_id);
+        }
+        options.where.category_id = { [seq.Op.in]: categoryIds };
+      } else if (data.category_id) {
+        options.where.category_id = data.category_id;
+      }
       if (data.carousel_id) options.where.carousel_id = data.carousel_id;
       if (data.product_name) options.where.product_name = { [seq.Op.regexp]: data.product_name };
       if (data.is_hot !== '') options.where.is_hot = Number(data.is_hot);
+      if (data.is_top !== '') options.where.is_top = Number(data.is_top);
       if (data.is_new !== '') options.where.is_new = Number(data.is_new);
       if (data.is_best !== '') options.where.is_best = Number(data.is_best);
       if (data.is_sale !== '') options.where.is_sale = Number(data.is_sale);

+ 4 - 0
app/models/mysql/products.js

@@ -78,6 +78,10 @@ module.exports = app => {
       type: DataTypes.INTEGER(1).UNSIGNED,
       allowNull: true,
     },
+    is_top: {
+      type: DataTypes.INTEGER(1).UNSIGNED,
+      allowNull: true,
+    },
     is_home: {
       type: DataTypes.INTEGER(1).UNSIGNED,
       allowNull: true,