'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 TransportService extends CrudService { constructor(ctx) { super(ctx, 'transport'); this.model = this.ctx.model.Transport; this.os = this.ctx.service.order.order; } async create(data) { const { goods, no, send_time } = data; // 需要将发走的货物找到其对应的订单,然后添加订单的发货数据记录 await this.os.sendGoods(goods, no, send_time); const res = await this.model.create(data); return res; } /** * 签收 * @param {Object} data 运输单数据 */ async sign(data) { const { id, sign_time } = data; const transport = await this.model.find({ _id: ObjectId(id) }); if (!transport) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到运输单信息'); const { split, no } = data; // 修改订单部分 await this.os.arriveGoods(split, no); // 修改运输单部分 transport.status = '1'; if (sign_time) transport.sign_time = sign_time; return await transport.save(); } } module.exports = TransportService;