liuyu 4 سال پیش
والد
کامیت
64b46c0fe8
3فایلهای تغییر یافته به همراه25 افزوده شده و 2 حذف شده
  1. 6 1
      app/controller/dock.js
  2. 1 0
      app/router.js
  3. 18 1
      app/service/dock.js

+ 6 - 1
app/controller/dock.js

@@ -38,10 +38,15 @@ class DockController extends Controller {
     this.ctx.ok({ res });
   }
 
-  async getdockByopenid(){
+  async getdockByopenid() {
     const res = await this.service.getdockByopenid(this.ctx.query);
     this.ctx.ok({ res });
   }
+
+  async getgoodslist() {
+    const data = await this.service.getgoodslist(this.ctx.query);
+    this.ctx.ok({ data });
+  }
 }
 
 module.exports = CrudController(DockController, meta);

+ 1 - 0
app/router.js

@@ -36,6 +36,7 @@ module.exports = app => {
   router.post('chat', '/api/live/chat/:id', controller.chat.update);
 
   // 对接会表设置路由
+  router.get('/api/live/dock/getgoodslist', controller.dock.getgoodslist); // 模糊查询商品列表
   router.get('/api/live/dock/dockopenid', controller.dock.getdockByopenid); // 查询申请的对接列表
   router.get('/api/live/dock/dockfetch/:id', controller.dock.dockfetch); // 查询申请的对接列表
   router.get('/api/live/dock/myapply', controller.dock.myapply); // 查询申请的对接列表

+ 18 - 1
app/service/dock.js

@@ -204,10 +204,27 @@ class ChatService extends CrudService {
     return res;
   }
 
-  async getdockByopenid({ openid }){
+  async getdockByopenid({ openid }) {
     const res = await this.model.findOne({ openid });
     return res;
   }
+
+  async getgoodslist({ name }) {
+    assert(name, '请输入产品名称');
+    const res = await this.model.find({ 'apply.goodsList.name': { $regex: name } });
+    const data = [];
+    for (const elm of res) {
+      const applys = elm.apply;
+      for (const el of applys) {
+        const goodlists = el.goodsList;
+        const goodlist = _.filter(goodlists, function(o) {
+          return _.includes(o.name, name);
+        });
+        data.concat(goodlist);
+      }
+    }
+    return data;
+  }
 }
 
 module.exports = ChatService;