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