lrf 2 years ago
parent
commit
fd4bd1fe95
2 changed files with 17 additions and 4 deletions
  1. 2 2
      app/service/trade/afterSale.js
  2. 15 2
      app/service/user/point.js

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

@@ -135,8 +135,8 @@ class AfterSaleService extends CrudService {
     const payOrder = _.get(orderDetail, 'order');
     await this.checkToReturnUserCoupon(payOrder, tran);
     // 退积分,退多钱就退多少积分
-    const { customer } = orderDetail;
-    await this.ctx.service.user.point.refundPoint({ customer, money: refundMoney, source_id: afterSale_id, source: '-1' }, tran);
+    const { _id } = orderDetail;
+    await this.ctx.service.user.point.refundOrderPoint(_id, tran);
     return refundInfo;
   }
 

+ 15 - 2
app/service/user/point.js

@@ -51,8 +51,21 @@ class PointService extends CrudService {
     return num > 0;
   }
 
-  async refundPoint({ customer, money, source, source_id }, tran) {
-    const data = { customer, money, time: moment().format('YYYY-MM-DD HH:mm:ss'), status: '1', source, source_id };
+  /**
+   * 订单退货,退积分
+   * @param {String} source_id 拆分后的订单id
+   * @param {Transaction} tran 数据库事务
+   */
+  async refundOrderPoint(source_id, tran) {
+    const record = await this.model.findOne({ source_id, source: '0' });
+    // 没有该订单收货后的积分记录,直接返回
+    if (!record) return;
+    // 查找该订单是否已经退积分
+    const num = await this.model.count({ source_id, source: '-1' });
+    // 有记录,返回
+    if (num > 0) return;
+    const { customer, point } = record;
+    const data = { customer, point, time: moment().format('YYYY-MM-DD HH:mm:ss'), source: '-1', source_id };
     tran.insert('Point', data);
   }
 }