bill.js 1.2 KB

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