|
@@ -4,6 +4,7 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const _ = require('lodash');
|
|
|
const assert = require('assert');
|
|
|
const Transaction = require('mongoose-transactions');
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
|
|
|
// 对账
|
|
|
class BillService extends CrudService {
|
|
@@ -22,21 +23,9 @@ class BillService extends CrudService {
|
|
|
* @param body.afterSale 对账的售后id集合
|
|
|
*/
|
|
|
async outBill({ order = [], afterSale = [] }) {
|
|
|
- try {
|
|
|
- for (const o of order) {
|
|
|
- this.tran.update('OrderDetail', o, { out_bill: '0' });
|
|
|
- }
|
|
|
- for (const as of afterSale) {
|
|
|
- this.tran.update('AfterSale', as, { out_bill: '0' });
|
|
|
- }
|
|
|
-
|
|
|
- this.tran.run();
|
|
|
- } catch (error) {
|
|
|
- this.tran.rollback();
|
|
|
- console.error(error);
|
|
|
- throw new BusinessError(ErrorCode.SERVICE_FAULT, '对账失败');
|
|
|
- }
|
|
|
-
|
|
|
+ const data = { out_bill: '0' };
|
|
|
+ await this.orderDetailModel.updateMany({ _id: order.map(i => ObjectId(i)) }, data);
|
|
|
+ await this.afterSaleModel.updateMany({ _id: afterSale.map(i => ObjectId(i)) }, data);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -133,7 +122,7 @@ class BillService extends CrudService {
|
|
|
const list = [];
|
|
|
for (const order of orderList) {
|
|
|
const o = _.cloneDeep(order);
|
|
|
- const type = dictData.find((f) => f.value === o.type);
|
|
|
+ const type = dictData.find(f => f.value === o.type);
|
|
|
const moneyDetail = this.moneyDetail(order);
|
|
|
const obj = {
|
|
|
_id: _.get(o, '_id'),
|