123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- '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 FubabceClaimsService extends CrudService {
- constructor(ctx) {
- super(ctx, 'loan_pro');
- this.model = this.ctx.model.Loanpro;
- }
- // 贷款显示列表(后台)
- async getLoanproList(data) {
- const match = {};
- if (data.name) { // 产品名称
- match.name = { $regex: data.name };
- }
- match.status = '0';
- match.jkid =data.jkid;
- 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).limit(limit).skip((skip - 1) * limit);
- const newres = {res,total};
- return newres;
- }
- async getLoanproListView(data){//={ $gt : 70, $lte : data.claimterm }
- const match = {};
- const finalsort = {};
- if(data.claimterm){//融资期限
- let finalclaimterm = Number.parseInt(data.claimterm);
- if(finalclaimterm>12){
- match.claims_max_term ={$gt :12};
- }else{
- match.claims_max_term ={$lte :finalclaimterm};
- }
- }
- if(data.claimmoney){//融资额度
- let finalclaimmoney = Number.parseInt(data.claimmoney);
- if(finalclaimmoney>1000){
- match.claims_max_money ={$gt :1000};
- }else{
- match.claims_min_money ={$lte :finalclaimmoney};//moneymatch = {$or: [ { $gt: [ "$claims_min_money", finalclaimmoney] }, { $lte: [ "$claims_max_money", finalclaimmoney] } ]}
- }
- }
- if(data.ecode){//担保方式CODE
- match.ensure_id = data.ecode;//match = {$or: [ { $eq: [ "$ensure_id", data.ecode ] }, { $eq: [ "$ensure_id", '不限的CODE' ] } ]}
- }
- if(data.rcode){//还款方式CODE
- match.repayment_id = data.rcode;
- }
- if(data.name){//标题
- match.name = { $regex:data.name};
- }
-
- let flag=false;
- if(data.mrate){//最低利率
- finalsort.claims_min_term=1;
- flag=true;
- }
- if(data.time){
- finalsort["loanfollow.accept_time"] = -1;
- flag=true;
- }
- if(!flag){
- finalsort.createtime= -1;
- }
-
- match.status = '0';
- const skip = Number.parseInt(data.skip) || 1;
- const limit = Number.parseInt(data.limit) || 10;
- let totalres=[];
- let res={};
- let total=0
- if(data.time){
- res = await this.model.aggregate([
- { $match: match},
- { $project: { id: {$toString: '$_id'},name:1,mongey_min_rate:1,mongey_max_rate:1,claims_min_term:1,
- claims_max_term:1,ensure_id:1,repayment_id:1,claims_min_money:1,claims_max_money:1,createtime:'$meta.createdAt'}},
- { $lookup: {
- from: 'loanfollow',
- localField: 'id',
- foreignField: 'loanid',
- as: 'loanfollow' } },
- { $unwind: '$loanfollow' },
- { $lookup: {
- from: 'dictionary',
- localField: 'ensure_id',
- foreignField: 'code',
- as: 'enew' } },
- { $unwind: '$enew' },
- { $lookup: {
- from: 'dictionary',
- localField: 'repayment_id',
- foreignField: 'code',
- as: 'rnew' } },
- { $unwind: '$rnew' },
- { $skip: (skip - 1) * limit },
- { $limit: limit },
- { $sort :finalsort}
- ]);
- totalres=await this.model.aggregate([
- { $match: match},
- { $project: { id: {$toString: '$_id'},name:1,mongey_min_rate:1,mongey_max_rate:1,claims_min_term:1,
- claims_max_term:1,ensure_id:1,repayment_id:1,claims_min_money:1,claims_max_money:1,createtime:'$meta.createdAt'}},
- { $lookup: {
- from: 'loanfollow',
- localField: 'id',
- foreignField: 'loanid',
- as: 'loanfollow' } },
- { $unwind: '$loanfollow' },
- { $lookup: {
- from: 'dictionary',
- localField: 'ensure_id',
- foreignField: 'code',
- as: 'enew' } },
- { $unwind: '$enew' },
- { $lookup: {
- from: 'dictionary',
- localField: 'repayment_id',
- foreignField: 'code',
- as: 'rnew' } },
- { $unwind: '$rnew' },
- { $count:'total'}
- ]);
- }else{
- res = await this.model.aggregate([
- { $match: match},
- { $project: { id: {$toString: '$_id'},name:1,mongey_min_rate:1,mongey_max_rate:1,claims_min_term:1,
- claims_max_term:1,ensure_id:1,repayment_id:1,claims_min_money:1,claims_max_money:1,createtime:'$meta.createdAt'}},
- { $lookup: {
- from: 'dictionary',
- localField: 'ensure_id',
- foreignField: 'code',
- as: 'enew' } },
- { $unwind: '$enew' },
- { $lookup: {
- from: 'dictionary',
- localField: 'repayment_id',
- foreignField: 'code',
- as: 'rnew' } },
- { $unwind: '$rnew' },
- { $skip: (skip - 1) * limit },
- { $limit: limit },
- { $sort :finalsort}
- ]);
- totalres=await this.model.aggregate([
- { $match: match},
- { $project: { id: {$toString: '$_id'},name:1,mongey_min_rate:1,mongey_max_rate:1,claims_min_term:1,
- claims_max_term:1,ensure_id:1,repayment_id:1,claims_min_money:1,claims_max_money:1,createtime:'$meta.createdAt'}},
- { $lookup: {
- from: 'dictionary',
- localField: 'ensure_id',
- foreignField: 'code',
- as: 'enew' } },
- { $unwind: '$enew' },
- { $lookup: {
- from: 'dictionary',
- localField: 'repayment_id',
- foreignField: 'code',
- as: 'rnew' } },
- { $unwind: '$rnew' },
- { $count:'total'}
- ]);
- }
- if(totalres.length>0){
- total= totalres[0].total;
- }
- const newres = {res,total};
- return newres;
- }
-
-
- }
- module.exports = FubabceClaimsService;
|