1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- '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 StockNeedService extends CrudService {
- constructor(ctx) {
- super(ctx, 'stock_need');
- this.model = this.ctx.model.Stockneed;
- this.followmodel = this.ctx.model.Financefollow;
- }
- //根据金融机构查询股权需求(列表)--分为指向(传金融机构ID)和非指向(不用传)
- async getStockList(data){
- const match = {};
- match.status='0';
- if (data.jg_id) {//金融机构ID
- match.jg_id =data.jg_id;
- }else{
- match.jg_id ='0';
- }
- const skip = Number.parseInt(data.skip) || 1;
- const limit = Number.parseInt(data.limit) || 10;
- const total = await this.model.count(match);
- const res = await this.model.find(match).sort({'meta.createdAt':-1}).limit(limit).skip((skip - 1) * limit);
- const newres = {res,total};
- return newres;
- }
- //根据企业用户查询股权需求(列表)
- async getQystock(data){
- const{userid} = data;
- const match = {};
- match.userid = userid;
- match.status = '0';
- if(data.title){
- match.title = { $regex: data.title };
- }
- const skip = Number.parseInt(data.skip) || 1;
- const limit = Number.parseInt(data.limit) || 10;
- const total = await this.model.count(match);
- const res = await this.model.find(match).sort({'meta.createdAt':-1}).limit(limit).skip((skip - 1) * limit);
- const result = {total,res}
- return result;
- }
- //金融机构关注股权需求
- async getFollowStock(data){
- const { finceId, userid } = data;//债权需求ID,金融机构ID
- const newdata={};
- newdata.finceType = '1';
- newdata.finceId = finceId;
- newdata.userid = userid;
- newdata.orcredit = '0';
- newdata.credit_money = 0;
- newdata.accept_time = 0;
- newdata.credit_time = 0;
- const res = await this.followmodel.create(newdata);
- const qy = await this.model.findById(finceId);
- this.ctx.service.viewnews.insertViewNews("股权需求信息","您有新的股权需求被关注,请查看需求列表",qy.userid);
- return res;
- }
- //股权需求详情
- async getOne(data){
- const { id } = data;//股权需求ID
- const res = await this.model.aggregate([
- { $match: {_id:ObjectId(id)}},
- { $lookup: {
- from: 'dictionary',
- localField: 'rz_id',
- foreignField: 'code',
- as: 'rznew' } },
- { $unwind: '$rznew' },
- { $lookup: {
- from: 'profession',
- localField: 'work_id',
- foreignField: 'code',
- as: 'worknew' } },
- { $unwind: '$worknew' },
- { $project: {title:1,stock_give:1,stock_money:1,rz_id:1,persion_name:1,persion_phone:1,stock_news:1,pro_book:1,jg_id:1,
- rzname:'$rznew.name',workname:'$worknew.name'} }
- ]);
- return res;
- }
-
-
- }
- module.exports = StockNeedService;
|