lrf 2 سال پیش
والد
کامیت
42b2880f46
3فایلهای تغییر یافته به همراه38 افزوده شده و 2 حذف شده
  1. 4 0
      app/controller/statistics/bill.js
  2. 29 0
      app/service/statistics/bill.js
  3. 5 2
      app/z_router/statistics/bill.js

+ 4 - 0
app/controller/statistics/bill.js

@@ -12,5 +12,9 @@ class BillController extends Controller {
     const data = await this.service.getBill(this.ctx.query);
     this.ctx.ok({ data });
   }
+  async outBill() {
+    await this.service.outBill(this.ctx.request.body);
+    this.ctx.ok();
+  }
 }
 module.exports = CrudController(BillController, {});

+ 29 - 0
app/service/statistics/bill.js

@@ -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,开始时间和结束时间,形成对账单

+ 5 - 2
app/z_router/statistics/bill.js

@@ -6,8 +6,11 @@ const routerRegister = require(regPath);
 const rkey = 'statistics/bill';
 const ckey = 'statistics.bill';
 const keyZh = '账单';
-const routes = [{ method: 'get', path: `${rkey}/getBill`, controller: `${ckey}.getBill`, name: `${ckey}getBill`, zh: `${keyZh}账单` }];
+const routes = [
+  { method: 'post', path: `${rkey}/outBill`, controller: `${ckey}.outBill`, name: `${ckey}outBill`, zh: `${keyZh}出账标记` },
+  { 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);
 };