cheny 4 years ago
parent
commit
34ef394b8a
2 changed files with 22 additions and 9 deletions
  1. 3 0
      app/controller/.dock.js
  2. 19 9
      app/service/dock.js

+ 3 - 0
app/controller/.dock.js

@@ -91,6 +91,7 @@ module.exports = {
   goods: {
   goods: {
     params: ["!id"],
     params: ["!id"],
     requestBody: [
     requestBody: [
+      "_id",
       "totaltype",
       "totaltype",
       "name",
       "name",
       "product_type_id",
       "product_type_id",
@@ -115,6 +116,8 @@ module.exports = {
       "coopercompany",
       "coopercompany",
       "other",
       "other",
       "contact_tel",
       "contact_tel",
+      "contact_user",
+      "dockStatus",
     ],
     ],
     service: "goods",
     service: "goods",
   },
   },

+ 19 - 9
app/service/dock.js

@@ -40,16 +40,26 @@ class ChatService extends CrudService {
   }
   }
   // 产品
   // 产品
   async goods({ id }, body) {
   async goods({ id }, body) {
-    const apply = await this.model.findOne({ _id: ObjectId(id) });
-    if (!apply) {
-      throw new BusinessError('没有查询到该申请用户');
+    // console.log(body);
+    const dock = await this.model.findOne({ _id: ObjectId(id) });
+    if (!dock) {
+      throw new BusinessError('没有查询到该对接会');
+    }
+    if (body._id) {
+      const goods = dock.apply.map(i => i.goodsList).flat().find(function(item) {
+        return item.id === body._id;
+      });
+      if (body.dockStatus) {
+        goods.dockStatus = body.dockStatus;
+      }
+    } else {
+      dock.apply.goodsList.push({
+        ...body,
+      });
     }
     }
-    apply.goods.push({
-      ...body,
-      // apply_time: moment().format('YYYY-MM-DD HH:mm:ss'),
-    });
-    const res = await apply.save();
-    const info = _.last(res.goods);
+
+    const res = await dock.save();
+    const info = _.last(res.apply.goodsList);
     return info;
     return info;
   }
   }