lrf 2 gadi atpakaļ
vecāks
revīzija
daa629a94d

+ 3 - 2
app/controller/shop/config/.goodsRate.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['orderDetail', 'customer', 'shop', 'goods', 'goodsSpec', 'reply', 'goods_score', 'shop_score', 'transport_score'],
+    requestBody: ['set_id', 'orderDetail', 'customer', 'shop', 'goods', 'goodsSpec', 'reply', 'goods_score', 'shop_score', 'transport_score'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['orderDetail', 'customer', 'shop', 'goods', 'goodsSpec', 'reply', 'goods_score', 'shop_score', 'transport_score'],
+    requestBody: ['set_id', 'orderDetail', 'customer', 'shop', 'goods', 'goodsSpec', 'reply', 'goods_score', 'shop_score', 'transport_score'],
   },
   show: {
     parameters: {
@@ -25,6 +25,7 @@ module.exports = {
         shop: 'shop',
         goods: 'goods',
         goodsSpec: 'goodsSpec',
+        set_id: 'set_id',
         orderDetail: 'orderDetail',
       },
       // options: {

+ 1 - 0
app/model/shop/goodsRate.js

@@ -16,6 +16,7 @@ const goodsRate = {
   shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
   goods: { type: String, required: false, zh: '商品', ref: 'Shop.Goods' }, //
   goodsSpec: { type: String, required: false, zh: '规格', ref: 'Shop.GoodsSpec' }, //
+  set_id: { type: String, required: false, zh: '套装id' },
   reply: { type: Array, required: false, zh: '回复' }, //
   goods_score: { type: Number, required: false, default: 5, zh: '商品评分' }, //
   shop_score: { type: Number, required: false, default: 5, zh: '服务评分' }, //

+ 3 - 4
app/service/trade/afterSale.js

@@ -53,7 +53,6 @@ class AfterSaleService extends CrudService {
           const newGoods = { ...spec, goods: sg };
           goods = newGoods;
         }
-
       }
       if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未在当前订单中搜索到要售后的商品');
     } else {
@@ -169,12 +168,12 @@ class AfterSaleService extends CrudService {
       }
       // 修改数据
       this.tran.update('AfterSale', entity._id, update);
-      await this.tran.run();
+      // await this.tran.run();
       // 退钱
       if (!refundInfo) return;
       // console.log(refundInfo);
-      const res = await this.ctx.service.trade.pay.refund(refundInfo);
-      if (res.errcode && res.errcode !== 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, res.errmsg);
+      // const res = await this.ctx.service.trade.pay.refund(refundInfo);
+      // if (res.errcode && res.errcode !== 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, res.errmsg);
     } catch (error) {
       console.error(error);
       await this.tran.rollback();

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

@@ -170,14 +170,31 @@ class OrderDetailService extends CrudService {
     const rate = await this.goodsRateModel.find({ orderDetail: res._id });
     const goods = _.get(res, 'goods', []);
     for (const g of goods) {
-      const r = afterSale.find(f => ObjectId(_.get(f, 'goods._id')).equals(g._id));
-      if (r) g.is_afterSale = true;
-      else g.is_afterSale = false;
-      const r2 = rate.find(f => ObjectId(_.get(f, 'goodsSpec')).equals(g._id));
-      if (r2) {
-        g.is_rate = true;
-        g.rate = r2._id;
-      } else g.is_rate = false;
+      const { is_set = '1' } = g;
+      if (is_set === '1') {
+        const r = afterSale.find(f => ObjectId(_.get(f, 'goods._id')).equals(g._id));
+        if (r) g.is_afterSale = true;
+        else g.is_afterSale = false;
+        const r2 = rate.find(f => ObjectId(_.get(f, 'goodsSpec')).equals(g._id));
+        if (r2) {
+          g.is_rate = true;
+          g.rate = r2._id;
+        } else g.is_rate = false;
+      } else {
+        const { set_id, goods } = g;
+        for (const i of goods) {
+          const { spec } = i;
+          const r = afterSale.find(f => f.set_id === set_id && _.get(f, 'goods._id') === _.get(spec, '_id'));
+          if (r) i.is_afterSale = true;
+          else i.is_afterSale = false;
+          const r2 = rate.find(f => f.set_id === set_id && f.goodsSpec === _.get(spec, '_id'));
+          if (r2) {
+            i.is_rate = true;
+            i.rate = r2._id;
+          } else i.is_rate = false;
+        }
+      }
+
     }
     res.goods = goods;
     // 整理total_detail为列表:让前端显示更方便