浏览代码

商品评价修改为查询每个商品的评价

lrf 2 年之前
父节点
当前提交
4468587d4d
共有 1 个文件被更改,包括 8 次插入5 次删除
  1. 8 5
      app/service/trade/orderDetail.js

+ 8 - 5
app/service/trade/orderDetail.js

@@ -217,23 +217,26 @@ class OrderDetailService extends CrudService {
     const total = _.get(_.head(t), 'id');
     const list = [];
     for (const i of rs) {
-      const { goods } = i;
+      const { goods, _id: orderDetail } = i;
       const obj = _.cloneDeep(i);
       const real_pay = this.ctx.service.util.orderDetail.computedRealPay(obj);
       obj.real_pay = real_pay;
       obj.buy_num_total = goods.reduce((p, n) => this.ctx.plus(p, n.buy_num), 0);
       for (const og of obj.goods) {
-        const { file = [] } = og;
+        const { file = [], _id: goodSpec } = og;
         const gfile = _.get(og, 'goods.file', []);
         const nf = [ ...file, ...gfile ];
         const url = _.get(_.head(nf), 'url');
         og.url = url;
         delete og.file;
         delete og.goods.file;
+        // 评价
+        const q = { orderDetail, goodSpec };
+        const rate = await this.goodsRateModel.findOne(q, { _id: 1 });
+        obj.rate = _.get(rate, '_id');
+
       }
-      // 评价与售后
-      const rate = await this.goodsRateModel.findOne({ orderDetail: obj._id }, { _id: 1 });
-      obj.rate = _.get(rate, '_id');
+      // 售后
       const asum = await this.afterSaleModel.count({ order_detail: obj._id, status: { $nin: [ '0', '!1', '!2', '!3', '!4', '!5' ] } });
       obj.is_afterSale = asum > 0;
       list.push(obj);