stockneed.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class StockNeedService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'stock_need');
  10. this.model = this.ctx.model.Stockneed;
  11. this.followmodel = this.ctx.model.Financefollow;
  12. }
  13. //根据金融机构查询股权需求(列表)--分为指向(传金融机构ID)和非指向(不用传)
  14. async getStockList(data){
  15. const match = {};
  16. match.status='0';
  17. if (data.jg_id) {//金融机构ID
  18. match.jg_id =data.jg_id;
  19. }else{
  20. match.jg_id ='0';
  21. }
  22. const skip = Number.parseInt(data.skip) || 1;
  23. const limit = Number.parseInt(data.limit) || 10;
  24. const total = await this.model.count(match);
  25. const res = await this.model.find(match).sort({'meta.createdAt':-1}).limit(limit).skip((skip - 1) * limit);
  26. const newres = {res,total};
  27. return newres;
  28. }
  29. //根据企业用户查询股权需求(列表)
  30. async getQystock(data){
  31. const{userid} = data;
  32. const match = {};
  33. match.userid = userid;
  34. match.status = '0';
  35. if(data.title){
  36. match.title = { $regex: data.title };
  37. }
  38. const skip = Number.parseInt(data.skip) || 1;
  39. const limit = Number.parseInt(data.limit) || 10;
  40. const total = await this.model.count(match);
  41. const res = await this.model.find(match).sort({'meta.createdAt':-1}).limit(limit).skip((skip - 1) * limit);
  42. const result = {total,res}
  43. return result;
  44. }
  45. //金融机构关注股权需求
  46. async getFollowStock(data){
  47. const { finceId, userid } = data;//债权需求ID,金融机构ID
  48. const newdata={};
  49. newdata.finceType = '1';
  50. newdata.finceId = finceId;
  51. newdata.userid = userid;
  52. newdata.orcredit = '0';
  53. newdata.credit_money = 0;
  54. newdata.accept_time = 0;
  55. newdata.credit_time = 0;
  56. const res = await this.followmodel.create(newdata);
  57. const qy = await this.model.findById(finceId);
  58. this.ctx.service.viewnews.insertViewNews("股权需求信息","您有新的股权需求被关注,请查看需求列表",qy.userid);
  59. return res;
  60. }
  61. //股权需求详情
  62. async getOne(data){
  63. const { id } = data;//股权需求ID
  64. const res = await this.model.aggregate([
  65. { $match: {_id:ObjectId(id)}},
  66. { $lookup: {
  67. from: 'dictionary',
  68. localField: 'rz_id',
  69. foreignField: 'code',
  70. as: 'rznew' } },
  71. { $unwind: '$rznew' },
  72. { $lookup: {
  73. from: 'profession',
  74. localField: 'work_id',
  75. foreignField: 'code',
  76. as: 'worknew' } },
  77. { $unwind: '$worknew' },
  78. { $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,
  79. rzname:'$rznew.name',workname:'$worknew.name'} }
  80. ]);
  81. return res;
  82. }
  83. }
  84. module.exports = StockNeedService;