lrf hace 2 años
padre
commit
0f2d9f6374
Se han modificado 2 ficheros con 13 adiciones y 5 borrados
  1. 12 3
      app/service/shop/shopInBill.js
  2. 1 2
      app/service/trade/afterSale.js

+ 12 - 3
app/service/shop/shopInBill.js

@@ -29,7 +29,8 @@ class ShopInBillService extends CrudService {
     obj.time = moment().format('YYYY-MM-DD HH:mm:ss');
     obj.source = '3';
     obj.source_id = _.get(orderDetail, '_id');
-    tran.insert('ShopInBill', obj);
+    const num = await this.model.count({ source: obj.source, source_id: obj.source_id });
+    if (num <= 0) tran.insert('ShopInBill', obj);
   }
 
   /**
@@ -38,11 +39,19 @@ class ShopInBillService extends CrudService {
    * @param {Transaction} tran 数据库事务
    */
   async createByAfterSale(afterSale, tran) {
-    const obj = { shop: _.get(afterSale, '_id') };
+    const query = { source_id: _.get(afterSale, 'order_detail'), source: '3' };
+    const inBill = await this.model.findOne(query);
+    // 该订单没有入账,就不需要退
+    if (inBill) return;
+    const q2 = { source: '-3', source_id: _.get(afterSale, '_id') };
+    const n2 = await this.model.count(q2);
+    // 有过售后退钱记录,不需要再生成
+    if (n2 > 0) return;
+    const obj = { shop: _.get(afterSale, 'shop') };
     obj.time = moment().format('YYYY-MM-DD HH:mm:ss');
     obj.source = '-3';
     obj.source_id = _.get(afterSale, '_id');
-    obj.receipts = _.get(afterSale, 'money');
+    obj.receipts = _.get(inBill, 'receipts');
     tran.insert('ShopInBill', obj);
   }
 }

+ 1 - 2
app/service/trade/afterSale.js

@@ -199,8 +199,7 @@ class AfterSaleService extends CrudService {
     // 退积分
     await this.ctx.service.user.point.refundOrderPoint(order_detail, tran);
     // 退商铺的入账流水金额
-    const shopBill = { shop: _.get(data, 'shop'), _id: _.get(data, '_id'), money: returnMoney };
-    await this.ctx.service.shop.shopInBill.createByAfterSale(shopBill, tran);
+    await this.ctx.service.shop.shopInBill.createByAfterSale(data, tran);
     return refundInfo;
   }
   /**