financefollow.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 FinanceFollowService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 't_finance_follow');
  10. this.model = this.ctx.model.Financefollow;
  11. }
  12. //授信接口
  13. async getCredit(data){
  14. const { id,money,orcredit,senhemessage,jindiaomessage,sxcpname,sxhowlong,sxcplilue} = data;//id:关注ID money:授信额度
  15. var now = new Date();
  16. var nowtime =now.getTime();//当前时间戳(授信时间)
  17. const financefollow = await this.model.findById(id);
  18. if(senhemessage){
  19. financefollow.senhemessage = senhemessage;
  20. }
  21. if(jindiaomessage){
  22. financefollow.jindiaomessage = jindiaomessage;
  23. }
  24. if(sxcpname){
  25. financefollow.sxcpname = sxcpname;
  26. }
  27. if(sxhowlong){
  28. financefollow.sxhowlong = sxhowlong;
  29. }
  30. if(sxcplilue){
  31. financefollow.sxcplilue = sxcplilue;
  32. }
  33. financefollow.orcredit = orcredit;
  34. if(money){
  35. financefollow.credit_money = parseInt(money);
  36. }
  37. var creattime = new Date(financefollow.meta.createdAt).getTime();//创建时间时的时间戳
  38. let accept_time = parseInt(nowtime)-parseInt(creattime);//授理时间(授信时间-创建时间)
  39. financefollow.accept_time=parseInt(accept_time);
  40. financefollow.credit_time=parseInt(nowtime);
  41. const res = await financefollow.save();
  42. return res;
  43. }
  44. //授信关注债权列表
  45. async getFollowList(data){
  46. const match = {};
  47. if (data.userid) {//金融机构ID
  48. match.uuid =data.userid;
  49. }
  50. if (data.finceType) {//债权和股权
  51. match.finceType =data.finceType;
  52. }
  53. if(data.finalorc){
  54. match.orcredit = data.finalorc;
  55. }
  56. // else{
  57. // match.orcredit={ $ne: '1' };
  58. // }
  59. const skip = Number.parseInt(data.skip) || 1;
  60. const limit = Number.parseInt(data.limit) || 10;
  61. const total = await this.model.count(match);
  62. const res = await this.model.aggregate([
  63. { $match: match},
  64. { $project: { finceId: {$toObjectId: '$finceId'},savetime:'$meta.createdAt',orcredit:1}},
  65. { $lookup: {
  66. from: 'claim_need',
  67. localField: 'finceId',
  68. foreignField: '_id',
  69. as: 'clamnew' } },
  70. { $unwind: '$clamnew' },
  71. { $lookup: {
  72. from: 'company_identify',
  73. localField: 'clamnew.userid',
  74. foreignField: 'uid',
  75. as: 'comnew' } },
  76. { $unwind: '$comnew' },
  77. { $project: {clamnew:1,finceId:1,savetime:1,orcredit:1,_id:1,comnewname:'$comnew.company_name'}},
  78. { $skip: (skip - 1) * limit },
  79. { $limit: limit },
  80. { $sort : { savetime:-1 } }
  81. ]);
  82. const newres = {res,total};
  83. return newres;
  84. }
  85. //授信关注股权列表
  86. async getFollowstock(data){
  87. const match = {};
  88. if (data.userid) {//金融机构ID
  89. match.userid =data.userid;
  90. }
  91. if (data.finceType) {//债权和股权
  92. match.finceType =data.finceType;
  93. }
  94. const skip = Number.parseInt(data.skip) || 1;
  95. const limit = Number.parseInt(data.limit) || 10;
  96. const total = await this.model.count(match);
  97. const res = await this.model.aggregate([
  98. { $match: match},
  99. { $project: { finceId: {$toObjectId: '$finceId'},savetime:'$meta.createdAt'}},
  100. { $lookup: {
  101. from: 'stock_need',
  102. localField: 'finceId',
  103. foreignField: '_id',
  104. as: 'stockmnew' } },
  105. { $unwind: '$stockmnew' },
  106. { $skip: (skip - 1) * limit },
  107. { $limit: limit },
  108. { $sort : { savetime:-1 } }
  109. ]);
  110. const newres = {res,total};
  111. return newres;
  112. }
  113. //授信债权历史列表
  114. async getFollowClaimHistory(data){
  115. const match = {};
  116. if (data.userid) {//金融机构ID
  117. match.userid =data.userid;
  118. }else if(data.userid){
  119. match.uuid =data.uid;
  120. }
  121. match.finceType ='0';
  122. match.orcredit='1';
  123. const skip = Number.parseInt(data.skip) || 1;
  124. const limit = Number.parseInt(data.limit) || 10;
  125. const total = await this.model.count(match);
  126. const res = await this.model.aggregate([
  127. { $match: match},
  128. { $project: { finceId: {$toObjectId: '$finceId'},savetime:'$meta.createdAt',credit_money:1,credit_time:1}},
  129. { $lookup: {
  130. from: 'claim_need',
  131. localField: 'finceId',
  132. foreignField: '_id',
  133. as: 'clamnew' } },
  134. { $unwind: '$clamnew' },
  135. { $skip: (skip - 1) * limit },
  136. { $limit: limit },
  137. { $sort : { savetime:-1 } }
  138. ]);
  139. const newres = {res,total};
  140. return newres;
  141. }
  142. //首页对接成功列表(详情)
  143. async getFirstsuccess(data){
  144. const match = {};
  145. if (data.finid) {//列表ID
  146. match._id =ObjectId(data.finid);
  147. }
  148. match.finceType ='0';
  149. match.orcredit='1';
  150. const skip = Number.parseInt(data.skip) || 1;
  151. const limit = Number.parseInt(data.limit) || 10;
  152. const total = await this.model.count(match);
  153. const res = await this.model.aggregate([
  154. { $match: match},
  155. { $project: { finceId: {$toObjectId: '$finceId'},userid:{$toObjectId: '$userid'},savetime:'$meta.createdAt',credit_money:1,credit_time:1}},
  156. { $lookup: {
  157. from: 'claim_need',
  158. localField: 'finceId',
  159. foreignField: '_id',
  160. as: 'clamnew' } },
  161. { $unwind: '$clamnew' },
  162. { $lookup: {
  163. from: 'institution',
  164. localField: 'userid',
  165. foreignField: '_id',
  166. as: 'jgnew' } },
  167. { $unwind: '$jgnew' },
  168. { $project: { finceId: {$toObjectId: '$finceId'},userid:{$toObjectId: '$userid'},qyid:{$toObjectId: '$clamnew.userid'},jgname:'$jgnew.name'}},
  169. { $lookup: {
  170. from: 'company_user',
  171. localField: 'qyid',
  172. foreignField: '_id',
  173. as: 'qynew' } },
  174. { $unwind: '$qynew' },
  175. { $skip: 0 },
  176. { $limit: 3 },
  177. { $sort : { savetime:-1 } }
  178. ]);
  179. const newres = {res,total};
  180. return newres;
  181. }
  182. async getFinceNews(data){
  183. const res = await this.model.aggregate([
  184. { $match: {finceId:data.finceId}},
  185. { $project: { userid: {$toObjectId: '$userid'},credit_money:1,meta:1,credit_time:1,orcredit:1}},
  186. { $lookup: {
  187. from: 'institution',
  188. localField: 'userid',
  189. foreignField: '_id',
  190. as: 'innew' } },
  191. { $unwind: '$innew' },
  192. { $skip: 0 },
  193. { $limit: 2 },
  194. { $sort : { orcredit:-1 } }
  195. ]);//.findOne({finceId:data.finceId});
  196. return res;
  197. }
  198. async getThreenews(){
  199. const res = await this.model.aggregate([
  200. { $match: {'orcredit':'1'}},
  201. { $project: { xqId: {$toObjectId: '$finceId'},jgId: {$toObjectId: '$userid'}}},
  202. { $lookup: {
  203. from: 'claim_need',
  204. localField: 'xqId',
  205. foreignField: '_id',
  206. as: 'clamnew' } },
  207. { $unwind: '$clamnew' },
  208. { $lookup: {
  209. from: 'institution',
  210. localField: 'jgId',
  211. foreignField: '_id',
  212. as: 'jgnew' } },
  213. { $unwind: '$jgnew' },
  214. { $project: { qyId: {$toObjectId: '$clamnew.userid'},jgname:'$jgnew.name'}},
  215. { $lookup: {
  216. from: 'company_user',
  217. localField: 'qyId',
  218. foreignField: '_id',
  219. as: 'qynew' } },
  220. { $unwind: '$qynew' },
  221. { $project: { qyname: '$qynew.company_name',jgname:1}},
  222. { $skip: 0},
  223. { $limit: 3 }
  224. ]);
  225. return res;
  226. }
  227. }
  228. module.exports = FinanceFollowService;