lrf 2 years ago
parent
commit
0ff34a08c3
2 changed files with 6 additions and 3 deletions
  1. 5 2
      app/service/shop/shopInBill.js
  2. 1 1
      app/service/trade/afterSale.js

+ 5 - 2
app/service/shop/shopInBill.js

@@ -36,9 +36,10 @@ class ShopInBillService extends CrudService {
   /**
    * 售后创建流水
    * @param {object} afterSale 订单详情数据
+   * @param {number} returnMoney 退款金额
    * @param {Transaction} tran 数据库事务
    */
-  async createByAfterSale(afterSale, tran) {
+  async createByAfterSale(afterSale, returnMoney, tran) {
     const query = { source_id: _.get(afterSale, 'order_detail'), source: '3' };
     const inBill = await this.model.findOne(query);
     // 该订单没有入账,就不需要退
@@ -51,7 +52,9 @@ class ShopInBillService extends CrudService {
     obj.time = moment().format('YYYY-MM-DD HH:mm:ss');
     obj.source = '-3';
     obj.source_id = _.get(afterSale, '_id');
-    obj.receipts = _.get(inBill, 'receipts');
+    const limit = _.get(inBill, 'receipts');
+    if (this.ctx.minus(limit, returnMoney) >= 0) obj.receipts = returnMoney;
+    else obj.receipts = limit;
     tran.insert('ShopInBill', obj);
   }
 }

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

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