bill.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 BillService extends CrudService {
  7. constructor(ctx) {
  8. super(ctx, 'in');
  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 inBill(data) {
  17. const { _id } = data;
  18. const res = await this.model.update({ _id: ObjectId(_id) }, data);
  19. try {
  20. this.os.record(res._id, { method: 'in' });
  21. } catch (error) {
  22. this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
  23. }
  24. return res;
  25. }
  26. /**
  27. *
  28. * @param {Object} data 订单数据
  29. */
  30. async outBill(data) {
  31. const { _id } = data;
  32. const res = await this.model.update({ _id: ObjectId(_id) }, data);
  33. try {
  34. this.os.record(res._id, { method: 'out' });
  35. } catch (error) {
  36. this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
  37. }
  38. return res;
  39. }
  40. }
  41. module.exports = BillService;