12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- '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, 'in');
- this.model = this.ctx.model.Order;
- this.os = this.ctx.service.order.order;
- }
- /**
- * 修改收入;订单收入,货物收入
- * @param {Object} data 订单数据
- */
- async inBill(data) {
- console.log(data);
- const { _id } = data;
- const res = await this.model.update({ _id: ObjectId(_id) }, data);
- try {
- this.os.record(_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(_id, { method: 'out' });
- } catch (error) {
- this.logger.error(`订单id:${res.id}记录创建失败:${error.toString()}`);
- }
- return res;
- }
- }
- module.exports = BillService;
|