12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- class InstitutionService extends CrudService {
- constructor(ctx) {
- super(ctx, 'institution');
- this.model = this.ctx.model.Institution;
- this.releaseModel = this.ctx.model.Release;
- }
- // publish:发布还是取消发布;finid:股权ID;userid:金控管理员ID;type:1-股权;
- async makePublish(data) {
- const { publish, finid } = data;
- const finalStutus = {};
- const newdata = {};
- newdata.review_id = data.userid;
- newdata.product_id = finid;
- newdata.type = '1';
- if (publish === 1) {
- newdata.status = publish;
- const financ = await this.model.findById(finid);
- financ.status = '2';
- const res = await financ.save();
- if (res) {
- finalStutus.status = 'SUCCESS';
- await this.releaseModel.create(newdata);
- } else {
- finalStutus.status = 'ERROR';
- }
- } else {
- newdata.status = publish;
- const financ = await this.model.findById(finid);
- financ.status = '1';
- const res = await financ.save();
- if (res) {
- finalStutus.status = 'SUCCESS';
- const relea = await this.releaseModel.find({ product_id: finid });
- relea.status = '0';
- await relea.save();
- } else {
- finalStutus.status = 'ERROR';
- }
- }
- return finalStutus;
- }
- // 查询股权信息详情
- async getOne(data) {
- const { insid } = data;
- const match = {};
- if (insid) { // 股权ID
- match._id = ObjectId(insid);
- }
- const res = await this.model.aggregate([
- { $match: match},
- { $lookup: {
- from: 'dictionary',
- localField: 'profession',
- foreignField: 'code',
- as: 'pronew' } },
- { $lookup: {
- from: 'dictionary',
- localField: 'round',
- foreignField: 'code',
- as: 'roundnew' } },
- { $project: { profession: 0, round: 0 } },
- ]);
- return res;
- }
- }
- module.exports = InstitutionService;
|