lrf402788946 3 years ago
parent
commit
b6561b0c7f
3 changed files with 28 additions and 1 deletions
  1. 4 0
      app/controller/dining/.order.js
  2. 1 0
      app/router/dining/order.js
  3. 23 1
      app/service/dining/order.js

+ 4 - 0
app/controller/dining/.order.js

@@ -52,4 +52,8 @@ module.exports = {
     },
     service: "getByOpenid",
   },
+  getMeal: {
+    params: ["!id"],
+    service: "getMeal",
+  },
 };

+ 1 - 0
app/router/dining/order.js

@@ -6,6 +6,7 @@ module.exports = app => {
   const profix = `/api${config.appName ? `/${config.appName}` : ''}`;
   const index = 'dining';
   const target = 'order';
+  router.get(target, `${profix}/${index}/${target}/getMeal/:id`, controller[index][target].getMeal);
   router.get(target, `${profix}/${index}/${target}/getByOpenid`, controller[index][target].getByOpenid);
   router.get(target, `${profix}/${index}/${target}/useMeal/:id`, controller[index][target].useMeal);
   router.post(target, `${profix}/${index}/${target}/mealCard/:openid`, controller[index][target].mealCard);

+ 23 - 1
app/service/dining/order.js

@@ -108,6 +108,29 @@ class OrderService extends CrudService {
     return false;
   }
 
+  /**
+   * 根据id获取某餐
+   * @param {Object} params
+   * @property {String} id 某餐的id
+   */
+  async getMeal({ id }) {
+    id = ObjectId(id);
+    const query = {
+      $or: [
+        { 'breakfast._id': id },
+        { 'lunch._id': id },
+        { 'dinner._id': id },
+      ],
+    };
+    const order = await this.model.findOne(query);
+    if (!order) return;
+    let meal = {};
+    if (ObjectId(id).equals(order.breakfast._id)) meal = order.breakfast;
+    else if (ObjectId(id).equals(order.lunch._id)) meal = order.lunch;
+    else if (ObjectId(id).equals(order.dinner._id)) meal = order.dinner;
+    if (meal) return meal;
+  }
+
   /**
    * 扫码领餐
    * @param {Object} query 参数
@@ -115,7 +138,6 @@ class OrderService extends CrudService {
    */
   async useMeal({ id }) {
     id = ObjectId(id);
-    console.log(this.ctx.tenant);
     const query = {
       $or: [
         { 'breakfast._id': id },