lrf 2 anni fa
parent
commit
b7fc1d2479
2 ha cambiato i file con 14 aggiunte e 10 eliminazioni
  1. 11 8
      app/service/trade/orderDetail.js
  2. 3 2
      app/service/trade/pay.js

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

@@ -26,10 +26,10 @@ class OrderDetailService extends CrudService {
     if (goods_id) {
       // 传来指定商品,查有该商品的订单,但是如果没有,就查每一项中是否有 shop_transport_no 和 shop_transport_type
       // 如果有这俩属性,说明也有单子,也查出来
-      toSearch = transport.filter((f) => _.isArray(f.goods) && f.goods.find((fg) => fg.goods_id === goods_id));
+      toSearch = transport.filter(f => _.isArray(f.goods) && f.goods.find(fg => fg.goods_id === goods_id));
       console.log(toSearch);
       if (toSearch.length <= 0) {
-        toSearch = transport.filter((f) => f.shop_transport_no && f.shop_transport_type);
+        toSearch = transport.filter(f => f.shop_transport_no && f.shop_transport_type);
       }
     } else {
       toSearch = transport;
@@ -62,6 +62,7 @@ class OrderDetailService extends CrudService {
     // 分订单计数器
     let noTimes = 1;
     // const list = [];
+    const ids = [];
     for (const s of shopGoods) {
       const shop = _.get(s, 'shop');
       const remarks = _.get(s, 'remarks');
@@ -79,10 +80,12 @@ class OrderDetailService extends CrudService {
       // 测试用
       obj.status = '1';
       // list.push(obj);
-      tran.insert('OrderDetail', obj);
+      const od_id = tran.insert('OrderDetail', obj);
+      ids.push(od_id);
       // 添加该商品是否和平台活动有关,做记录
       // await this.ctx.service.trade.actOrder.create(orderDetail_id, obj, tran);
     }
+    return ids;
     // await this.model.insertMany(list);
   }
 
@@ -129,10 +132,10 @@ 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));
+      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));
+      const r2 = rate.find(f => ObjectId(_.get(f, 'goodsSpec')).equals(g._id));
       if (r2) {
         g.is_rate = true;
         g.rate = r2._id;
@@ -178,7 +181,7 @@ class OrderDetailService extends CrudService {
     if (sort && _.isString(sort)) {
       sort = { [sort]: desc ? -1 : 1 };
     } else if (sort && _.isArray(sort)) {
-      sort = sort.map((f) => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
+      sort = sort.map(f => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
     }
     let condition = _.cloneDeep(filter);
     condition = await this.beforeQuery(condition);
@@ -263,7 +266,7 @@ class OrderDetailService extends CrudService {
       for (const og of obj.goods) {
         const { file = [], _id: goodsSpec } = og;
         const gfile = _.get(og, 'goods.file', []);
-        const nf = [...file, ...gfile];
+        const nf = [ ...file, ...gfile ];
         const url = _.get(_.head(nf), 'url');
         og.url = url;
         delete og.file;
@@ -275,7 +278,7 @@ class OrderDetailService extends CrudService {
         obj.price = _.get(obj, 'price', obj.sell_money);
       }
       // 售后
-      const asum = await this.afterSaleModel.count({ order_detail: obj._id, status: { $nin: ['-1', '!1', '-2', '!2', '-3', '!3', '-4', '!4', '-5', '!5'] } });
+      const asum = await this.afterSaleModel.count({ order_detail: obj._id, status: { $nin: [ '-1', '!1', '-2', '!2', '-3', '!3', '-4', '!4', '-5', '!5' ] } });
       obj.is_afterSale = asum > 0;
       list.push(obj);
     }

+ 3 - 2
app/service/trade/pay.js

@@ -127,6 +127,7 @@ class PayService extends CrudService {
     }
     orderData = JSON.parse(JSON.stringify(orderData));
     const payData = _.get(orderData, 'pay', {});
+    let odIds = [];
     // 支付结果全都存起来
     payData.result = result;
     // 支付时间
@@ -136,7 +137,7 @@ class PayService extends CrudService {
       this.tran.update('Order', orderData._id, { pay: payData, status: '1' });
       await this.tran.run();
       // 拆订单
-      await this.ctx.service.trade.orderDetail.create({ order_id: orderData._id }, this.tran);
+      odIds = await this.ctx.service.trade.orderDetail.create({ order_id: orderData._id }, this.tran);
       // 加销量
       await this.addSell(orderData, this.tran);
       await this.tran.run();
@@ -160,7 +161,7 @@ class PayService extends CrudService {
       this.tran.clean();
     }
     // 发送系统消息,让对应的店铺接收消息
-    const msgData = { source_id: orderData._id, type: '0' };
+    const msgData = { source_id: odIds, type: '0' };
     await this.ctx.service.shop.shopNotice.remindToSend(msgData);
   }
   /**