|
@@ -3,6 +3,7 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const _ = require('lodash');
|
|
|
const assert = require('assert');
|
|
|
+const Transaction = require('mongoose-transactions');
|
|
|
|
|
|
// 对账
|
|
|
class BillService extends CrudService {
|
|
@@ -10,7 +11,35 @@ class BillService extends CrudService {
|
|
|
super(ctx, 'bill');
|
|
|
this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
|
|
|
this.afterSaleModel = this.ctx.model.Trade.AfterSale;
|
|
|
+ this.tran = new Transaction();
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 对账标记
|
|
|
+ * @param {Object} body 参数体
|
|
|
+ * @param body.order 对账的订单内容
|
|
|
+ // ** _id:orderDetail的id
|
|
|
+ // ** spec_id: 商品规格id
|
|
|
+ * @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, '对账失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 生成店铺对账单
|
|
|
** 根据店铺id,开始时间和结束时间,形成对账单
|