financefollow.js 7.9 KB

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