bill.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. const { ObjectId } = require('mongoose').Types;
  3. const { CrudService } = require('naf-framework-mongoose/lib/service');
  4. class BillService extends CrudService {
  5. constructor(ctx) {
  6. super(ctx, 'in');
  7. this.model = this.ctx.model.Order;
  8. this.os = this.ctx.service.order.order;
  9. }
  10. /**
  11. * 修改收入;订单收入,货物收入
  12. * @param {Object} data 订单数据
  13. */
  14. async inBill(data) {
  15. console.log(data);
  16. const { _id } = data;
  17. const res = await this.model.update({ _id: ObjectId(_id) }, data);
  18. try {
  19. this.os.record(_id, { method: 'in' });
  20. } catch (error) {
  21. this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
  22. }
  23. return res;
  24. }
  25. /**
  26. *
  27. * @param {Object} data 订单数据
  28. */
  29. async outBill(data) {
  30. const { _id } = data;
  31. const res = await this.model.update({ _id: ObjectId(_id) }, data);
  32. try {
  33. this.os.record(_id, { method: 'out' });
  34. } catch (error) {
  35. this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
  36. }
  37. return res;
  38. }
  39. }
  40. module.exports = BillService;