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