lrf 2 years ago
parent
commit
66a3a766b3
3 changed files with 9 additions and 5 deletions
  1. 4 4
      app/controller/shop/config/.goods.js
  2. 4 0
      app/model/shop/goods.js
  3. 1 1
      app/service/view/goods.js

+ 4 - 4
app/controller/shop/config/.goods.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['act_tags', 'shop', 'name', 'shot_brief', 'send_time', 'brief', 'file', 'tags', 'status'],
+    requestBody: ['source', 'url', 'act_tags', 'shop', 'name', 'shot_brief', 'send_time', 'brief', 'file', 'tags', 'status'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['act_tags', 'shop', 'name', 'shot_brief', 'send_time', 'brief', 'file', 'tags', 'status'],
+    requestBody: ['source', 'url', 'act_tags', 'shop', 'name', 'shot_brief', 'send_time', 'brief', 'file', 'tags', 'status'],
   },
   show: {
     parameters: {
@@ -34,8 +34,8 @@ module.exports = {
     service: 'query',
     options: {
       query: ['skip', 'limit'],
-      sort: ['meta.createdAt'],
-      desc: true,
+      sort: ['sort'],
+      asc: true,
       count: true,
     },
   },

+ 4 - 0
app/model/shop/goods.js

@@ -14,6 +14,9 @@ const goods = {
   view_num: { type: Number, required: false, default: 0, zh: '浏览量' }, //
   status: { type: String, required: false, default: '0', zh: '商品状态' }, // 字典:goods_status
   act_tags: { type: Array, required: false, zh: '活动标签' }, // 字典:act_tags
+  sort: { type: Number, required: false, default: 0, zh: '排序' }, //
+  source: { type: String, required: false, zh: '来源' }, //
+  url: { type: String, required: false, zh: '网址' }, //
 };
 const schema = new Schema(goods, { toJSON: { getters: true, virtuals: true } });
 schema.index({ id: 1 });
@@ -23,6 +26,7 @@ schema.index({ name: 1 });
 schema.index({ status: 1 });
 schema.index({ view_num: 1 });
 schema.index({ act_tags: 1 });
+schema.index({ sort: 1 });
 
 schema.plugin(metaPlugin);
 

+ 1 - 1
app/service/view/goods.js

@@ -38,7 +38,7 @@ class GoodsService extends CrudService {
 
   async indexGoodsList(condition, { skip = 0, limit = 20 } = {}) {
     condition = this.dealFilter(condition);
-    const pipline = [{ $sort: { 'meta.createdAt': -1 } }, { $match: { status: { $ne: '0' } } }];
+    const pipline = [{ $sort: { sort: 1 } }, { $match: { status: { $ne: '0' } } }];
     const { view_num, sell_num, sell_money, name, shop, tags } = condition;
     const sort = {};
     if (view_num) sort.view_num = view_num;