split.js 817 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. const _ = require('lodash');
  3. const { ObjectId } = require('mongoose').Types;
  4. const { CrudService } = require('naf-framework-mongoose/lib/service');
  5. const { BusinessError, ErrorCode } = require('naf-core').Error;
  6. class SplitService extends CrudService {
  7. constructor(ctx) {
  8. super(ctx, 'split');
  9. this.model = this.ctx.model.Order;
  10. this.os = this.ctx.service.order.order;
  11. }
  12. /**
  13. * 拆分货物
  14. * @param {Object} data 订单数据
  15. */
  16. async splitGoods(data) {
  17. const { _id } = data;
  18. const res = await this.model.update({ _id: ObjectId(_id) }, data);
  19. try {
  20. this.os.record(_id, { method: 'split' });
  21. } catch (error) {
  22. this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
  23. }
  24. return res;
  25. }
  26. }
  27. module.exports = SplitService;