lrf402788946 преди 4 години
родител
ревизия
07516aeea2
променени са 6 файла, в които са добавени 111 реда и са изтрити 18 реда
  1. 28 1
      app/controller/order/order.js
  2. 0 1
      app/model/order.js
  3. 7 0
      app/router/order.js
  4. 42 0
      app/service/order/bill.js
  5. 7 16
      app/service/order/order.js
  6. 27 0
      app/service/order/split.js

+ 28 - 1
app/controller/order/order.js

@@ -5,11 +5,38 @@ const meta = require('./.order.js');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
-// 客户/供应商
+// 订单
 class OrderController extends Controller {
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.order.order;
+    this.bill_service = this.ctx.service.order.bill;
+    this.split_service = this.ctx.service.order.split;
+  }
+
+  /**
+   * 修改收入
+   */
+  async inBill() {
+    await this.bill_service.inBill(this.ctx.request.body);
+    this.ctx.ok();
+  }
+
+  /**
+   * 拆分货物
+   */
+  async splitGoods() {
+    await this.split_service.splitGoods(this.ctx.request.body);
+    this.ctx.ok();
+  }
+
+
+  /**
+   * 修改支出
+   */
+  async outBill() {
+    await this.bill_service.outBill(this.ctx.request.body);
+    this.ctx.ok();
   }
 }
 

+ 0 - 1
app/model/order.js

@@ -58,7 +58,6 @@ const recordList = new Schema({
 // 货物收入
 const goods_bill = new Schema({
   name: { type: String, maxlength: 200 }, // 货物名称
-  // TODO 2种模式:合同+项目+线路+计费方式/计费方式
   mode: { type: String, maxlength: 200 }, // 计费方式
   number: { type: Number, maxLength: 200 }, // 数量
   weight: { type: Number, maxLength: 200 }, // 重量

+ 7 - 0
app/router/order.js

@@ -6,6 +6,13 @@ module.exports = app => {
   const prefix = '/api/servicezhwl';
   const index = 'order';
   const { router, controller } = app;
+  // 收入
+  router.post('order', `${prefix}/order/inBill`, controller[index].order.inBill);
+  // 拆分货物
+  router.post('order', `${prefix}/order/split`, controller[index].order.splitGoods);
+  // 支出
+  router.post('order', `${prefix}/order/outBill`, controller[index].order.outBill);
+
   router.resources(`${prefix}/order`, controller[index].order); // index、create、show、destroy
   router.post('order', `${prefix}/order/update/:id`, controller[index].order.update);
 };

+ 42 - 0
app/service/order/bill.js

@@ -0,0 +1,42 @@
+'use strict';
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+class BillService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'order');
+    this.model = this.ctx.model.Order;
+    this.os = this.ctx.service.order;
+  }
+
+  /**
+   * 修改收入;订单收入,货物收入
+   * @param {Object} data 订单数据
+   */
+  async inBill(data) {
+    const { _id } = data;
+    const res = await this.model.update({ _id: ObjectId(_id) }, data);
+    try {
+      this.os.record(res._id, { method: 'in' });
+    } catch (error) {
+      this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
+    }
+    return res;
+  }
+  /**
+   *
+   * @param {Object} data 订单数据
+   */
+  async outBill(data) {
+    const { _id } = data;
+    const res = await this.model.update({ _id: ObjectId(_id) }, data);
+    try {
+      this.os.record(res._id, { method: 'out' });
+    } catch (error) {
+      this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
+    }
+    return res;
+  }
+}
+module.exports = BillService;

+ 7 - 16
app/service/order/order.js

@@ -170,22 +170,13 @@ class OrderService extends CrudService {
     if (!user) { throw new BusinessError(ErrorCode.USER_NOT_EXIST, '未找到操作人'); }
     user = JSON.parse(user);
     const { id: userid, name: username } = user;
-    let record = {};
-    if (method === 'create') {
-      // 创建记录
-      record = {
-        opera: username,
-        operaid: userid,
-        message: `${username}创建订单`,
-      };
-    } else if (method === 'update') {
-      record = {
-        opera: username,
-        operaid: userid,
-        message: `${username}修改订单`,
-      };
-    }
-
+    const record = { opera: username, operaid: userid };
+    // 创建记录
+    if (method === 'create') record.message = `${username}创建订单`;
+    else if (method === 'update') record.message = `${username}修改订单`;
+    else if (method === 'in') record.message = `${username}修改收入`;
+    else if (method === 'out') record.message = `${username}修改支出`;
+    else if (method === 'split') record.message = `${username}拆分货物`;
     order.record.push(record);
     await order.save();
   }

+ 27 - 0
app/service/order/split.js

@@ -0,0 +1,27 @@
+'use strict';
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+class SplitService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'order');
+    this.model = this.ctx.model.Order;
+    this.os = this.ctx.service.order;
+  }
+  /**
+   * 拆分货物
+   * @param {Object} data 订单数据
+   */
+  async splitGoods(data) {
+    const { _id } = data;
+    const res = await this.model.update({ _id: ObjectId(_id) }, data);
+    try {
+      this.os.record(res._id, { method: 'split' });
+    } catch (error) {
+      this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
+    }
+    return res;
+  }
+}
+module.exports = SplitService;