|
@@ -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);
|
|
|
}
|
|
|
}
|