lrf преди 2 години
родител
ревизия
a2d80e2c5f
променени са 2 файла, в които са добавени 6 реда и са изтрити 17 реда
  1. 5 16
      app/service/statistics/bill.js
  2. 1 1
      app/z_router/statistics/bill.js

+ 5 - 16
app/service/statistics/bill.js

@@ -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'),

+ 1 - 1
app/z_router/statistics/bill.js

@@ -11,6 +11,6 @@ const routes = [
   { method: 'get', path: `${rkey}/getBill`, controller: `${ckey}.getBill`, name: `${ckey}getBill`, zh: `${keyZh}账单` },
 ];
 
-module.exports = (app) => {
+module.exports = app => {
   routerRegister(app, routes, keyZh, rkey, ckey);
 };