12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- '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 LoanFollowService extends CrudService {
- constructor(ctx) {
- super(ctx, 'loanfollow');
- this.model = this.ctx.model.Loanfollow;
- }
- //授信接口
- async getCredit(data){
- const { id,money} = data;//id:贷款表id money:授信额度
- var now = new Date();
- var nowtime =now.getTime();//当前时间戳(授信时间)
- const financefollow = await this.model.findById(id);
- financefollow.orcredit = '1';
- financefollow.credit_money = parseInt(money);
- var creattime = new Date(financefollow.meta.createdAt).getTime();//创建时间时的时间戳
- let accept_time = parseInt(nowtime)-parseInt(creattime);//授理时间(授信时间-创建时间)
- financefollow.accept_time=parseInt(accept_time);
- financefollow.credit_time=parseInt(nowtime);
- const res = await financefollow.save();
- return res;
- }
- async getLoanfList(data){
- const match = {};
- console.log(JSON.stringify(data))
- match.jkid =data.jkid;
- if(data.orcredit){
- match.orcredit=data.orcredit;
- }
- 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.aggregate([
- { $match: match},
- { $project: { loanid: {$toObjectId: '$loanid'},savetime:'$meta.createdAt'}},
- { $lookup: {
- from: 'loan_pro',
- localField: 'loanid',
- foreignField: '_id',
- as: 'loanpronew' } },
- { $unwind: '$loanpronew' },
- { $skip: (skip - 1) * limit },
- { $limit: limit },
- { $sort : { savetime:-1 } }
- ]);
- const newres = {res,total};
- return newres;
- }
- async getLoanfOne(data){
- let loanfid = data.id;
- const res = await this.model.aggregate([
- { $match:{ _id: ObjectId(loanfid) } },
- { $project: { loanid: {$toObjectId: '$loanid'},savetime:'$meta.createdAt',credit_money:1,orcredit:1,qyid:1}},
- { $lookup: {
- from: 'loan_pro',
- localField: 'loanid',
- foreignField: '_id',
- as: 'loanpronew' } },
- { $unwind: '$loanpronew' },
- { $lookup: {
- from: 'company',
- localField: 'qyid',
- foreignField: 'uid',
- as: 'cnew' } },
- { $unwind: '$cnew' },
- { $sort : { savetime:-1 } }
- ]);
- return res;
- }
- async getBeforefollow(data){
- const res = await this.model.find({"loanid":data.loanid,"qyid":data.qyid})
- return res;
- }
- }
- module.exports = LoanFollowService;
|