|
@@ -97,10 +97,10 @@ module.exports = class ProductsController extends shopController {
|
|
cate.push(category.category_id);
|
|
cate.push(category.category_id);
|
|
}
|
|
}
|
|
const result = await that.useModel.findAll({
|
|
const result = await that.useModel.findAll({
|
|
- offset: 0, limit: 100,
|
|
|
|
|
|
+ // offset: 0, limit: 100,
|
|
where: { is_home: 1, product_stock: { [seq.Op.gte]: 1 }, is_sale: 1, category_id: { [seq.Op.in]: cate } },
|
|
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' ],
|
|
attributes: [ 'product_id', 'category_id', 'product_name', 'product_image', 'shop_price', 'market_price', 'is_new', 'is_hot' ],
|
|
- order: [[ 'is_top', 'desc' ], [ '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));
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|
|
} catch (err) {
|
|
} catch (err) {
|
|
@@ -127,10 +127,10 @@ module.exports = class ProductsController extends shopController {
|
|
cate.push(category.category_id);
|
|
cate.push(category.category_id);
|
|
}
|
|
}
|
|
const result = await that.useModel.findAll({
|
|
const result = await that.useModel.findAll({
|
|
- offset: 0, limit: 100,
|
|
|
|
|
|
+ // offset: 0, limit: 100,
|
|
where: { is_home: 1, product_stock: { [seq.Op.gte]: 1 }, is_sale: 1, category_id: { [seq.Op.in]: cate } },
|
|
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' ],
|
|
attributes: [ 'product_id', 'category_id', 'product_name', 'product_image', 'shop_price', 'market_price', 'is_new', 'is_hot' ],
|
|
- order: [[ 'is_top', 'desc' ], [ '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));
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|
|
} catch (err) {
|
|
} catch (err) {
|
|
@@ -146,12 +146,29 @@ module.exports = class ProductsController extends shopController {
|
|
async search() {
|
|
async search() {
|
|
const that = this;
|
|
const that = this;
|
|
try {
|
|
try {
|
|
|
|
+ const seq = that.app.Sequelize;
|
|
const data = await that.ctx.validate(that.searchValidate, await that.ctx.getParse());
|
|
const data = await that.ctx.validate(that.searchValidate, await that.ctx.getParse());
|
|
|
|
+ // 2023/9/19 查询家具分类 1:办公家具 4:家用家具
|
|
|
|
+ const opts = data.pid ? {
|
|
|
|
+ where: { pid: data.pid },
|
|
|
|
+ } : {};
|
|
|
|
+ console.log(opts);
|
|
|
|
+ const categoryResult = await that.app.model.ProductCategory.findAll(opts);
|
|
|
|
+ const categorys = JSON.parse(JSON.stringify(categoryResult));
|
|
|
|
+ console.log(categorys);
|
|
|
|
+ const cate = [];
|
|
|
|
+ for (const category of categorys) {
|
|
|
|
+ cate.push(category.category_id);
|
|
|
|
+ }
|
|
const result = await that.useModel.findAll({
|
|
const result = await that.useModel.findAll({
|
|
- 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 },
|
|
|
|
|
|
+ // 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 },
|
|
|
|
+ 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' ],
|
|
attributes: [ 'product_id', 'category_id', 'product_name', 'product_image', 'shop_price', 'market_price', 'is_new', 'is_hot' ],
|
|
});
|
|
});
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|
|
@@ -210,7 +227,7 @@ module.exports = class ProductsController extends shopController {
|
|
{ model: that.app.model.ProductTypesItem, as: 'product_types_item', attributes: [] },
|
|
{ model: that.app.model.ProductTypesItem, as: 'product_types_item', attributes: [] },
|
|
],
|
|
],
|
|
attributes: {
|
|
attributes: {
|
|
- include: [[ seq.col('product_types_item.item_name'), 'item_name' ]],
|
|
|
|
|
|
+ include: [ [ seq.col('product_types_item.item_name'), 'item_name' ] ],
|
|
exclude: [ 'product_id', 'item_id', 'admin_id', 'create_time', 'update_time', 'spe_id' ],
|
|
exclude: [ 'product_id', 'item_id', 'admin_id', 'create_time', 'update_time', 'spe_id' ],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
@@ -269,7 +286,7 @@ module.exports = class ProductsController extends shopController {
|
|
[ seq.col('users.nickname'), 'nickname' ], [ seq.col('users.account_name'), 'account_name' ],
|
|
[ seq.col('users.nickname'), 'nickname' ], [ seq.col('users.account_name'), 'account_name' ],
|
|
[ seq.col('users.headimgurl'), 'headimgurl' ], 'comment', 'create_time',
|
|
[ seq.col('users.headimgurl'), 'headimgurl' ], 'comment', 'create_time',
|
|
],
|
|
],
|
|
- order: [[ 'comment_id', 'desc' ]],
|
|
|
|
|
|
+ order: [ [ 'comment_id', 'desc' ] ],
|
|
});
|
|
});
|
|
const result = await that.service.base.select(selectBean, that.app.model.ProductComment, '查询商品评论失败,请稍候重试', true, true);
|
|
const result = await that.service.base.select(selectBean, that.app.model.ProductComment, '查询商品评论失败,请稍候重试', true, true);
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|