12345678910111213141516171819202122232425262728293031323334353637 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- const { ObjectId } = require('mongoose').Types;
- // 审批
- class ExamineService extends CrudService {
- constructor(ctx) {
- super(ctx, 'examine');
- this.model = this.ctx.model.Examine;
- }
- async getGoods({ examine_id, buy_id, mech_id, market_id, status }) {
- assert(examine_id, '缺少审批表信息');
- assert(buy_id, '缺少购买人信息');
- assert(mech_id, '缺少商铺信息');
- assert(market_id, '缺少商品信息');
- assert(status, '缺少货物状态');
- const query = {
- _id: ObjectId(examine_id),
- buy_id: ObjectId(buy_id),
- };
- let data = await this.model.findOne(query);
- if (!data) BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到信息');
- const i = data.order.findIndex(f => ObjectId(f.mech_id).equals(mech_id) && ObjectId(f.id).equals(market_id));
- if (i < 0)BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到货物信息');
- data.order[i].status = status;
- data = _.omit(data, [ 'meta' ]);
- data = JSON.parse(JSON.stringify(data));
- const res = await this.model.updateOne(query, data);
- return res;
- }
- }
- module.exports = ExamineService;
|